eslint 5.9.0 → 5.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/README.md +2 -2
  3. package/conf/eslint-recommended.js +1 -0
  4. package/lib/cli-engine.js +1 -1
  5. package/lib/config/autoconfig.js +0 -1
  6. package/lib/config/config-file.js +2 -2
  7. package/lib/config/config-rule.js +4 -4
  8. package/lib/config/config-validator.js +2 -2
  9. package/lib/config.js +15 -2
  10. package/lib/linter.js +8 -120
  11. package/lib/rules/array-element-newline.js +0 -1
  12. package/lib/rules/block-spacing.js +2 -2
  13. package/lib/rules/camelcase.js +24 -14
  14. package/lib/rules/capitalized-comments.js +2 -2
  15. package/lib/rules/comma-style.js +7 -2
  16. package/lib/rules/eqeqeq.js +0 -1
  17. package/lib/rules/func-name-matching.js +4 -4
  18. package/lib/rules/handle-callback-err.js +1 -1
  19. package/lib/rules/implicit-arrow-linebreak.js +143 -2
  20. package/lib/rules/indent-legacy.js +0 -3
  21. package/lib/rules/indent.js +29 -23
  22. package/lib/rules/keyword-spacing.js +5 -1
  23. package/lib/rules/max-classes-per-file.js +1 -1
  24. package/lib/rules/newline-before-return.js +1 -1
  25. package/lib/rules/no-constant-condition.js +0 -1
  26. package/lib/rules/no-else-return.js +0 -1
  27. package/lib/rules/no-implied-eval.js +1 -1
  28. package/lib/rules/no-irregular-whitespace.js +1 -1
  29. package/lib/rules/no-param-reassign.js +8 -0
  30. package/lib/rules/no-restricted-imports.js +1 -1
  31. package/lib/rules/no-this-before-super.js +0 -1
  32. package/lib/rules/no-useless-catch.js +52 -0
  33. package/lib/rules/object-curly-newline.js +0 -1
  34. package/lib/rules/one-var.js +0 -1
  35. package/lib/rules/padding-line-between-statements.js +37 -0
  36. package/lib/rules/prefer-object-spread.js +2 -2
  37. package/lib/rules/quotes.js +48 -25
  38. package/lib/rules/require-jsdoc.js +4 -1
  39. package/lib/rules/sort-imports.js +43 -37
  40. package/lib/rules/space-in-parens.js +0 -1
  41. package/lib/rules/space-infix-ops.js +4 -1
  42. package/lib/rules/valid-jsdoc.js +4 -1
  43. package/lib/util/config-comment-parser.js +144 -0
  44. package/lib/util/glob-utils.js +1 -1
  45. package/lib/{ignored-paths.js → util/ignored-paths.js} +4 -4
  46. package/lib/{report-translator.js → util/report-translator.js} +2 -2
  47. package/lib/util/source-code.js +2 -1
  48. package/messages/all-files-ignored.txt +1 -1
  49. package/package.json +7 -8
package/CHANGELOG.md CHANGED
@@ -1,3 +1,58 @@
1
+ v5.12.0 - January 4, 2019
2
+
3
+ * [`0d91e7d`](https://github.com/eslint/eslint/commit/0d91e7d28e5eba79a6032165cdef5d4549d26462) Update: Add sort-imports ignoreDeclarationSort (fixes #11019) (#11040) (Remco Haszing)
4
+ * [`f92d6f0`](https://github.com/eslint/eslint/commit/f92d6f05c4dcd4a3a0616871e10b31edae9dfad5) Build: Add karma-chrome-launcher support (#11027) (薛定谔的猫)
5
+ * [`166853d`](https://github.com/eslint/eslint/commit/166853d9c59db493f0b1bb68a67ad868662a4205) Upgrade: eslint-plugin-eslint-plugin@2.0.1 (#11220) (薛定谔的猫)
6
+ * [`bfff77a`](https://github.com/eslint/eslint/commit/bfff77ad4eaa02e2e62481c986634df38d5db6e5) Fix: no-param-reassign parameter in ternary operator (fixes #11236) (#11239) (周昊宇)
7
+ * [`258b654`](https://github.com/eslint/eslint/commit/258b6541f61dc3a9ae64e200680766a11c3dd316) Upgrade: require-uncached renamed to import-fresh (#11066) (薛定谔的猫)
8
+
9
+ v5.11.1 - December 26, 2018
10
+
11
+ * [`de79f10`](https://github.com/eslint/eslint/commit/de79f1026b7035f0296d7876f1db64f225cca1b8) Fix: handle optional catch bindings in no-useless-catch (#11205) (Colin Ihrig)
12
+
13
+ v5.11.0 - December 22, 2018
14
+
15
+ * [`b4395f6`](https://github.com/eslint/eslint/commit/b4395f671442a7e0be956382c24cce38025a6df6) New: add option `first` for VariableDeclarator in indent (fixes #8976) (#11193) (Pig Fang)
16
+ * [`2b5a602`](https://github.com/eslint/eslint/commit/2b5a60284670a3ab1281b206941ed38faf2ea10c) New: no-useless-catch rule (fixes #11174) (#11198) (Alexander Grasley)
17
+ * [`06b3b5b`](https://github.com/eslint/eslint/commit/06b3b5bfcf0429c5078d4f4af3c03bb777e4f022) Fix: Account for comments in implicit-arrow-linebreak (#10545) (Mark de Dios)
18
+ * [`4242314`](https://github.com/eslint/eslint/commit/4242314215a6f35e432860433906f47af1a29724) Update: handle computed properties in camelcase (fixes #11084) (#11113) (Bence Dányi)
19
+ * [`1009304`](https://github.com/eslint/eslint/commit/100930493d9ab802a94dac5c761515b12241ddd2) Docs: add a note for no-unused-expressions (fixes #11169) (#11192) (Pig Fang)
20
+ * [`88f99d3`](https://github.com/eslint/eslint/commit/88f99d31b88a4cde4563bc4a6f4c41f0cc557885) Docs: clarify how to use configs in plugins (#11199) (Kai Cataldo)
21
+ * [`bcf558b`](https://github.com/eslint/eslint/commit/bcf558b2f7036f487af2bdb2b2d34b6cdf7fc174) Docs: Clarify the no-unused-vars docs (#11195) (Jed Fox)
22
+ * [`a470eb7`](https://github.com/eslint/eslint/commit/a470eb73d52fae0f0bc48de5a487e23cf78fcfa9) Docs: Fix no-irregular-whitespace description (#11196) (Jed Fox)
23
+ * [`8abc8af`](https://github.com/eslint/eslint/commit/8abc8afe71691b747cbd1819a13d896e8aa5b92a) Docs: Remove a misleading example (#11204) (Bogdan Gradinariu)
24
+ * [`733d936`](https://github.com/eslint/eslint/commit/733d93618a99758a05453ab94505a9f1330950e0) Docs: link to JSDoc EOL blogpost in valid-jsdoc and require-jsdoc (#11191) (Nathan Diddle)
25
+ * [`d5eb108`](https://github.com/eslint/eslint/commit/d5eb108e17f676d0e4fcddeb1211b4bdfac760c1) Docs: Ensure `triage` label is added to new issues (#11182) (Teddy Katz)
26
+ * [`617a287`](https://github.com/eslint/eslint/commit/617a2874ed085bca36ca289aac55e3b7f7ce937e) Docs: add missing deprecation notices for jsdoc rules (#11171) (Teddy Katz)
27
+
28
+ v5.10.0 - December 8, 2018
29
+
30
+ * [`4b0f517`](https://github.com/eslint/eslint/commit/4b0f517cd317e5f1b99a1e8a0392332bd8a2e231) Upgrade: single- and multiline const, let, var statements (fixes #10721) (#10919) (Tom Panier)
31
+ * [`9666aba`](https://github.com/eslint/eslint/commit/9666abaf46c841fba7b5d4e53c6998cd25b9bc33) Update: space-infix-ops reports violating operator (#10934) (Bence Dányi)
32
+ * [`c14f717`](https://github.com/eslint/eslint/commit/c14f717f4c32860766185da47f64f8eb0c2d2998) Fix: Update all-files-ignored.txt message to be less confusing (#11075) (z.ky)
33
+ * [`9f3573d`](https://github.com/eslint/eslint/commit/9f3573dda3dc35bc220e945686cc835eaad0ac2c) Docs: Clarify the CLIEngine options (#10995) (Ed Morley)
34
+ * [`dd7b0cb`](https://github.com/eslint/eslint/commit/dd7b0cb019d94964930d30fec36f7b22ef072822) Chore: refactor template literal feature detection in 'quotes' rule (#11125) (Bryan)
35
+ * [`3bf0332`](https://github.com/eslint/eslint/commit/3bf0332508b921cb660c2e8a1ab7ddf46a2013b6) Fix: fix the fixer of lone comma with comments (fixes #10632) (#11154) (Pig Fang)
36
+ * [`f850726`](https://github.com/eslint/eslint/commit/f8507260c2091d18488fde20e466639d1a7f913c) Upgrade: Espree v5.0.0 (#11161) (Kai Cataldo)
37
+ * [`4490d7a`](https://github.com/eslint/eslint/commit/4490d7af529d4ecc18b6874f1d838869656da58a) Update: deprecate valid-jsdoc and require-jsdoc (#11145) (Teddy Katz)
38
+ * [`60dfb6c`](https://github.com/eslint/eslint/commit/60dfb6c623dfe829e5350dabe507e7850c1beacf) Docs: Update issue templates (#11163) (Teddy Katz)
39
+ * [`958987a`](https://github.com/eslint/eslint/commit/958987aa6f5630faa051d8f822f0200faff41924) Docs: Fix link to rule no-useless-rename (#11165) (Brian)
40
+ * [`62fd2b9`](https://github.com/eslint/eslint/commit/62fd2b93448966331db3eb2dfbe4e1273eb032b2) Update: Amend keyword-spacing to validate `default` keywords (#11097) (Bin Ury)
41
+ * [`4bcdfd0`](https://github.com/eslint/eslint/commit/4bcdfd07d514fd7a6b8672d33703d0b6c606f214) Chore: fix some jsdoc-related issues (#11148) (薛定谔的猫)
42
+ * [`c6471ed`](https://github.com/eslint/eslint/commit/c6471ed6feb3e71e239379a7042deb9b8ab3cf39) Docs: fix typo in issue-templates/new-rule (#11149) (薛定谔的猫)
43
+ * [`5d451c5`](https://github.com/eslint/eslint/commit/5d451c510c15abc41b5bb14b4955a7db96aeb100) Chore: Remove dependency on is-resolvable (#11128) (Matt Grande)
44
+ * [`bc50dc7`](https://github.com/eslint/eslint/commit/bc50dc7737496712463220e662946eb516e36ae1) Chore: Move ignored-paths, report-translator to lib/util (refs #10559) (#11116) (Kevin Partington)
45
+ * [`c0a80d0`](https://github.com/eslint/eslint/commit/c0a80d0ca3c80ca27694fc8aedcf84b72bfd9465) Fix: Do not strip underscores in camelcase allow (fixes #11000) (#11001) (Luke Page)
46
+ * [`a675c89`](https://github.com/eslint/eslint/commit/a675c89573836adaf108a932696b061946abf1e6) Docs: (Grammar) "the setup" -> "to set up" (#11117) (MarvinJWendt)
47
+ * [`54dfa60`](https://github.com/eslint/eslint/commit/54dfa602f62e6d183d57d60d5fdd417a263f479e) Fix: Typo in function comment parameters (#11111) (Pierre Maoui)
48
+ * [`cf296bd`](https://github.com/eslint/eslint/commit/cf296bdabf0dbbfbae491419e38aee4ecd63ec71) Docs: switch incorrect example with correct one (#11107) (Romain Le Quellec)
49
+ * [`d2d500c`](https://github.com/eslint/eslint/commit/d2d500ca5dff307189b9d4161a5e7b8282557dd6) Docs: no-console#When-Not-To-Use provides incorrect rule snippet (#11093) (Lawrence Chou)
50
+ * [`f394a1d`](https://github.com/eslint/eslint/commit/f394a1dfc5eb4874f899b7bc19685896893af7b8) Chore: Extract config comment parsing (#11091) (Nicholas C. Zakas)
51
+ * [`709190f`](https://github.com/eslint/eslint/commit/709190f8c5d7559b1e0915e25af60b50a94ba1c7) Build: fix test failure on Node 11 (#11100) (Teddy Katz)
52
+ * [`3025cdd`](https://github.com/eslint/eslint/commit/3025cddf0a2ea8461ce05575098a5714fcf6278d) Update: don't indent leading semi in line after import (fixes #11082) (#11085) (Pig Fang)
53
+ * [`e18c827`](https://github.com/eslint/eslint/commit/e18c827cc12cb1c52e5d0aa993f572cb56238704) Chore: refactor linter#parseBooleanConfig to improve readability (#11074) (薛定谔的猫)
54
+ * [`5da378a`](https://github.com/eslint/eslint/commit/5da378ac922d732ca1765f08edee0face1b1b924) Upgrade: eslint-release@1.2.0 (#11073) (Teddy Katz)
55
+
1
56
  v5.9.0 - November 9, 2018
2
57
 
3
58
  * 9436712 Fix: Unused recursive function expressions (fixes #10982) (#11032) (Sergei Startsev)
package/README.md CHANGED
@@ -38,7 +38,7 @@ If you want to include ESLint as part of your project's build system, we recomme
38
38
  $ npm install eslint --save-dev
39
39
  ```
40
40
 
41
- You should then setup a configuration file:
41
+ You should then set up a configuration file:
42
42
 
43
43
  ```
44
44
  $ ./node_modules/.bin/eslint --init
@@ -60,7 +60,7 @@ If you want to make ESLint available to tools that run across all of your projec
60
60
  $ npm install -g eslint
61
61
  ```
62
62
 
63
- You should then setup a configuration file:
63
+ You should then set up a configuration file:
64
64
 
65
65
  ```
66
66
  $ eslint --init
@@ -207,6 +207,7 @@ module.exports = {
207
207
  "no-unused-vars": "error",
208
208
  "no-use-before-define": "off",
209
209
  "no-useless-call": "off",
210
+ "no-useless-catch": "off",
210
211
  "no-useless-computed-key": "off",
211
212
  "no-useless-concat": "off",
212
213
  "no-useless-constructor": "off",
package/lib/cli-engine.js CHANGED
@@ -20,7 +20,7 @@ const fs = require("fs"),
20
20
  defaultOptions = require("../conf/default-cli-options"),
21
21
  Linter = require("./linter"),
22
22
  lodash = require("lodash"),
23
- IgnoredPaths = require("./ignored-paths"),
23
+ IgnoredPaths = require("./util/ignored-paths"),
24
24
  Config = require("./config"),
25
25
  ConfigOps = require("./config/config-ops"),
26
26
  LintResultCache = require("./util/lint-result-cache"),
@@ -102,7 +102,6 @@ class Registry {
102
102
  *
103
103
  * The length of the returned array will be <= MAX_CONFIG_COMBINATIONS.
104
104
  *
105
- * @param {Object} registry The autoconfig registry
106
105
  * @returns {Object[]} "rules" configurations to use for linting
107
106
  */
108
107
  buildRuleSets() {
@@ -18,7 +18,7 @@ const fs = require("fs"),
18
18
  pathIsInside = require("path-is-inside"),
19
19
  stripComments = require("strip-json-comments"),
20
20
  stringify = require("json-stable-stringify-without-jsonify"),
21
- requireUncached = require("require-uncached");
21
+ importFresh = require("import-fresh");
22
22
 
23
23
  const debug = require("debug")("eslint:config-file");
24
24
 
@@ -156,7 +156,7 @@ function loadLegacyConfigFile(filePath) {
156
156
  function loadJSConfigFile(filePath) {
157
157
  debug(`Loading JS config file: ${filePath}`);
158
158
  try {
159
- return requireUncached(filePath);
159
+ return importFresh(filePath);
160
160
  } catch (e) {
161
161
  debug(`Error reading JavaScript file: ${filePath}`);
162
162
  e.message = `Cannot read config file: ${filePath}\nError: ${e.message}`;
@@ -37,9 +37,9 @@ function explodeArray(xs) {
37
37
  * For example:
38
38
  * combineArrays([a, [b, c]], [x, y]); // -> [[a, x], [a, y], [b, c, x], [b, c, y]]
39
39
  *
40
- * @param {array} arr1 The first array to combine.
41
- * @param {array} arr2 The second array to combine.
42
- * @returns {array} A mixture of the elements of the first and second arrays.
40
+ * @param {Array} arr1 The first array to combine.
41
+ * @param {Array} arr2 The second array to combine.
42
+ * @returns {Array} A mixture of the elements of the first and second arrays.
43
43
  */
44
44
  function combineArrays(arr1, arr2) {
45
45
  const res = [];
@@ -268,7 +268,7 @@ class RuleConfigSet {
268
268
  /**
269
269
  * Generate valid rule configurations based on a schema object
270
270
  * @param {Object} schema A rule's schema object
271
- * @returns {array[]} Valid rule configurations
271
+ * @returns {Array[]} Valid rule configurations
272
272
  */
273
273
  function generateConfigsFromSchema(schema) {
274
274
  const configSet = new RuleConfigSet();
@@ -83,7 +83,7 @@ function validateRuleSeverity(options) {
83
83
  /**
84
84
  * Validates the non-severity options passed to a rule, based on its schema.
85
85
  * @param {{create: Function}} rule The rule to validate
86
- * @param {array} localOptions The options for the rule, excluding severity
86
+ * @param {Array} localOptions The options for the rule, excluding severity
87
87
  * @returns {void}
88
88
  */
89
89
  function validateRuleSchema(rule, localOptions) {
@@ -111,7 +111,7 @@ function validateRuleSchema(rule, localOptions) {
111
111
  * Validates a rule's options against its schema.
112
112
  * @param {{create: Function}|null} rule The rule that the config is being validated for
113
113
  * @param {string} ruleId The rule's unique name.
114
- * @param {array|number} options The given options for the rule.
114
+ * @param {Array|number} options The given options for the rule.
115
115
  * @param {string|null} source The name of the configuration source to report in any errors. If null or undefined,
116
116
  * no source is prepended to the message.
117
117
  * @returns {void}
package/lib/config.js CHANGED
@@ -15,8 +15,7 @@ const path = require("path"),
15
15
  ConfigFile = require("./config/config-file"),
16
16
  ConfigCache = require("./config/config-cache"),
17
17
  Plugins = require("./config/plugins"),
18
- FileFinder = require("./util/file-finder"),
19
- isResolvable = require("is-resolvable");
18
+ FileFinder = require("./util/file-finder");
20
19
 
21
20
  const debug = require("debug")("eslint:config");
22
21
 
@@ -41,6 +40,20 @@ function hasRules(options) {
41
40
  return options.rules && Object.keys(options.rules).length > 0;
42
41
  }
43
42
 
43
+ /**
44
+ * Determines if a module is can be resolved.
45
+ * @param {string} moduleId The ID (name) of the module
46
+ * @returns {boolean} True if it is resolvable; False otherwise.
47
+ */
48
+ function isResolvable(moduleId) {
49
+ try {
50
+ require.resolve(moduleId);
51
+ return true;
52
+ } catch (err) {
53
+ return false;
54
+ }
55
+ }
56
+
44
57
  //------------------------------------------------------------------------------
45
58
  // API
46
59
  //------------------------------------------------------------------------------
package/lib/linter.js CHANGED
@@ -11,7 +11,6 @@
11
11
 
12
12
  const eslintScope = require("eslint-scope"),
13
13
  evk = require("eslint-visitor-keys"),
14
- levn = require("levn"),
15
14
  lodash = require("lodash"),
16
15
  CodePathAnalyzer = require("./code-path-analysis/code-path-analyzer"),
17
16
  ConfigOps = require("./config/config-ops"),
@@ -22,9 +21,10 @@ const eslintScope = require("eslint-scope"),
22
21
  NodeEventGenerator = require("./util/node-event-generator"),
23
22
  SourceCode = require("./util/source-code"),
24
23
  Traverser = require("./util/traverser"),
25
- createReportTranslator = require("./report-translator"),
24
+ createReportTranslator = require("./util/report-translator"),
26
25
  Rules = require("./rules"),
27
26
  timing = require("./util/timing"),
27
+ ConfigCommentParser = require("./util/config-comment-parser"),
28
28
  astUtils = require("./util/ast-utils"),
29
29
  pkg = require("../package.json"),
30
30
  SourceCodeFixer = require("./util/source-code-fixer");
@@ -32,6 +32,7 @@ const eslintScope = require("eslint-scope"),
32
32
  const debug = require("debug")("eslint:linter");
33
33
  const MAX_AUTOFIX_PASSES = 10;
34
34
  const DEFAULT_PARSER_NAME = "espree";
35
+ const commentParser = new ConfigCommentParser();
35
36
 
36
37
  //------------------------------------------------------------------------------
37
38
  // Typedefs
@@ -59,117 +60,6 @@ const DEFAULT_PARSER_NAME = "espree";
59
60
  // Helpers
60
61
  //------------------------------------------------------------------------------
61
62
 
62
- /**
63
- * Parses a list of "name:boolean_value" or/and "name" options divided by comma or
64
- * whitespace.
65
- * @param {string} string The string to parse.
66
- * @param {Comment} comment The comment node which has the string.
67
- * @returns {Object} Result map object of names and boolean values
68
- */
69
- function parseBooleanConfig(string, comment) {
70
- const items = {};
71
-
72
- // Collapse whitespace around `:` and `,` to make parsing easier
73
- const trimmedString = string.replace(/\s*([:,])\s*/g, "$1");
74
-
75
- trimmedString.split(/\s|,+/).forEach(name => {
76
- if (!name) {
77
- return;
78
- }
79
- const pos = name.indexOf(":");
80
-
81
- if (pos === -1) {
82
- items[name] = {
83
- value: false,
84
- comment
85
- };
86
- } else {
87
- items[name.slice(0, pos)] = {
88
- value: name.slice(pos + 1) === "true",
89
- comment
90
- };
91
- }
92
- });
93
- return items;
94
- }
95
-
96
- /**
97
- * Parses a JSON-like config.
98
- * @param {string} string The string to parse.
99
- * @param {Object} location Start line and column of comments for potential error message.
100
- * @returns {({success: true, config: Object}|{success: false, error: Problem})} Result map object
101
- */
102
- function parseJsonConfig(string, location) {
103
- let items = {};
104
-
105
- // Parses a JSON-like comment by the same way as parsing CLI option.
106
- try {
107
- items = levn.parse("Object", string) || {};
108
-
109
- // Some tests say that it should ignore invalid comments such as `/*eslint no-alert:abc*/`.
110
- // Also, commaless notations have invalid severity:
111
- // "no-alert: 2 no-console: 2" --> {"no-alert": "2 no-console: 2"}
112
- // Should ignore that case as well.
113
- if (ConfigOps.isEverySeverityValid(items)) {
114
- return {
115
- success: true,
116
- config: items
117
- };
118
- }
119
- } catch (ex) {
120
-
121
- // ignore to parse the string by a fallback.
122
- }
123
-
124
- /*
125
- * Optionator cannot parse commaless notations.
126
- * But we are supporting that. So this is a fallback for that.
127
- */
128
- items = {};
129
- const normalizedString = string.replace(/([a-zA-Z0-9\-/]+):/g, "\"$1\":").replace(/(]|[0-9])\s+(?=")/, "$1,");
130
-
131
- try {
132
- items = JSON.parse(`{${normalizedString}}`);
133
- } catch (ex) {
134
- return {
135
- success: false,
136
- error: {
137
- ruleId: null,
138
- fatal: true,
139
- severity: 2,
140
- message: `Failed to parse JSON from '${normalizedString}': ${ex.message}`,
141
- line: location.start.line,
142
- column: location.start.column + 1
143
- }
144
- };
145
-
146
- }
147
-
148
- return {
149
- success: true,
150
- config: items
151
- };
152
- }
153
-
154
- /**
155
- * Parses a config of values separated by comma.
156
- * @param {string} string The string to parse.
157
- * @returns {Object} Result map of values and true values
158
- */
159
- function parseListConfig(string) {
160
- const items = {};
161
-
162
- // Collapse whitespace around ,
163
- string.replace(/\s*,\s*/g, ",").split(/,+/).forEach(name => {
164
- const trimmedName = name.trim();
165
-
166
- if (trimmedName) {
167
- items[trimmedName] = true;
168
- }
169
- });
170
- return items;
171
- }
172
-
173
63
  /**
174
64
  * Ensures that variables representing built-in properties of the Global Object,
175
65
  * and any globals declared by special block comments, are present in the global
@@ -248,7 +138,7 @@ function addDeclaredGlobals(globalScope, configGlobals, commentDirectives) {
248
138
  * @returns {DisableDirective[]} Directives from the comment
249
139
  */
250
140
  function createDisableDirectives(type, loc, value) {
251
- const ruleIds = Object.keys(parseListConfig(value));
141
+ const ruleIds = Object.keys(commentParser.parseListConfig(value));
252
142
  const directiveRules = ruleIds.length ? ruleIds : [null];
253
143
 
254
144
  return directiveRules.map(ruleId => ({ type, line: loc.line, column: loc.column + 1, ruleId }));
@@ -301,12 +191,12 @@ function getDirectiveComments(filename, ast, ruleMapper) {
301
191
  } else if (comment.type === "Block") {
302
192
  switch (match[1]) {
303
193
  case "exported":
304
- Object.assign(exportedVariables, parseBooleanConfig(directiveValue, comment));
194
+ Object.assign(exportedVariables, commentParser.parseBooleanConfig(directiveValue, comment));
305
195
  break;
306
196
 
307
197
  case "globals":
308
198
  case "global":
309
- Object.assign(enabledGlobals, parseBooleanConfig(directiveValue, comment));
199
+ Object.assign(enabledGlobals, commentParser.parseBooleanConfig(directiveValue, comment));
310
200
  break;
311
201
 
312
202
  case "eslint-disable":
@@ -318,7 +208,7 @@ function getDirectiveComments(filename, ast, ruleMapper) {
318
208
  break;
319
209
 
320
210
  case "eslint": {
321
- const parseResult = parseJsonConfig(directiveValue, comment.loc);
211
+ const parseResult = commentParser.parseJsonConfig(directiveValue, comment.loc);
322
212
 
323
213
  if (parseResult.success) {
324
214
  Object.keys(parseResult.config).forEach(name => {
@@ -398,7 +288,7 @@ function findEslintEnv(text) {
398
288
  eslintEnvPattern.lastIndex = 0;
399
289
 
400
290
  while ((match = eslintEnvPattern.exec(text))) {
401
- retv = Object.assign(retv || {}, parseListConfig(match[1]));
291
+ retv = Object.assign(retv || {}, commentParser.parseListConfig(match[1]));
402
292
  }
403
293
 
404
294
  return retv;
@@ -1032,8 +922,6 @@ module.exports = class Linter {
1032
922
  * @param {(string|Object)} [filenameOrOptions] The optional filename of the file being checked.
1033
923
  * If this is not set, the filename will default to '<input>' in the rule context. If
1034
924
  * an object, then it has "filename", "saveState", and "allowInlineConfig" properties.
1035
- * @param {boolean} [saveState] Indicates if the state from the last run should be saved.
1036
- * Mostly useful for testing purposes.
1037
925
  * @param {boolean} [filenameOrOptions.allowInlineConfig] Allow/disallow inline comments' ability to change config once it is set. Defaults to true if not supplied.
1038
926
  * Useful if you want to validate JS without comments overriding rules.
1039
927
  * @param {function(string): string[]} [filenameOrOptions.preprocess] preprocessor for source text. If provided,
@@ -173,7 +173,6 @@ module.exports = {
173
173
  * Reports a given node if it violated this rule.
174
174
  *
175
175
  * @param {ASTNode} node - A node to check. This is an ObjectExpression node or an ObjectPattern node.
176
- * @param {{multiline: boolean, minItems: number}} options - An option object.
177
176
  * @returns {void}
178
177
  */
179
178
  function check(node) {
@@ -29,8 +29,8 @@ module.exports = {
29
29
  ],
30
30
 
31
31
  messages: {
32
- missing: "Requires a space {{location}} '{{token}}'",
33
- extra: "Unexpected space(s) {{location}} '{{token}}'"
32
+ missing: "Requires a space {{location}} '{{token}}'.",
33
+ extra: "Unexpected space(s) {{location}} '{{token}}'."
34
34
  }
35
35
  },
36
36
 
@@ -100,14 +100,20 @@ module.exports = {
100
100
  * @private
101
101
  */
102
102
  function isInsideObjectPattern(node) {
103
- let { parent } = node;
103
+ let current = node;
104
104
 
105
- while (parent) {
106
- if (parent.type === "ObjectPattern") {
105
+ while (current) {
106
+ const parent = current.parent;
107
+
108
+ if (parent && parent.type === "Property" && parent.computed && parent.key === current) {
109
+ return false;
110
+ }
111
+
112
+ if (current.type === "ObjectPattern") {
107
113
  return true;
108
114
  }
109
115
 
110
- parent = parent.parent;
116
+ current = parent;
111
117
  }
112
118
 
113
119
  return false;
@@ -132,9 +138,10 @@ module.exports = {
132
138
 
133
139
  /*
134
140
  * Leading and trailing underscores are commonly used to flag
135
- * private/protected identifiers, strip them
141
+ * private/protected identifiers, strip them before checking if underscored
136
142
  */
137
- const name = node.name.replace(/^_+|_+$/g, ""),
143
+ const name = node.name,
144
+ nameIsUnderscored = isUnderscored(name.replace(/^_+|_+$/g, "")),
138
145
  effectiveParent = (node.parent.type === "MemberExpression") ? node.parent.parent : node.parent;
139
146
 
140
147
  // First, we ignore the node if it match the ignore list
@@ -151,11 +158,11 @@ module.exports = {
151
158
  }
152
159
 
153
160
  // Always report underscored object names
154
- if (node.parent.object.type === "Identifier" && node.parent.object.name === node.name && isUnderscored(name)) {
161
+ if (node.parent.object.type === "Identifier" && node.parent.object.name === node.name && nameIsUnderscored) {
155
162
  report(node);
156
163
 
157
164
  // Report AssignmentExpressions only if they are the left side of the assignment
158
- } else if (effectiveParent.type === "AssignmentExpression" && isUnderscored(name) && (effectiveParent.right.type !== "MemberExpression" || effectiveParent.left.type === "MemberExpression" && effectiveParent.left.property.name === node.name)) {
165
+ } else if (effectiveParent.type === "AssignmentExpression" && nameIsUnderscored && (effectiveParent.right.type !== "MemberExpression" || effectiveParent.left.type === "MemberExpression" && effectiveParent.left.property.name === node.name)) {
159
166
  report(node);
160
167
  }
161
168
 
@@ -167,19 +174,22 @@ module.exports = {
167
174
  } else if (node.parent.type === "Property" || node.parent.type === "AssignmentPattern") {
168
175
 
169
176
  if (node.parent.parent && node.parent.parent.type === "ObjectPattern") {
170
- if (node.parent.shorthand && node.parent.value.left && isUnderscored(name)) {
171
-
177
+ if (node.parent.shorthand && node.parent.value.left && nameIsUnderscored) {
172
178
  report(node);
173
179
  }
174
180
 
175
181
  const assignmentKeyEqualsValue = node.parent.key.name === node.parent.value.name;
176
182
 
183
+ if (isUnderscored(name) && node.parent.computed) {
184
+ report(node);
185
+ }
186
+
177
187
  // prevent checking righthand side of destructured object
178
188
  if (node.parent.key === node && node.parent.value !== node) {
179
189
  return;
180
190
  }
181
191
 
182
- const valueIsUnderscored = node.parent.value.name && isUnderscored(name);
192
+ const valueIsUnderscored = node.parent.value.name && nameIsUnderscored;
183
193
 
184
194
  // ignore destructuring if the option is set, unless a new identifier is created
185
195
  if (valueIsUnderscored && !(assignmentKeyEqualsValue && ignoreDestructuring)) {
@@ -193,7 +203,7 @@ module.exports = {
193
203
  }
194
204
 
195
205
  // don't check right hand side of AssignmentExpression to prevent duplicate warnings
196
- if (isUnderscored(name) && !ALLOWED_PARENT_TYPES.has(effectiveParent.type) && !(node.parent.right === node)) {
206
+ if (nameIsUnderscored && !ALLOWED_PARENT_TYPES.has(effectiveParent.type) && !(node.parent.right === node)) {
197
207
  report(node);
198
208
  }
199
209
 
@@ -201,12 +211,12 @@ module.exports = {
201
211
  } else if (["ImportSpecifier", "ImportNamespaceSpecifier", "ImportDefaultSpecifier"].indexOf(node.parent.type) >= 0) {
202
212
 
203
213
  // Report only if the local imported identifier is underscored
204
- if (node.parent.local && node.parent.local.name === node.name && isUnderscored(name)) {
214
+ if (node.parent.local && node.parent.local.name === node.name && nameIsUnderscored) {
205
215
  report(node);
206
216
  }
207
217
 
208
218
  // Report anything that is underscored that isn't a CallExpression
209
- } else if (isUnderscored(name) && !ALLOWED_PARENT_TYPES.has(effectiveParent.type)) {
219
+ } else if (nameIsUnderscored && !ALLOWED_PARENT_TYPES.has(effectiveParent.type)) {
210
220
  report(node);
211
221
  }
212
222
  }
@@ -137,8 +137,8 @@ module.exports = {
137
137
  ],
138
138
 
139
139
  messages: {
140
- unexpectedLowercaseComment: "Comments should not begin with a lowercase character",
141
- unexpectedUppercaseComment: "Comments should not begin with an uppercase character"
140
+ unexpectedLowercaseComment: "Comments should not begin with a lowercase character.",
141
+ unexpectedUppercaseComment: "Comments should not begin with an uppercase character."
142
142
  }
143
143
  },
144
144
 
@@ -85,7 +85,7 @@ module.exports = {
85
85
  function getReplacedText(styleType, text) {
86
86
  switch (styleType) {
87
87
  case "between":
88
- return `,${text.replace("\n", "")}`;
88
+ return `,${text.replace(astUtils.LINEBREAK_MATCHER, "")}`;
89
89
 
90
90
  case "first":
91
91
  return `${text},`;
@@ -138,6 +138,11 @@ module.exports = {
138
138
  } else if (!astUtils.isTokenOnSameLine(commaToken, currentItemToken) &&
139
139
  !astUtils.isTokenOnSameLine(previousItemToken, commaToken)) {
140
140
 
141
+ const comment = sourceCode.getCommentsAfter(commaToken)[0];
142
+ const styleType = comment && comment.type === "Block" && astUtils.isTokenOnSameLine(commaToken, comment)
143
+ ? style
144
+ : "between";
145
+
141
146
  // lone comma
142
147
  context.report({
143
148
  node: reportItem,
@@ -146,7 +151,7 @@ module.exports = {
146
151
  column: commaToken.loc.start.column
147
152
  },
148
153
  messageId: "unexpectedLineBeforeAndAfterComma",
149
- fix: getFixerFunction("between", previousItemToken, commaToken, currentItemToken)
154
+ fix: getFixerFunction(styleType, previousItemToken, commaToken, currentItemToken)
150
155
  });
151
156
 
152
157
  } else if (style === "first" && !astUtils.isTokenOnSameLine(commaToken, currentItemToken)) {
@@ -119,7 +119,6 @@ module.exports = {
119
119
  /**
120
120
  * Gets the location (line and column) of the binary expression's operator
121
121
  * @param {ASTNode} node The binary expression node to check
122
- * @param {string} operator The operator to find
123
122
  * @returns {Object} { line, column } location of operator
124
123
  * @private
125
124
  */
@@ -92,10 +92,10 @@ module.exports = {
92
92
  },
93
93
 
94
94
  messages: {
95
- matchProperty: "Function name `{{funcName}}` should match property name `{{name}}`",
96
- matchVariable: "Function name `{{funcName}}` should match variable name `{{name}}`",
97
- notMatchProperty: "Function name `{{funcName}}` should not match property name `{{name}}`",
98
- notMatchVariable: "Function name `{{funcName}}` should not match variable name `{{name}}`"
95
+ matchProperty: "Function name `{{funcName}}` should match property name `{{name}}`.",
96
+ matchVariable: "Function name `{{funcName}}` should match variable name `{{name}}`.",
97
+ notMatchProperty: "Function name `{{funcName}}` should not match property name `{{name}}`.",
98
+ notMatchVariable: "Function name `{{funcName}}` should not match variable name `{{name}}`."
99
99
  }
100
100
  },
101
101
 
@@ -59,7 +59,7 @@ module.exports = {
59
59
  /**
60
60
  * Get the parameters of a given function scope.
61
61
  * @param {Object} scope The function scope.
62
- * @returns {array} All parameters of the given scope.
62
+ * @returns {Array} All parameters of the given scope.
63
63
  */
64
64
  function getParameters(scope) {
65
65
  return scope.variables.filter(variable => variable.defs[0] && variable.defs[0].type === "Parameter");