eslint 5.13.0 → 5.15.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 (148) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/README.md +68 -156
  3. package/lib/built-in-rules-index.js +1 -0
  4. package/lib/cli-engine.js +5 -2
  5. package/lib/config/config-file.js +27 -4
  6. package/lib/config/config-initializer.js +151 -144
  7. package/lib/config/config-ops.js +2 -0
  8. package/lib/config/config-validator.js +1 -1
  9. package/lib/config/plugins.js +1 -1
  10. package/lib/formatters/codeframe.js +1 -1
  11. package/lib/formatters/stylish.js +2 -2
  12. package/lib/linter.js +7 -4
  13. package/lib/rules/accessor-pairs.js +4 -2
  14. package/lib/rules/array-callback-return.js +4 -3
  15. package/lib/rules/arrow-body-style.js +1 -1
  16. package/lib/rules/arrow-parens.js +2 -1
  17. package/lib/rules/arrow-spacing.js +7 -6
  18. package/lib/rules/brace-style.js +2 -1
  19. package/lib/rules/camelcase.js +5 -4
  20. package/lib/rules/capitalized-comments.js +10 -14
  21. package/lib/rules/class-methods-use-this.js +1 -1
  22. package/lib/rules/comma-spacing.js +10 -4
  23. package/lib/rules/complexity.js +6 -7
  24. package/lib/rules/consistent-return.js +2 -1
  25. package/lib/rules/curly.js +1 -1
  26. package/lib/rules/default-case.js +2 -2
  27. package/lib/rules/dot-notation.js +7 -5
  28. package/lib/rules/eol-last.js +1 -1
  29. package/lib/rules/func-call-spacing.js +2 -2
  30. package/lib/rules/func-style.js +3 -2
  31. package/lib/rules/getter-return.js +3 -2
  32. package/lib/rules/handle-callback-err.js +1 -1
  33. package/lib/rules/id-length.js +3 -2
  34. package/lib/rules/id-match.js +7 -4
  35. package/lib/rules/indent-legacy.js +1 -1
  36. package/lib/rules/indent.js +9 -6
  37. package/lib/rules/jsx-quotes.js +2 -2
  38. package/lib/rules/key-spacing.js +1 -1
  39. package/lib/rules/keyword-spacing.js +14 -14
  40. package/lib/rules/line-comment-position.js +5 -4
  41. package/lib/rules/lines-around-comment.js +14 -14
  42. package/lib/rules/lines-between-class-members.js +2 -1
  43. package/lib/rules/max-depth.js +5 -5
  44. package/lib/rules/max-len.js +21 -14
  45. package/lib/rules/max-lines-per-function.js +13 -17
  46. package/lib/rules/max-lines.js +3 -5
  47. package/lib/rules/max-nested-callbacks.js +6 -7
  48. package/lib/rules/max-params.js +5 -5
  49. package/lib/rules/max-statements-per-line.js +3 -2
  50. package/lib/rules/max-statements.js +6 -7
  51. package/lib/rules/multiline-comment-style.js +9 -9
  52. package/lib/rules/new-cap.js +9 -6
  53. package/lib/rules/newline-per-chained-call.js +2 -1
  54. package/lib/rules/no-alert.js +1 -1
  55. package/lib/rules/no-bitwise.js +2 -1
  56. package/lib/rules/no-caller.js +1 -1
  57. package/lib/rules/no-confusing-arrow.js +1 -1
  58. package/lib/rules/no-constant-condition.js +2 -1
  59. package/lib/rules/no-dupe-keys.js +2 -2
  60. package/lib/rules/no-duplicate-imports.js +2 -1
  61. package/lib/rules/no-else-return.js +4 -3
  62. package/lib/rules/no-empty-character-class.js +1 -1
  63. package/lib/rules/no-empty.js +2 -1
  64. package/lib/rules/no-eval.js +1 -1
  65. package/lib/rules/no-extra-parens.js +7 -1
  66. package/lib/rules/no-fallthrough.js +4 -3
  67. package/lib/rules/no-implicit-coercion.js +10 -7
  68. package/lib/rules/no-implied-eval.js +1 -1
  69. package/lib/rules/no-invalid-regexp.js +2 -2
  70. package/lib/rules/no-irregular-whitespace.js +11 -7
  71. package/lib/rules/no-labels.js +6 -4
  72. package/lib/rules/no-lonely-if.js +1 -1
  73. package/lib/rules/no-magic-numbers.js +6 -3
  74. package/lib/rules/no-mixed-operators.js +6 -5
  75. package/lib/rules/no-mixed-requires.js +1 -1
  76. package/lib/rules/no-mixed-spaces-and-tabs.js +2 -2
  77. package/lib/rules/no-multi-spaces.js +2 -1
  78. package/lib/rules/no-octal-escape.js +1 -1
  79. package/lib/rules/no-octal.js +1 -1
  80. package/lib/rules/no-param-reassign.js +2 -2
  81. package/lib/rules/no-path-concat.js +1 -1
  82. package/lib/rules/no-plusplus.js +2 -1
  83. package/lib/rules/no-redeclare.js +2 -2
  84. package/lib/rules/no-regex-spaces.js +1 -1
  85. package/lib/rules/no-return-assign.js +1 -1
  86. package/lib/rules/no-self-assign.js +3 -2
  87. package/lib/rules/no-shadow-restricted-names.js +16 -2
  88. package/lib/rules/no-shadow.js +3 -3
  89. package/lib/rules/no-sync.js +2 -1
  90. package/lib/rules/no-tabs.js +4 -3
  91. package/lib/rules/no-template-curly-in-string.js +1 -1
  92. package/lib/rules/no-trailing-spaces.js +7 -5
  93. package/lib/rules/no-undef.js +2 -1
  94. package/lib/rules/no-underscore-dangle.js +6 -3
  95. package/lib/rules/no-unexpected-multiline.js +1 -1
  96. package/lib/rules/no-unmodified-loop-condition.js +5 -5
  97. package/lib/rules/no-unneeded-ternary.js +2 -1
  98. package/lib/rules/no-unsafe-finally.js +3 -3
  99. package/lib/rules/no-unused-expressions.js +8 -5
  100. package/lib/rules/no-unused-vars.js +6 -6
  101. package/lib/rules/no-use-before-define.js +2 -2
  102. package/lib/rules/no-useless-escape.js +1 -1
  103. package/lib/rules/no-useless-rename.js +3 -3
  104. package/lib/rules/no-var.js +1 -1
  105. package/lib/rules/no-warning-comments.js +6 -6
  106. package/lib/rules/object-property-newline.js +5 -3
  107. package/lib/rules/one-var.js +18 -35
  108. package/lib/rules/padded-blocks.js +32 -9
  109. package/lib/rules/padding-line-between-statements.js +4 -3
  110. package/lib/rules/prefer-arrow-callback.js +4 -2
  111. package/lib/rules/prefer-const.js +5 -5
  112. package/lib/rules/prefer-destructuring.js +56 -5
  113. package/lib/rules/prefer-named-capture-group.js +123 -0
  114. package/lib/rules/prefer-object-spread.js +1 -1
  115. package/lib/rules/prefer-promise-reject-errors.js +1 -1
  116. package/lib/rules/prefer-spread.js +2 -13
  117. package/lib/rules/prefer-template.js +3 -3
  118. package/lib/rules/quotes.js +2 -2
  119. package/lib/rules/require-jsdoc.js +13 -7
  120. package/lib/rules/semi-spacing.js +6 -8
  121. package/lib/rules/semi.js +4 -4
  122. package/lib/rules/sort-imports.js +6 -3
  123. package/lib/rules/sort-keys.js +13 -5
  124. package/lib/rules/sort-vars.js +2 -1
  125. package/lib/rules/space-infix-ops.js +2 -1
  126. package/lib/rules/space-unary-ops.js +5 -3
  127. package/lib/rules/spaced-comment.js +6 -5
  128. package/lib/rules/switch-colon-spacing.js +2 -2
  129. package/lib/rules/template-curly-spacing.js +2 -2
  130. package/lib/rules/use-isnan.js +1 -1
  131. package/lib/rules/valid-jsdoc.js +12 -7
  132. package/lib/rules/valid-typeof.js +2 -1
  133. package/lib/rules/vars-on-top.js +1 -1
  134. package/lib/rules/wrap-iife.js +3 -2
  135. package/lib/rules/yoda.js +6 -4
  136. package/lib/util/ajv.js +1 -0
  137. package/lib/util/ast-utils.js +12 -12
  138. package/lib/util/config-comment-parser.js +4 -4
  139. package/lib/util/glob-utils.js +3 -3
  140. package/lib/util/ignored-paths.js +4 -4
  141. package/lib/util/interpolate.js +1 -1
  142. package/lib/util/naming.js +6 -6
  143. package/lib/util/node-event-generator.js +1 -1
  144. package/lib/util/path-utils.js +2 -2
  145. package/lib/util/patterns/letters.js +1 -1
  146. package/lib/util/source-code.js +2 -2
  147. package/lib/util/xml-escape.js +1 -1
  148. package/package.json +25 -23
@@ -16,13 +16,8 @@ const astUtils = require("../util/ast-utils");
16
16
  //------------------------------------------------------------------------------
17
17
 
18
18
  const DEFAULT_IGNORE_PATTERN = astUtils.COMMENTS_IGNORE_PATTERN,
19
- WHITESPACE = /\s/g,
20
- MAYBE_URL = /^\s*[^:/?#\s]+:\/\/[^?#]/, // TODO: Combine w/ max-len pattern?
21
- DEFAULTS = {
22
- ignorePattern: null,
23
- ignoreInlineComments: false,
24
- ignoreConsecutiveComments: false
25
- };
19
+ WHITESPACE = /\s/gu,
20
+ MAYBE_URL = /^\s*[^:/?#\s]+:\/\/[^?#]/u; // TODO: Combine w/ max-len pattern?
26
21
 
27
22
  /*
28
23
  * Base schema body for defining the basic capitalization rule, ignorePattern,
@@ -44,6 +39,11 @@ const SCHEMA_BODY = {
44
39
  },
45
40
  additionalProperties: false
46
41
  };
42
+ const DEFAULTS = {
43
+ ignorePattern: "",
44
+ ignoreInlineComments: false,
45
+ ignoreConsecutiveComments: false
46
+ };
47
47
 
48
48
  /**
49
49
  * Get normalized options for either block or line comments from the given
@@ -59,11 +59,7 @@ const SCHEMA_BODY = {
59
59
  * @param {string} which Either "line" or "block".
60
60
  * @returns {Object} The normalized options.
61
61
  */
62
- function getNormalizedOptions(rawOptions, which) {
63
- if (!rawOptions) {
64
- return Object.assign({}, DEFAULTS);
65
- }
66
-
62
+ function getNormalizedOptions(rawOptions = {}, which) {
67
63
  return Object.assign({}, DEFAULTS, rawOptions[which] || rawOptions);
68
64
  }
69
65
 
@@ -95,7 +91,7 @@ function createRegExpForIgnorePatterns(normalizedOptions) {
95
91
  const ignorePatternStr = normalizedOptions[key].ignorePattern;
96
92
 
97
93
  if (ignorePatternStr) {
98
- const regExp = RegExp(`^\\s*(?:${ignorePatternStr})`);
94
+ const regExp = RegExp(`^\\s*(?:${ignorePatternStr})`); // eslint-disable-line require-unicode-regexp
99
95
 
100
96
  normalizedOptions[key].ignorePatternRegExp = regExp;
101
97
  }
@@ -214,7 +210,7 @@ module.exports = {
214
210
 
215
211
  // 2. Check for custom ignore pattern.
216
212
  const commentWithoutAsterisks = comment.value
217
- .replace(/\*/g, "");
213
+ .replace(/\*/gu, "");
218
214
 
219
215
  if (options.ignorePatternRegExp && options.ignorePatternRegExp.test(commentWithoutAsterisks)) {
220
216
  return true;
@@ -38,7 +38,7 @@ module.exports = {
38
38
  }
39
39
  },
40
40
  create(context) {
41
- const config = context.options[0] ? Object.assign({}, context.options[0]) : {};
41
+ const config = Object.assign({}, context.options[0]);
42
42
  const exceptMethods = new Set(config.exceptMethods || []);
43
43
 
44
44
  const stack = [];
@@ -28,10 +28,12 @@ module.exports = {
28
28
  type: "object",
29
29
  properties: {
30
30
  before: {
31
- type: "boolean"
31
+ type: "boolean",
32
+ default: false
32
33
  },
33
34
  after: {
34
- type: "boolean"
35
+ type: "boolean",
36
+ default: true
35
37
  }
36
38
  },
37
39
  additionalProperties: false
@@ -50,8 +52,8 @@ module.exports = {
50
52
  const tokensAndComments = sourceCode.tokensAndComments;
51
53
 
52
54
  const options = {
53
- before: context.options[0] ? !!context.options[0].before : false,
54
- after: context.options[0] ? !!context.options[0].after : true
55
+ before: context.options[0] ? context.options[0].before : false,
56
+ after: context.options[0] ? context.options[0].after : true
55
57
  };
56
58
 
57
59
  //--------------------------------------------------------------------------
@@ -118,6 +120,10 @@ module.exports = {
118
120
  report(reportItem, "before", tokens.left);
119
121
  }
120
122
 
123
+ if (tokens.right && astUtils.isClosingParenToken(tokens.right)) {
124
+ return;
125
+ }
126
+
121
127
  if (tokens.right && !options.after && tokens.right.type === "Line") {
122
128
  return;
123
129
  }
@@ -63,13 +63,12 @@ module.exports = {
63
63
  const option = context.options[0];
64
64
  let THRESHOLD = 20;
65
65
 
66
- if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "maximum") && typeof option.maximum === "number") {
67
- THRESHOLD = option.maximum;
68
- }
69
- if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "max") && typeof option.max === "number") {
70
- THRESHOLD = option.max;
71
- }
72
- if (typeof option === "number") {
66
+ if (
67
+ typeof option === "object" &&
68
+ (Object.prototype.hasOwnProperty.call(option, "maximum") || Object.prototype.hasOwnProperty.call(option, "max"))
69
+ ) {
70
+ THRESHOLD = option.maximum || option.max;
71
+ } else if (typeof option === "number") {
73
72
  THRESHOLD = option;
74
73
  }
75
74
 
@@ -66,7 +66,8 @@ module.exports = {
66
66
  type: "object",
67
67
  properties: {
68
68
  treatUndefinedAsUnspecified: {
69
- type: "boolean"
69
+ type: "boolean",
70
+ default: false
70
71
  }
71
72
  },
72
73
  additionalProperties: false
@@ -191,7 +191,7 @@ module.exports = {
191
191
  return true;
192
192
  }
193
193
 
194
- if (/^[([/`+-]/.test(tokenAfter.value)) {
194
+ if (/^[([/`+-]/u.test(tokenAfter.value)) {
195
195
 
196
196
  // If the next token starts with a character that would disrupt ASI, insert a semicolon.
197
197
  return true;
@@ -4,7 +4,7 @@
4
4
  */
5
5
  "use strict";
6
6
 
7
- const DEFAULT_COMMENT_PATTERN = /^no default$/i;
7
+ const DEFAULT_COMMENT_PATTERN = /^no default$/iu;
8
8
 
9
9
  //------------------------------------------------------------------------------
10
10
  // Rule Definition
@@ -39,7 +39,7 @@ module.exports = {
39
39
  create(context) {
40
40
  const options = context.options[0] || {};
41
41
  const commentPattern = options.commentPattern
42
- ? new RegExp(options.commentPattern)
42
+ ? new RegExp(options.commentPattern) // eslint-disable-line require-unicode-regexp
43
43
  : DEFAULT_COMMENT_PATTERN;
44
44
 
45
45
  const sourceCode = context.getSourceCode();
@@ -14,7 +14,7 @@ const astUtils = require("../util/ast-utils");
14
14
  // Rule Definition
15
15
  //------------------------------------------------------------------------------
16
16
 
17
- const validIdentifier = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
17
+ const validIdentifier = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/u;
18
18
  const keywords = require("../util/keywords");
19
19
 
20
20
  module.exports = {
@@ -33,10 +33,12 @@ module.exports = {
33
33
  type: "object",
34
34
  properties: {
35
35
  allowKeywords: {
36
- type: "boolean"
36
+ type: "boolean",
37
+ default: true
37
38
  },
38
39
  allowPattern: {
39
- type: "string"
40
+ type: "string",
41
+ default: ""
40
42
  }
41
43
  },
42
44
  additionalProperties: false
@@ -53,13 +55,13 @@ module.exports = {
53
55
 
54
56
  create(context) {
55
57
  const options = context.options[0] || {};
56
- const allowKeywords = options.allowKeywords === void 0 || !!options.allowKeywords;
58
+ const allowKeywords = options.allowKeywords === void 0 || options.allowKeywords;
57
59
  const sourceCode = context.getSourceCode();
58
60
 
59
61
  let allowPattern;
60
62
 
61
63
  if (options.allowPattern) {
62
- allowPattern = new RegExp(options.allowPattern);
64
+ allowPattern = new RegExp(options.allowPattern); // eslint-disable-line require-unicode-regexp
63
65
  }
64
66
 
65
67
  /**
@@ -97,7 +97,7 @@ module.exports = {
97
97
  loc: location,
98
98
  messageId: "unexpected",
99
99
  fix(fixer) {
100
- const finalEOLs = /(?:\r?\n)+$/,
100
+ const finalEOLs = /(?:\r?\n)+$/u,
101
101
  match = finalEOLs.exec(sourceCode.text),
102
102
  start = match.index,
103
103
  end = sourceCode.text.length;
@@ -92,8 +92,8 @@ module.exports = {
92
92
  return;
93
93
  }
94
94
 
95
- const textBetweenTokens = text.slice(prevToken.range[1], parenToken.range[0]).replace(/\/\*.*?\*\//g, "");
96
- const hasWhitespace = /\s/.test(textBetweenTokens);
95
+ const textBetweenTokens = text.slice(prevToken.range[1], parenToken.range[0]).replace(/\/\*.*?\*\//gu, "");
96
+ const hasWhitespace = /\s/u.test(textBetweenTokens);
97
97
  const hasNewline = hasWhitespace && astUtils.LINEBREAK_MATCHER.test(textBetweenTokens);
98
98
 
99
99
  /*
@@ -27,7 +27,8 @@ module.exports = {
27
27
  type: "object",
28
28
  properties: {
29
29
  allowArrowFunctions: {
30
- type: "boolean"
30
+ type: "boolean",
31
+ default: false
31
32
  }
32
33
  },
33
34
  additionalProperties: false
@@ -43,7 +44,7 @@ module.exports = {
43
44
  create(context) {
44
45
 
45
46
  const style = context.options[0],
46
- allowArrowFunctions = context.options[1] && context.options[1].allowArrowFunctions === true,
47
+ allowArrowFunctions = context.options[1] && context.options[1].allowArrowFunctions,
47
48
  enforceDeclarations = (style === "declaration"),
48
49
  stack = [];
49
50
 
@@ -14,7 +14,7 @@ const astUtils = require("../util/ast-utils");
14
14
  //------------------------------------------------------------------------------
15
15
  // Helpers
16
16
  //------------------------------------------------------------------------------
17
- const TARGET_NODE_TYPE = /^(?:Arrow)?FunctionExpression$/;
17
+ const TARGET_NODE_TYPE = /^(?:Arrow)?FunctionExpression$/u;
18
18
 
19
19
  /**
20
20
  * Checks a given code path segment is reachable.
@@ -60,7 +60,8 @@ module.exports = {
60
60
  type: "object",
61
61
  properties: {
62
62
  allowImplicit: {
63
- type: "boolean"
63
+ type: "boolean",
64
+ default: false
64
65
  }
65
66
  },
66
67
  additionalProperties: false
@@ -52,7 +52,7 @@ module.exports = {
52
52
  */
53
53
  function matchesConfiguredErrorName(name) {
54
54
  if (isPattern(errorArgument)) {
55
- const regexp = new RegExp(errorArgument);
55
+ const regexp = new RegExp(errorArgument); // eslint-disable-line require-unicode-regexp
56
56
 
57
57
  return regexp.test(name);
58
58
  }
@@ -26,10 +26,11 @@ module.exports = {
26
26
  type: "object",
27
27
  properties: {
28
28
  min: {
29
- type: "number"
29
+ type: "integer",
30
+ default: 2
30
31
  },
31
32
  max: {
32
- type: "number"
33
+ type: "integer"
33
34
  },
34
35
  exceptions: {
35
36
  type: "array",
@@ -28,13 +28,16 @@ module.exports = {
28
28
  type: "object",
29
29
  properties: {
30
30
  properties: {
31
- type: "boolean"
31
+ type: "boolean",
32
+ default: false
32
33
  },
33
34
  onlyDeclarations: {
34
- type: "boolean"
35
+ type: "boolean",
36
+ default: false
35
37
  },
36
38
  ignoreDestructuring: {
37
- type: "boolean"
39
+ type: "boolean",
40
+ default: false
38
41
  }
39
42
  }
40
43
  }
@@ -50,7 +53,7 @@ module.exports = {
50
53
  // Options
51
54
  //--------------------------------------------------------------------------
52
55
  const pattern = context.options[0] || "^.+$",
53
- regexp = new RegExp(pattern);
56
+ regexp = new RegExp(pattern); // eslint-disable-line require-unicode-regexp
54
57
 
55
58
  const options = context.options[1] || {},
56
59
  properties = !!options.properties,
@@ -975,7 +975,7 @@ module.exports = {
975
975
  * @returns {boolean} the result
976
976
  */
977
977
  function isWrappedInParenthesis(node) {
978
- const regex = /^return\s*?\(\s*?\);*?/;
978
+ const regex = /^return\s*?\(\s*?\);*?/u;
979
979
 
980
980
  const statementWithoutArgument = sourceCode.getText(node).replace(
981
981
  sourceCode.getText(node.argument), ""
@@ -442,7 +442,7 @@ class OffsetStorage {
442
442
  const offset = (
443
443
  offsetInfo.from &&
444
444
  offsetInfo.from.loc.start.line === token.loc.start.line &&
445
- !/^\s*?\n/.test(token.value) &&
445
+ !/^\s*?\n/u.test(token.value) &&
446
446
  !offsetInfo.force
447
447
  ) ? 0 : offsetInfo.offset * this._indentSize;
448
448
 
@@ -518,7 +518,8 @@ module.exports = {
518
518
  properties: {
519
519
  SwitchCase: {
520
520
  type: "integer",
521
- minimum: 0
521
+ minimum: 0,
522
+ default: 0
522
523
  },
523
524
  VariableDeclarator: {
524
525
  oneOf: [
@@ -582,7 +583,8 @@ module.exports = {
582
583
  ObjectExpression: ELEMENT_LIST_SCHEMA,
583
584
  ImportDeclaration: ELEMENT_LIST_SCHEMA,
584
585
  flatTernaryExpressions: {
585
- type: "boolean"
586
+ type: "boolean",
587
+ default: false
586
588
  },
587
589
  ignoredNodes: {
588
590
  type: "array",
@@ -594,7 +596,8 @@ module.exports = {
594
596
  }
595
597
  },
596
598
  ignoreComments: {
597
- type: "boolean"
599
+ type: "boolean",
600
+ default: false
598
601
  }
599
602
  },
600
603
  additionalProperties: false
@@ -650,7 +653,7 @@ module.exports = {
650
653
  }
651
654
 
652
655
  if (context.options[1]) {
653
- lodash.merge(options, context.options[1]);
656
+ Object.assign(options, context.options[1]);
654
657
 
655
658
  if (typeof options.VariableDeclarator === "number" || options.VariableDeclarator === "first") {
656
659
  options.VariableDeclarator = {
@@ -782,7 +785,7 @@ module.exports = {
782
785
  * or the total number of linebreaks if the string is all whitespace.
783
786
  */
784
787
  function countTrailingLinebreaks(string) {
785
- const trailingWhitespace = string.match(/\s*$/)[0];
788
+ const trailingWhitespace = string.match(/\s*$/u)[0];
786
789
  const linebreakMatches = trailingWhitespace.match(astUtils.createGlobalLinebreakMatcher());
787
790
 
788
791
  return linebreakMatches === null ? 0 : linebreakMatches.length;
@@ -20,14 +20,14 @@ const QUOTE_SETTINGS = {
20
20
  quote: "\"",
21
21
  description: "singlequote",
22
22
  convert(str) {
23
- return str.replace(/'/g, "\"");
23
+ return str.replace(/'/gu, "\"");
24
24
  }
25
25
  },
26
26
  "prefer-single": {
27
27
  quote: "'",
28
28
  description: "doublequote",
29
29
  convert(str) {
30
- return str.replace(/"/g, "'");
30
+ return str.replace(/"/gu, "'");
31
31
  }
32
32
  }
33
33
  };
@@ -501,7 +501,7 @@ module.exports = {
501
501
  * @returns {Object} Whitespace before and after the property's colon.
502
502
  */
503
503
  function getPropertyWhitespace(property) {
504
- const whitespace = /(\s*):(\s*)/.exec(sourceCode.getText().slice(
504
+ const whitespace = /(\s*):(\s*)/u.exec(sourceCode.getText().slice(
505
505
  property.key.range[1], property.value.range[0]
506
506
  ));
507
507
 
@@ -16,13 +16,13 @@ const astUtils = require("../util/ast-utils"),
16
16
  // Constants
17
17
  //------------------------------------------------------------------------------
18
18
 
19
- const PREV_TOKEN = /^[)\]}>]$/;
20
- const NEXT_TOKEN = /^(?:[([{<~!]|\+\+?|--?)$/;
21
- const PREV_TOKEN_M = /^[)\]}>*]$/;
22
- const NEXT_TOKEN_M = /^[{*]$/;
23
- const TEMPLATE_OPEN_PAREN = /\$\{$/;
24
- const TEMPLATE_CLOSE_PAREN = /^\}/;
25
- const CHECK_TYPE = /^(?:JSXElement|RegularExpression|String|Template)$/;
19
+ const PREV_TOKEN = /^[)\]}>]$/u;
20
+ const NEXT_TOKEN = /^(?:[([{<~!]|\+\+?|--?)$/u;
21
+ const PREV_TOKEN_M = /^[)\]}>*]$/u;
22
+ const NEXT_TOKEN_M = /^[{*]$/u;
23
+ const TEMPLATE_OPEN_PAREN = /\$\{$/u;
24
+ const TEMPLATE_CLOSE_PAREN = /^\}/u;
25
+ const CHECK_TYPE = /^(?:JSXElement|RegularExpression|String|Template)$/u;
26
26
  const KEYS = keywords.concat(["as", "async", "await", "from", "get", "let", "of", "set", "yield"]);
27
27
 
28
28
  // check duplications.
@@ -80,16 +80,16 @@ module.exports = {
80
80
  {
81
81
  type: "object",
82
82
  properties: {
83
- before: { type: "boolean" },
84
- after: { type: "boolean" },
83
+ before: { type: "boolean", default: true },
84
+ after: { type: "boolean", default: true },
85
85
  overrides: {
86
86
  type: "object",
87
87
  properties: KEYS.reduce((retv, key) => {
88
88
  retv[key] = {
89
89
  type: "object",
90
90
  properties: {
91
- before: { type: "boolean" },
92
- after: { type: "boolean" }
91
+ before: { type: "boolean", default: true },
92
+ after: { type: "boolean", default: true }
93
93
  },
94
94
  additionalProperties: false
95
95
  };
@@ -228,9 +228,9 @@ module.exports = {
228
228
  * Keys are keywords (there are for every keyword).
229
229
  * Values are instances of `{"before": function, "after": function}`.
230
230
  */
231
- function parseOptions(options) {
232
- const before = !options || options.before !== false;
233
- const after = !options || options.after !== false;
231
+ function parseOptions(options = {}) {
232
+ const before = options.before !== false;
233
+ const after = options.after !== false;
234
234
  const defaultValue = {
235
235
  before: before ? expectSpaceBefore : unexpectSpaceBefore,
236
236
  after: after ? expectSpaceAfter : unexpectSpaceAfter
@@ -31,7 +31,8 @@ module.exports = {
31
31
  type: "object",
32
32
  properties: {
33
33
  position: {
34
- enum: ["above", "beside"]
34
+ enum: ["above", "beside"],
35
+ default: "above"
35
36
  },
36
37
  ignorePattern: {
37
38
  type: "string"
@@ -69,15 +70,15 @@ module.exports = {
69
70
  ignorePattern = options.ignorePattern;
70
71
 
71
72
  if (Object.prototype.hasOwnProperty.call(options, "applyDefaultIgnorePatterns")) {
72
- applyDefaultIgnorePatterns = options.applyDefaultIgnorePatterns !== false;
73
+ applyDefaultIgnorePatterns = options.applyDefaultIgnorePatterns;
73
74
  } else {
74
75
  applyDefaultIgnorePatterns = options.applyDefaultPatterns !== false;
75
76
  }
76
77
  }
77
78
 
78
79
  const defaultIgnoreRegExp = astUtils.COMMENTS_IGNORE_PATTERN;
79
- const fallThroughRegExp = /^\s*falls?\s?through/;
80
- const customIgnoreRegExp = new RegExp(ignorePattern);
80
+ const fallThroughRegExp = /^\s*falls?\s?through/u;
81
+ const customIgnoreRegExp = new RegExp(ignorePattern); // eslint-disable-line require-unicode-regexp
81
82
  const sourceCode = context.getSourceCode();
82
83
 
83
84
  //--------------------------------------------------------------------------
@@ -68,22 +68,28 @@ module.exports = {
68
68
  type: "object",
69
69
  properties: {
70
70
  beforeBlockComment: {
71
- type: "boolean"
71
+ type: "boolean",
72
+ default: true
72
73
  },
73
74
  afterBlockComment: {
74
- type: "boolean"
75
+ type: "boolean",
76
+ default: false
75
77
  },
76
78
  beforeLineComment: {
77
- type: "boolean"
79
+ type: "boolean",
80
+ default: false
78
81
  },
79
82
  afterLineComment: {
80
- type: "boolean"
83
+ type: "boolean",
84
+ default: false
81
85
  },
82
86
  allowBlockStart: {
83
- type: "boolean"
87
+ type: "boolean",
88
+ default: false
84
89
  },
85
90
  allowBlockEnd: {
86
- type: "boolean"
91
+ type: "boolean",
92
+ default: false
87
93
  },
88
94
  allowClassStart: {
89
95
  type: "boolean"
@@ -121,19 +127,13 @@ module.exports = {
121
127
 
122
128
  create(context) {
123
129
 
124
- const options = context.options[0] ? Object.assign({}, context.options[0]) : {};
130
+ const options = Object.assign({}, context.options[0]);
125
131
  const ignorePattern = options.ignorePattern;
126
132
  const defaultIgnoreRegExp = astUtils.COMMENTS_IGNORE_PATTERN;
127
- const customIgnoreRegExp = new RegExp(ignorePattern);
133
+ const customIgnoreRegExp = new RegExp(ignorePattern); // eslint-disable-line require-unicode-regexp
128
134
  const applyDefaultIgnorePatterns = options.applyDefaultIgnorePatterns !== false;
129
135
 
130
-
131
- options.beforeLineComment = options.beforeLineComment || false;
132
- options.afterLineComment = options.afterLineComment || false;
133
136
  options.beforeBlockComment = typeof options.beforeBlockComment !== "undefined" ? options.beforeBlockComment : true;
134
- options.afterBlockComment = options.afterBlockComment || false;
135
- options.allowBlockStart = options.allowBlockStart || false;
136
- options.allowBlockEnd = options.allowBlockEnd || false;
137
137
 
138
138
  const sourceCode = context.getSourceCode();
139
139
 
@@ -31,7 +31,8 @@ module.exports = {
31
31
  type: "object",
32
32
  properties: {
33
33
  exceptAfterSingleLine: {
34
- type: "boolean"
34
+ type: "boolean",
35
+ default: false
35
36
  }
36
37
  },
37
38
  additionalProperties: false
@@ -59,11 +59,11 @@ module.exports = {
59
59
  option = context.options[0];
60
60
  let maxDepth = 4;
61
61
 
62
- if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "maximum") && typeof option.maximum === "number") {
63
- maxDepth = option.maximum;
64
- }
65
- if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "max") && typeof option.max === "number") {
66
- maxDepth = option.max;
62
+ if (
63
+ typeof option === "object" &&
64
+ (Object.prototype.hasOwnProperty.call(option, "maximum") || Object.prototype.hasOwnProperty.call(option, "max"))
65
+ ) {
66
+ maxDepth = option.maximum || option.max;
67
67
  }
68
68
  if (typeof option === "number") {
69
69
  maxDepth = option;