Skip to content

Latest commit

 

History

History
65 lines (45 loc) · 2.42 KB

migration-from-4-to-5.md

File metadata and controls

65 lines (45 loc) · 2.42 KB

Migration Guide from v4.x to v5.x

The change from v4 to v5 includes two main items:

  • Adding Prettier as code formatter.
  • Moving the peerDependencies into dependencies to simplify the usage.

Moving peerDependencies into dependencies

eslint-config-skyscanner used to require a few devDependencies that had to be installed manually. When upgrading to v5, all these dependencies can be removed from the project (unless used explicitly):

  • babel-eslint
  • eslint
  • eslint-config-airbnb
  • eslint-plugin-eslint-comments
  • eslint-plugin-import
  • eslint-plugin-jest
  • eslint-plugin-jsx-a11y
  • eslint-plugin-react
  • eslint-plugin-backpack
  • eslint-plugin-skyscanner-dates

Once the dependencies have been removed and eslint-config-skyscanner updated, it's recommended to run npm dedupe and npm prune to clean up package-lock.json.

Using Prettier

Prettier is an opinionated code formatter, with few configuration options. When installing eslint-config-skyscanner, the file .prettierrc is automatically generated with the default configuration.

Prettier is able to fix many of the issues that reports, so after installing v5, eslint must be executed with the --fix flag to format the code according to the new rules.

Pre-commit hook integration

It's possible to add a pre-commit hook that automatically fixes code formatting issues when committing using husky and lint-staged. The source code of this repo can be used as a reference for this configuration.

Editor integration

Many editors allow running eslint fix on save.

Testing framework

Jest is the standard testing framework defined by eslint-config-skyscanner, and it includes eslint-plugin-jest, a plugin that enforces good testing practices with Jest.

In case of using a different testing framework, the rules defined in eslint-plugin-jest/recommended can be disabled to prevent false errors being reported.

Edit .eslintrc file to disable (globally) the needed rules, e.g.:

"rules": {
  "jest/valid-expect": "off"
}

The rules can also be disabled per file/folder:

"overrides": [{
  "files": ["test/**/*.test.js"],
  "rules": {
    "jest/valid-expect": "off"
  }
}]