@gpa-lab/eslint-config
v1.6.1
Published
An ESLint configuration conforming to the GPA/LAB style guide
Downloads
36
Readme
GPA/LAB ESLint Config
This package provides an opinionated but extensible ESLint configuration that enforces the JavaScript coding preferences defined by the GPA/LAB style guide.
Installation
Run the following command from the root of your project to install the config.
npm install @gpa-lab/eslint-config --save-dev
There are a number of peer dependencies listened for this project. Namely:
- eslint - Required
- eslint-plugin-cypress - Required for Cypress
- eslint-plugin-import - Required
- eslint-plugin-jest - Required
- eslint-plugin-jsx-a11y - Required for React
- eslint-plugin-node - Required
- eslint-plugin-react - Required for React
- eslint-plugin-react-hooks - Required for React
Please note that several of these peer dependencies pertain only to the optional React and Cypress configurations available as sub-packages (see more details below).
To install the minimum dependencies required for the base configuration run the command:
npm i -D @gpa-lab/eslint-config eslint eslint-plugin-import eslint-plugin-jest eslint-plugin-node
If you intend to also use the React sub-package, run the following install the React-specific plugins as well:
npm i -D @gpa-lab/eslint-config eslint eslint-plugin-import eslint-plugin-jest eslint-plugin-jsx-a11y eslint-plugin-node eslint-plugin-react eslint-plugin-react-hooks
Usage
Basic
Once installed, add an .eslintrc
file to your project root and extend the GPA/LAB eslint-config as such:
{
"extends": ["@gpa-lab/eslint-config"]
}
This will apply the base ruleset to your project.
Note: More details on configuring ESLint for you project can be found in ESLint's official documentation.
Sub-packages
React
This optional package includes an additional set of rules pertaining to React applications. To enable the React sub-package, add @gpa-lab/eslint-config/react
to the extends array as such:
{
"extends": ["@gpa-lab/eslint-config", "@gpa-lab/eslint-config/react"]
}
The React sub-package depends on some ESLint plugins not needed by the base configuration. If you did not install them during the initial setup, you will need to run the following command to install these required peer dependencies.
npm i -D eslint-plugin-jsx-a11y eslint-plugin-react eslint-plugin-react-hooks
CommonJS Scripts
The default configuration supports Node.js out of the box, however, it assumes that ES6 modules are supported. This configuration can be used when ES6 import syntax is not desired.
{
"extends": ["@gpa-lab/eslint-config/script"]
}
Cypress
This optional package extends the base ESLint rules from this package, adding a ruleset for the Cypress end-to-end testing tool and removing the Jest ruleset (which can conflict with Cypress rules). As such, it should be used in lieu of, rather than in addition to the base configuration. We recommend putting a distinct .eslintrc
in the cypress
directory and setting it to root so that it does not conflict with your project-wide .eslintrc
. The result should look something like:
{
"extends": ["@gpa-lab/eslint-config/cypress"],
"root": true
}
The Cypress sub-package depends on the Cypress ESLint plugin which can be installed by running the following command:
npm i -D eslint-plugin-cypress