Disabling Rules with Inline Comments
// eslint-disable-next-line no-alert
alert('foo');
// eslint-disable-line
as formatter like prettier
will move them to a separate line.
/* eslint-disable no-alert */
alert('doing awful things');
/* eslint-enable no-alert */
/* eslint-disable */
…
/* eslint-enable */
// eslint-disable-next-line
Separate them with ,
(comma)
/* eslint-disable no-alert, no-console */
…
/* eslint-enable */
// eslint-disable-next-line no-alert, no-console
You can do that at several levels: file, globally or per directory.
For the common use-cases you can leverage the env
property to setup an environment that defines global variables.
/* global loginUser, logmatic */
or
/* eslint-env node, browser, jquery */
Edit your configuration file to add a globals
object where each key is a global variable we want to use:
{
globals: {
loginUser: true,
logmatic: true
}
}
or add a env
object where each key is a predefined preset of globals:
{
env : {
node: true,
jquery: true,
browser: true,
}
}
Create a .eslintrc.js
file in the targeted directory.
module.exports = {
globals: {
logmatic: true,
}
};
Core configuration, currently design for
ES6
. All others configurations extend this one.
- file: core.js
- usage: not directly, refer to Default Configuration
Default configuration, extends
eslint:recommended
andcore.js
.
-
usage:
extends: [ 'peopledoc' ]
-
file: index.js
For Ember project, extends
eslint:recommended
,ember/recommended
andcore.js
.
-
usage:
extends: [ 'peopledoc/ember' ]
-
file: ember.js
For legacy projects using
ES5
andjquery
, it disablesES2015
andES2016
feature based ones5
-
usage:
extends: [ 'peopledoc/es5' ]
-
file: es5.js
-
targeted environment: browser
Let's assume you want to create a new preset for ES8
.
- First, write documentation of your preset in the README.md ;
- Next, create a new file at the root of the project
es8.js
; - Then add a basic configuration that extends at least
eslint:recommended
:
module.exports = {
extends: [ 'eslint:recommended' ]
};
- Be sure to update the package.json
files
property in order to make it available duringnpm install
:
"files": [
"core.js",
…
+ "es8.js"
]
-
Create a pull request es8;
-
Try to install your PR on a project:
npm install --save-dev peopledoc/eslint-config-peopledoc
Specify the version of ECMAScript syntax you want to use.
-
what to use:
parserOptions.ecmaVersion
-
example: for
ES6
syntax, use{ parserOptions: { ecmaVersion: 6 } }
This will declare globals variable and other options.
-
what to use:
env
-
values:
es6
,browser
,node
, much more -
dive in: environments.js and globals.
-
example: for new ES6 global variables, use
{ "env": { "es6": true } }
Plugins can expose additional rules and environments
-
what to use:
plugins
-
dive in: Working with Plugins
-
example: use
eslint-plugin-es5
to forbidES2015
andES2016
in ourES5
config:plugins: ['es5'], extends: [ 'eslint:recommended', 'plugin:es5/no-es2015', 'plugin:es5/no-es2016' ],