Skip to content

Commit 4369c7c

Browse files
committed
Use a custom eslint rule list
1 parent b8a2b98 commit 4369c7c

File tree

9 files changed

+328
-27
lines changed

9 files changed

+328
-27
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Currently it is a thin layer on top of many amazing community projects, such as:
8686
* [webpack](https://webpack.github.io/) with [webpack-dev-server](https://github.com/webpack/webpack-dev-server), [html-webpack-plugin](https://github.com/ampedandwired/html-webpack-plugin) and [style-loader](https://github.com/webpack/style-loader)
8787
* [Babel](http://babeljs.io/) with [preset-es2015](https://www.npmjs.com/package/babel-preset-es2015), [preset-es2016](https://www.npmjs.com/package/babel-preset-es2016), [preset-react](https://www.npmjs.com/package/babel-preset-react) and [transform-rest-spread](https://babeljs.io/docs/plugins/transform-object-rest-spread/)
8888
* [Autoprefixer](https://github.com/postcss/autoprefixer)
89-
* [ESLint](http://eslint.org/) with [eslint-config-airbnb](https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb)
89+
* [ESLint](http://eslint.org/)
9090
* and more.
9191

9292
All of them are transient dependencies of the provided npm package.

config/.eslintrc

Lines changed: 0 additions & 3 deletions
This file was deleted.

config/babel.dev.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
module.exports = {
11+
cacheDirectory: true,
12+
presets: ['es2015', 'es2016', 'react'],
13+
plugins: ['transform-object-rest-spread']
14+
};

config/babel.prod.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
module.exports = {
11+
presets: ['es2015', 'es2016', 'react'],
12+
plugins: [
13+
'transform-object-rest-spread',
14+
'transform-react-constant-elements'
15+
]
16+
};

config/eslint.js

Lines changed: 280 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,280 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
// Inspired by https://github.com/airbnb/javascript but less opinionated.
11+
12+
var OFF = 0; // rules that split the community (e.g. semicolons)
13+
var WARNING = 1; // style rules accepted by the majority of popular styleguides
14+
var ERROR = 2; // rules that prevent common mistakes
15+
16+
module.exports = {
17+
root: true,
18+
19+
plugins: ['react', 'import'],
20+
21+
env: {
22+
es6: true,
23+
commonjs: true,
24+
browser: true
25+
},
26+
27+
parserOptions: {
28+
ecmaVersion: 6,
29+
sourceType: 'module',
30+
ecmaFeatures: {
31+
jsx: true,
32+
generators: true,
33+
experimentalObjectRestSpread: true
34+
}
35+
},
36+
37+
settings: {
38+
'import/resolver': {
39+
node: {
40+
extensions: ['.js', '.json']
41+
}
42+
},
43+
'import/extensions': ['.js'],
44+
'import/ignore': [
45+
'node_modules',
46+
'\\.(json|css|jpg|png|gif|svg|eot|svg|ttf|woff|woff2|mp4|webm)$',
47+
]
48+
},
49+
50+
rules: {
51+
52+
// http://eslint.org/docs/rules/
53+
54+
'array-callback-return': ERROR,
55+
'block-scoped-var': WARNING,
56+
curly: [WARNING, 'multi-line'],
57+
'default-case': [ERROR, { commentPattern: '^no default$' }],
58+
'dot-notation': [WARNING, { allowKeywords: true }],
59+
'dot-location': [ERROR, 'property'],
60+
eqeqeq: [ERROR, 'allow-null'],
61+
'guard-for-in': ERROR,
62+
'no-caller': ERROR,
63+
'no-case-declarations': WARNING,
64+
'no-empty-pattern': ERROR,
65+
'no-eval': ERROR,
66+
'no-extend-native': ERROR,
67+
'no-extra-bind': ERROR,
68+
'no-extra-label': ERROR,
69+
'no-fallthrough': ERROR,
70+
'no-implied-eval': ERROR,
71+
'no-invalid-this': WARNING,
72+
'no-iterator': ERROR,
73+
'no-labels': [ERROR, { allowLoop: false, allowSwitch: false }],
74+
'no-lone-blocks': ERROR,
75+
'no-loop-func': ERROR,
76+
'no-multi-spaces': WARNING,
77+
'no-multi-str': ERROR,
78+
'no-native-reassign': ERROR,
79+
'no-new': ERROR,
80+
'no-new-func': ERROR,
81+
'no-new-wrappers': ERROR,
82+
'no-octal': ERROR,
83+
'no-octal-escape': ERROR,
84+
'no-redeclare': ERROR,
85+
'no-return-assign': ERROR,
86+
'no-script-url': ERROR,
87+
'no-self-assign': ERROR,
88+
'no-self-compare': ERROR,
89+
'no-sequences': ERROR,
90+
'no-throw-literal': ERROR,
91+
'no-unused-expressions': ERROR,
92+
'no-unused-labels': ERROR,
93+
'no-useless-concat': ERROR,
94+
'no-useless-escape': ERROR,
95+
'no-with': ERROR,
96+
radix: ERROR,
97+
yoda: WARNING,
98+
'no-cond-assign': [ERROR, 'always'],
99+
'no-console': OFF, // TODO: enable for production?
100+
'no-constant-condition': WARNING,
101+
'no-control-regex': ERROR,
102+
'no-debugger': WARNING, // TODO: enable for production?
103+
'no-dupe-args': ERROR,
104+
'no-dupe-keys': ERROR,
105+
'no-duplicate-case': ERROR,
106+
'no-empty': [WARNING, {
107+
allowEmptyCatch: true
108+
}],
109+
'no-empty-character-class': ERROR,
110+
'no-ex-assign': ERROR,
111+
'no-extra-boolean-cast': WARNING,
112+
'no-extra-semi': WARNING,
113+
'no-func-assign': ERROR,
114+
'no-invalid-regexp': ERROR,
115+
'no-irregular-whitespace': WARNING,
116+
'no-negated-in-lhs': ERROR,
117+
'no-obj-calls': ERROR,
118+
'no-prototype-builtins': WARNING,
119+
'no-regex-spaces': ERROR,
120+
'no-sparse-arrays': ERROR,
121+
'no-unexpected-multiline': ERROR,
122+
'no-unreachable': ERROR,
123+
'no-unsafe-finally': WARNING,
124+
'use-isnan': ERROR,
125+
'valid-typeof': ERROR,
126+
'block-spacing': [WARNING, 'always'],
127+
'brace-style': [WARNING, '1tbs', { allowSingleLine: true }],
128+
camelcase: [WARNING, { properties: 'never' }],
129+
'comma-spacing': [WARNING, { before: false, after: true }],
130+
'comma-style': [WARNING, 'last'],
131+
'computed-property-spacing': [WARNING, 'never'],
132+
'eol-last': WARNING,
133+
indent: [WARNING, 2],
134+
'key-spacing': [WARNING, { beforeColon: false, afterColon: true }],
135+
'keyword-spacing': [WARNING, {
136+
before: true,
137+
after: true,
138+
overrides: {
139+
return: { after: true },
140+
throw: { after: true },
141+
case: { after: true }
142+
}
143+
}],
144+
'linebreak-style': [WARNING, 'unix'],
145+
'new-cap': [ERROR, { newIsCap: true }],
146+
'new-parens': ERROR,
147+
'newline-per-chained-call': [WARNING, { ignoreChainWithDepth: 4 }],
148+
'no-array-constructor': ERROR,
149+
'no-mixed-operators': [ERROR, {
150+
groups: [
151+
['+', '-', '*', '/', '%', '**'],
152+
['&', '|', '^', '~', '<<', '>>', '>>>'],
153+
['==', '!=', '===', '!==', '>', '>=', '<', '<='],
154+
['&&', '||'],
155+
['in', 'instanceof']
156+
],
157+
allowSamePrecedence: false
158+
}],
159+
'no-mixed-spaces-and-tabs': WARNING,
160+
'no-multiple-empty-lines': [WARNING, { max: 2, maxEOF: 1 }],
161+
'no-nested-ternary': WARNING,
162+
'no-new-object': ERROR,
163+
'no-restricted-syntax': [
164+
ERROR,
165+
'LabeledStatement',
166+
'WithStatement',
167+
],
168+
'no-spaced-func': WARNING,
169+
'no-trailing-spaces': WARNING,
170+
'no-unneeded-ternary': [WARNING, { defaultAssignment: false }],
171+
'no-whitespace-before-property': ERROR,
172+
'object-property-newline': [WARNING, {
173+
allowMultiplePropertiesPerLine: true,
174+
}],
175+
'one-var': [WARNING, 'never'],
176+
'one-var-declaration-per-line': [WARNING, 'always'],
177+
'operator-assignment': [ERROR, 'always'],
178+
'semi-spacing': [WARNING, { before: false, after: true }],
179+
'space-before-blocks': WARNING,
180+
'space-before-function-paren': [WARNING, { anonymous: 'always', named: 'never' }],
181+
'space-in-parens': [WARNING, 'never'],
182+
'space-infix-ops': WARNING,
183+
'space-unary-ops': [WARNING, {
184+
words: true,
185+
nonwords: false,
186+
overrides: {},
187+
}],
188+
'spaced-comment': [WARNING, 'always', {
189+
exceptions: ['-', '+'],
190+
markers: ['=', '!']
191+
}],
192+
'unicode-bom': [ERROR, 'never'],
193+
'no-delete-var': ERROR,
194+
'no-label-var': ERROR,
195+
'no-shadow': WARNING,
196+
'no-shadow-restricted-names': ERROR,
197+
'no-undef': ERROR,
198+
'no-unused-vars': [ERROR, { vars: 'local', args: 'after-used' }],
199+
'no-use-before-define': [ERROR, 'nofunc'],
200+
'arrow-spacing': [WARNING, { before: true, after: true }],
201+
'generator-star-spacing': [WARNING, { before: false, after: true }],
202+
'no-confusing-arrow': [WARNING, {
203+
allowParens: true,
204+
}],
205+
'no-const-assign': ERROR,
206+
'no-dupe-class-members': ERROR,
207+
'no-duplicate-imports': WARNING,
208+
'no-new-symbol': ERROR,
209+
'no-this-before-super': ERROR,
210+
'no-useless-computed-key': ERROR,
211+
'no-useless-constructor': ERROR,
212+
'no-useless-rename': [ERROR, {
213+
ignoreDestructuring: false,
214+
ignoreImport: false,
215+
ignoreExport: false,
216+
}],
217+
'no-var': WARNING,
218+
'prefer-arrow-callback': [WARNING, {
219+
allowNamedFunctions: false,
220+
allowUnboundThis: true,
221+
}],
222+
'prefer-rest-params': ERROR,
223+
'require-yield': ERROR,
224+
'rest-spread-spacing': [ERROR, 'never'],
225+
'template-curly-spacing': WARNING,
226+
'yield-star-spacing': [WARNING, 'after'],
227+
strict: [ERROR, 'never'],
228+
229+
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/
230+
231+
'import/no-unresolved': [ERROR, { commonjs: true }],
232+
'import/named': ERROR,
233+
'import/default': ERROR,
234+
'import/namespace': ERROR,
235+
'import/export': ERROR,
236+
'import/no-named-as-default': ERROR,
237+
'import/no-named-as-default-member': ERROR,
238+
'import/no-extraneous-dependencies': ERROR,
239+
'import/no-mutable-exports': WARNING,
240+
'import/no-commonjs': WARNING,
241+
'import/no-amd': ERROR,
242+
'import/imports-first': WARNING,
243+
'import/no-duplicates': ERROR,
244+
'import/prefer-default-export': WARNING,
245+
246+
// https://github.com/yannickcr/eslint-plugin-react/tree/master/docs/rules
247+
'react/jsx-handler-names': [WARNING, {
248+
eventHandlerPrefix: 'handle',
249+
eventHandlerPropPrefix: 'on',
250+
}],
251+
'react/jsx-key': WARNING,
252+
'react/jsx-no-duplicate-props': [ERROR, { ignoreCase: true }],
253+
'react/jsx-no-undef': ERROR,
254+
'react/jsx-pascal-case': [ERROR, {
255+
allowAllCaps: true,
256+
ignore: [],
257+
}],
258+
'react/jsx-uses-react': [ERROR, { pragma: 'React' }],
259+
'react/jsx-uses-vars': ERROR,
260+
'react/no-deprecated': ERROR,
261+
'react/no-did-mount-set-state': [WARNING, 'allow-in-func'],
262+
'react/no-did-update-set-state': [WARNING, 'allow-in-func'],
263+
'react/no-direct-mutation-state': ERROR,
264+
'react/no-is-mounted': ERROR,
265+
'react/no-multi-comp': [WARNING, { ignoreStateless: true }],
266+
'react/no-string-refs': WARNING,
267+
'react/prefer-es6-class': OFF, // TODO: revisit after updating docs
268+
'react/prefer-stateless-function': OFF, // TODO: revisit after updating docs
269+
'react/react-in-jsx-scope': ERROR,
270+
'react/require-render-return': ERROR,
271+
'react/jsx-space-before-closing': WARNING,
272+
'react/wrap-multilines': [WARNING, {
273+
declaration: true,
274+
assignment: true,
275+
return: true
276+
}],
277+
'react/jsx-equals-spacing': [ERROR, 'never'],
278+
'react/jsx-indent': [WARNING, 2]
279+
}
280+
};

config/webpack.config.dev.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ var relative = isInNodeModules ? '../../..' : '..';
1919
module.exports = {
2020
devtool: 'eval',
2121
entry: [
22-
'./src/index.js',
23-
'webpack-dev-server/client?http://localhost:3000'
22+
'webpack-dev-server/client?http://localhost:3000',
23+
'./src/index.js'
2424
],
2525
output: {
2626
// Next line is not used in dev but WebpackDevServer crashes without it:
@@ -42,11 +42,7 @@ module.exports = {
4242
test: /\.js$/,
4343
include: path.resolve(__dirname, relative, 'src'),
4444
loader: 'babel',
45-
query: {
46-
cacheDirectory: true,
47-
presets: ['es2015', 'es2016', 'react'],
48-
plugins: ['transform-object-rest-spread']
49-
}
45+
query: require('./babel.dev')
5046
},
5147
{
5248
test: /\.css$/,
@@ -58,7 +54,7 @@ module.exports = {
5854
loader: 'json'
5955
},
6056
{
61-
test: /\.(jpg|png|gif|eot|svg|ttf|woff|woff2)$/,
57+
test: /\.(jpg|png|gif|svg|eot|svg|ttf|woff|woff2)$/,
6258
loader: 'file',
6359
},
6460
{
@@ -68,7 +64,8 @@ module.exports = {
6864
]
6965
},
7066
eslint: {
71-
configFile: path.join(__dirname, '.eslintrc')
67+
configFile: path.join(__dirname, 'eslint.js'),
68+
useEslintrc: false
7269
},
7370
postcss: function() {
7471
return [autoprefixer];

0 commit comments

Comments
 (0)