@typescript-eslint/eslint-plugin 8.24.2-alpha.2 → 8.24.2-alpha.4

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 (32) hide show
  1. package/dist/rules/no-deprecated.d.ts.map +1 -1
  2. package/dist/rules/no-deprecated.js +11 -1
  3. package/dist/rules/no-floating-promises.d.ts.map +1 -1
  4. package/dist/rules/no-floating-promises.js +1 -4
  5. package/dist/rules/no-inferrable-types.d.ts.map +1 -1
  6. package/dist/rules/no-inferrable-types.js +4 -6
  7. package/dist/rules/no-invalid-void-type.d.ts.map +1 -1
  8. package/dist/rules/no-invalid-void-type.js +22 -0
  9. package/dist/rules/prefer-find.d.ts.map +1 -1
  10. package/dist/rules/prefer-find.js +8 -11
  11. package/dist/rules/prefer-nullish-coalescing.d.ts.map +1 -1
  12. package/dist/rules/prefer-nullish-coalescing.js +61 -26
  13. package/dist/rules/prefer-promise-reject-errors.d.ts.map +1 -1
  14. package/dist/rules/prefer-promise-reject-errors.js +2 -7
  15. package/dist/rules/prefer-string-starts-ends-with.d.ts.map +1 -1
  16. package/dist/rules/prefer-string-starts-ends-with.js +3 -11
  17. package/dist/rules/strict-boolean-expressions.d.ts +2 -1
  18. package/dist/rules/strict-boolean-expressions.d.ts.map +1 -1
  19. package/dist/rules/strict-boolean-expressions.js +457 -512
  20. package/dist/rules/unified-signatures.d.ts.map +1 -1
  21. package/dist/rules/unified-signatures.js +10 -3
  22. package/dist/util/hasOverloadSignatures.d.ts +7 -0
  23. package/dist/util/hasOverloadSignatures.d.ts.map +1 -0
  24. package/dist/util/hasOverloadSignatures.js +47 -0
  25. package/dist/util/index.d.ts +2 -0
  26. package/dist/util/index.d.ts.map +1 -1
  27. package/dist/util/index.js +2 -0
  28. package/dist/util/skipChainExpression.d.ts +3 -0
  29. package/dist/util/skipChainExpression.d.ts.map +1 -0
  30. package/dist/util/skipChainExpression.js +7 -0
  31. package/docs/rules/consistent-type-definitions.mdx +43 -4
  32. package/package.json +7 -7
@@ -1 +1 @@
1
- {"version":3,"file":"unified-signatures.d.ts","sourceRoot":"","sources":["../../src/rules/unified-signatures.ts"],"names":[],"mappings":"AAuDA,MAAM,MAAM,UAAU,GAClB,uBAAuB,GACvB,yBAAyB,GACzB,2BAA2B,CAAC;AAEhC,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,gCAAgC,CAAC,EAAE,OAAO,CAAC;KAC5C;CACF,CAAC;;AAEF,wBAugBG"}
1
+ {"version":3,"file":"unified-signatures.d.ts","sourceRoot":"","sources":["../../src/rules/unified-signatures.ts"],"names":[],"mappings":"AAuDA,MAAM,MAAM,UAAU,GAClB,uBAAuB,GACvB,yBAAyB,GACzB,2BAA2B,CAAC;AAEhC,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,gCAAgC,CAAC,EAAE,OAAO,CAAC;KAC5C;CACF,CAAC;;AAEF,wBA2gBG"}
@@ -334,12 +334,12 @@ exports.default = (0, util_1.createRule)({
334
334
  TSTypeLiteral: createScope,
335
335
  // collect overloads
336
336
  MethodDefinition(node) {
337
- if (!node.value.body) {
337
+ if (!node.value.body && !isGetterOrSetter(node)) {
338
338
  addOverload(node);
339
339
  }
340
340
  },
341
341
  TSAbstractMethodDefinition(node) {
342
- if (!node.value.body) {
342
+ if (!node.value.body && !isGetterOrSetter(node)) {
343
343
  addOverload(node);
344
344
  }
345
345
  },
@@ -349,7 +349,11 @@ exports.default = (0, util_1.createRule)({
349
349
  const exportingNode = getExportingNode(node);
350
350
  addOverload(node, node.id?.name ?? exportingNode?.type, exportingNode);
351
351
  },
352
- TSMethodSignature: addOverload,
352
+ TSMethodSignature(node) {
353
+ if (!isGetterOrSetter(node)) {
354
+ addOverload(node);
355
+ }
356
+ },
353
357
  // validate scopes
354
358
  'ClassDeclaration:exit': checkScope,
355
359
  'Program:exit': checkScope,
@@ -396,3 +400,6 @@ function getStaticParameterName(param) {
396
400
  function isIdentifier(node) {
397
401
  return node.type === utils_1.AST_NODE_TYPES.Identifier;
398
402
  }
403
+ function isGetterOrSetter(node) {
404
+ return node.kind === 'get' || node.kind === 'set';
405
+ }
@@ -0,0 +1,7 @@
1
+ import type { TSESTree } from '@typescript-eslint/utils';
2
+ import type { RuleContext } from '@typescript-eslint/utils/ts-eslint';
3
+ /**
4
+ * @return `true` if the function or method node has overload signatures.
5
+ */
6
+ export declare function hasOverloadSignatures(node: TSESTree.FunctionDeclaration | TSESTree.MethodDefinition, context: RuleContext<string, unknown[]>): boolean;
7
+ //# sourceMappingURL=hasOverloadSignatures.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hasOverloadSignatures.d.ts","sourceRoot":"","sources":["../../src/util/hasOverloadSignatures.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAMtE;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,QAAQ,CAAC,mBAAmB,GAAG,QAAQ,CAAC,gBAAgB,EAC9D,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,GACtC,OAAO,CAqCT"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasOverloadSignatures = hasOverloadSignatures;
4
+ const utils_1 = require("@typescript-eslint/utils");
5
+ const misc_1 = require("./misc");
6
+ /**
7
+ * @return `true` if the function or method node has overload signatures.
8
+ */
9
+ function hasOverloadSignatures(node, context) {
10
+ // `export default function () {}`
11
+ if (node.parent.type === utils_1.AST_NODE_TYPES.ExportDefaultDeclaration) {
12
+ return node.parent.parent.body.some(member => {
13
+ return (member.type === utils_1.AST_NODE_TYPES.ExportDefaultDeclaration &&
14
+ member.declaration.type === utils_1.AST_NODE_TYPES.TSDeclareFunction);
15
+ });
16
+ }
17
+ // `export function f() {}`
18
+ if (node.parent.type === utils_1.AST_NODE_TYPES.ExportNamedDeclaration) {
19
+ return node.parent.parent.body.some(member => {
20
+ return (member.type === utils_1.AST_NODE_TYPES.ExportNamedDeclaration &&
21
+ member.declaration?.type === utils_1.AST_NODE_TYPES.TSDeclareFunction &&
22
+ getFunctionDeclarationName(member.declaration, context) ===
23
+ getFunctionDeclarationName(node, context));
24
+ });
25
+ }
26
+ // either:
27
+ // - `function f() {}`
28
+ // - `class T { foo() {} }`
29
+ const nodeKey = getFunctionDeclarationName(node, context);
30
+ return node.parent.body.some(member => {
31
+ return ((member.type === utils_1.AST_NODE_TYPES.TSDeclareFunction ||
32
+ (member.type === utils_1.AST_NODE_TYPES.MethodDefinition &&
33
+ member.value.body == null)) &&
34
+ nodeKey === getFunctionDeclarationName(member, context));
35
+ });
36
+ }
37
+ function getFunctionDeclarationName(node, context) {
38
+ if (node.type === utils_1.AST_NODE_TYPES.FunctionDeclaration ||
39
+ node.type === utils_1.AST_NODE_TYPES.TSDeclareFunction) {
40
+ // For a `FunctionDeclaration` or `TSDeclareFunction` this may be `null` if
41
+ // and only if the parent is an `ExportDefaultDeclaration`.
42
+ //
43
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
44
+ return node.id.name;
45
+ }
46
+ return (0, misc_1.getStaticMemberAccessValue)(node, context);
47
+ }
@@ -10,6 +10,7 @@ export * from './getStringLength';
10
10
  export * from './getTextWithParentheses';
11
11
  export * from './getThisExpression';
12
12
  export * from './getWrappingFixer';
13
+ export * from './hasOverloadSignatures';
13
14
  export * from './isArrayMethodCallWithPredicate';
14
15
  export * from './isAssignee';
15
16
  export * from './isNodeEqual';
@@ -25,6 +26,7 @@ export * from './types';
25
26
  export * from './getConstraintInfo';
26
27
  export * from './getValueOfLiteralType';
27
28
  export * from './truthinessAndNullishUtils';
29
+ export * from './skipChainExpression';
28
30
  export * from '@typescript-eslint/type-utils';
29
31
  export declare const applyDefault: typeof ESLintUtils.applyDefault, deepMerge: typeof ESLintUtils.deepMerge, getParserServices: typeof ESLintUtils.getParserServices, isObjectNotArray: typeof ESLintUtils.isObjectNotArray, nullThrows: typeof ESLintUtils.nullThrows, NullThrowsReasons: {
30
32
  readonly MissingParent: "Expected node to have a parent.";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,cAAc,YAAY,CAAC;AAC3B,cAAc,0BAA0B,CAAC;AACzC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kCAAkC,CAAC;AACjD,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC;AACxC,cAAc,QAAQ,CAAC;AACvB,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAG5C,cAAc,+BAA+B,CAAC;AAE9C,eAAO,MACL,YAAY,mCACZ,SAAS,gCACT,iBAAiB,wCACjB,gBAAgB,uCAChB,UAAU,iCACV,iBAAiB;;;CACJ,CAAC;AAChB,MAAM,MAAM,2BAA2B,CAAC,CAAC,IACvC,WAAW,CAAC,2BAA2B,CAAC,CAAC,CAAC,CAAC;AAC7C,MAAM,MAAM,wBAAwB,CAAC,CAAC,IACpC,WAAW,CAAC,wBAAwB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getStringLength"), exports);
27
27
  __exportStar(require("./getTextWithParentheses"), exports);
28
28
  __exportStar(require("./getThisExpression"), exports);
29
29
  __exportStar(require("./getWrappingFixer"), exports);
30
+ __exportStar(require("./hasOverloadSignatures"), exports);
30
31
  __exportStar(require("./isArrayMethodCallWithPredicate"), exports);
31
32
  __exportStar(require("./isAssignee"), exports);
32
33
  __exportStar(require("./isNodeEqual"), exports);
@@ -42,6 +43,7 @@ __exportStar(require("./types"), exports);
42
43
  __exportStar(require("./getConstraintInfo"), exports);
43
44
  __exportStar(require("./getValueOfLiteralType"), exports);
44
45
  __exportStar(require("./truthinessAndNullishUtils"), exports);
46
+ __exportStar(require("./skipChainExpression"), exports);
45
47
  // this is done for convenience - saves migrating all of the old rules
46
48
  __exportStar(require("@typescript-eslint/type-utils"), exports);
47
49
  exports.applyDefault = utils_1.ESLintUtils.applyDefault, exports.deepMerge = utils_1.ESLintUtils.deepMerge, exports.getParserServices = utils_1.ESLintUtils.getParserServices, exports.isObjectNotArray = utils_1.ESLintUtils.isObjectNotArray, exports.nullThrows = utils_1.ESLintUtils.nullThrows, exports.NullThrowsReasons = utils_1.ESLintUtils.NullThrowsReasons;
@@ -0,0 +1,3 @@
1
+ import type { TSESTree } from '@typescript-eslint/utils';
2
+ export declare function skipChainExpression<T extends TSESTree.Node>(node: T): T | TSESTree.ChainElement;
3
+ //# sourceMappingURL=skipChainExpression.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skipChainExpression.d.ts","sourceRoot":"","sources":["../../src/util/skipChainExpression.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAIzD,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,QAAQ,CAAC,IAAI,EACzD,IAAI,EAAE,CAAC,GACN,CAAC,GAAG,QAAQ,CAAC,YAAY,CAE3B"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.skipChainExpression = skipChainExpression;
4
+ const utils_1 = require("@typescript-eslint/utils");
5
+ function skipChainExpression(node) {
6
+ return node.type === utils_1.AST_NODE_TYPES.ChainExpression ? node.expression : node;
7
+ }
@@ -82,13 +82,52 @@ type T = { x: number };
82
82
  </TabItem>
83
83
  </Tabs>
84
84
 
85
+ ## FAQs
86
+
87
+ ### What are the differences between `interface` and `type`?
88
+
89
+ There are very few differences between interfaces and object types in TypeScript.
90
+ Other than type aliases being used to represent union types, it is rare that you will need to choose one over the other.
91
+
92
+ | Feature | Interfaces | Object Types | Explanation |
93
+ | --------------------- | ---------- | ------------ | ------------------------------------------------------------------------------------------------------ |
94
+ | Object shapes | ✅ | ✅ | Both can be used to represent general object shapes. |
95
+ | General performance | ✅ | ✅ | Both are optimized for performance in TypeScript's type checker. |
96
+ | Edge case performance | ✅ | | Large, complex logical types can be optimized better with interfaces by TypeScript's type checker. |
97
+ | Traditional semantics | ✅ | | Interfaces are typically the default in much -though not all- of the TypeScript community. |
98
+ | Non-object shapes | | ✅ | Object types may describe literals, primitives, unions, and intersections. |
99
+ | Logical types | | ✅ | Object types may include conditional and mapped types. |
100
+ | Merging | Allowed | Not allowed | Interfaces of the same name are treated as one interface ("merged"); type aliases may not share names. |
101
+
102
+ We recommend choosing one definition style, using it when possible, and falling back to the other style when needed.
103
+ The benefits of remaining consistent within a codebase almost always outweigh the benefits of either definition style.
104
+
105
+ ### When do the performance differences between `interface` and `type` matter?
106
+
107
+ Almost never.
108
+ Most TypeScript projects do not -and should not- utilize types that exercise the performance differences between the two kinds of definitions.
109
+
110
+ If you are having problems with type checking performance, see the [TypeScript Wiki's Performance page](https://github.com/microsoft/TypeScript/wiki/Performance).
111
+
112
+ ### Why is the default `interface`?
113
+
114
+ Interfaces are the prevailing, most common style in the TypeScript.
115
+ `interface` has traditionally been TypeScript's intended ("semantic") way to convey _"an object with these fields"_.
116
+
117
+ We generally recommend staying with the default, `'interface'`, to be stylistically consistent with the majority of TypeScript projects.
118
+ If you strongly prefer `'type'`, that's fine too.
119
+
85
120
  ## When Not To Use It
86
121
 
87
- If you specifically want to use an interface or type literal for stylistic reasons, you can avoid this rule.
122
+ If you specifically want to manually choose whether to use an interface or type literal for stylistic reasons each time you define a type, you can avoid this rule.
88
123
 
89
124
  However, keep in mind that inconsistent style can harm readability in a project.
90
125
  We recommend picking a single option for this rule that works best for your project.
91
126
 
92
- There are also subtle differences between `Record` and `interface` that can be difficult to catch statically.
93
- For example, if your project is a dependency of another project that relies on a specific type definition style, this rule may be counterproductive.
94
- You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.
127
+ You might occasionally need to a different definition type in specific cases, such as if your project is a dependency or dependent of another project that relies on a specific type definition style.
128
+ Consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.
129
+
130
+ ## Further Reading
131
+
132
+ - [TypeScript Handbook > Everyday Types > Differences Between Type Aliases and Interfaces](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#differences-between-type-aliases-and-interfaces)
133
+ - [StackOverflow: Interfaces vs Types in TypeScript](https://stackoverflow.com/questions/37233735/interfaces-vs-types-in-typescript)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typescript-eslint/eslint-plugin",
3
- "version": "8.24.2-alpha.2",
3
+ "version": "8.24.2-alpha.4",
4
4
  "description": "TypeScript plugin for ESLint",
5
5
  "files": [
6
6
  "dist",
@@ -62,10 +62,10 @@
62
62
  },
63
63
  "dependencies": {
64
64
  "@eslint-community/regexpp": "^4.10.0",
65
- "@typescript-eslint/scope-manager": "8.24.2-alpha.2",
66
- "@typescript-eslint/type-utils": "8.24.2-alpha.2",
67
- "@typescript-eslint/utils": "8.24.2-alpha.2",
68
- "@typescript-eslint/visitor-keys": "8.24.2-alpha.2",
65
+ "@typescript-eslint/scope-manager": "8.24.2-alpha.4",
66
+ "@typescript-eslint/type-utils": "8.24.2-alpha.4",
67
+ "@typescript-eslint/utils": "8.24.2-alpha.4",
68
+ "@typescript-eslint/visitor-keys": "8.24.2-alpha.4",
69
69
  "graphemer": "^1.4.0",
70
70
  "ignore": "^5.3.1",
71
71
  "natural-compare": "^1.4.0",
@@ -76,8 +76,8 @@
76
76
  "@types/marked": "^5.0.2",
77
77
  "@types/mdast": "^4.0.3",
78
78
  "@types/natural-compare": "*",
79
- "@typescript-eslint/rule-schema-to-typescript-types": "8.24.2-alpha.2",
80
- "@typescript-eslint/rule-tester": "8.24.2-alpha.2",
79
+ "@typescript-eslint/rule-schema-to-typescript-types": "8.24.2-alpha.4",
80
+ "@typescript-eslint/rule-tester": "8.24.2-alpha.4",
81
81
  "ajv": "^6.12.6",
82
82
  "cross-env": "^7.0.3",
83
83
  "cross-fetch": "*",