Skip to content

JavaScript

Code styling

We combine a set of EsLint rules (to avoid errors, ensure security and best practices) with Prettier (to enforce a certain style).

Setup

Install dependencies:

bash
npm i -D eslint prettier eslint-config-prettier eslint-plugin-prettier @liip-lausanne/eslint-config
npm i -D eslint prettier eslint-config-prettier eslint-plugin-prettier @liip-lausanne/eslint-config

NOTICE

We prefer JavaScript configuration files over JSON so we can add comments and logic if necessary.

Create an EsLint config file named .eslintrc.js at the project root with:

js
module.exports = {
  env: {
    browser: true,
    es2021: true,
  },
  extends: ['@liip-lausanne', 'prettier'],
  parserOptions: {
    ecmaVersion: 2021,
    sourceType: 'module',
  },
};
module.exports = {
  env: {
    browser: true,
    es2021: true,
  },
  extends: ['@liip-lausanne', 'prettier'],
  parserOptions: {
    ecmaVersion: 2021,
    sourceType: 'module',
  },
};

Create a Prettier config file named prettier.config.js at the project root with:

js
module.exports = {
  singleQuote: true,
  trailingComma: 'es5',
};
module.exports = {
  singleQuote: true,
  trailingComma: 'es5',
};

Add some scripts in your package.json to validate/format files:

json
// ...
"scripts": {
  // ...
  "eslint": "eslint .",
  "eslint:fix": "npm run eslint -- --fix",
  // ...
}
// ...
// ...
"scripts": {
  // ...
  "eslint": "eslint .",
  "eslint:fix": "npm run eslint -- --fix",
  // ...
}
// ...

See scripts for conventions.

Testing

We prefer Vitest or Jest to run unit & functional tests and Cypress for end-to-end tests.

We enjoy msw to mock asynchronous requests.

Third-parties

Our go-to framework is Vue.js, with its friends Pinia (or Vuex on legacy projects) and/or Vue Router if necessary. In the case of a SPA, we use Create Vue to scaffold the project.

Libraries we often use accross projects: