Configuring ESLint

The ScandiPWA out of the box comes with a very strict linter. It is here to ensure the quality and consistency of the code between projects. In some cases, the configured defaults might seem too strict, this guide is here to help developers configure to match their needs.

Some rules are our preference, some are "essential" to make sure the code you are writing is compatible with ScandiPWA's plugin architecture. The list of such rules can be found below.

Essential rules

All scandipwa specific rules can be found in @scandipwa/eslint-plugin-scandipwa-guidelines NPM package. To use it in your ESLint configuration, add the following fields to your declaration:

{
"plugins": [
"@scandipwa/scandipwa-guidelines"
],
"rules": {
// Force @namespace comments in the code
"@scandipwa/scandipwa-guidelines/use-namespace": "error",
// Use "__construct" instead of "constructor"
"@scandipwa/scandipwa-guidelines/use-magic-construct": "error",
}
}

How to disable ESLint

By default, ESLint is always enabled and check on every compilation. This ensures the quality of code before committing it (otherwise if checked on commit, the changes made are commonly not checked by the developer on a working site).

To disable the ESLint, the following configuration must be added to the ScandiPWA theme's package.json file:

{
...
"eslintConfig": {
"extends": "@scandipwa",
"ignorePatterns": ["src/**"]
},
...
}

Learn more about ignorePatterns in official ESLint docs.

How to change ESlint configurations

You have two main options to change (learn about more options in the official ESLint guide):

  • Extend a completely different preset

  • Add "overrides" to default configuration values

To change any of these, the ScandiPWA theme's package.json file's eslintConfig fields. For example:

{
...
"eslintConfig": {
"extends": [
"react-app"
],
"overrides": [
"react/jsx-props-no-spreading": "off"
]
}
...
}