eslint-linter-browserify 10.4.1 → 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.
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.1";
4219
+ var version = "10.5.0";
4220
4220
  var require$$3$1 = {
4221
4221
  version: version};
4222
4222
 
@@ -50101,6 +50101,36 @@ function requireArrayBracketSpacing () {
50101
50101
  return arrayBracketSpacing;
50102
50102
  }
50103
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
+
50104
50134
  /**
50105
50135
  * @fileoverview Rule to enforce return statements in callbacks of array's methods
50106
50136
  * @author Toru Nagashima
@@ -50118,6 +50148,7 @@ function requireArrayCallbackReturn () {
50118
50148
  //------------------------------------------------------------------------------
50119
50149
 
50120
50150
  const astUtils = requireAstUtils();
50151
+ const { isAnySegmentReachable } = requireCodePathUtils();
50121
50152
 
50122
50153
  //------------------------------------------------------------------------------
50123
50154
  // Helpers
@@ -50138,21 +50169,6 @@ function requireArrayCallbackReturn () {
50138
50169
  return astUtils.isSpecificMemberAccess(node, null, TARGET_METHODS);
50139
50170
  }
50140
50171
 
50141
- /**
50142
- * Checks all segments in a set and returns true if any are reachable.
50143
- * @param {Set<CodePathSegment>} segments The segments to check.
50144
- * @returns {boolean} True if any segment is reachable; false otherwise.
50145
- */
50146
- function isAnySegmentReachable(segments) {
50147
- for (const segment of segments) {
50148
- if (segment.reachable) {
50149
- return true;
50150
- }
50151
- }
50152
-
50153
- return false;
50154
- }
50155
-
50156
50172
  /**
50157
50173
  * Returns a human-legible description of an array method
50158
50174
  * @param {string} arrayMethodName A method name to fully qualify
@@ -55364,26 +55380,12 @@ function requireConsistentReturn () {
55364
55380
 
55365
55381
  const astUtils = requireAstUtils();
55366
55382
  const { upperCaseFirst } = requireStringUtils();
55383
+ const { isAnySegmentReachable } = requireCodePathUtils();
55367
55384
 
55368
55385
  //------------------------------------------------------------------------------
55369
55386
  // Helpers
55370
55387
  //------------------------------------------------------------------------------
55371
55388
 
55372
- /**
55373
- * Checks all segments in a set and returns true if all are unreachable.
55374
- * @param {Set<CodePathSegment>} segments The segments to check.
55375
- * @returns {boolean} True if all segments are unreachable; false otherwise.
55376
- */
55377
- function areAllSegmentsUnreachable(segments) {
55378
- for (const segment of segments) {
55379
- if (segment.reachable) {
55380
- return false;
55381
- }
55382
- }
55383
-
55384
- return true;
55385
- }
55386
-
55387
55389
  /**
55388
55390
  * Checks whether a given node is a `constructor` method in an ES6 class
55389
55391
  * @param {ASTNode} node A node to check
@@ -55454,7 +55456,7 @@ function requireConsistentReturn () {
55454
55456
  */
55455
55457
  if (
55456
55458
  !funcInfo.hasReturnValue ||
55457
- areAllSegmentsUnreachable(funcInfo.currentSegments) ||
55459
+ !isAnySegmentReachable(funcInfo.currentSegments) ||
55458
55460
  astUtils.isES5Constructor(node) ||
55459
55461
  isClassConstructor(node)
55460
55462
  ) {
@@ -59846,6 +59848,7 @@ function requireGetterReturn () {
59846
59848
  //------------------------------------------------------------------------------
59847
59849
 
59848
59850
  const astUtils = requireAstUtils();
59851
+ const { isAnySegmentReachable } = requireCodePathUtils();
59849
59852
 
59850
59853
  //------------------------------------------------------------------------------
59851
59854
  // Helpers
@@ -59853,21 +59856,6 @@ function requireGetterReturn () {
59853
59856
 
59854
59857
  const TARGET_NODE_TYPE = /^(?:Arrow)?FunctionExpression$/u;
59855
59858
 
59856
- /**
59857
- * Checks all segments in a set and returns true if any are reachable.
59858
- * @param {Set<CodePathSegment>} segments The segments to check.
59859
- * @returns {boolean} True if any segment is reachable; false otherwise.
59860
- */
59861
- function isAnySegmentReachable(segments) {
59862
- for (const segment of segments) {
59863
- if (segment.reachable) {
59864
- return true;
59865
- }
59866
- }
59867
-
59868
- return false;
59869
- }
59870
-
59871
59859
  //------------------------------------------------------------------------------
59872
59860
  // Rule Definition
59873
59861
  //------------------------------------------------------------------------------
@@ -69861,6 +69849,8 @@ function requireMaxDepth () {
69861
69849
  },
69862
69850
 
69863
69851
  create(context) {
69852
+ const sourceCode = context.sourceCode;
69853
+
69864
69854
  //--------------------------------------------------------------------------
69865
69855
  // Helpers
69866
69856
  //--------------------------------------------------------------------------
@@ -69909,6 +69899,7 @@ function requireMaxDepth () {
69909
69899
  if (len > maxDepth) {
69910
69900
  context.report({
69911
69901
  node,
69902
+ loc: sourceCode.getFirstToken(node).loc,
69912
69903
  messageId: "tooDeeply",
69913
69904
  data: { depth: len, maxDepth },
69914
69905
  });
@@ -69924,6 +69915,18 @@ function requireMaxDepth () {
69924
69915
  functionStack[functionStack.length - 1]--;
69925
69916
  }
69926
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
+
69927
69930
  //--------------------------------------------------------------------------
69928
69931
  // Public API
69929
69932
  //--------------------------------------------------------------------------
@@ -69936,7 +69939,7 @@ function requireMaxDepth () {
69936
69939
  StaticBlock: startFunction,
69937
69940
 
69938
69941
  IfStatement(node) {
69939
- if (node.parent.type !== "IfStatement") {
69942
+ if (!isElseIf(node)) {
69940
69943
  pushBlock(node);
69941
69944
  }
69942
69945
  },
@@ -69949,7 +69952,11 @@ function requireMaxDepth () {
69949
69952
  ForInStatement: pushBlock,
69950
69953
  ForOfStatement: pushBlock,
69951
69954
 
69952
- "IfStatement:exit": popBlock,
69955
+ "IfStatement:exit"(node) {
69956
+ if (!isElseIf(node)) {
69957
+ popBlock();
69958
+ }
69959
+ },
69953
69960
  "SwitchStatement:exit": popBlock,
69954
69961
  "TryStatement:exit": popBlock,
69955
69962
  "DoWhileStatement:exit": popBlock,
@@ -70906,6 +70913,7 @@ function requireMaxLinesPerFunction () {
70906
70913
 
70907
70914
  context.report({
70908
70915
  node,
70916
+ loc: astUtils.getFunctionHeadLoc(funcNode, sourceCode),
70909
70917
  messageId: "exceed",
70910
70918
  data: { name, lineCount, maxLines },
70911
70919
  });
@@ -70938,6 +70946,12 @@ function requireMaxNestedCallbacks () {
70938
70946
  if (hasRequiredMaxNestedCallbacks) return maxNestedCallbacks;
70939
70947
  hasRequiredMaxNestedCallbacks = 1;
70940
70948
 
70949
+ //------------------------------------------------------------------------------
70950
+ // Requirements
70951
+ //------------------------------------------------------------------------------
70952
+
70953
+ const astUtils = requireAstUtils();
70954
+
70941
70955
  //------------------------------------------------------------------------------
70942
70956
  // Rule Definition
70943
70957
  //------------------------------------------------------------------------------
@@ -70986,6 +71000,8 @@ function requireMaxNestedCallbacks () {
70986
71000
  },
70987
71001
 
70988
71002
  create(context) {
71003
+ const sourceCode = context.sourceCode;
71004
+
70989
71005
  //--------------------------------------------------------------------------
70990
71006
  // Constants
70991
71007
  //--------------------------------------------------------------------------
@@ -71023,17 +71039,25 @@ function requireMaxNestedCallbacks () {
71023
71039
  if (callbackStack.length > THRESHOLD) {
71024
71040
  const opts = { num: callbackStack.length, max: THRESHOLD };
71025
71041
 
71026
- 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
+ });
71027
71048
  }
71028
71049
  }
71029
71050
 
71030
71051
  /**
71031
71052
  * Pops the call stack.
71053
+ * @param {ASTNode} node The node to check.
71032
71054
  * @returns {void}
71033
71055
  * @private
71034
71056
  */
71035
- function popStack() {
71036
- callbackStack.pop();
71057
+ function popStack(node) {
71058
+ if (callbackStack.at(-1) === node) {
71059
+ callbackStack.pop();
71060
+ }
71037
71061
  }
71038
71062
 
71039
71063
  //--------------------------------------------------------------------------
@@ -71325,6 +71349,7 @@ function requireMaxStatements () {
71325
71349
 
71326
71350
  context.report({
71327
71351
  node,
71352
+ loc: astUtils.getFunctionHeadLoc(node, context.sourceCode),
71328
71353
  messageId: "exceed",
71329
71354
  data: { name, count, max },
71330
71355
  });
@@ -85431,6 +85456,7 @@ function requireNoFallthrough () {
85431
85456
  //------------------------------------------------------------------------------
85432
85457
 
85433
85458
  const { directivesPattern } = requireDirectives();
85459
+ const { isAnySegmentReachable } = requireCodePathUtils();
85434
85460
 
85435
85461
  //------------------------------------------------------------------------------
85436
85462
  // Helpers
@@ -85438,21 +85464,6 @@ function requireNoFallthrough () {
85438
85464
 
85439
85465
  const DEFAULT_FALLTHROUGH_COMMENT = /falls?\s?through/iu;
85440
85466
 
85441
- /**
85442
- * Checks all segments in a set and returns true if any are reachable.
85443
- * @param {Set<CodePathSegment>} segments The segments to check.
85444
- * @returns {boolean} True if any segment is reachable; false otherwise.
85445
- */
85446
- function isAnySegmentReachable(segments) {
85447
- for (const segment of segments) {
85448
- if (segment.reachable) {
85449
- return true;
85450
- }
85451
- }
85452
-
85453
- return false;
85454
- }
85455
-
85456
85467
  /**
85457
85468
  * Checks whether or not a given comment string is really a fallthrough comment and not an ESLint directive.
85458
85469
  * @param {string} comment The comment string to check.
@@ -102039,6 +102050,12 @@ function requireNoUnreachable () {
102039
102050
  if (hasRequiredNoUnreachable) return noUnreachable;
102040
102051
  hasRequiredNoUnreachable = 1;
102041
102052
 
102053
+ //------------------------------------------------------------------------------
102054
+ // Requirements
102055
+ //------------------------------------------------------------------------------
102056
+
102057
+ const { isAnySegmentReachable } = requireCodePathUtils();
102058
+
102042
102059
  //------------------------------------------------------------------------------
102043
102060
  // Helpers
102044
102061
  //------------------------------------------------------------------------------
@@ -102058,21 +102075,6 @@ function requireNoUnreachable () {
102058
102075
  return Boolean(node.init);
102059
102076
  }
102060
102077
 
102061
- /**
102062
- * Checks all segments in a set and returns true if all are unreachable.
102063
- * @param {Set<CodePathSegment>} segments The segments to check.
102064
- * @returns {boolean} True if all segments are unreachable; false otherwise.
102065
- */
102066
- function areAllSegmentsUnreachable(segments) {
102067
- for (const segment of segments) {
102068
- if (segment.reachable) {
102069
- return false;
102070
- }
102071
- }
102072
-
102073
- return true;
102074
- }
102075
-
102076
102078
  /**
102077
102079
  * The class to distinguish consecutive unreachable statements.
102078
102080
  */
@@ -102189,7 +102191,7 @@ function requireNoUnreachable () {
102189
102191
  if (
102190
102192
  node &&
102191
102193
  (node.type === "PropertyDefinition" ||
102192
- areAllSegmentsUnreachable(currentCodePathSegments))
102194
+ !isAnySegmentReachable(currentCodePathSegments))
102193
102195
  ) {
102194
102196
  // Store this statement to distinguish consecutive statements.
102195
102197
  if (range.isEmpty) {
@@ -102348,6 +102350,8 @@ function requireNoUnreachableLoop () {
102348
102350
  if (hasRequiredNoUnreachableLoop) return noUnreachableLoop;
102349
102351
  hasRequiredNoUnreachableLoop = 1;
102350
102352
 
102353
+ const { isAnySegmentReachable } = requireCodePathUtils();
102354
+
102351
102355
  //------------------------------------------------------------------------------
102352
102356
  // Helpers
102353
102357
  //------------------------------------------------------------------------------
@@ -102360,21 +102364,6 @@ function requireNoUnreachableLoop () {
102360
102364
  "ForOfStatement",
102361
102365
  ];
102362
102366
 
102363
- /**
102364
- * Checks all segments in a set and returns true if any are reachable.
102365
- * @param {Set<CodePathSegment>} segments The segments to check.
102366
- * @returns {boolean} True if any segment is reachable; false otherwise.
102367
- */
102368
- function isAnySegmentReachable(segments) {
102369
- for (const segment of segments) {
102370
- if (segment.reachable) {
102371
- return true;
102372
- }
102373
- }
102374
-
102375
- return false;
102376
- }
102377
-
102378
102367
  /**
102379
102368
  * Determines whether the given node is the first node in the code path to which a loop statement
102380
102369
  * 'loops' for the next iteration.
@@ -108448,6 +108437,7 @@ function requireNoUselessReturn () {
108448
108437
 
108449
108438
  const astUtils = requireAstUtils(),
108450
108439
  FixTracker = requireFixTracker();
108440
+ const { isAnySegmentReachable } = requireCodePathUtils();
108451
108441
 
108452
108442
  //------------------------------------------------------------------------------
108453
108443
  // Helpers
@@ -108498,21 +108488,6 @@ function requireNoUselessReturn () {
108498
108488
  return false;
108499
108489
  }
108500
108490
 
108501
- /**
108502
- * Checks all segments in a set and returns true if any are reachable.
108503
- * @param {Set<CodePathSegment>} segments The segments to check.
108504
- * @returns {boolean} True if any segment is reachable; false otherwise.
108505
- */
108506
- function isAnySegmentReachable(segments) {
108507
- for (const segment of segments) {
108508
- if (segment.reachable) {
108509
- return true;
108510
- }
108511
- }
108512
-
108513
- return false;
108514
- }
108515
-
108516
108491
  //------------------------------------------------------------------------------
108517
108492
  // Rule Definition
108518
108493
  //------------------------------------------------------------------------------
@@ -109739,9 +109714,15 @@ function requireNoWith () {
109739
109714
  },
109740
109715
 
109741
109716
  create(context) {
109717
+ const sourceCode = context.sourceCode;
109718
+
109742
109719
  return {
109743
109720
  WithStatement(node) {
109744
- context.report({ node, messageId: "unexpectedWith" });
109721
+ context.report({
109722
+ node,
109723
+ loc: sourceCode.getFirstToken(node).loc,
109724
+ messageId: "unexpectedWith",
109725
+ });
109745
109726
  },
109746
109727
  };
109747
109728
  },