Skip to content

Commit 125919c

Browse files
author
Ives van Hoorne
committed
Update linter
1 parent a701cdb commit 125919c

File tree

3 files changed

+144317
-26
lines changed

3 files changed

+144317
-26
lines changed

config/webpack.config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ const config = {
159159
},
160160

161161
plugins: [
162-
new webpack.optimize.ModuleConcatenationPlugin(),
163162
// Generates an `index.html` file with the <script> injected.
164163
new HtmlWebpackPlugin({
165164
inject: true,
@@ -260,12 +259,12 @@ if (__DEV__) {
260259
if (__PROD__) {
261260
config.plugins = [
262261
...config.plugins,
262+
new webpack.optimize.ModuleConcatenationPlugin(),
263263
// Minify the code.
264264
new webpack.LoaderOptionsPlugin({
265265
minimize: true,
266266
debug: false
267267
}),
268-
// new BabiliPlugin(),
269268
new webpack.optimize.UglifyJsPlugin({
270269
beautify: false,
271270
compress: {

src/app/utils/codemirror/eslint-lint.js

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const allRules = {
4242
'react/jsx-indent-props': require('eslint-plugin-react/lib/rules/jsx-indent-props'),
4343
'react/jsx-indent': require('eslint-plugin-react/lib/rules/jsx-indent'),
4444
'react/jsx-closing-bracket-location': require('eslint-plugin-react/lib/rules/jsx-closing-bracket-location'),
45-
'react/jsx-space-before-closing': require('eslint-plugin-react/lib/rules/jsx-space-before-closing'),
45+
'react/jsx-tag-spacing': require('eslint-plugin-react/lib/rules/jsx-tag-spacing'),
4646
'react/no-direct-mutation-state': require('eslint-plugin-react/lib/rules/no-direct-mutation-state'),
4747
'react/forbid-component-props': require('eslint-plugin-react/lib/rules/forbid-component-props'),
4848
'react/forbid-elements': require('eslint-plugin-react/lib/rules/forbid-elements'),
@@ -998,19 +998,23 @@ const defaultConfig = {
998998
'error',
999999
{
10001000
selector: 'ForInStatement',
1001-
message: 'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.',
1001+
message:
1002+
'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.',
10021003
},
10031004
{
10041005
selector: 'ForOfStatement',
1005-
message: 'iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations.',
1006+
message:
1007+
'iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations.',
10061008
},
10071009
{
10081010
selector: 'LabeledStatement',
1009-
message: 'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
1011+
message:
1012+
'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
10101013
},
10111014
{
10121015
selector: 'WithStatement',
1013-
message: '`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
1016+
message:
1017+
'`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
10141018
},
10151019
],
10161020

@@ -1425,7 +1429,12 @@ const defaultConfig = {
14251429

14261430
// Enforce spaces before the closing bracket of self-closing JSX elements
14271431
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-space-before-closing.md
1428-
'react/jsx-space-before-closing': ['error', 'always'],
1432+
'react/jsx-tag-spacing': [
1433+
'error',
1434+
{
1435+
beforeSelfClosing: true,
1436+
},
1437+
],
14291438

14301439
// Enforce component methods order
14311440
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md
@@ -1444,18 +1453,6 @@ const defaultConfig = {
14441453
},
14451454
],
14461455

1447-
// Prevent missing parentheses around multilines JSX
1448-
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-wrap-multilines.md
1449-
'react/jsx-wrap-multilines': [
1450-
'error',
1451-
{
1452-
declaration: true,
1453-
assignment: true,
1454-
return: true,
1455-
},
1456-
],
1457-
'react/wrap-multilines': 'off', // deprecated version
1458-
14591456
// Require that the first prop in a JSX element be on a new line when the element is multiline
14601457
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-first-prop-new-line.md
14611458
'react/jsx-first-prop-new-line': ['error', 'multiline'],
@@ -1556,6 +1553,8 @@ const defaultConfig = {
15561553
},
15571554
};
15581555

1556+
let linter = null;
1557+
15591558
function getPos(error, from) {
15601559
let line = error.line - 1;
15611560
let ch = from ? error.column : error.column + 1;
@@ -1583,8 +1582,8 @@ function getSeverity(error) {
15831582
}
15841583

15851584
function eslintValidate(text) {
1586-
if (!window.eslint) return [];
1587-
return window.eslint.verify(text, defaultConfig);
1585+
if (!linter) return [];
1586+
return linter.verify(text, defaultConfig);
15881587
}
15891588

15901589
export function validator(text: string) {
@@ -1598,16 +1597,16 @@ export function validator(text: string) {
15981597

15991598
export function fix(source: string) {
16001599
const errors = eslintValidate(source);
1601-
return fixer.applyFixes(window.eslint.getSourceCode(), errors);
1600+
return fixer.applyFixes(linter.getSourceCode(), errors);
16021601
}
16031602

16041603
export default (async function initialize() {
1605-
if (!window.eslint) {
1604+
if (!window.eslint && linter === null) {
16061605
// Add eslint as script
16071606
const script = document.createElement('script');
16081607
const src = process.env.NODE_ENV === 'development'
16091608
? 'http://eslint.org/js/app/eslint.js'
1610-
: '/static/js/eslint.3.18.0.js';
1609+
: '/static/js/eslint.4.0.0.js';
16111610
script.setAttribute('src', src);
16121611
script.setAttribute('async', false);
16131612

@@ -1619,6 +1618,7 @@ export default (async function initialize() {
16191618
await delay(100);
16201619
}
16211620

1622-
window.eslint.defineRules(allRules);
1621+
linter = new window.eslint();
1622+
linter.defineRules(allRules);
16231623
CodeMirror.registerHelper('lint', 'javascript', validator);
16241624
});

0 commit comments

Comments
 (0)