eslint 6.0.0-alpha.1 → 6.0.1

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 (246) hide show
  1. package/CHANGELOG.md +71 -0
  2. package/README.md +28 -21
  3. package/bin/eslint.js +2 -2
  4. package/conf/config-schema.js +38 -31
  5. package/conf/environments.js +1 -1
  6. package/conf/eslint-all.js +2 -2
  7. package/conf/eslint-recommended.js +1 -1
  8. package/lib/api.js +7 -3
  9. package/lib/cli-engine/cascading-config-array-factory.js +20 -8
  10. package/lib/{cli-engine.js → cli-engine/cli-engine.js} +44 -21
  11. package/lib/cli-engine/config-array/config-array.js +7 -8
  12. package/lib/cli-engine/config-array/config-dependency.js +2 -2
  13. package/lib/cli-engine/config-array/extracted-config.js +3 -3
  14. package/lib/cli-engine/config-array/override-tester.js +11 -1
  15. package/lib/cli-engine/config-array-factory.js +75 -65
  16. package/lib/cli-engine/file-enumerator.js +14 -6
  17. package/lib/{formatters → cli-engine/formatters}/checkstyle.js +1 -1
  18. package/lib/{formatters → cli-engine/formatters}/codeframe.js +0 -0
  19. package/lib/{formatters → cli-engine/formatters}/compact.js +0 -0
  20. package/lib/{formatters → cli-engine/formatters}/html-template-message.html +0 -0
  21. package/lib/{formatters → cli-engine/formatters}/html-template-page.html +0 -0
  22. package/lib/{formatters → cli-engine/formatters}/html-template-result.html +0 -0
  23. package/lib/{formatters → cli-engine/formatters}/html.js +0 -0
  24. package/lib/{formatters → cli-engine/formatters}/jslint-xml.js +1 -1
  25. package/lib/{formatters → cli-engine/formatters}/json-with-metadata.js +0 -0
  26. package/lib/{formatters → cli-engine/formatters}/json.js +0 -0
  27. package/lib/{formatters → cli-engine/formatters}/junit.js +15 -3
  28. package/lib/{formatters → cli-engine/formatters}/stylish.js +0 -0
  29. package/lib/{formatters → cli-engine/formatters}/table.js +0 -0
  30. package/lib/{formatters → cli-engine/formatters}/tap.js +0 -0
  31. package/lib/{formatters → cli-engine/formatters}/unix.js +0 -0
  32. package/lib/{formatters → cli-engine/formatters}/visualstudio.js +0 -0
  33. package/lib/{util → cli-engine}/hash.js +0 -0
  34. package/lib/{util → cli-engine}/ignored-paths.js +6 -1
  35. package/lib/cli-engine/index.js +7 -0
  36. package/lib/{util → cli-engine}/lint-result-cache.js +0 -0
  37. package/lib/{load-rules.js → cli-engine/load-rules.js} +0 -0
  38. package/lib/{util → cli-engine}/naming.js +0 -0
  39. package/lib/{util → cli-engine}/xml-escape.js +0 -0
  40. package/lib/cli.js +3 -3
  41. package/lib/{config → init}/autoconfig.js +3 -3
  42. package/lib/{config → init}/config-file.js +0 -0
  43. package/lib/{config → init}/config-initializer.js +6 -6
  44. package/lib/{config → init}/config-rule.js +8 -2
  45. package/lib/{util → init}/npm-utils.js +1 -1
  46. package/lib/{util → init}/source-code-utils.js +16 -1
  47. package/lib/{util → linter}/apply-disable-directives.js +0 -0
  48. package/lib/{code-path-analysis → linter/code-path-analysis}/code-path-analyzer.js +19 -6
  49. package/lib/{code-path-analysis → linter/code-path-analysis}/code-path-segment.js +0 -0
  50. package/lib/{code-path-analysis → linter/code-path-analysis}/code-path-state.js +0 -0
  51. package/lib/{code-path-analysis → linter/code-path-analysis}/code-path.js +0 -0
  52. package/lib/{code-path-analysis → linter/code-path-analysis}/debug-helpers.js +0 -0
  53. package/lib/{code-path-analysis → linter/code-path-analysis}/fork-context.js +0 -0
  54. package/lib/{code-path-analysis → linter/code-path-analysis}/id-generator.js +0 -0
  55. package/lib/{util → linter}/config-comment-parser.js +1 -1
  56. package/lib/linter/index.js +13 -0
  57. package/lib/{util → linter}/interpolate.js +0 -0
  58. package/lib/{linter.js → linter/linter.js} +298 -152
  59. package/lib/{util → linter}/node-event-generator.js +7 -5
  60. package/lib/{util → linter}/report-translator.js +0 -0
  61. package/lib/{util → linter}/rule-fixer.js +0 -0
  62. package/lib/{rules.js → linter/rules.js} +3 -29
  63. package/lib/{util → linter}/safe-emitter.js +0 -0
  64. package/lib/{util → linter}/source-code-fixer.js +0 -0
  65. package/lib/{util → linter}/timing.js +1 -1
  66. package/lib/rule-tester/index.js +5 -0
  67. package/lib/{testers → rule-tester}/rule-tester.js +43 -15
  68. package/lib/rules/array-bracket-newline.js +1 -1
  69. package/lib/rules/array-bracket-spacing.js +1 -1
  70. package/lib/rules/array-callback-return.js +1 -1
  71. package/lib/rules/array-element-newline.js +1 -1
  72. package/lib/rules/arrow-body-style.js +1 -1
  73. package/lib/rules/arrow-parens.js +22 -1
  74. package/lib/rules/arrow-spacing.js +1 -1
  75. package/lib/rules/block-spacing.js +1 -1
  76. package/lib/rules/brace-style.js +1 -1
  77. package/lib/rules/capitalized-comments.js +2 -2
  78. package/lib/rules/comma-dangle.js +1 -1
  79. package/lib/rules/comma-spacing.js +1 -1
  80. package/lib/rules/comma-style.js +1 -1
  81. package/lib/rules/complexity.js +3 -3
  82. package/lib/rules/computed-property-spacing.js +1 -1
  83. package/lib/rules/consistent-return.js +1 -1
  84. package/lib/rules/curly.js +1 -1
  85. package/lib/rules/dot-location.js +1 -1
  86. package/lib/rules/dot-notation.js +2 -2
  87. package/lib/rules/eqeqeq.js +1 -1
  88. package/lib/rules/func-call-spacing.js +1 -1
  89. package/lib/rules/func-name-matching.js +1 -1
  90. package/lib/rules/func-names.js +1 -1
  91. package/lib/rules/function-paren-newline.js +1 -1
  92. package/lib/rules/getter-return.js +1 -1
  93. package/lib/rules/implicit-arrow-linebreak.js +1 -1
  94. package/lib/rules/indent-legacy.js +1 -1
  95. package/lib/rules/indent.js +1 -1
  96. package/lib/rules/index.js +281 -0
  97. package/lib/rules/jsx-quotes.js +1 -1
  98. package/lib/rules/key-spacing.js +1 -1
  99. package/lib/rules/keyword-spacing.js +2 -2
  100. package/lib/rules/line-comment-position.js +1 -1
  101. package/lib/rules/linebreak-style.js +1 -1
  102. package/lib/rules/lines-around-comment.js +1 -1
  103. package/lib/rules/lines-around-directive.js +1 -1
  104. package/lib/rules/lines-between-class-members.js +1 -1
  105. package/lib/rules/max-classes-per-file.js +2 -1
  106. package/lib/rules/max-depth.js +2 -2
  107. package/lib/rules/max-len.js +11 -4
  108. package/lib/rules/max-lines-per-function.js +4 -2
  109. package/lib/rules/max-lines.js +2 -2
  110. package/lib/rules/max-params.js +1 -1
  111. package/lib/rules/max-statements-per-line.js +1 -1
  112. package/lib/rules/max-statements.js +1 -1
  113. package/lib/rules/multiline-comment-style.js +3 -2
  114. package/lib/rules/multiline-ternary.js +1 -1
  115. package/lib/rules/new-parens.js +43 -11
  116. package/lib/rules/newline-after-var.js +1 -1
  117. package/lib/rules/newline-per-chained-call.js +1 -1
  118. package/lib/rules/no-alert.js +1 -1
  119. package/lib/rules/no-catch-shadow.js +1 -1
  120. package/lib/rules/no-class-assign.js +1 -1
  121. package/lib/rules/no-cond-assign.js +1 -1
  122. package/lib/rules/no-confusing-arrow.js +1 -1
  123. package/lib/rules/no-console.js +1 -1
  124. package/lib/rules/no-const-assign.js +1 -1
  125. package/lib/rules/no-div-regex.js +9 -1
  126. package/lib/rules/no-dupe-keys.js +1 -1
  127. package/lib/rules/no-else-return.js +129 -2
  128. package/lib/rules/no-empty-function.js +1 -1
  129. package/lib/rules/no-empty.js +1 -1
  130. package/lib/rules/no-eval.js +1 -1
  131. package/lib/rules/no-ex-assign.js +1 -1
  132. package/lib/rules/no-extend-native.js +1 -1
  133. package/lib/rules/no-extra-bind.js +1 -1
  134. package/lib/rules/no-extra-boolean-cast.js +1 -1
  135. package/lib/rules/no-extra-label.js +1 -1
  136. package/lib/rules/no-extra-parens.js +1 -1
  137. package/lib/rules/no-extra-semi.js +2 -2
  138. package/lib/rules/no-floating-decimal.js +1 -1
  139. package/lib/rules/no-func-assign.js +1 -1
  140. package/lib/rules/no-implicit-coercion.js +1 -1
  141. package/lib/rules/no-inline-comments.js +1 -1
  142. package/lib/rules/no-invalid-this.js +1 -1
  143. package/lib/rules/no-irregular-whitespace.js +1 -1
  144. package/lib/rules/no-label-var.js +1 -1
  145. package/lib/rules/no-labels.js +1 -1
  146. package/lib/rules/no-misleading-character-class.js +1 -1
  147. package/lib/rules/no-mixed-operators.js +1 -1
  148. package/lib/rules/no-multi-spaces.js +1 -1
  149. package/lib/rules/no-multi-str.js +1 -1
  150. package/lib/rules/no-octal.js +1 -1
  151. package/lib/rules/no-redeclare.js +1 -1
  152. package/lib/rules/no-regex-spaces.js +1 -1
  153. package/lib/rules/no-restricted-imports.js +18 -14
  154. package/lib/rules/no-restricted-properties.js +1 -1
  155. package/lib/rules/no-return-assign.js +1 -1
  156. package/lib/rules/no-return-await.js +1 -1
  157. package/lib/rules/no-self-assign.js +1 -1
  158. package/lib/rules/no-sequences.js +1 -1
  159. package/lib/rules/no-shadow.js +1 -1
  160. package/lib/rules/no-this-before-super.js +1 -1
  161. package/lib/rules/no-throw-literal.js +1 -1
  162. package/lib/rules/no-trailing-spaces.js +1 -1
  163. package/lib/rules/no-undef-init.js +1 -1
  164. package/lib/rules/no-unexpected-multiline.js +1 -1
  165. package/lib/rules/no-unmodified-loop-condition.js +2 -2
  166. package/lib/rules/no-unneeded-ternary.js +1 -1
  167. package/lib/rules/no-unsafe-negation.js +1 -1
  168. package/lib/rules/no-unused-vars.js +1 -1
  169. package/lib/rules/no-useless-call.js +1 -1
  170. package/lib/rules/no-useless-computed-key.js +1 -1
  171. package/lib/rules/no-useless-concat.js +1 -1
  172. package/lib/rules/no-useless-escape.js +7 -2
  173. package/lib/rules/no-useless-return.js +2 -2
  174. package/lib/rules/no-var.js +15 -2
  175. package/lib/rules/no-warning-comments.js +1 -1
  176. package/lib/rules/no-whitespace-before-property.js +1 -1
  177. package/lib/rules/object-curly-newline.js +1 -1
  178. package/lib/rules/object-curly-spacing.js +1 -1
  179. package/lib/rules/object-shorthand.js +1 -1
  180. package/lib/rules/operator-assignment.js +1 -1
  181. package/lib/rules/operator-linebreak.js +1 -1
  182. package/lib/rules/padded-blocks.js +1 -1
  183. package/lib/rules/padding-line-between-statements.js +1 -1
  184. package/lib/rules/prefer-const.js +1 -1
  185. package/lib/rules/prefer-object-spread.js +1 -1
  186. package/lib/rules/prefer-promise-reject-errors.js +1 -1
  187. package/lib/rules/prefer-spread.js +1 -1
  188. package/lib/rules/prefer-template.js +1 -1
  189. package/lib/rules/quote-props.js +1 -1
  190. package/lib/rules/quotes.js +1 -1
  191. package/lib/rules/radix.js +1 -1
  192. package/lib/rules/require-atomic-updates.js +63 -84
  193. package/lib/rules/require-await.js +1 -1
  194. package/lib/rules/semi-spacing.js +1 -1
  195. package/lib/rules/semi-style.js +1 -1
  196. package/lib/rules/semi.js +2 -2
  197. package/lib/rules/sort-keys.js +12 -4
  198. package/lib/rules/space-before-blocks.js +1 -1
  199. package/lib/rules/space-before-function-paren.js +1 -1
  200. package/lib/rules/space-in-parens.js +1 -1
  201. package/lib/rules/space-unary-ops.js +1 -1
  202. package/lib/rules/spaced-comment.js +1 -1
  203. package/lib/rules/strict.js +1 -1
  204. package/lib/rules/switch-colon-spacing.js +1 -1
  205. package/lib/rules/symbol-description.js +1 -1
  206. package/lib/rules/template-curly-spacing.js +1 -1
  207. package/lib/{util → rules/utils}/ast-utils.js +8 -27
  208. package/lib/{util → rules/utils}/fix-tracker.js +1 -1
  209. package/lib/{util → rules/utils}/keywords.js +0 -0
  210. package/lib/{util → rules/utils}/lazy-loading-rule-map.js +0 -0
  211. package/lib/{util → rules/utils}/patterns/letters.js +0 -0
  212. package/lib/{util → rules/utils}/unicode/index.js +0 -0
  213. package/lib/{util → rules/utils}/unicode/is-combining-character.js +0 -0
  214. package/lib/{util → rules/utils}/unicode/is-emoji-modifier.js +0 -0
  215. package/lib/{util → rules/utils}/unicode/is-regional-indicator-symbol.js +0 -0
  216. package/lib/{util → rules/utils}/unicode/is-surrogate-pair.js +0 -0
  217. package/lib/rules/valid-typeof.js +1 -1
  218. package/lib/rules/wrap-iife.js +1 -1
  219. package/lib/rules/yoda.js +1 -1
  220. package/lib/{util → shared}/ajv.js +0 -0
  221. package/lib/shared/ast-utils.js +29 -0
  222. package/lib/{config → shared}/config-ops.js +0 -0
  223. package/lib/{config → shared}/config-validator.js +22 -7
  224. package/lib/{util → shared}/logging.js +0 -0
  225. package/lib/{util → shared}/relative-module-resolver.js +10 -3
  226. package/lib/{util → shared}/traverser.js +0 -0
  227. package/lib/{util → shared}/types.js +4 -0
  228. package/lib/source-code/index.js +5 -0
  229. package/lib/{util → source-code}/source-code.js +10 -8
  230. package/lib/{token-store → source-code/token-store}/backward-token-comment-cursor.js +0 -0
  231. package/lib/{token-store → source-code/token-store}/backward-token-cursor.js +0 -0
  232. package/lib/{token-store → source-code/token-store}/cursor.js +0 -0
  233. package/lib/{token-store → source-code/token-store}/cursors.js +0 -0
  234. package/lib/{token-store → source-code/token-store}/decorative-cursor.js +0 -0
  235. package/lib/{token-store → source-code/token-store}/filter-cursor.js +0 -0
  236. package/lib/{token-store → source-code/token-store}/forward-token-comment-cursor.js +0 -0
  237. package/lib/{token-store → source-code/token-store}/forward-token-cursor.js +0 -0
  238. package/lib/{token-store → source-code/token-store}/index.js +3 -3
  239. package/lib/{token-store → source-code/token-store}/limit-cursor.js +0 -0
  240. package/lib/{token-store → source-code/token-store}/padded-token-cursor.js +0 -0
  241. package/lib/{token-store → source-code/token-store}/skip-cursor.js +0 -0
  242. package/lib/{token-store → source-code/token-store}/utils.js +0 -0
  243. package/messages/extend-config-missing.txt +2 -0
  244. package/messages/print-config-with-directory-path.txt +2 -0
  245. package/package.json +8 -11
  246. package/lib/built-in-rules-index.js +0 -281
@@ -108,7 +108,7 @@ class ConfigDependency {
108
108
  }
109
109
  }
110
110
 
111
- /** @typedef {ConfigDependency<import("../../util/types").Parser>} DependentParser */
112
- /** @typedef {ConfigDependency<import("../../util/types").Plugin>} DependentPlugin */
111
+ /** @typedef {ConfigDependency<import("../../shared/types").Parser>} DependentParser */
112
+ /** @typedef {ConfigDependency<import("../../shared/types").Plugin>} DependentPlugin */
113
113
 
114
114
  module.exports = { ConfigDependency };
@@ -17,9 +17,9 @@
17
17
  "use strict";
18
18
 
19
19
  // For VSCode intellisense
20
- /** @typedef {import("../../util/types").ConfigData} ConfigData */
21
- /** @typedef {import("../../util/types").GlobalConf} GlobalConf */
22
- /** @typedef {import("../../util/types").SeverityConf} SeverityConf */
20
+ /** @typedef {import("../../shared/types").ConfigData} ConfigData */
21
+ /** @typedef {import("../../shared/types").GlobalConf} GlobalConf */
22
+ /** @typedef {import("../../shared/types").SeverityConf} SeverityConf */
23
23
  /** @typedef {import("./config-dependency").DependentParser} DependentParser */
24
24
  /** @typedef {import("./config-dependency").DependentPlugin} DependentPlugin */
25
25
 
@@ -55,7 +55,17 @@ function toMatcher(patterns) {
55
55
  if (patterns.length === 0) {
56
56
  return null;
57
57
  }
58
- return patterns.map(pattern => new Minimatch(pattern, minimatchOpts));
58
+ return patterns.map(pattern => {
59
+ if (/^\.[/\\]/u.test(pattern)) {
60
+ return new Minimatch(
61
+ pattern.slice(2),
62
+
63
+ // `./*.js` should not match with `subdir/foo.js`
64
+ { ...minimatchOpts, matchBase: false }
65
+ );
66
+ }
67
+ return new Minimatch(pattern, minimatchOpts);
68
+ });
59
69
  }
60
70
 
61
71
  /**
@@ -37,10 +37,10 @@ const fs = require("fs");
37
37
  const path = require("path");
38
38
  const importFresh = require("import-fresh");
39
39
  const stripComments = require("strip-json-comments");
40
- const { validateConfigSchema } = require("../config/config-validator");
40
+ const { validateConfigSchema } = require("../shared/config-validator");
41
+ const ModuleResolver = require("../shared/relative-module-resolver");
41
42
  const { ConfigArray, ConfigDependency, OverrideTester } = require("./config-array");
42
- const ModuleResolver = require("../util/relative-module-resolver");
43
- const naming = require("../util/naming");
43
+ const naming = require("./naming");
44
44
  const debug = require("debug")("eslint:config-array-factory");
45
45
 
46
46
  //------------------------------------------------------------------------------
@@ -59,10 +59,10 @@ const configFilenames = [
59
59
  ];
60
60
 
61
61
  // Define types for VSCode IntelliSense.
62
- /** @typedef {import("../util/types").ConfigData} ConfigData */
63
- /** @typedef {import("../util/types").OverrideConfigData} OverrideConfigData */
64
- /** @typedef {import("../util/types").Parser} Parser */
65
- /** @typedef {import("../util/types").Plugin} Plugin */
62
+ /** @typedef {import("../shared/types").ConfigData} ConfigData */
63
+ /** @typedef {import("../shared/types").OverrideConfigData} OverrideConfigData */
64
+ /** @typedef {import("../shared/types").Parser} Parser */
65
+ /** @typedef {import("../shared/types").Plugin} Plugin */
66
66
  /** @typedef {import("./config-array/config-dependency").DependentParser} DependentParser */
67
67
  /** @typedef {import("./config-array/config-dependency").DependentPlugin} DependentPlugin */
68
68
  /** @typedef {ConfigArray[0]} ConfigArrayElement */
@@ -224,15 +224,16 @@ function loadPackageJSONConfigFile(filePath) {
224
224
  /**
225
225
  * Creates an error to notify about a missing config to extend from.
226
226
  * @param {string} configName The name of the missing config.
227
+ * @param {string} importerName The name of the config that imported the missing config
227
228
  * @returns {Error} The error object to throw
228
229
  * @private
229
230
  */
230
- function configMissingError(configName) {
231
+ function configMissingError(configName, importerName) {
231
232
  return Object.assign(
232
233
  new Error(`Failed to load config "${configName}" to extend from.`),
233
234
  {
234
235
  messageTemplate: "extend-config-missing",
235
- messageData: { configName }
236
+ messageData: { configName, importerName }
236
237
  }
237
238
  );
238
239
  }
@@ -427,28 +428,22 @@ class ConfigArrayFactory {
427
428
  _loadConfigDataInDirectory(directoryPath, name) {
428
429
  for (const filename of configFilenames) {
429
430
  const filePath = path.join(directoryPath, filename);
430
- const originalDebugEnabled = debug.enabled;
431
- let configData;
432
431
 
433
- // Make silent temporary because of too verbose.
434
- debug.enabled = false;
435
- try {
436
- configData = loadConfigFile(filePath);
437
- } catch (error) {
438
- if (
439
- error.code !== "ENOENT" &&
440
- error.code !== "MODULE_NOT_FOUND" &&
441
- error.code !== "ESLINT_CONFIG_FIELD_NOT_FOUND"
442
- ) {
443
- throw error;
432
+ if (fs.existsSync(filePath)) {
433
+ let configData;
434
+
435
+ try {
436
+ configData = loadConfigFile(filePath);
437
+ } catch (error) {
438
+ if (!error || error.code !== "ESLINT_CONFIG_FIELD_NOT_FOUND") {
439
+ throw error;
440
+ }
444
441
  }
445
- } finally {
446
- debug.enabled = originalDebugEnabled;
447
- }
448
442
 
449
- if (configData) {
450
- debug(`Config file found: ${filePath}`);
451
- return this._normalizeConfigData(configData, filePath, name);
443
+ if (configData) {
444
+ debug(`Config file found: ${filePath}`);
445
+ return this._normalizeConfigData(configData, filePath, name);
446
+ }
452
447
  }
453
448
  }
454
449
 
@@ -506,6 +501,14 @@ class ConfigArrayFactory {
506
501
  */
507
502
  element.criteria = OverrideTester.and(criteria, element.criteria);
508
503
 
504
+ /*
505
+ * Remove `root` property to ignore `root` settings which came from
506
+ * `extends` in `overrides`.
507
+ */
508
+ if (element.criteria) {
509
+ element.root = void 0;
510
+ }
511
+
509
512
  yield element;
510
513
  }
511
514
  }
@@ -526,7 +529,7 @@ class ConfigArrayFactory {
526
529
  parser: parserName,
527
530
  parserOptions,
528
531
  plugins: pluginList,
529
- processor, // processor is only for file extension processors.
532
+ processor,
530
533
  root,
531
534
  rules,
532
535
  settings,
@@ -635,7 +638,7 @@ class ConfigArrayFactory {
635
638
  return this._loadConfigData(eslintAllPath, name);
636
639
  }
637
640
 
638
- throw configMissingError(extendName);
641
+ throw configMissingError(extendName, importerName);
639
642
  }
640
643
 
641
644
  /**
@@ -668,7 +671,7 @@ class ConfigArrayFactory {
668
671
  );
669
672
  }
670
673
 
671
- throw plugin.error || configMissingError(extendName);
674
+ throw plugin.error || configMissingError(extendName, importerPath);
672
675
  }
673
676
 
674
677
  /**
@@ -695,20 +698,20 @@ class ConfigArrayFactory {
695
698
  );
696
699
  }
697
700
 
698
- try {
699
- const filePath = ModuleResolver.resolve(request, relativeTo);
700
-
701
- writeDebugLogForLoading(request, relativeTo, filePath);
701
+ let filePath;
702
702
 
703
- return this._loadConfigData(filePath, `${importerName} » ${request}`);
703
+ try {
704
+ filePath = ModuleResolver.resolve(request, relativeTo);
704
705
  } catch (error) {
705
- /* istanbul ignore next */
706
- if (!error || error.code !== "MODULE_NOT_FOUND") {
707
- throw error;
706
+ /* istanbul ignore else */
707
+ if (error && error.code === "MODULE_NOT_FOUND") {
708
+ throw configMissingError(extendName, importerPath);
708
709
  }
710
+ throw error;
709
711
  }
710
712
 
711
- throw configMissingError(extendName);
713
+ writeDebugLogForLoading(request, relativeTo, filePath);
714
+ return this._loadConfigData(filePath, `${importerName} » ${request}`);
712
715
  }
713
716
 
714
717
  /**
@@ -797,6 +800,7 @@ class ConfigArrayFactory {
797
800
  const { additionalPluginPool, resolvePluginsRelativeTo } = internalSlotsMap.get(this);
798
801
  const request = naming.normalizePackageName(name, "eslint-plugin");
799
802
  const id = naming.getShorthandName(request, "eslint-plugin");
803
+ const relativeTo = path.join(resolvePluginsRelativeTo, "__placeholder__.js");
800
804
 
801
805
  if (name.match(/\s+/u)) {
802
806
  const error = Object.assign(
@@ -830,25 +834,15 @@ class ConfigArrayFactory {
830
834
  });
831
835
  }
832
836
 
833
- try {
834
-
835
- // Resolve the plugin file
836
- const relativeTo = path.join(resolvePluginsRelativeTo, "__placeholder__.js");
837
- const filePath = ModuleResolver.resolve(request, relativeTo);
838
-
839
- writeDebugLogForLoading(request, relativeTo, filePath);
840
-
841
- return new ConfigDependency({
842
- definition: normalizePlugin(require(filePath)),
843
- filePath,
844
- id,
845
- importerName,
846
- importerPath
847
- });
848
- } catch (error) {
849
- debug("Failed to load plugin '%s' declared in '%s'.", name, importerName);
837
+ let filePath;
838
+ let error;
850
839
 
851
- if (error && error.code === "MODULE_NOT_FOUND" && error.message.includes(request)) {
840
+ try {
841
+ filePath = ModuleResolver.resolve(request, relativeTo);
842
+ } catch (resolveError) {
843
+ error = resolveError;
844
+ /* istanbul ignore else */
845
+ if (error && error.code === "MODULE_NOT_FOUND") {
852
846
  error.messageTemplate = "plugin-missing";
853
847
  error.messageData = {
854
848
  pluginName: request,
@@ -856,15 +850,31 @@ class ConfigArrayFactory {
856
850
  importerName
857
851
  };
858
852
  }
859
- error.message = `Failed to load plugin '${name}' declared in '${importerName}': ${error.message}`;
853
+ }
860
854
 
861
- return new ConfigDependency({
862
- error,
863
- id,
864
- importerName,
865
- importerPath
866
- });
855
+ if (filePath) {
856
+ try {
857
+ writeDebugLogForLoading(request, relativeTo, filePath);
858
+ return new ConfigDependency({
859
+ definition: normalizePlugin(require(filePath)),
860
+ filePath,
861
+ id,
862
+ importerName,
863
+ importerPath
864
+ });
865
+ } catch (loadError) {
866
+ error = loadError;
867
+ }
867
868
  }
869
+
870
+ debug("Failed to load plugin '%s' declared in '%s'.", name, importerName);
871
+ error.message = `Failed to load plugin '${name}' declared in '${importerName}': ${error.message}`;
872
+ return new ConfigDependency({
873
+ error,
874
+ id,
875
+ importerName,
876
+ importerPath
877
+ });
868
878
  }
869
879
 
870
880
  /**
@@ -41,7 +41,7 @@ const isGlob = require("is-glob");
41
41
  const { escapeRegExp } = require("lodash");
42
42
  const { Minimatch } = require("minimatch");
43
43
  const { CascadingConfigArrayFactory } = require("./cascading-config-array-factory");
44
- const { IgnoredPaths } = require("../util/ignored-paths");
44
+ const { IgnoredPaths } = require("./ignored-paths");
45
45
  const debug = require("debug")("eslint:file-enumerator");
46
46
 
47
47
  //------------------------------------------------------------------------------
@@ -89,7 +89,7 @@ const IGNORED = 2;
89
89
  * @typedef {Object} FileEnumeratorInternalSlots
90
90
  * @property {CascadingConfigArrayFactory} configArrayFactory The factory for config arrays.
91
91
  * @property {string} cwd The base directory to start lookup.
92
- * @property {RegExp} extRegExp The RegExp to test if a string ends with specific file extensions.
92
+ * @property {RegExp} extensionRegExp The RegExp to test if a string ends with specific file extensions.
93
93
  * @property {boolean} globInputPaths Set to false to skip glob resolution of input file paths to lint (default: true). If false, each input file paths is assumed to be a non-glob path to an existing file.
94
94
  * @property {boolean} ignoreFlag The flag to check ignored files.
95
95
  * @property {IgnoredPaths} ignoredPathsWithDotfiles The ignored paths but don't include dot files.
@@ -196,7 +196,7 @@ class FileEnumerator {
196
196
  internalSlotsMap.set(this, {
197
197
  configArrayFactory,
198
198
  cwd,
199
- extRegExp: new RegExp(
199
+ extensionRegExp: new RegExp(
200
200
  `.\\.(?:${extensions
201
201
  .map(ext => escapeRegExp(
202
202
  ext.startsWith(".")
@@ -217,6 +217,14 @@ class FileEnumerator {
217
217
  });
218
218
  }
219
219
 
220
+ /**
221
+ * The `RegExp` object that tests if a file path has the allowed file extensions.
222
+ * @type {RegExp}
223
+ */
224
+ get extensionRegExp() {
225
+ return internalSlotsMap.get(this).extensionRegExp;
226
+ }
227
+
220
228
  /**
221
229
  * Iterate files which are matched by given glob patterns.
222
230
  * @param {string|string[]} patternOrPatterns The glob patterns to iterate files.
@@ -380,11 +388,11 @@ class FileEnumerator {
380
388
  * @private
381
389
  */
382
390
  *_iterateFilesRecursive(directoryPath, options) {
383
- if (this._isIgnoredFile(directoryPath, options)) {
391
+ if (this._isIgnoredFile(directoryPath + path.sep, options)) {
384
392
  return;
385
393
  }
386
394
  debug(`Enter the directory: ${directoryPath}`);
387
- const { configArrayFactory, extRegExp } = internalSlotsMap.get(this);
395
+ const { configArrayFactory, extensionRegExp } = internalSlotsMap.get(this);
388
396
 
389
397
  /** @type {ConfigArray|null} */
390
398
  let config = null;
@@ -407,7 +415,7 @@ class FileEnumerator {
407
415
  ? options.selector.match(filePath)
408
416
 
409
417
  // Started with a directory path; choose by file extensions.
410
- : extRegExp.test(filePath);
418
+ : extensionRegExp.test(filePath);
411
419
 
412
420
  if (matched) {
413
421
  debug(`Yield: ${filename}${ignored ? " but ignored" : ""}`);
@@ -4,7 +4,7 @@
4
4
  */
5
5
  "use strict";
6
6
 
7
- const xmlEscape = require("../util/xml-escape");
7
+ const xmlEscape = require("../xml-escape");
8
8
 
9
9
  //------------------------------------------------------------------------------
10
10
  // Helper Functions
@@ -4,7 +4,7 @@
4
4
  */
5
5
  "use strict";
6
6
 
7
- const xmlEscape = require("../util/xml-escape");
7
+ const xmlEscape = require("../xml-escape");
8
8
 
9
9
  //------------------------------------------------------------------------------
10
10
  // Public Interface
@@ -4,7 +4,8 @@
4
4
  */
5
5
  "use strict";
6
6
 
7
- const xmlEscape = require("../util/xml-escape");
7
+ const xmlEscape = require("../xml-escape");
8
+ const path = require("path");
8
9
 
9
10
  //------------------------------------------------------------------------------
10
11
  // Helper Functions
@@ -24,6 +25,16 @@ function getMessageType(message) {
24
25
 
25
26
  }
26
27
 
28
+ /**
29
+ * Returns a full file path without extension
30
+ * @param {string} filePath input file path
31
+ * @returns {string} file path without extension
32
+ * @private
33
+ */
34
+ function pathWithoutExt(filePath) {
35
+ return path.posix.join(path.posix.dirname(filePath), path.basename(filePath, path.extname(filePath)));
36
+ }
37
+
27
38
  //------------------------------------------------------------------------------
28
39
  // Public Interface
29
40
  //------------------------------------------------------------------------------
@@ -38,13 +49,14 @@ module.exports = function(results) {
38
49
  results.forEach(result => {
39
50
 
40
51
  const messages = result.messages;
52
+ const classname = pathWithoutExt(result.filePath);
41
53
 
42
54
  if (messages.length > 0) {
43
55
  output += `<testsuite package="org.eslint" time="0" tests="${messages.length}" errors="${messages.length}" name="${result.filePath}">\n`;
44
56
  messages.forEach(message => {
45
57
  const type = message.fatal ? "error" : "failure";
46
58
 
47
- output += `<testcase time="0" name="org.eslint.${message.ruleId || "unknown"}">`;
59
+ output += `<testcase time="0" name="org.eslint.${message.ruleId || "unknown"}" classname="${classname}">`;
48
60
  output += `<${type} message="${xmlEscape(message.message || "")}">`;
49
61
  output += "<![CDATA[";
50
62
  output += `line ${message.line || 0}, col `;
@@ -58,7 +70,7 @@ module.exports = function(results) {
58
70
  output += "</testsuite>\n";
59
71
  } else {
60
72
  output += `<testsuite package="org.eslint" time="0" tests="1" errors="0" name="${result.filePath}">\n`;
61
- output += `<testcase time="0" name="${result.filePath}" />\n`;
73
+ output += `<testcase time="0" name="${result.filePath}" classname="${classname}" />\n`;
62
74
  output += "</testsuite>\n";
63
75
  }
64
76
 
File without changes
File without changes
@@ -328,12 +328,17 @@ class IgnoredPaths {
328
328
  * @returns {boolean} true if the file path matches one or more patterns, false otherwise
329
329
  */
330
330
  contains(filepath, category) {
331
+ const isDir = filepath.endsWith(path.sep) ||
332
+ (path.sep === "\\" && filepath.endsWith("/"));
331
333
  let result = false;
332
334
  const basePath = this.getBaseDir();
333
335
  const absolutePath = path.resolve(this.options.cwd, filepath);
334
- const relativePath = path.relative(basePath, absolutePath);
336
+ let relativePath = path.relative(basePath, absolutePath);
335
337
 
336
338
  if (relativePath) {
339
+ if (isDir) {
340
+ relativePath += path.sep;
341
+ }
337
342
  if (typeof category === "undefined") {
338
343
  result =
339
344
  (this.ig.default.filter([relativePath]).length === 0) ||
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ const { CLIEngine } = require("./cli-engine");
4
+
5
+ module.exports = {
6
+ CLIEngine
7
+ };
File without changes
File without changes
File without changes
File without changes
package/lib/cli.js CHANGED
@@ -17,10 +17,10 @@
17
17
 
18
18
  const fs = require("fs"),
19
19
  path = require("path"),
20
- options = require("./options"),
21
- CLIEngine = require("./cli-engine").CLIEngine,
22
20
  mkdirp = require("mkdirp"),
23
- log = require("./util/logging");
21
+ { CLIEngine } = require("./cli-engine"),
22
+ options = require("./options"),
23
+ log = require("./shared/logging");
24
24
 
25
25
  const debug = require("debug")("eslint:cli");
26
26
 
@@ -10,10 +10,10 @@
10
10
  //------------------------------------------------------------------------------
11
11
 
12
12
  const lodash = require("lodash"),
13
+ recConfig = require("../../conf/eslint-recommended"),
14
+ ConfigOps = require("../shared/config-ops"),
13
15
  { Linter } = require("../linter"),
14
- configRule = require("./config-rule"),
15
- ConfigOps = require("./config-ops"),
16
- recConfig = require("../../conf/eslint-recommended");
16
+ configRule = require("./config-rule");
17
17
 
18
18
  const debug = require("debug")("eslint:autoconfig");
19
19
  const linter = new Linter();
File without changes
@@ -15,14 +15,14 @@ const util = require("util"),
15
15
  inquirer = require("inquirer"),
16
16
  ProgressBar = require("progress"),
17
17
  semver = require("semver"),
18
+ recConfig = require("../../conf/eslint-recommended"),
19
+ ConfigOps = require("../shared/config-ops"),
20
+ log = require("../shared/logging"),
21
+ ModuleResolver = require("../shared/relative-module-resolver"),
18
22
  autoconfig = require("./autoconfig.js"),
19
23
  ConfigFile = require("./config-file"),
20
- ConfigOps = require("./config-ops"),
21
- { getSourceCodeOfFiles } = require("../util/source-code-utils"),
22
- ModuleResolver = require("../util/relative-module-resolver"),
23
- npmUtils = require("../util/npm-utils"),
24
- recConfig = require("../../conf/eslint-recommended"),
25
- log = require("../util/logging");
24
+ npmUtils = require("./npm-utils"),
25
+ { getSourceCodeOfFiles } = require("./source-code-utils");
26
26
 
27
27
  const debug = require("debug")("eslint:config-initializer");
28
28
 
@@ -9,7 +9,7 @@
9
9
  // Requirements
10
10
  //------------------------------------------------------------------------------
11
11
 
12
- const builtInRules = require("../built-in-rules-index");
12
+ const builtInRules = require("../rules");
13
13
 
14
14
  //------------------------------------------------------------------------------
15
15
  // Helpers
@@ -293,11 +293,17 @@ function generateConfigsFromSchema(schema) {
293
293
 
294
294
  /**
295
295
  * Generate possible rule configurations for all of the core rules
296
+ * @param {boolean} noDeprecated Indicates whether ignores deprecated rules or not.
296
297
  * @returns {rulesConfig} Hash of rule names and arrays of possible configurations
297
298
  */
298
- function createCoreRuleConfigs() {
299
+ function createCoreRuleConfigs(noDeprecated = false) {
299
300
  return Array.from(builtInRules).reduce((accumulator, [id, rule]) => {
300
301
  const schema = (typeof rule === "function") ? rule.schema : rule.meta.schema;
302
+ const isDeprecated = (typeof rule === "function") ? rule.deprecated : rule.meta.deprecated;
303
+
304
+ if (noDeprecated && isDeprecated) {
305
+ return accumulator;
306
+ }
301
307
 
302
308
  accumulator[id] = generateConfigsFromSchema(schema);
303
309
  return accumulator;
@@ -12,7 +12,7 @@
12
12
  const fs = require("fs"),
13
13
  spawn = require("cross-spawn"),
14
14
  path = require("path"),
15
- log = require("./logging");
15
+ log = require("../shared/logging");
16
16
 
17
17
  //------------------------------------------------------------------------------
18
18
  // Helpers
@@ -9,7 +9,22 @@
9
9
  // Requirements
10
10
  //------------------------------------------------------------------------------
11
11
 
12
- const { CLIEngine, getCLIEngineInternalSlots } = require("../cli-engine");
12
+ const { CLIEngine } = require("../cli-engine");
13
+
14
+ /*
15
+ * This is used for:
16
+ *
17
+ * 1. Enumerate target file because we have not expose such a API on `CLIEngine`
18
+ * (https://github.com/eslint/eslint/issues/11222).
19
+ * 2. Create `SourceCode` instances. Because we don't have any function which
20
+ * instantiate `SourceCode` so it needs to take the created `SourceCode`
21
+ * instance out after linting.
22
+ *
23
+ * TODO1: Expose the API that enumerates target files.
24
+ * TODO2: Extract the creation logic of `SourceCode` from `Linter` class.
25
+ */
26
+ const { getCLIEngineInternalSlots } = require("../cli-engine/cli-engine"); // eslint-disable-line no-restricted-modules
27
+
13
28
  const debug = require("debug")("eslint:source-code-utils");
14
29
 
15
30
  //------------------------------------------------------------------------------
File without changes