eslint-plugin-complete 1.0.12 → 1.1.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.
@@ -1 +1 @@
1
- {"version":3,"file":"no-mutable-return.d.ts","sourceRoot":"","sources":["../../src/rules/no-mutable-return.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAMvD,KAAK,UAAU,GAAG,cAAc,GAAG,YAAY,GAAG,YAAY,CAAC;AAE/D,eAAO,MAAM,eAAe,wHAoD1B,CAAC"}
1
+ {"version":3,"file":"no-mutable-return.d.ts","sourceRoot":"","sources":["../../src/rules/no-mutable-return.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAMvD,KAAK,UAAU,GAAG,cAAc,GAAG,YAAY,GAAG,YAAY,CAAC;AAE/D,eAAO,MAAM,eAAe,wHAsD1B,CAAC"}
@@ -1,6 +1,5 @@
1
- import { isTypeReferenceType } from "@typescript-eslint/type-utils";
2
1
  import { ESLintUtils } from "@typescript-eslint/utils";
3
- import { getTypeName, unionTypeParts } from "../typeUtils.js";
2
+ import { getRealType, getTypeName, unionTypeParts } from "../typeUtils.js";
4
3
  import { createRule } from "../utils.js";
5
4
  export const noMutableReturn = createRule({
6
5
  name: "no-mutable-return",
@@ -28,7 +27,8 @@ export const noMutableReturn = createRule({
28
27
  const signatures = type.getCallSignatures();
29
28
  for (const signature of signatures) {
30
29
  const returnType = signature.getReturnType();
31
- for (const t of unionTypeParts(returnType)) {
30
+ const realReturnType = getRealType(parserServices.program, returnType);
31
+ for (const t of unionTypeParts(realReturnType)) {
32
32
  const messageId = getErrorMessageId(t);
33
33
  if (messageId !== undefined) {
34
34
  context.report({
@@ -52,15 +52,6 @@ function getErrorMessageId(type) {
52
52
  if (typeName === undefined) {
53
53
  return undefined;
54
54
  }
55
- // Handle unwrapping promises.
56
- if (typeName === "Promise"
57
- && isTypeReferenceType(type)
58
- && type.typeArguments !== undefined) {
59
- const typeArgument = type.typeArguments[0];
60
- if (typeArgument !== undefined) {
61
- return getErrorMessageId(typeArgument);
62
- }
63
- }
64
55
  // This would be "ReadonlyMap" if it was the read-only version.
65
56
  if (typeName === "Map") {
66
57
  return "mutableMap";
@@ -1,2 +1,3 @@
1
- export declare const noVoidReturnType: import("@typescript-eslint/utils/ts-eslint").RuleModule<"voidReturnType", [], import("../interfaces/MyPluginDocs.js").MyPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
1
+ import { ESLintUtils } from "@typescript-eslint/utils";
2
+ export declare const noVoidReturnType: ESLintUtils.RuleModule<"voidReturnType", [], import("../interfaces/MyPluginDocs.js").MyPluginDocs, ESLintUtils.RuleListener>;
2
3
  //# sourceMappingURL=no-void-return-type.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"no-void-return-type.d.ts","sourceRoot":"","sources":["../../src/rules/no-void-return-type.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,gBAAgB,gMAmD3B,CAAC"}
1
+ {"version":3,"file":"no-void-return-type.d.ts","sourceRoot":"","sources":["../../src/rules/no-void-return-type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAKvE,eAAO,MAAM,gBAAgB,8HAuD3B,CAAC"}
@@ -1,4 +1,5 @@
1
- import { AST_NODE_TYPES } from "@typescript-eslint/utils";
1
+ import { AST_NODE_TYPES, ESLintUtils } from "@typescript-eslint/utils";
2
+ import { getRealType, isVoid } from "../typeUtils.js";
2
3
  import { createRule } from "../utils.js";
3
4
  export const noVoidReturnType = createRule({
4
5
  name: "no-void-return-type",
@@ -7,7 +8,7 @@ export const noVoidReturnType = createRule({
7
8
  docs: {
8
9
  description: "Disallows `void` return types on non-exported functions",
9
10
  recommended: true,
10
- requiresTypeChecking: false,
11
+ requiresTypeChecking: true,
11
12
  },
12
13
  schema: [],
13
14
  messages: {
@@ -17,6 +18,8 @@ export const noVoidReturnType = createRule({
17
18
  },
18
19
  defaultOptions: [],
19
20
  create(context) {
21
+ const parserServices = ESLintUtils.getParserServices(context);
22
+ const checker = parserServices.program.getTypeChecker();
20
23
  return {
21
24
  FunctionDeclaration(node) {
22
25
  // Exported functions are exempt from this rule.
@@ -33,17 +36,22 @@ export const noVoidReturnType = createRule({
33
36
  return;
34
37
  }
35
38
  const { typeAnnotation } = returnType;
36
- if (typeAnnotation.type !== AST_NODE_TYPES.TSVoidKeyword) {
37
- return;
39
+ const tsNode = parserServices.esTreeNodeToTSNodeMap.get(typeAnnotation);
40
+ const type = checker.getTypeAtLocation(tsNode);
41
+ if (isVoidOrPromiseVoid(parserServices.program, type)) {
42
+ context.report({
43
+ loc: typeAnnotation.loc,
44
+ messageId: "voidReturnType",
45
+ fix(fixer) {
46
+ return fixer.remove(returnType);
47
+ },
48
+ });
38
49
  }
39
- context.report({
40
- loc: typeAnnotation.loc,
41
- messageId: "voidReturnType",
42
- fix(fixer) {
43
- return fixer.remove(returnType);
44
- },
45
- });
46
50
  },
47
51
  };
48
52
  },
49
53
  });
54
+ function isVoidOrPromiseVoid(program, type) {
55
+ const realType = getRealType(program, type);
56
+ return isVoid(realType);
57
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"prefer-readonly-parameter-types.d.ts","sourceRoot":"","sources":["../../src/rules/prefer-readonly-parameter-types.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAY1E,KAAK,OAAO,GAAG;IACb;QACE,KAAK,CAAC,EAAE,oBAAoB,EAAE,CAAC;QAC/B,wBAAwB,CAAC,EAAE,OAAO,CAAC;QACnC,mBAAmB,CAAC,EAAE,OAAO,CAAC;QAC9B,sBAAsB,CAAC,EAAE,OAAO,CAAC;QACjC,wBAAwB,CAAC,EAAE,OAAO,CAAC;KACpC;CACF,CAAC;AAGF,eAAO,MAAM,4BAA4B,6MA6MvC,CAAC"}
1
+ {"version":3,"file":"prefer-readonly-parameter-types.d.ts","sourceRoot":"","sources":["../../src/rules/prefer-readonly-parameter-types.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAY1E,KAAK,OAAO,GAAG;IACb;QACE,KAAK,CAAC,EAAE,oBAAoB,EAAE,CAAC;QAC/B,wBAAwB,CAAC,EAAE,OAAO,CAAC;QACnC,mBAAmB,CAAC,EAAE,OAAO,CAAC;QAC9B,sBAAsB,CAAC,EAAE,OAAO,CAAC;QACjC,wBAAwB,CAAC,EAAE,OAAO,CAAC;KACpC;CACF,CAAC;AAGF,eAAO,MAAM,4BAA4B,6MA2MvC,CAAC"}
@@ -55,9 +55,7 @@ export const preferReadonlyParameterTypes = createRule({
55
55
  ],
56
56
  create(context, [{ allow, checkParameterProperties, ignoreInferredTypes, treatMethodsAsReadonly, onlyRecordsArraysMapsSet, },]) {
57
57
  const services = getParserServices(context);
58
- if (allow === undefined) {
59
- allow = [];
60
- }
58
+ allow ??= [];
61
59
  allow.push("ReadonlyMap", "ReadonlySet");
62
60
  return {
63
61
  [[
@@ -1,4 +1,6 @@
1
1
  import ts from "typescript";
2
+ /** If the type is a `Promise`, this will unwrap it. */
3
+ export declare function getRealType(program: ts.Program, type: ts.Type): ts.Type;
2
4
  export declare function getTypeName(type: ts.Type): string | undefined;
3
5
  /**
4
6
  * @param symbol The symbol to check.
@@ -14,6 +16,7 @@ export declare function isSymbolFlagSet(symbol: ts.Symbol, flagsToCheck: number
14
16
  */
15
17
  export declare function isTypeArrayTupleTypeOrUnionOfArrayTupleTypes(type: ts.Type, checker: ts.TypeChecker): boolean;
16
18
  export declare function isAny(type: ts.Type): boolean;
19
+ export declare function isVoid(type: ts.Type): boolean;
17
20
  /** Returns all types of a union type or an array containing `type` itself if it's no union type. */
18
21
  export declare function unionTypeParts(type: ts.Type): readonly ts.Type[];
19
22
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"typeUtils.d.ts","sourceRoot":"","sources":["../src/typeUtils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,YAAY,CAAC;AAW5B,wBAAgB,WAAW,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,MAAM,GAAG,SAAS,CAoB7D;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,EAAE,CAAC,MAAM,EACjB,YAAY,EAAE,MAAM,GAAG,EAAE,CAAC,WAAW,GACpC,OAAO,CAET;AAED;;;;;;GAMG;AACH,wBAAgB,4CAA4C,CAC1D,IAAI,EAAE,EAAE,CAAC,IAAI,EACb,OAAO,EAAE,EAAE,CAAC,WAAW,GACtB,OAAO,CAQT;AAED,wBAAgB,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,OAAO,CAE5C;AAED,oGAAoG;AACpG,wBAAgB,cAAc,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,SAAS,EAAE,CAAC,IAAI,EAAE,CAEhE;AAOD;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,EAAE,CAAC,IAAI,EACb,YAAY,EAAE,MAAM,GAAG,EAAE,CAAC,SAAS,GAClC,OAAO,CAGT;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAE9D"}
1
+ {"version":3,"file":"typeUtils.d.ts","sourceRoot":"","sources":["../src/typeUtils.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,YAAY,CAAC;AAW5B,uDAAuD;AACvD,wBAAgB,WAAW,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,CAavE;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,MAAM,GAAG,SAAS,CAoB7D;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,EAAE,CAAC,MAAM,EACjB,YAAY,EAAE,MAAM,GAAG,EAAE,CAAC,WAAW,GACpC,OAAO,CAET;AAED;;;;;;GAMG;AACH,wBAAgB,4CAA4C,CAC1D,IAAI,EAAE,EAAE,CAAC,IAAI,EACb,OAAO,EAAE,EAAE,CAAC,WAAW,GACtB,OAAO,CAQT;AAED,wBAAgB,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,OAAO,CAE5C;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,OAAO,CAE7C;AAED,oGAAoG;AACpG,wBAAgB,cAAc,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,SAAS,EAAE,CAAC,IAAI,EAAE,CAEhE;AAOD;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,EAAE,CAAC,IAAI,EACb,YAAY,EAAE,MAAM,GAAG,EAAE,CAAC,SAAS,GAClC,OAAO,CAGT;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAE9D"}
package/dist/typeUtils.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // Some of the functions are copy-pasted here from the `typescript-eslint` repository and slightly
2
2
  // modified.
3
+ import { isPromiseLike, isTypeReferenceType, } from "@typescript-eslint/type-utils";
3
4
  import ts from "typescript";
4
5
  /** Gets all of the type flags in a type, iterating through unions automatically. */
5
6
  function getTypeFlags(type) {
@@ -9,6 +10,18 @@ function getTypeFlags(type) {
9
10
  }
10
11
  return flags;
11
12
  }
13
+ /** If the type is a `Promise`, this will unwrap it. */
14
+ export function getRealType(program, type) {
15
+ if (isPromiseLike(program, type)
16
+ && isTypeReferenceType(type)
17
+ && type.typeArguments !== undefined) {
18
+ const typeArgument = type.typeArguments[0];
19
+ if (typeArgument !== undefined) {
20
+ return typeArgument;
21
+ }
22
+ }
23
+ return type;
24
+ }
12
25
  export function getTypeName(type) {
13
26
  const escapedName = type.getSymbol()?.escapedName;
14
27
  if (escapedName !== undefined && escapedName !== "__type") {
@@ -52,6 +65,9 @@ export function isTypeArrayTupleTypeOrUnionOfArrayTupleTypes(type, checker) {
52
65
  export function isAny(type) {
53
66
  return isTypeFlagSet(type, ts.TypeFlags.Any);
54
67
  }
68
+ export function isVoid(type) {
69
+ return isTypeFlagSet(type, ts.TypeFlags.Void);
70
+ }
55
71
  /** Returns all types of a union type or an array containing `type` itself if it's no union type. */
56
72
  export function unionTypeParts(type) {
57
73
  return isUnion(type) ? type.types : [type];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-complete",
3
- "version": "1.0.12",
3
+ "version": "1.1.0",
4
4
  "description": "An ESLint plugin that contains useful rules.",
5
5
  "keywords": [
6
6
  "eslint",
@@ -44,23 +44,23 @@
44
44
  "test": "jest"
45
45
  },
46
46
  "dependencies": {
47
- "@typescript-eslint/type-utils": "8.26.0",
48
- "@typescript-eslint/utils": "8.26.0",
49
- "typescript-eslint": "8.26.0"
47
+ "@typescript-eslint/type-utils": "8.34.1",
48
+ "@typescript-eslint/utils": "8.34.1",
49
+ "typescript-eslint": "8.34.1"
50
50
  },
51
51
  "devDependencies": {
52
- "@babel/core": "7.26.9",
53
- "@babel/preset-env": "7.26.9",
54
- "@babel/preset-typescript": "7.26.0",
55
- "@types/jest": "29.5.14",
56
- "@types/node": "22.13.9",
57
- "@typescript-eslint/rule-tester": "8.26.0",
58
- "@typescript-eslint/types": "8.26.0",
59
- "complete-common": "1.3.0",
60
- "complete-node": "5.1.1",
61
- "jest": "29.7.0",
52
+ "@babel/core": "7.27.4",
53
+ "@babel/preset-env": "7.27.2",
54
+ "@babel/preset-typescript": "7.27.1",
55
+ "@types/jest": "30.0.0",
56
+ "@types/node": "24.0.3",
57
+ "@typescript-eslint/rule-tester": "8.34.1",
58
+ "@typescript-eslint/types": "8.34.1",
59
+ "complete-common": "2.2.0",
60
+ "complete-node": "5.1.6",
61
+ "jest": "30.0.2",
62
62
  "prettier": "3.5.3",
63
- "typescript": "5.8.2"
63
+ "typescript": "5.8.3"
64
64
  },
65
65
  "peerDependencies": {
66
66
  "eslint": ">= 9.0.0",