eslint-config
MOXY eslint configuration to be used across several JavaScript projects.
Installation
$ npm install --save-dev eslint eslint-config-moxy
NOTE: npm
v3 or greater is required for this package to work correctly until #3458 is resolved - this means that you must run node
v6 or greater.
Usage
Create a .eslintrc.json
file in the project root using a base configuration and addons.
First you need to choose the base configuration to use:
es5
- The configuration to be used in ECMAScript 5 based projectses6
- The configuration to be used in ECMAScript 6 based projects (aka 2015)es7
- The configuration to be used in ECMAScript 7 based projects (aka 2016)es8
- The configuration to be used in ECMAScript 8 based projects (aka 2017)es9
- The configuration to be used in ECMAScript 9 based projects (aka 2018)
Then enhance it with one or more addons:
browser
- If you are going to develop code for the browser (assumes you use CommonJS or AMD)node
- If you are going to develop code for NodeJSes6-modules
: If you are going to use ES6 import & export instead of CommonJS or AMDobject-spread
: Allows to use object rest spread when destructuring objects (not necessary if you are using the es9
base configuration)babel-parser
: Use babel-eslint parser so that you may use language features that are not yet implemented in eslint (e.g.: dynamic imports)react
- If you are going to use React (requires es6
base configuration or higher)jest
- If you are going to use Jest to develop tests
Examples
Cutting edge react in the browser:
{
"root": true,
"extends": [
"eslint-config-moxy/es8",
"eslint-config-moxy/addons/browser",
"eslint-config-moxy/addons/es6-modules",
"eslint-config-moxy/addons/react"
]
}
ES6 with modules in NodeJS (requires a transpiler such as Babel or similar):
{
"root": true,
"extends": [
"eslint-config-moxy/es6",
"eslint-config-moxy/addons/node",
"eslint-config-moxy/addons/es6-modules"
]
}
Use ES6 in NodeJS without any transpiler:
{
"root": true,
"extends": [
"eslint-config-moxy/es6",
"eslint-config-moxy/addons/node"
]
}
Old ES5 in the browser:
{
"root": true,
"extends": [
"eslint-config-moxy/es5",
"eslint-config-moxy/addons/browser"
]
}
Note that by setting root
to true, we ensure that no ancestor configuration is used which also improves ESLint
performance because no more file lookups need to be done.
File naming convention
If your file exports a single class, your filename should be exactly the name of the class. For other cases, the name of the file should be the same as the default exports. If the file doesn't have a default export, the name can be in kebab-case
(e.g.: some-file.js
).
Tests
$ npm test
$ npm test -- --watch
during development
License
MIT License