eslint-linter-browserify 10.4.0 → 10.5.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 (5) hide show
  1. package/linter.cjs +125 -130
  2. package/linter.js +125 -130
  3. package/linter.min.js +3 -3
  4. package/linter.mjs +125 -130
  5. package/package.json +3 -3
package/linter.cjs CHANGED
@@ -4216,7 +4216,7 @@ function requireEslintVisitorKeys$2 () {
4216
4216
  return eslintVisitorKeys$2;
4217
4217
  }
4218
4218
 
4219
- var version = "10.4.0";
4219
+ var version = "10.5.0";
4220
4220
  var require$$3$1 = {
4221
4221
  version: version};
4222
4222
 
@@ -12737,11 +12737,12 @@ function requireCodePathState () {
12737
12737
  }
12738
12738
 
12739
12739
  /**
12740
- * Makes a code path segment from the first throwable node to the `catch`
12741
- * block or the `finally` block.
12740
+ * Makes a code path segment from the first throwable node in a `try` block to the `catch`
12741
+ * block or the `finally` block or from the first throwable node in a `catch` block
12742
+ * to the `finally` block.
12742
12743
  * @returns {void}
12743
12744
  */
12744
- makeFirstThrowablePathInTryBlock() {
12745
+ makeFirstThrowablePathInTryOrCatchBlock() {
12745
12746
  const forkContext = this.forkContext;
12746
12747
 
12747
12748
  if (!forkContext.reachable) {
@@ -12750,10 +12751,13 @@ function requireCodePathState () {
12750
12751
 
12751
12752
  const context = getThrowContext(this);
12752
12753
 
12754
+ if (context === this || !context.thrownForkContext.empty) {
12755
+ return;
12756
+ }
12757
+
12753
12758
  if (
12754
- context === this ||
12755
- context.position !== "try" ||
12756
- !context.thrownForkContext.empty
12759
+ context.position !== "try" &&
12760
+ (context.position !== "catch" || !context.hasFinalizer)
12757
12761
  ) {
12758
12762
  return;
12759
12763
  }
@@ -14363,7 +14367,7 @@ function requireCodePathAnalyzer () {
14363
14367
 
14364
14368
  case "Identifier":
14365
14369
  if (isIdentifierReference(node)) {
14366
- state.makeFirstThrowablePathInTryBlock();
14370
+ state.makeFirstThrowablePathInTryOrCatchBlock();
14367
14371
  dontForward = true;
14368
14372
  }
14369
14373
  break;
@@ -14372,7 +14376,7 @@ function requireCodePathAnalyzer () {
14372
14376
  case "ImportExpression":
14373
14377
  case "MemberExpression":
14374
14378
  case "NewExpression":
14375
- state.makeFirstThrowablePathInTryBlock();
14379
+ state.makeFirstThrowablePathInTryOrCatchBlock();
14376
14380
  break;
14377
14381
 
14378
14382
  case "YieldExpression":
@@ -50097,6 +50101,36 @@ function requireArrayBracketSpacing () {
50097
50101
  return arrayBracketSpacing;
50098
50102
  }
50099
50103
 
50104
+ /**
50105
+ * @fileoverview Code path related utilities.
50106
+ */
50107
+
50108
+ var codePathUtils;
50109
+ var hasRequiredCodePathUtils;
50110
+
50111
+ function requireCodePathUtils () {
50112
+ if (hasRequiredCodePathUtils) return codePathUtils;
50113
+ hasRequiredCodePathUtils = 1;
50114
+
50115
+ /**
50116
+ * Checks all segments in a set and returns true if any are reachable.
50117
+ * @param {Set<CodePathSegment>} segments The segments to check.
50118
+ * @returns {boolean} `true` if any segment is reachable; `false` otherwise.
50119
+ */
50120
+ function isAnySegmentReachable(segments) {
50121
+ for (const segment of segments) {
50122
+ if (segment.reachable) {
50123
+ return true;
50124
+ }
50125
+ }
50126
+
50127
+ return false;
50128
+ }
50129
+
50130
+ codePathUtils = { isAnySegmentReachable };
50131
+ return codePathUtils;
50132
+ }
50133
+
50100
50134
  /**
50101
50135
  * @fileoverview Rule to enforce return statements in callbacks of array's methods
50102
50136
  * @author Toru Nagashima
@@ -50114,6 +50148,7 @@ function requireArrayCallbackReturn () {
50114
50148
  //------------------------------------------------------------------------------
50115
50149
 
50116
50150
  const astUtils = requireAstUtils();
50151
+ const { isAnySegmentReachable } = requireCodePathUtils();
50117
50152
 
50118
50153
  //------------------------------------------------------------------------------
50119
50154
  // Helpers
@@ -50134,21 +50169,6 @@ function requireArrayCallbackReturn () {
50134
50169
  return astUtils.isSpecificMemberAccess(node, null, TARGET_METHODS);
50135
50170
  }
50136
50171
 
50137
- /**
50138
- * Checks all segments in a set and returns true if any are reachable.
50139
- * @param {Set<CodePathSegment>} segments The segments to check.
50140
- * @returns {boolean} True if any segment is reachable; false otherwise.
50141
- */
50142
- function isAnySegmentReachable(segments) {
50143
- for (const segment of segments) {
50144
- if (segment.reachable) {
50145
- return true;
50146
- }
50147
- }
50148
-
50149
- return false;
50150
- }
50151
-
50152
50172
  /**
50153
50173
  * Returns a human-legible description of an array method
50154
50174
  * @param {string} arrayMethodName A method name to fully qualify
@@ -55360,26 +55380,12 @@ function requireConsistentReturn () {
55360
55380
 
55361
55381
  const astUtils = requireAstUtils();
55362
55382
  const { upperCaseFirst } = requireStringUtils();
55383
+ const { isAnySegmentReachable } = requireCodePathUtils();
55363
55384
 
55364
55385
  //------------------------------------------------------------------------------
55365
55386
  // Helpers
55366
55387
  //------------------------------------------------------------------------------
55367
55388
 
55368
- /**
55369
- * Checks all segments in a set and returns true if all are unreachable.
55370
- * @param {Set<CodePathSegment>} segments The segments to check.
55371
- * @returns {boolean} True if all segments are unreachable; false otherwise.
55372
- */
55373
- function areAllSegmentsUnreachable(segments) {
55374
- for (const segment of segments) {
55375
- if (segment.reachable) {
55376
- return false;
55377
- }
55378
- }
55379
-
55380
- return true;
55381
- }
55382
-
55383
55389
  /**
55384
55390
  * Checks whether a given node is a `constructor` method in an ES6 class
55385
55391
  * @param {ASTNode} node A node to check
@@ -55450,7 +55456,7 @@ function requireConsistentReturn () {
55450
55456
  */
55451
55457
  if (
55452
55458
  !funcInfo.hasReturnValue ||
55453
- areAllSegmentsUnreachable(funcInfo.currentSegments) ||
55459
+ !isAnySegmentReachable(funcInfo.currentSegments) ||
55454
55460
  astUtils.isES5Constructor(node) ||
55455
55461
  isClassConstructor(node)
55456
55462
  ) {
@@ -59842,6 +59848,7 @@ function requireGetterReturn () {
59842
59848
  //------------------------------------------------------------------------------
59843
59849
 
59844
59850
  const astUtils = requireAstUtils();
59851
+ const { isAnySegmentReachable } = requireCodePathUtils();
59845
59852
 
59846
59853
  //------------------------------------------------------------------------------
59847
59854
  // Helpers
@@ -59849,21 +59856,6 @@ function requireGetterReturn () {
59849
59856
 
59850
59857
  const TARGET_NODE_TYPE = /^(?:Arrow)?FunctionExpression$/u;
59851
59858
 
59852
- /**
59853
- * Checks all segments in a set and returns true if any are reachable.
59854
- * @param {Set<CodePathSegment>} segments The segments to check.
59855
- * @returns {boolean} True if any segment is reachable; false otherwise.
59856
- */
59857
- function isAnySegmentReachable(segments) {
59858
- for (const segment of segments) {
59859
- if (segment.reachable) {
59860
- return true;
59861
- }
59862
- }
59863
-
59864
- return false;
59865
- }
59866
-
59867
59859
  //------------------------------------------------------------------------------
59868
59860
  // Rule Definition
59869
59861
  //------------------------------------------------------------------------------
@@ -69857,6 +69849,8 @@ function requireMaxDepth () {
69857
69849
  },
69858
69850
 
69859
69851
  create(context) {
69852
+ const sourceCode = context.sourceCode;
69853
+
69860
69854
  //--------------------------------------------------------------------------
69861
69855
  // Helpers
69862
69856
  //--------------------------------------------------------------------------
@@ -69905,6 +69899,7 @@ function requireMaxDepth () {
69905
69899
  if (len > maxDepth) {
69906
69900
  context.report({
69907
69901
  node,
69902
+ loc: sourceCode.getFirstToken(node).loc,
69908
69903
  messageId: "tooDeeply",
69909
69904
  data: { depth: len, maxDepth },
69910
69905
  });
@@ -69920,6 +69915,18 @@ function requireMaxDepth () {
69920
69915
  functionStack[functionStack.length - 1]--;
69921
69916
  }
69922
69917
 
69918
+ /**
69919
+ * Checks whether a node is an else-if statement.
69920
+ * @param {ASTNode} node node to evaluate
69921
+ * @returns {boolean} Whether the node is an else-if statement
69922
+ */
69923
+ function isElseIf(node) {
69924
+ return (
69925
+ node.parent.type === "IfStatement" &&
69926
+ node.parent.alternate === node
69927
+ );
69928
+ }
69929
+
69923
69930
  //--------------------------------------------------------------------------
69924
69931
  // Public API
69925
69932
  //--------------------------------------------------------------------------
@@ -69932,7 +69939,7 @@ function requireMaxDepth () {
69932
69939
  StaticBlock: startFunction,
69933
69940
 
69934
69941
  IfStatement(node) {
69935
- if (node.parent.type !== "IfStatement") {
69942
+ if (!isElseIf(node)) {
69936
69943
  pushBlock(node);
69937
69944
  }
69938
69945
  },
@@ -69945,7 +69952,11 @@ function requireMaxDepth () {
69945
69952
  ForInStatement: pushBlock,
69946
69953
  ForOfStatement: pushBlock,
69947
69954
 
69948
- "IfStatement:exit": popBlock,
69955
+ "IfStatement:exit"(node) {
69956
+ if (!isElseIf(node)) {
69957
+ popBlock();
69958
+ }
69959
+ },
69949
69960
  "SwitchStatement:exit": popBlock,
69950
69961
  "TryStatement:exit": popBlock,
69951
69962
  "DoWhileStatement:exit": popBlock,
@@ -70902,6 +70913,7 @@ function requireMaxLinesPerFunction () {
70902
70913
 
70903
70914
  context.report({
70904
70915
  node,
70916
+ loc: astUtils.getFunctionHeadLoc(funcNode, sourceCode),
70905
70917
  messageId: "exceed",
70906
70918
  data: { name, lineCount, maxLines },
70907
70919
  });
@@ -70934,6 +70946,12 @@ function requireMaxNestedCallbacks () {
70934
70946
  if (hasRequiredMaxNestedCallbacks) return maxNestedCallbacks;
70935
70947
  hasRequiredMaxNestedCallbacks = 1;
70936
70948
 
70949
+ //------------------------------------------------------------------------------
70950
+ // Requirements
70951
+ //------------------------------------------------------------------------------
70952
+
70953
+ const astUtils = requireAstUtils();
70954
+
70937
70955
  //------------------------------------------------------------------------------
70938
70956
  // Rule Definition
70939
70957
  //------------------------------------------------------------------------------
@@ -70982,6 +71000,8 @@ function requireMaxNestedCallbacks () {
70982
71000
  },
70983
71001
 
70984
71002
  create(context) {
71003
+ const sourceCode = context.sourceCode;
71004
+
70985
71005
  //--------------------------------------------------------------------------
70986
71006
  // Constants
70987
71007
  //--------------------------------------------------------------------------
@@ -71019,17 +71039,25 @@ function requireMaxNestedCallbacks () {
71019
71039
  if (callbackStack.length > THRESHOLD) {
71020
71040
  const opts = { num: callbackStack.length, max: THRESHOLD };
71021
71041
 
71022
- context.report({ node, messageId: "exceed", data: opts });
71042
+ context.report({
71043
+ node,
71044
+ loc: astUtils.getFunctionHeadLoc(node, sourceCode),
71045
+ messageId: "exceed",
71046
+ data: opts,
71047
+ });
71023
71048
  }
71024
71049
  }
71025
71050
 
71026
71051
  /**
71027
71052
  * Pops the call stack.
71053
+ * @param {ASTNode} node The node to check.
71028
71054
  * @returns {void}
71029
71055
  * @private
71030
71056
  */
71031
- function popStack() {
71032
- callbackStack.pop();
71057
+ function popStack(node) {
71058
+ if (callbackStack.at(-1) === node) {
71059
+ callbackStack.pop();
71060
+ }
71033
71061
  }
71034
71062
 
71035
71063
  //--------------------------------------------------------------------------
@@ -71321,6 +71349,7 @@ function requireMaxStatements () {
71321
71349
 
71322
71350
  context.report({
71323
71351
  node,
71352
+ loc: astUtils.getFunctionHeadLoc(node, context.sourceCode),
71324
71353
  messageId: "exceed",
71325
71354
  data: { name, count, max },
71326
71355
  });
@@ -85427,6 +85456,7 @@ function requireNoFallthrough () {
85427
85456
  //------------------------------------------------------------------------------
85428
85457
 
85429
85458
  const { directivesPattern } = requireDirectives();
85459
+ const { isAnySegmentReachable } = requireCodePathUtils();
85430
85460
 
85431
85461
  //------------------------------------------------------------------------------
85432
85462
  // Helpers
@@ -85434,21 +85464,6 @@ function requireNoFallthrough () {
85434
85464
 
85435
85465
  const DEFAULT_FALLTHROUGH_COMMENT = /falls?\s?through/iu;
85436
85466
 
85437
- /**
85438
- * Checks all segments in a set and returns true if any are reachable.
85439
- * @param {Set<CodePathSegment>} segments The segments to check.
85440
- * @returns {boolean} True if any segment is reachable; false otherwise.
85441
- */
85442
- function isAnySegmentReachable(segments) {
85443
- for (const segment of segments) {
85444
- if (segment.reachable) {
85445
- return true;
85446
- }
85447
- }
85448
-
85449
- return false;
85450
- }
85451
-
85452
85467
  /**
85453
85468
  * Checks whether or not a given comment string is really a fallthrough comment and not an ESLint directive.
85454
85469
  * @param {string} comment The comment string to check.
@@ -102035,6 +102050,12 @@ function requireNoUnreachable () {
102035
102050
  if (hasRequiredNoUnreachable) return noUnreachable;
102036
102051
  hasRequiredNoUnreachable = 1;
102037
102052
 
102053
+ //------------------------------------------------------------------------------
102054
+ // Requirements
102055
+ //------------------------------------------------------------------------------
102056
+
102057
+ const { isAnySegmentReachable } = requireCodePathUtils();
102058
+
102038
102059
  //------------------------------------------------------------------------------
102039
102060
  // Helpers
102040
102061
  //------------------------------------------------------------------------------
@@ -102054,21 +102075,6 @@ function requireNoUnreachable () {
102054
102075
  return Boolean(node.init);
102055
102076
  }
102056
102077
 
102057
- /**
102058
- * Checks all segments in a set and returns true if all are unreachable.
102059
- * @param {Set<CodePathSegment>} segments The segments to check.
102060
- * @returns {boolean} True if all segments are unreachable; false otherwise.
102061
- */
102062
- function areAllSegmentsUnreachable(segments) {
102063
- for (const segment of segments) {
102064
- if (segment.reachable) {
102065
- return false;
102066
- }
102067
- }
102068
-
102069
- return true;
102070
- }
102071
-
102072
102078
  /**
102073
102079
  * The class to distinguish consecutive unreachable statements.
102074
102080
  */
@@ -102185,7 +102191,7 @@ function requireNoUnreachable () {
102185
102191
  if (
102186
102192
  node &&
102187
102193
  (node.type === "PropertyDefinition" ||
102188
- areAllSegmentsUnreachable(currentCodePathSegments))
102194
+ !isAnySegmentReachable(currentCodePathSegments))
102189
102195
  ) {
102190
102196
  // Store this statement to distinguish consecutive statements.
102191
102197
  if (range.isEmpty) {
@@ -102344,6 +102350,8 @@ function requireNoUnreachableLoop () {
102344
102350
  if (hasRequiredNoUnreachableLoop) return noUnreachableLoop;
102345
102351
  hasRequiredNoUnreachableLoop = 1;
102346
102352
 
102353
+ const { isAnySegmentReachable } = requireCodePathUtils();
102354
+
102347
102355
  //------------------------------------------------------------------------------
102348
102356
  // Helpers
102349
102357
  //------------------------------------------------------------------------------
@@ -102356,21 +102364,6 @@ function requireNoUnreachableLoop () {
102356
102364
  "ForOfStatement",
102357
102365
  ];
102358
102366
 
102359
- /**
102360
- * Checks all segments in a set and returns true if any are reachable.
102361
- * @param {Set<CodePathSegment>} segments The segments to check.
102362
- * @returns {boolean} True if any segment is reachable; false otherwise.
102363
- */
102364
- function isAnySegmentReachable(segments) {
102365
- for (const segment of segments) {
102366
- if (segment.reachable) {
102367
- return true;
102368
- }
102369
- }
102370
-
102371
- return false;
102372
- }
102373
-
102374
102367
  /**
102375
102368
  * Determines whether the given node is the first node in the code path to which a loop statement
102376
102369
  * 'loops' for the next iteration.
@@ -108444,6 +108437,7 @@ function requireNoUselessReturn () {
108444
108437
 
108445
108438
  const astUtils = requireAstUtils(),
108446
108439
  FixTracker = requireFixTracker();
108440
+ const { isAnySegmentReachable } = requireCodePathUtils();
108447
108441
 
108448
108442
  //------------------------------------------------------------------------------
108449
108443
  // Helpers
@@ -108494,21 +108488,6 @@ function requireNoUselessReturn () {
108494
108488
  return false;
108495
108489
  }
108496
108490
 
108497
- /**
108498
- * Checks all segments in a set and returns true if any are reachable.
108499
- * @param {Set<CodePathSegment>} segments The segments to check.
108500
- * @returns {boolean} True if any segment is reachable; false otherwise.
108501
- */
108502
- function isAnySegmentReachable(segments) {
108503
- for (const segment of segments) {
108504
- if (segment.reachable) {
108505
- return true;
108506
- }
108507
- }
108508
-
108509
- return false;
108510
- }
108511
-
108512
108491
  //------------------------------------------------------------------------------
108513
108492
  // Rule Definition
108514
108493
  //------------------------------------------------------------------------------
@@ -109735,9 +109714,15 @@ function requireNoWith () {
109735
109714
  },
109736
109715
 
109737
109716
  create(context) {
109717
+ const sourceCode = context.sourceCode;
109718
+
109738
109719
  return {
109739
109720
  WithStatement(node) {
109740
- context.report({ node, messageId: "unexpectedWith" });
109721
+ context.report({
109722
+ node,
109723
+ loc: sourceCode.getFirstToken(node).loc,
109724
+ messageId: "unexpectedWith",
109725
+ });
109741
109726
  },
109742
109727
  };
109743
109728
  },
@@ -114285,6 +114270,24 @@ function requirePreferArrowCallback () {
114285
114270
  return;
114286
114271
  }
114287
114272
 
114273
+ const functionToken = sourceCode.getFirstToken(
114274
+ node,
114275
+ node.async ? 1 : 0,
114276
+ );
114277
+ const leftParenToken = sourceCode.getTokenAfter(
114278
+ functionToken,
114279
+ astUtils.isOpeningParenToken,
114280
+ );
114281
+
114282
+ if (node.async) {
114283
+ if (
114284
+ functionToken.loc.end.line <
114285
+ leftParenToken.loc.start.line
114286
+ ) {
114287
+ return;
114288
+ }
114289
+ }
114290
+
114288
114291
  // Remove `.bind(this)` if exists.
114289
114292
  if (callbackInfo.isLexicalThis) {
114290
114293
  const memberNode = node.parent;
@@ -114337,14 +114340,6 @@ function requirePreferArrowCallback () {
114337
114340
  }
114338
114341
 
114339
114342
  // Convert the function expression to an arrow function.
114340
- const functionToken = sourceCode.getFirstToken(
114341
- node,
114342
- node.async ? 1 : 0,
114343
- );
114344
- const leftParenToken = sourceCode.getTokenAfter(
114345
- functionToken,
114346
- astUtils.isOpeningParenToken,
114347
- );
114348
114343
  const tokenBeforeBody = sourceCode.getTokenBefore(
114349
114344
  node.body,
114350
114345
  );