@typescript-eslint/eslint-plugin 8.20.1-alpha.5 → 8.20.1-alpha.6

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.
@@ -33,6 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
+ const tsutils = __importStar(require("ts-api-utils"));
36
37
  const ts = __importStar(require("typescript"));
37
38
  const util_1 = require("../util");
38
39
  const getForStatementHeadLoc_1 = require("../util/getForStatementHeadLoc");
@@ -57,8 +58,7 @@ exports.default = (0, util_1.createRule)({
57
58
  const services = (0, util_1.getParserServices)(context);
58
59
  const checker = services.program.getTypeChecker();
59
60
  const type = (0, util_1.getConstrainedTypeAtLocation)(services, node.right);
60
- if ((0, util_1.isTypeArrayTypeOrUnionOfArrayTypes)(type, checker) ||
61
- (type.flags & ts.TypeFlags.StringLike) !== 0) {
61
+ if (isArrayLike(checker, type)) {
62
62
  context.report({
63
63
  loc: (0, getForStatementHeadLoc_1.getForStatementHeadLoc)(context.sourceCode, node),
64
64
  messageId: 'forInViolation',
@@ -68,4 +68,20 @@ exports.default = (0, util_1.createRule)({
68
68
  };
69
69
  },
70
70
  });
71
+ function isArrayLike(checker, type) {
72
+ return isTypeRecurser(type, t => t.getNumberIndexType() != null && hasArrayishLength(checker, t));
73
+ }
74
+ function hasArrayishLength(checker, type) {
75
+ const lengthProperty = type.getProperty('length');
76
+ if (lengthProperty == null) {
77
+ return false;
78
+ }
79
+ return tsutils.isTypeFlagSet(checker.getTypeOfSymbol(lengthProperty), ts.TypeFlags.NumberLike);
80
+ }
81
+ function isTypeRecurser(type, predicate) {
82
+ if (type.isUnionOrIntersection()) {
83
+ return type.types.some(t => isTypeRecurser(t, predicate));
84
+ }
85
+ return predicate(type);
86
+ }
71
87
  //# sourceMappingURL=no-for-in-array.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"no-for-in-array.js","sourceRoot":"","sources":["../../src/rules/no-for-in-array.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAiC;AAEjC,kCAKiB;AACjB,2EAAwE;AAExE,kBAAe,IAAA,iBAAU,EAAC;IACxB,IAAI,EAAE,iBAAiB;IACvB,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EAAE,qDAAqD;YAClE,WAAW,EAAE,aAAa;YAC1B,oBAAoB,EAAE,IAAI;SAC3B;QACD,QAAQ,EAAE;YACR,cAAc,EACZ,iNAAiN;SACpN;QACD,MAAM,EAAE,EAAE;KACX;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,CAAC,OAAO;QACZ,OAAO;YACL,cAAc,CAAC,IAAI;gBACjB,MAAM,QAAQ,GAAG,IAAA,wBAAiB,EAAC,OAAO,CAAC,CAAC;gBAC5C,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC;gBAElD,MAAM,IAAI,GAAG,IAAA,mCAA4B,EAAC,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;gBAEhE,IACE,IAAA,yCAAkC,EAAC,IAAI,EAAE,OAAO,CAAC;oBACjD,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,EAC5C,CAAC;oBACD,OAAO,CAAC,MAAM,CAAC;wBACb,GAAG,EAAE,IAAA,+CAAsB,EAAC,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC;wBACrD,SAAS,EAAE,gBAAgB;qBAC5B,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
1
+ {"version":3,"file":"no-for-in-array.js","sourceRoot":"","sources":["../../src/rules/no-for-in-array.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAAwC;AACxC,+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,IAAI,cAAc,IAAI,IAAI,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,OAAO,CAAC,aAAa,CAC1B,OAAO,CAAC,eAAe,CAAC,cAAc,CAAC,EACvC,EAAE,CAAC,SAAS,CAAC,UAAU,CACxB,CAAC;AACJ,CAAC;AAED,SAAS,cAAc,CACrB,IAAa,EACb,SAAkC;IAElC,IAAI,IAAI,CAAC,qBAAqB,EAAE,EAAE,CAAC;QACjC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC;IAC5D,CAAC;IAED,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typescript-eslint/eslint-plugin",
3
- "version": "8.20.1-alpha.5",
3
+ "version": "8.20.1-alpha.6",
4
4
  "description": "TypeScript plugin for ESLint",
5
5
  "files": [
6
6
  "dist",
@@ -61,10 +61,10 @@
61
61
  },
62
62
  "dependencies": {
63
63
  "@eslint-community/regexpp": "^4.10.0",
64
- "@typescript-eslint/scope-manager": "8.20.1-alpha.5",
65
- "@typescript-eslint/type-utils": "8.20.1-alpha.5",
66
- "@typescript-eslint/utils": "8.20.1-alpha.5",
67
- "@typescript-eslint/visitor-keys": "8.20.1-alpha.5",
64
+ "@typescript-eslint/scope-manager": "8.20.1-alpha.6",
65
+ "@typescript-eslint/type-utils": "8.20.1-alpha.6",
66
+ "@typescript-eslint/utils": "8.20.1-alpha.6",
67
+ "@typescript-eslint/visitor-keys": "8.20.1-alpha.6",
68
68
  "graphemer": "^1.4.0",
69
69
  "ignore": "^5.3.1",
70
70
  "natural-compare": "^1.4.0",
@@ -75,8 +75,8 @@
75
75
  "@types/marked": "^5.0.2",
76
76
  "@types/mdast": "^4.0.3",
77
77
  "@types/natural-compare": "*",
78
- "@typescript-eslint/rule-schema-to-typescript-types": "8.20.1-alpha.5",
79
- "@typescript-eslint/rule-tester": "8.20.1-alpha.5",
78
+ "@typescript-eslint/rule-schema-to-typescript-types": "8.20.1-alpha.6",
79
+ "@typescript-eslint/rule-tester": "8.20.1-alpha.6",
80
80
  "ajv": "^6.12.6",
81
81
  "cross-env": "^7.0.3",
82
82
  "cross-fetch": "*",