gatsby-plugin-eslint
Adds ESLint to your Gatsby dev environment, maintaining code quality as you develop.
NOTE: Plugin has different installation and usage instructions to support both Gatsby V1 and V2.
Install
Gatsby V2 Instructions
-
Install the
gatsby-plugin-eslintplugin:npm install --save-dev gatsby-plugin-eslintor
yarn add --dev gatsby-plugin-eslint -
Install ESLint and
eslint-loader:npm install --save-dev eslint eslint-loaderor
yarn add --dev eslint eslint-loader
Gatsby V1 Instructions
-
Install the
gatsby-plugin-eslintplugin:npm install --save-dev gatsby-plugin-eslint@^1.0.3or
yarn add --dev gatsby-plugin-eslint@^1.0.3 -
Install ESLint and
eslint-loader:npm install --save-dev eslint eslint-loaderor
yarn add --dev eslint eslint-loader
Usage
- Create a
.eslintrcfile in your project root. Otherwise ESLint will complain. - Add into
gatsby-config.js.
// gatsby-config.js
module.exports = {
plugins: [
'gatsby-plugin-eslint'
]
}If no options are specified, the plugin defaults to:
- Lint
.jsand.jsxfiles. - Exclude
node_modules,.cache, andpublicfolders from linting. Refrain from naming your project these folder names, otherwise make your own config option exclusions. - Only lints in development in the
'develop'stage. You may enable linting during other build/dev stages by adding any Webpack Config Stage into thestagesarray. For example, adding'build-javascript'into thestagesarray will enable linting during JS build time. - Default ESLint-Loader options.
You can specify your own linting filetypes, exclusions, and ESLint-Loader options:
// gatsby-config.js
module.exports = {
plugins: [
{
resolve: 'gatsby-plugin-eslint',
options: {
test: /\.js$|\.jsx$/,
exclude: /(node_modules|.cache|public)/,
stages: ['develop'],
options: {
emitWarning: true,
failOnError: false
}
}
}
]
}Configuring ESLint
You’re free to install your own ESLint plugins and rules. Here are 2 easy ways to start linting:
Basic eslint-plugin-react Linting
-
Follow
eslint-plugin-reactplugin installation procedures:npm install --save-dev babel-eslint eslint-plugin-import eslint-plugin-reactor
yarn add --dev babel-eslint eslint-plugin-import eslint-plugin-react -
Add
.eslintrcfile to project root:{ "parser": "babel-eslint", "rules": { "strict": 0 }, "extends": [ "eslint:recommended", "plugin:react/recommended" ] }
AirBnB’s eslint-config-airbnb Linting
-
Follow
eslint-config-airbnbplugin installation procedures:npm install --save-dev eslint-config-airbnb eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-reactor
yarn add --dev eslint-config-airbnb eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-react -
Add
.eslintrcfile to project root:{ "extends": "airbnb" }