diff --git a/src/main/resources/docs/description/max-classes-per-file.md b/src/main/resources/docs/description/max-classes-per-file.md new file mode 100644 index 0000000..adea18f --- /dev/null +++ b/src/main/resources/docs/description/max-classes-per-file.md @@ -0,0 +1,13 @@ +This rule enforces that each file may contain only a particular number +of classes and no more. + +``` +//Bad (with parameter 1): +class Foo {} +class Bar {} + +//Good (with parameter 1): +class Foo {} +``` + +[Source](http://eslint.org/docs/rules/max-classes-per-file) diff --git a/src/main/resources/docs/description/max-lines-per-function.md b/src/main/resources/docs/description/max-lines-per-function.md new file mode 100644 index 0000000..65ad86d --- /dev/null +++ b/src/main/resources/docs/description/max-lines-per-function.md @@ -0,0 +1,3 @@ +This rule enforces a maximum number of lines per function, in order to aid in maintainability and reduce complexity. + +[Source](http://eslint.org/docs/rules/max-lines-per-function) diff --git a/src/main/resources/docs/description/no-async-promise-executor.md b/src/main/resources/docs/description/no-async-promise-executor.md new file mode 100644 index 0000000..e9c55c8 --- /dev/null +++ b/src/main/resources/docs/description/no-async-promise-executor.md @@ -0,0 +1,31 @@ +This rule aims to disallow async Promise executor functions. + +``` +//Bad: +const result = new Promise(async (resolve, reject) => { + readFile('foo.txt', function(err, result) { + if (err) { + reject(err); + } else { + resolve(result); + } + }); +}); +const result = new Promise(async (resolve, reject) => { + resolve(await foo); +}); + +//Good: +const result = new Promise((resolve, reject) => { + readFile('foo.txt', function(err, result) { + if (err) { + reject(err); + } else { + resolve(result); + } + }); +}); +const result = Promise.resolve(foo); +``` + +[Source](http://eslint.org/docs/rules/no-async-promise-executor) diff --git a/src/main/resources/docs/description/no-catch-shadow.md b/src/main/resources/docs/description/no-catch-shadow.md deleted file mode 100644 index 9f3cf21..0000000 --- a/src/main/resources/docs/description/no-catch-shadow.md +++ /dev/null @@ -1,26 +0,0 @@ -In IE 8 and earlier, the catch clause parameter can overwrite the value of a variable in the outer scope, if that variable has the same name as the catch clause parameter. -This rule is aimed at preventing unexpected behavior in your program that may arise from a bug in IE 8 and earlier, in which the catch clause parameter can leak into outer scopes. This rule will warn whenever it encounters a catch clause parameter that has the same name as a variable in an outer scope. - - -``` - -//Bad: -var err = "x"; -try { - throw "problem"; -} catch (err) { - -} - -//Good: -var err = "x"; - -try { - throw "problem"; -} catch (e) { - -} - -``` - -[Source](http://eslint.org/docs/rules/no-catch-shadow) diff --git a/src/main/resources/docs/description/no-misleading-character-class.md b/src/main/resources/docs/description/no-misleading-character-class.md new file mode 100644 index 0000000..682d9f6 --- /dev/null +++ b/src/main/resources/docs/description/no-misleading-character-class.md @@ -0,0 +1,17 @@ +This rule reports the regular expressions which include multiple code point characters in character class syntax. + +``` +//Bad: +/^[Á]$/u +/^[❇️]$/u +/^[πŸ‘ΆπŸ»]$/u +/^[πŸ‡―πŸ‡΅]$/u +/^[πŸ‘¨β€πŸ‘©β€πŸ‘¦]$/u +/^[πŸ‘]$/ + +//Good: +/^[abc]$/ +/^[πŸ‘]$/u +``` + +[Source](http://eslint.org/docs/rules/no-misleading-character-class) diff --git a/src/main/resources/docs/description/prefer-object-spread.md b/src/main/resources/docs/description/prefer-object-spread.md new file mode 100644 index 0000000..5e49328 --- /dev/null +++ b/src/main/resources/docs/description/prefer-object-spread.md @@ -0,0 +1,24 @@ +Prefer use of an object spread over `Object.assign`. + +``` +//Bad: +Object.assign({}, foo) +Object.assign({}, {foo: 'bar'}) +Object.assign({ foo: 'bar'}, baz) +Object.assign({ foo: 'bar' }, Object.assign({ bar: 'foo' })) +Object.assign({}, { foo, bar, baz }) +Object.assign({}, { ...baz }) +// Object.assign with a single argument that is an object literal +Object.assign({}); +Object.assign({ foo: bar }); + +//Good: +Object.assign(...foo); +// Any Object.assign call without an object literal as the first argument +Object.assign(foo, { bar: baz }); +Object.assign(foo, Object.assign(bar)); +Object.assign(foo, { bar, baz }) +Object.assign(foo, { ...baz }); +``` + +[Source](http://eslint.org/docs/rules/prefer-object-spread) diff --git a/src/main/resources/docs/description/require-atomic-updates.md b/src/main/resources/docs/description/require-atomic-updates.md new file mode 100644 index 0000000..fc3ed7d --- /dev/null +++ b/src/main/resources/docs/description/require-atomic-updates.md @@ -0,0 +1,39 @@ +This rule aims to report assignments to variables or properties where all of the following are true: + +* A variable or property is reassigned to a new value which is based on its old value. +* A `yield` or `await` expression interrupts the assignment after the old value is read, and before the new value is set. +* The rule cannot easily verify that the assignment is safe (e.g. if an assigned variable is local and would not be readable from anywhere else while the function is paused). + +Examples of **incorrect** code for this rule: + +``` +//Bad: +let result; +async function foo() { + result += await somethingElse; + result = result + await somethingElse; + result = result + doSomething(await somethingElse); +} +function* bar() { + result += yield; + result = result + (yield somethingElse); + result = result + doSomething(yield somethingElse); +} + +//Good: +let result; +async function foo() { + result = await somethingElse + result; + let tmp = await somethingElse; + result += tmp; + let localVariable = 0; + localVariable += await somethingElse; +} +function* bar() { + result += yield; + result = (yield somethingElse) + result; + result = doSomething(yield somethingElse, result); +} +``` + +[Source](http://eslint.org/docs/rules/require-atomic-updates) diff --git a/src/main/resources/docs/description/require-unicode-regexp.md b/src/main/resources/docs/description/require-unicode-regexp.md new file mode 100644 index 0000000..b350c11 --- /dev/null +++ b/src/main/resources/docs/description/require-unicode-regexp.md @@ -0,0 +1,17 @@ +This rule aims to enforce the use of `u` flag on regular expressions. + +``` +//Bad: +const a = /aaa/ +const b = /bbb/gi +const c = new RegExp("ccc") +const d = new RegExp("ddd", "gi") + +//Good: +const a = /aaa/u +const b = /bbb/giu +const c = new RegExp("ccc", "u") +const d = new RegExp("ddd", "giu") +``` + +[Source](http://eslint.org/docs/rules/require-unicode-regexp) diff --git a/src/main/resources/docs/patterns.json b/src/main/resources/docs/patterns.json index 2c0f4be..2dd31c9 100644 --- a/src/main/resources/docs/patterns.json +++ b/src/main/resources/docs/patterns.json @@ -1,6 +1,6 @@ { "name": "eslint", - "version": "4.15.0", + "version": "5.7.0", "patterns": [ { "patternId": "comma-dangle", @@ -522,11 +522,6 @@ } ] }, - { - "patternId": "no-catch-shadow", - "level": "Warning", - "category": "ErrorProne" - }, { "patternId": "no-delete-var", "level": "Warning", @@ -988,11 +983,21 @@ } ] }, + { + "patternId": "require-atomic-updates", + "level": "Error", + "category": "ErrorProne" + }, { "patternId": "require-jsdoc", "level": "Info", "category": "CodeStyle" }, + { + "patternId": "require-unicode-regexp", + "level": "Warning", + "category": "ErrorProne" + }, { "patternId": "semi-spacing", "level": "Info", @@ -1159,6 +1164,11 @@ "level": "Info", "category": "CodeStyle" }, + { + "patternId": "prefer-object-spread", + "level": "Info", + "category": "CodeStyle" + }, { "patternId": "prefer-spread", "level": "Info", @@ -1259,6 +1269,17 @@ "level": "Warning", "category": "CodeStyle" }, + { + "patternId": "max-classes-per-file", + "level": "Warning", + "category": "CodeStyle", + "parameters": [ + { + "name": "unnamedParam", + "default": 0 + } + ] + }, { "patternId": "max-depth", "level": "Warning", @@ -1274,6 +1295,29 @@ "level": "Warning", "category": "CodeStyle" }, + { + "patternId": "max-lines-per-function", + "level": "Warning", + "category": "CodeStyle", + "parameters": [ + { + "name": "max", + "default": 50 + }, + { + "name": "skipBlankLines", + "default": false + }, + { + "name": "skipComments", + "default": false + }, + { + "name": "IIFEs", + "default": false + } + ] + }, { "patternId": "max-params", "level": "Warning", @@ -1304,6 +1348,11 @@ "level": "Warning", "category": "ErrorProne" }, + { + "patternId": "no-misleading-character-class", + "level": "Warning", + "category": "ErrorProne" + }, { "patternId": "no-mixed-operators", "level": "Warning", @@ -1424,6 +1473,11 @@ "level": "Info", "category": "CodeStyle" }, + { + "patternId": "no-async-promise-executor", + "level": "Error", + "category": "ErrorProne" + }, { "patternId": "no-comma-dangle", "level": "Info", diff --git a/src/main/resources/docs/tests/indent.js b/src/main/resources/docs/tests/indent.js index a7734cd..7d2eb80 100644 --- a/src/main/resources/docs/tests/indent.js +++ b/src/main/resources/docs/tests/indent.js @@ -3,14 +3,14 @@ if (a) { -//ok + //ok b=c; //#Info: indent b=c; //#Info: indent -function foo(d) { +function foo(d) { //#Info: indent - e=f; + e=f; } } diff --git a/src/main/resources/docs/tests/no-catch-shadow.js b/src/main/resources/docs/tests/no-catch-shadow.js deleted file mode 100644 index af1f0ee..0000000 --- a/src/main/resources/docs/tests/no-catch-shadow.js +++ /dev/null @@ -1,17 +0,0 @@ -//#Patterns: no-catch-shadow - - - -var err = "x"; -try { - throw "problem"; -//#Warn: no-catch-shadow -} catch (err) { -} - -var err = "x"; -try { - throw "problem"; -} catch (e) { - -} diff --git a/src/main/resources/docs/tests/valid-jsdoc.js b/src/main/resources/docs/tests/valid-jsdoc.js index 1873e63..795149e 100644 --- a/src/main/resources/docs/tests/valid-jsdoc.js +++ b/src/main/resources/docs/tests/valid-jsdoc.js @@ -1,5 +1,5 @@ //#Patterns: valid-jsdoc -//#Issue: {"severity": "Info", "line": 5, "patternId": "valid-jsdoc"} +//#Issue: {"severity": "Info", "line": 7, "patternId": "valid-jsdoc"} //#Issue: {"severity": "Info", "line": 14, "patternId": "valid-jsdoc"} /** //error Missing JSDoc parameter description for 'num1'. @@ -17,4 +17,4 @@ function foo(num1) { */ function foo() { // ... -} \ No newline at end of file +}