@typescript-eslint/eslint-plugin 8.46.2 → 8.46.4-alpha.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.
@@ -24,33 +24,47 @@ exports.default = (0, util_1.createRule)({
24
24
  function isNumberLiteral(node) {
25
25
  return (node.type === utils_1.AST_NODE_TYPES.Literal && typeof node.value === 'number');
26
26
  }
27
+ function isSupportedUnary(node) {
28
+ return (node.type === utils_1.AST_NODE_TYPES.UnaryExpression &&
29
+ ['-', '+'].includes(node.operator));
30
+ }
27
31
  function isStaticTemplateLiteral(node) {
28
32
  return (node.type === utils_1.AST_NODE_TYPES.TemplateLiteral &&
29
33
  node.expressions.length === 0 &&
30
34
  node.quasis.length === 1);
31
35
  }
36
+ function getMemberValue(initializer) {
37
+ switch (true) {
38
+ case isStringLiteral(initializer):
39
+ case isNumberLiteral(initializer):
40
+ return initializer.value;
41
+ case isSupportedUnary(initializer): {
42
+ const inner = Number(getMemberValue(initializer.argument));
43
+ if (Number.isNaN(inner)) {
44
+ return undefined;
45
+ }
46
+ return initializer.operator === '-' ? -inner : inner;
47
+ }
48
+ case isStaticTemplateLiteral(initializer):
49
+ return initializer.quasis[0].value.cooked;
50
+ default:
51
+ return undefined;
52
+ }
53
+ }
32
54
  return {
33
55
  TSEnumDeclaration(node) {
34
56
  const enumMembers = node.body.members;
35
- const seenValues = new Set();
57
+ const seenValues = [];
36
58
  enumMembers.forEach(member => {
37
59
  if (member.initializer == null) {
38
60
  return;
39
61
  }
40
- let value;
41
- if (isStringLiteral(member.initializer)) {
42
- value = member.initializer.value;
43
- }
44
- else if (isNumberLiteral(member.initializer)) {
45
- value = member.initializer.value;
46
- }
47
- else if (isStaticTemplateLiteral(member.initializer)) {
48
- value = member.initializer.quasis[0].value.cooked;
49
- }
62
+ const value = getMemberValue(member.initializer);
50
63
  if (value == null) {
51
64
  return;
52
65
  }
53
- if (seenValues.has(value)) {
66
+ const isAlreadyPresent = seenValues.some(seenValue => Object.is(seenValue, value));
67
+ if (isAlreadyPresent) {
54
68
  context.report({
55
69
  node: member,
56
70
  messageId: 'duplicateValue',
@@ -60,7 +74,7 @@ exports.default = (0, util_1.createRule)({
60
74
  });
61
75
  }
62
76
  else {
63
- seenValues.add(value);
77
+ seenValues.push(value);
64
78
  }
65
79
  });
66
80
  },
@@ -422,7 +422,10 @@ exports.default = (0, util_1.createRule)({
422
422
  if (objType == null) {
423
423
  return;
424
424
  }
425
- const propertySymbol = checker.getPropertyOfType(objType, tsNode.name.text);
425
+ const propertySymbol = tsutils
426
+ .unionConstituents(objType)
427
+ .map(t => checker.getPropertyOfType(t, tsNode.name.getText()))
428
+ .find(p => p);
426
429
  if (propertySymbol == null) {
427
430
  return;
428
431
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typescript-eslint/eslint-plugin",
3
- "version": "8.46.2",
3
+ "version": "8.46.4-alpha.0",
4
4
  "description": "TypeScript plugin for ESLint",
5
5
  "files": [
6
6
  "dist",
@@ -59,10 +59,10 @@
59
59
  },
60
60
  "dependencies": {
61
61
  "@eslint-community/regexpp": "^4.10.0",
62
- "@typescript-eslint/scope-manager": "8.46.2",
63
- "@typescript-eslint/type-utils": "8.46.2",
64
- "@typescript-eslint/utils": "8.46.2",
65
- "@typescript-eslint/visitor-keys": "8.46.2",
62
+ "@typescript-eslint/scope-manager": "8.46.4-alpha.0",
63
+ "@typescript-eslint/type-utils": "8.46.4-alpha.0",
64
+ "@typescript-eslint/utils": "8.46.4-alpha.0",
65
+ "@typescript-eslint/visitor-keys": "8.46.4-alpha.0",
66
66
  "graphemer": "^1.4.0",
67
67
  "ignore": "^7.0.0",
68
68
  "natural-compare": "^1.4.0",
@@ -71,8 +71,8 @@
71
71
  "devDependencies": {
72
72
  "@types/mdast": "^4.0.3",
73
73
  "@types/natural-compare": "*",
74
- "@typescript-eslint/rule-schema-to-typescript-types": "8.46.2",
75
- "@typescript-eslint/rule-tester": "8.46.2",
74
+ "@typescript-eslint/rule-schema-to-typescript-types": "8.46.4-alpha.0",
75
+ "@typescript-eslint/rule-tester": "8.46.4-alpha.0",
76
76
  "@vitest/coverage-v8": "^3.1.3",
77
77
  "ajv": "^6.12.6",
78
78
  "cross-fetch": "*",
@@ -92,7 +92,7 @@
92
92
  "vitest": "^3.1.3"
93
93
  },
94
94
  "peerDependencies": {
95
- "@typescript-eslint/parser": "^8.46.2",
95
+ "@typescript-eslint/parser": "^8.46.4-alpha.0",
96
96
  "eslint": "^8.57.0 || ^9.0.0",
97
97
  "typescript": ">=4.8.4 <6.0.0"
98
98
  },