eslint 4.18.0 → 4.19.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 (65) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/README.md +2 -2
  3. package/conf/environments.js +3 -1
  4. package/conf/eslint-recommended.js +0 -0
  5. package/lib/ast-utils.js +25 -29
  6. package/lib/cli-engine.js +29 -28
  7. package/lib/code-path-analysis/code-path-state.js +5 -5
  8. package/lib/code-path-analysis/code-path.js +11 -6
  9. package/lib/code-path-analysis/fork-context.js +10 -12
  10. package/lib/config/config-file.js +20 -11
  11. package/lib/config/config-ops.js +8 -10
  12. package/lib/config/config-rule.js +2 -3
  13. package/lib/config/plugins.js +20 -0
  14. package/lib/config.js +7 -8
  15. package/lib/file-finder.js +9 -10
  16. package/lib/ignored-paths.js +4 -4
  17. package/lib/linter.js +397 -406
  18. package/lib/load-rules.js +6 -7
  19. package/lib/rules/accessor-pairs.js +4 -4
  20. package/lib/rules/array-callback-return.js +8 -6
  21. package/lib/rules/array-element-newline.js +4 -4
  22. package/lib/rules/curly.js +11 -10
  23. package/lib/rules/generator-star-spacing.js +1 -2
  24. package/lib/rules/indent-legacy.js +7 -10
  25. package/lib/rules/indent.js +51 -29
  26. package/lib/rules/keyword-spacing.js +6 -18
  27. package/lib/rules/max-len.js +12 -5
  28. package/lib/rules/no-await-in-loop.js +1 -1
  29. package/lib/rules/no-buffer-constructor.js +1 -1
  30. package/lib/rules/no-control-regex.js +51 -72
  31. package/lib/rules/no-else-return.js +7 -6
  32. package/lib/rules/no-empty-character-class.js +1 -1
  33. package/lib/rules/no-eval.js +7 -8
  34. package/lib/rules/no-extra-parens.js +5 -4
  35. package/lib/rules/no-implicit-coercion.js +6 -9
  36. package/lib/rules/no-invalid-regexp.js +53 -36
  37. package/lib/rules/no-irregular-whitespace.js +1 -1
  38. package/lib/rules/no-loop-func.js +9 -11
  39. package/lib/rules/no-magic-numbers.js +17 -10
  40. package/lib/rules/no-return-assign.js +4 -3
  41. package/lib/rules/no-unexpected-multiline.js +1 -1
  42. package/lib/rules/no-unsafe-finally.js +7 -4
  43. package/lib/rules/no-useless-escape.js +2 -2
  44. package/lib/rules/no-useless-return.js +10 -9
  45. package/lib/rules/no-var.js +8 -8
  46. package/lib/rules/object-curly-newline.js +2 -1
  47. package/lib/rules/one-var.js +140 -97
  48. package/lib/rules/padding-line-between-statements.js +6 -4
  49. package/lib/rules/prefer-arrow-callback.js +5 -4
  50. package/lib/rules/prefer-template.js +5 -3
  51. package/lib/rules/space-unary-ops.js +1 -3
  52. package/lib/rules/spaced-comment.js +3 -7
  53. package/lib/rules/template-tag-spacing.js +0 -0
  54. package/lib/rules/valid-jsdoc.js +6 -6
  55. package/lib/rules/vars-on-top.js +7 -17
  56. package/lib/timing.js +3 -5
  57. package/lib/util/glob-util.js +11 -11
  58. package/lib/util/interpolate.js +5 -1
  59. package/lib/util/naming.js +11 -10
  60. package/lib/util/npm-util.js +4 -6
  61. package/lib/util/path-util.js +6 -8
  62. package/lib/util/source-code-util.js +23 -26
  63. package/lib/util/source-code.js +4 -3
  64. package/package.json +4 -3
  65. package/conf/default-config-options.js +0 -29
@@ -48,20 +48,18 @@ function convertPathToPosix(filepath) {
48
48
  * @returns {string} Relative filepath
49
49
  */
50
50
  function getRelativePath(filepath, baseDir) {
51
- let relativePath;
51
+ const absolutePath = path.isAbsolute(filepath)
52
+ ? filepath
53
+ : path.resolve(filepath);
52
54
 
53
- if (!path.isAbsolute(filepath)) {
54
- filepath = path.resolve(filepath);
55
- }
56
55
  if (baseDir) {
57
56
  if (!path.isAbsolute(baseDir)) {
58
57
  throw new Error("baseDir should be an absolute path");
59
58
  }
60
- relativePath = path.relative(baseDir, filepath);
61
- } else {
62
- relativePath = filepath.replace(/^\//, "");
59
+ return path.relative(baseDir, absolutePath);
63
60
  }
64
- return relativePath;
61
+ return absolutePath.replace(/^\//, "");
62
+
65
63
  }
66
64
 
67
65
  //------------------------------------------------------------------------------
@@ -55,50 +55,47 @@ function getSourceCodeOfFile(filename, options) {
55
55
 
56
56
  /**
57
57
  * Gets the SourceCode of a single file, or set of files.
58
- * @param {string[]|string} patterns A filename, directory name, or glob,
59
- * or an array of them
60
- * @param {Object} [options] A CLIEngine options object. If not provided,
61
- * the default cli options will be used.
62
- * @param {progressCallback} [cb] Callback for reporting execution status
63
- * @returns {Object} The SourceCode of all processed files.
58
+ * @param {string[]|string} patterns A filename, directory name, or glob, or an array of them
59
+ * @param {Object} [providedOptions] A CLIEngine options object. If not provided, the default cli options will be used.
60
+ * @param {progressCallback} [providedCallback] Callback for reporting execution status
61
+ * @returns {Object} The SourceCode of all processed files.
64
62
  */
65
- function getSourceCodeOfFiles(patterns, options, cb) {
63
+ function getSourceCodeOfFiles(patterns, providedOptions, providedCallback) {
66
64
  const sourceCodes = {};
67
- let opts;
68
-
69
- if (typeof patterns === "string") {
70
- patterns = [patterns];
71
- }
65
+ const globPatternsList = typeof patterns === "string" ? [patterns] : patterns;
66
+ let options, callback;
72
67
 
73
68
  const defaultOptions = Object.assign({}, baseDefaultOptions, { cwd: process.cwd() });
74
69
 
75
- if (typeof options === "undefined") {
76
- opts = defaultOptions;
77
- } else if (typeof options === "function") {
78
- cb = options;
79
- opts = defaultOptions;
80
- } else if (typeof options === "object") {
81
- opts = Object.assign({}, defaultOptions, options);
70
+ if (typeof providedOptions === "undefined") {
71
+ options = defaultOptions;
72
+ callback = null;
73
+ } else if (typeof providedOptions === "function") {
74
+ callback = providedOptions;
75
+ options = defaultOptions;
76
+ } else if (typeof providedOptions === "object") {
77
+ options = Object.assign({}, defaultOptions, providedOptions);
78
+ callback = providedCallback;
82
79
  }
83
- debug("constructed options:", opts);
84
- patterns = globUtil.resolveFileGlobPatterns(patterns, opts);
80
+ debug("constructed options:", options);
81
+ const resolvedPatterns = globUtil.resolveFileGlobPatterns(globPatternsList, options);
85
82
 
86
- const filenames = globUtil.listFilesToProcess(patterns, opts)
83
+ const filenames = globUtil.listFilesToProcess(resolvedPatterns, options)
87
84
  .filter(fileInfo => !fileInfo.ignored)
88
85
  .reduce((files, fileInfo) => files.concat(fileInfo.filename), []);
89
86
 
90
87
  if (filenames.length === 0) {
91
- debug(`Did not find any files matching pattern(s): ${patterns}`);
88
+ debug(`Did not find any files matching pattern(s): ${resolvedPatterns}`);
92
89
  }
93
90
  filenames.forEach(filename => {
94
- const sourceCode = getSourceCodeOfFile(filename, opts);
91
+ const sourceCode = getSourceCodeOfFile(filename, options);
95
92
 
96
93
  if (sourceCode) {
97
94
  debug("got sourceCode of", filename);
98
95
  sourceCodes[filename] = sourceCode;
99
96
  }
100
- if (cb) {
101
- cb(filenames.length); // eslint-disable-line callback-return
97
+ if (callback) {
98
+ callback(filenames.length); // eslint-disable-line callback-return
102
99
  }
103
100
  });
104
101
  return sourceCodes;
@@ -90,15 +90,16 @@ class SourceCode extends TokenStore {
90
90
  * @param {Object|null} textOrConfig.parserServices - The parser srevices.
91
91
  * @param {ScopeManager|null} textOrConfig.scopeManager - The scope of this source code.
92
92
  * @param {Object|null} textOrConfig.visitorKeys - The visitor keys to traverse AST.
93
- * @param {ASTNode} [ast] - The Program node of the AST representing the code. This AST should be created from the text that BOM was stripped.
93
+ * @param {ASTNode} [astIfNoConfig] - The Program node of the AST representing the code. This AST should be created from the text that BOM was stripped.
94
94
  * @constructor
95
95
  */
96
- constructor(textOrConfig, ast) {
97
- let text, parserServices, scopeManager, visitorKeys;
96
+ constructor(textOrConfig, astIfNoConfig) {
97
+ let text, ast, parserServices, scopeManager, visitorKeys;
98
98
 
99
99
  // Process overloading.
100
100
  if (typeof textOrConfig === "string") {
101
101
  text = textOrConfig;
102
+ ast = astIfNoConfig;
102
103
  } else if (typeof textOrConfig === "object" && textOrConfig !== null) {
103
104
  text = textOrConfig.text;
104
105
  ast = textOrConfig.ast;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint",
3
- "version": "4.18.0",
3
+ "version": "4.19.1",
4
4
  "author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
5
5
  "description": "An AST-based pattern checker for JavaScript.",
6
6
  "bin": {
@@ -43,7 +43,7 @@
43
43
  "doctrine": "^2.1.0",
44
44
  "eslint-scope": "^3.7.1",
45
45
  "eslint-visitor-keys": "^1.0.0",
46
- "espree": "^3.5.2",
46
+ "espree": "^3.5.4",
47
47
  "esquery": "^1.0.0",
48
48
  "esutils": "^2.0.2",
49
49
  "file-entry-cache": "^2.0.0",
@@ -65,11 +65,12 @@
65
65
  "path-is-inside": "^1.0.2",
66
66
  "pluralize": "^7.0.0",
67
67
  "progress": "^2.0.0",
68
+ "regexpp": "^1.0.1",
68
69
  "require-uncached": "^1.0.3",
69
70
  "semver": "^5.3.0",
70
71
  "strip-ansi": "^4.0.0",
71
72
  "strip-json-comments": "~2.0.1",
72
- "table": "^4.0.1",
73
+ "table": "4.0.2",
73
74
  "text-table": "~0.2.0"
74
75
  },
75
76
  "devDependencies": {
@@ -1,29 +0,0 @@
1
- /**
2
- * @fileoverview Default config options
3
- * @author Teddy Katz
4
- */
5
-
6
- "use strict";
7
-
8
- /**
9
- * Freezes an object and all its nested properties
10
- * @param {Object} obj The object to deeply freeze
11
- * @returns {Object} `obj` after freezing it
12
- */
13
- function deepFreeze(obj) {
14
- if (obj === null || typeof obj !== "object") {
15
- return obj;
16
- }
17
-
18
- Object.keys(obj).map(key => obj[key]).forEach(deepFreeze);
19
- return Object.freeze(obj);
20
- }
21
-
22
- module.exports = deepFreeze({
23
- env: {},
24
- globals: {},
25
- rules: {},
26
- settings: {},
27
- parser: "espree",
28
- parserOptions: {}
29
- });