JavaScript and TypeScript ========================= .. note:: Don't use `CoffeeScript `__. Unless the repository is a fork, use `Decaffeinate `__ to convert CoffeeScript to ECMAScript. .. _javascript-license: License ------- Use the `MIT license `__. Version ------- ECMAScript ~~~~~~~~~~ Frontend code is written for ECMAScript 6 (ES6) (`see the status of feature support in modern browsers `__). We don't support `Internet Explorer 11 `__. .. tip:: To transform older code to ECMAScript 6, use `lebab `__, but be aware of its `bugs `__. There is a lebab `plugin `__ for `Sublime Text `__. Use these preferences (*Preferences* > *Package Settings* > *Lebab* > *Settings - User*): .. code-block:: json { "transforms": [ "arrow", "arrow-return", "let", "for-of", "for-each", "arg-rest", "arg-spread", "obj-method", "obj-shorthand", "no-strict", "exponent", "class", "commonjs", "template", "default-param", "includes" ] } To transform newer code to ECMAScript 6, use `Babel `__ with the `defaults `__ query from `browserlist `__. Node ~~~~ Applications are written for the latest LTS version of Node. Packages are written for non-end-of-life versions (`see the status of Node versions `__). To upgrade Node, change the ``node-version`` key in GitHub Actions workflows and the ``node`` (or ``nikolaik/python-nodejs``) image in Dockerfiles. Check the relevant `changelog `__ for breaking changes. .. _javascript-preferences: Preferences ----------- Plain JavaScript is preferred to using jQuery, unless functionality depends on jQuery plugins. To replace jQuery in a project, refer to `You Might Not Need jQuery `__. Similarly, use the `Fetch `__ API instead of the `Axios `__ package, etc. Package manager `npm `__, the default package manager of Node.js. Do not use `yarn `__. Yarn has no equivalent to ``npm audit fix``. User interface `Vue `__ is preferred to `React `__. That said, do not use frameworks for simple interfaces. Asset management `webpack `__, unless a framework provides its own, like `Vue `__. Sass `sass `__ (dart-sass). Do not use `node-sass `__, which is deprecated. Formatter `Biome `__. Requirements ------------ Use `npm `__, not ``yarn``. Set the Node version in ``package.json``, `as documented `__. List outdated dependencies: .. code-block:: bash npm outdated Upgrade outdated dependencies: .. code-block:: bash npm update Upgrade Vue dependencies: .. code-block:: bash vue upgrade --next Vulnerabilities ~~~~~~~~~~~~~~~ .. admonition:: Dependabot alerts If the Dependabot alert is for a build dependency (like ``node-sass``) or a test dependency (like ``mocha``), you can dismiss it with "Risk is tolerable for this project". The npm ecosystem has `false positives `__. To check for vulnerable dependencies: .. code-block:: bash npm audit --production .. note:: ``npm audit`` (without ``--production``) has `false positives `__ (`Vue example `__). To upgrade vulnerable dependencies: #. Check the version of Node: .. code-block:: bash node --version #. Upgrade npm: .. code-block:: bash npm install -g npm@latest #. Run: .. code-block:: bash npm audit fix #. Manually update version numbers in ``package.json``: #. Find a "fix available" line #. Read its following line ("Will install @") #. Check the package's changelog for changes between the two versions #. Update ``package.json``, and repeat Code style ---------- package.json ~~~~~~~~~~~~ - Do not set the `scripts `__ property. Instead, document the full commands in the readme, to reduce indirection and obfuscation. Vue ~~~ - When navigating between "pages", respect native browser behaviors (open in new tab, etc.) by using an ```` link or ````. Internationalization (i18n) --------------------------- See the `Transifex Native `__ documentation for your framework. .. _javascript-ci: Continuous integration ---------------------- Create a ``.github/workflows/js.yml`` file. As a base, use: .. literalinclude:: samples/js.yml :language: yaml .. tip:: In most cases, you can reuse the `js `__ workflow. For example: .. code-block:: yaml jobs: lint: uses: open-contracting/.github/.github/workflows/js.yml@main with: filenames: path/to/file.js Reference --------- - `MDN Web Docs `__ - `Can I use... `__