corsa-oxlint 0.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.
Files changed (121) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +171 -0
  3. package/dist/_virtual/_rolldown/runtime.js +13 -0
  4. package/dist/ast_utils.d.ts +17 -0
  5. package/dist/ast_utils.js +21 -0
  6. package/dist/ast_utils.js.map +1 -0
  7. package/dist/checker.d.ts +11 -0
  8. package/dist/checker.js +80 -0
  9. package/dist/checker.js.map +1 -0
  10. package/dist/compat.d.ts +194 -0
  11. package/dist/compat.js +103 -0
  12. package/dist/compat.js.map +1 -0
  13. package/dist/context.d.ts +24 -0
  14. package/dist/context.js +134 -0
  15. package/dist/context.js.map +1 -0
  16. package/dist/eslint_utils.d.ts +19 -0
  17. package/dist/eslint_utils.js +48 -0
  18. package/dist/eslint_utils.js.map +1 -0
  19. package/dist/index.d.ts +12 -0
  20. package/dist/index.js +11 -0
  21. package/dist/json_schema.d.ts +11 -0
  22. package/dist/json_schema.js +17 -0
  23. package/dist/json_schema.js.map +1 -0
  24. package/dist/node_map.d.ts +18 -0
  25. package/dist/node_map.js +52 -0
  26. package/dist/node_map.js.map +1 -0
  27. package/dist/parser_services.d.ts +16 -0
  28. package/dist/parser_services.js +48 -0
  29. package/dist/parser_services.js.map +1 -0
  30. package/dist/plugin.d.ts +26 -0
  31. package/dist/plugin.js +83 -0
  32. package/dist/plugin.js.map +1 -0
  33. package/dist/registry.d.ts +12 -0
  34. package/dist/registry.js +35 -0
  35. package/dist/registry.js.map +1 -0
  36. package/dist/rule_tester.d.ts +37 -0
  37. package/dist/rule_tester.js +120 -0
  38. package/dist/rule_tester.js.map +1 -0
  39. package/dist/rules/ast.d.ts +16 -0
  40. package/dist/rules/ast.js +56 -0
  41. package/dist/rules/ast.js.map +1 -0
  42. package/dist/rules/await_thenable.d.ts +16 -0
  43. package/dist/rules/await_thenable.js +23 -0
  44. package/dist/rules/await_thenable.js.map +1 -0
  45. package/dist/rules/index.d.ts +473 -0
  46. package/dist/rules/index.js +120 -0
  47. package/dist/rules/index.js.map +1 -0
  48. package/dist/rules/no_array_delete.d.ts +16 -0
  49. package/dist/rules/no_array_delete.js +29 -0
  50. package/dist/rules/no_array_delete.js.map +1 -0
  51. package/dist/rules/no_base_to_string.d.ts +16 -0
  52. package/dist/rules/no_base_to_string.js +66 -0
  53. package/dist/rules/no_base_to_string.js.map +1 -0
  54. package/dist/rules/no_floating_promises.d.ts +16 -0
  55. package/dist/rules/no_floating_promises.js +42 -0
  56. package/dist/rules/no_floating_promises.js.map +1 -0
  57. package/dist/rules/no_for_in_array.d.ts +16 -0
  58. package/dist/rules/no_for_in_array.js +16 -0
  59. package/dist/rules/no_for_in_array.js.map +1 -0
  60. package/dist/rules/no_implied_eval.d.ts +16 -0
  61. package/dist/rules/no_implied_eval.js +35 -0
  62. package/dist/rules/no_implied_eval.js.map +1 -0
  63. package/dist/rules/no_mixed_enums.d.ts +16 -0
  64. package/dist/rules/no_mixed_enums.js +41 -0
  65. package/dist/rules/no_mixed_enums.js.map +1 -0
  66. package/dist/rules/no_unsafe_assignment.d.ts +16 -0
  67. package/dist/rules/no_unsafe_assignment.js +41 -0
  68. package/dist/rules/no_unsafe_assignment.js.map +1 -0
  69. package/dist/rules/no_unsafe_return.d.ts +16 -0
  70. package/dist/rules/no_unsafe_return.js +56 -0
  71. package/dist/rules/no_unsafe_return.js.map +1 -0
  72. package/dist/rules/no_unsafe_unary_minus.d.ts +16 -0
  73. package/dist/rules/no_unsafe_unary_minus.js +28 -0
  74. package/dist/rules/no_unsafe_unary_minus.js.map +1 -0
  75. package/dist/rules/only_throw_error.d.ts +16 -0
  76. package/dist/rules/only_throw_error.js +16 -0
  77. package/dist/rules/only_throw_error.js.map +1 -0
  78. package/dist/rules/prefer_find.d.ts +16 -0
  79. package/dist/rules/prefer_find.js +25 -0
  80. package/dist/rules/prefer_find.js.map +1 -0
  81. package/dist/rules/prefer_includes.d.ts +16 -0
  82. package/dist/rules/prefer_includes.js +21 -0
  83. package/dist/rules/prefer_includes.js.map +1 -0
  84. package/dist/rules/prefer_promise_reject_errors.d.ts +16 -0
  85. package/dist/rules/prefer_promise_reject_errors.js +52 -0
  86. package/dist/rules/prefer_promise_reject_errors.js.map +1 -0
  87. package/dist/rules/prefer_regexp_exec.d.ts +16 -0
  88. package/dist/rules/prefer_regexp_exec.js +20 -0
  89. package/dist/rules/prefer_regexp_exec.js.map +1 -0
  90. package/dist/rules/prefer_string_starts_ends_with.d.ts +16 -0
  91. package/dist/rules/prefer_string_starts_ends_with.js +53 -0
  92. package/dist/rules/prefer_string_starts_ends_with.js.map +1 -0
  93. package/dist/rules/require_array_sort_compare.d.ts +16 -0
  94. package/dist/rules/require_array_sort_compare.js +36 -0
  95. package/dist/rules/require_array_sort_compare.js.map +1 -0
  96. package/dist/rules/restrict_plus_operands.d.ts +16 -0
  97. package/dist/rules/restrict_plus_operands.js +62 -0
  98. package/dist/rules/restrict_plus_operands.js.map +1 -0
  99. package/dist/rules/rule_creator.d.ts +16 -0
  100. package/dist/rules/rule_creator.js +22 -0
  101. package/dist/rules/rule_creator.js.map +1 -0
  102. package/dist/rules/type_utils.d.ts +56 -0
  103. package/dist/rules/type_utils.js +102 -0
  104. package/dist/rules/type_utils.js.map +1 -0
  105. package/dist/rules/use_unknown_in_catch_callback_variable.d.ts +16 -0
  106. package/dist/rules/use_unknown_in_catch_callback_variable.js +19 -0
  107. package/dist/rules/use_unknown_in_catch_callback_variable.js.map +1 -0
  108. package/dist/session.d.ts +32 -0
  109. package/dist/session.js +179 -0
  110. package/dist/session.js.map +1 -0
  111. package/dist/ts_eslint.d.ts +22 -0
  112. package/dist/ts_eslint.js +30 -0
  113. package/dist/ts_eslint.js.map +1 -0
  114. package/dist/ts_estree.d.ts +2 -0
  115. package/dist/ts_estree.js +2 -0
  116. package/dist/types.d.ts +136 -0
  117. package/dist/types.js +1 -0
  118. package/dist/utils.d.ts +22 -0
  119. package/dist/utils.js +22 -0
  120. package/dist/utils.js.map +1 -0
  121. package/package.json +69 -0
@@ -0,0 +1,66 @@
1
+ import { calleePropertyName, isIdentifierNamed, isLiteralString, stripChainExpression } from "./ast.js";
2
+ import { createNativeRule } from "./rule_creator.js";
3
+ import { classifyTypeText, isStringLikeNode, splitTopLevelTypeText, typeTextsAtNode } from "./type_utils.js";
4
+ //#region src/bindings/nodejs/typescript_oxlint/ts/rules/no_base_to_string.ts
5
+ const knownSafeObjectTypes = new Set([
6
+ "Date",
7
+ "Error",
8
+ "EvalError",
9
+ "RangeError",
10
+ "ReferenceError",
11
+ "RegExp",
12
+ "SyntaxError",
13
+ "TypeError",
14
+ "URIError",
15
+ "URL",
16
+ "URLSearchParams"
17
+ ]);
18
+ const noBaseToStringRule = createNativeRule("no-base-to-string", {
19
+ docs: { description: "Disallow stringifying values that fall back to Object.prototype.toString()." },
20
+ messages: { unexpected: "This value is stringified through its base Object#toString() representation." }
21
+ }, (context) => ({
22
+ BinaryExpression(node) {
23
+ if (node.operator !== "+") return;
24
+ if (isLiteralString(node.left) || isStringLikeNode(context, node.left)) reportIfUnsafe(context, node.right);
25
+ if (isLiteralString(node.right) || isStringLikeNode(context, node.right)) reportIfUnsafe(context, node.left);
26
+ },
27
+ CallExpression(node) {
28
+ const [firstArgument] = node.arguments;
29
+ if (!firstArgument) return;
30
+ if (isIdentifierNamed(node.callee, "String")) {
31
+ reportIfUnsafe(context, firstArgument);
32
+ return;
33
+ }
34
+ if (calleePropertyName(node) === "toString") reportIfUnsafe(context, stripChainExpression(node.callee).object);
35
+ },
36
+ TemplateLiteral(node) {
37
+ for (const expression of node.expressions ?? []) reportIfUnsafe(context, expression);
38
+ }
39
+ }));
40
+ function reportIfUnsafe(context, node) {
41
+ if (!node || !isPossiblyBaseToString(context, node)) return;
42
+ context.report({
43
+ node,
44
+ messageId: "unexpected"
45
+ });
46
+ }
47
+ function isPossiblyBaseToString(context, node) {
48
+ const current = stripChainExpression(node);
49
+ if (current?.type === "ArrayExpression" || current?.type === "ObjectExpression" || current?.type === "ArrowFunctionExpression" || current?.type === "FunctionExpression") return true;
50
+ const typeTexts = typeTextsAtNode(context, node);
51
+ if (typeTexts.length === 0) return false;
52
+ return typeTexts.some((text) => splitTopLevelTypeText(text, "|").some(isUnsafeStringifiedText));
53
+ }
54
+ function isUnsafeStringifiedText(text) {
55
+ const current = text.trim();
56
+ const kind = classifyTypeText(current);
57
+ if (kind === "string" || kind === "number" || kind === "bigint" || kind === "boolean" || kind === "nullish" || kind === "regexp") return false;
58
+ if (current === "symbol") return true;
59
+ if (knownSafeObjectTypes.has(current)) return false;
60
+ if (current === "object" || current === "Object" || current.startsWith("{") || current.endsWith("[]") || current.startsWith("[") || current.startsWith("Array<") || current.startsWith("ReadonlyArray<") || current.startsWith("Map<") || current.startsWith("ReadonlyMap<") || current.startsWith("Set<") || current.startsWith("ReadonlySet<") || current.startsWith("Record<") || current.startsWith("WeakMap<") || current.startsWith("WeakSet<") || current.startsWith("Promise<") || current.includes("=>")) return true;
61
+ return false;
62
+ }
63
+ //#endregion
64
+ export { noBaseToStringRule };
65
+
66
+ //# sourceMappingURL=no_base_to_string.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no_base_to_string.js","names":[],"sources":["../../ts/rules/no_base_to_string.ts"],"sourcesContent":["import {\n calleePropertyName,\n isIdentifierNamed,\n isLiteralString,\n stripChainExpression,\n} from \"./ast\";\nimport { createNativeRule } from \"./rule_creator\";\nimport {\n classifyTypeText,\n isStringLikeNode,\n splitTopLevelTypeText,\n typeTextsAtNode,\n} from \"./type_utils\";\n\nconst knownSafeObjectTypes = new Set([\n \"Date\",\n \"Error\",\n \"EvalError\",\n \"RangeError\",\n \"ReferenceError\",\n \"RegExp\",\n \"SyntaxError\",\n \"TypeError\",\n \"URIError\",\n \"URL\",\n \"URLSearchParams\",\n]);\n\nexport const noBaseToStringRule = createNativeRule(\n \"no-base-to-string\",\n {\n docs: {\n description: \"Disallow stringifying values that fall back to Object.prototype.toString().\",\n },\n messages: {\n unexpected: \"This value is stringified through its base Object#toString() representation.\",\n },\n },\n (context) => ({\n BinaryExpression(node: any) {\n if (node.operator !== \"+\") {\n return;\n }\n if (isLiteralString(node.left) || isStringLikeNode(context, node.left)) {\n reportIfUnsafe(context, node.right);\n }\n if (isLiteralString(node.right) || isStringLikeNode(context, node.right)) {\n reportIfUnsafe(context, node.left);\n }\n },\n CallExpression(node: any) {\n const [firstArgument] = node.arguments;\n if (!firstArgument) {\n return;\n }\n if (isIdentifierNamed(node.callee, \"String\")) {\n reportIfUnsafe(context, firstArgument);\n return;\n }\n if (calleePropertyName(node) === \"toString\") {\n const callee = stripChainExpression(node.callee) as any;\n reportIfUnsafe(context, callee.object);\n }\n },\n TemplateLiteral(node: any) {\n for (const expression of node.expressions ?? []) {\n reportIfUnsafe(context, expression);\n }\n },\n }),\n);\n\nfunction reportIfUnsafe(context: any, node: any): void {\n if (!node || !isPossiblyBaseToString(context, node)) {\n return;\n }\n context.report({\n node,\n messageId: \"unexpected\",\n });\n}\n\nfunction isPossiblyBaseToString(context: any, node: any): boolean {\n const current = stripChainExpression(node) as any;\n if (\n current?.type === \"ArrayExpression\" ||\n current?.type === \"ObjectExpression\" ||\n current?.type === \"ArrowFunctionExpression\" ||\n current?.type === \"FunctionExpression\"\n ) {\n return true;\n }\n const typeTexts = typeTextsAtNode(context, node);\n if (typeTexts.length === 0) {\n return false;\n }\n return typeTexts.some((text) => splitTopLevelTypeText(text, \"|\").some(isUnsafeStringifiedText));\n}\n\nfunction isUnsafeStringifiedText(text: string): boolean {\n const current = text.trim();\n const kind = classifyTypeText(current);\n if (\n kind === \"string\" ||\n kind === \"number\" ||\n kind === \"bigint\" ||\n kind === \"boolean\" ||\n kind === \"nullish\" ||\n kind === \"regexp\"\n ) {\n return false;\n }\n if (current === \"symbol\") {\n return true;\n }\n if (knownSafeObjectTypes.has(current)) {\n return false;\n }\n if (\n current === \"object\" ||\n current === \"Object\" ||\n current.startsWith(\"{\") ||\n current.endsWith(\"[]\") ||\n current.startsWith(\"[\") ||\n current.startsWith(\"Array<\") ||\n current.startsWith(\"ReadonlyArray<\") ||\n current.startsWith(\"Map<\") ||\n current.startsWith(\"ReadonlyMap<\") ||\n current.startsWith(\"Set<\") ||\n current.startsWith(\"ReadonlySet<\") ||\n current.startsWith(\"Record<\") ||\n current.startsWith(\"WeakMap<\") ||\n current.startsWith(\"WeakSet<\") ||\n current.startsWith(\"Promise<\") ||\n current.includes(\"=>\")\n ) {\n return true;\n }\n return false;\n}\n"],"mappings":";;;;AAcA,MAAM,uBAAuB,IAAI,IAAI;CACnC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,MAAa,qBAAqB,iBAChC,qBACA;CACE,MAAM,EACJ,aAAa,+EACd;CACD,UAAU,EACR,YAAY,gFACb;CACF,GACA,aAAa;CACZ,iBAAiB,MAAW;AAC1B,MAAI,KAAK,aAAa,IACpB;AAEF,MAAI,gBAAgB,KAAK,KAAK,IAAI,iBAAiB,SAAS,KAAK,KAAK,CACpE,gBAAe,SAAS,KAAK,MAAM;AAErC,MAAI,gBAAgB,KAAK,MAAM,IAAI,iBAAiB,SAAS,KAAK,MAAM,CACtE,gBAAe,SAAS,KAAK,KAAK;;CAGtC,eAAe,MAAW;EACxB,MAAM,CAAC,iBAAiB,KAAK;AAC7B,MAAI,CAAC,cACH;AAEF,MAAI,kBAAkB,KAAK,QAAQ,SAAS,EAAE;AAC5C,kBAAe,SAAS,cAAc;AACtC;;AAEF,MAAI,mBAAmB,KAAK,KAAK,WAE/B,gBAAe,SADA,qBAAqB,KAAK,OAAO,CACjB,OAAO;;CAG1C,gBAAgB,MAAW;AACzB,OAAK,MAAM,cAAc,KAAK,eAAe,EAAE,CAC7C,gBAAe,SAAS,WAAW;;CAGxC,EACF;AAED,SAAS,eAAe,SAAc,MAAiB;AACrD,KAAI,CAAC,QAAQ,CAAC,uBAAuB,SAAS,KAAK,CACjD;AAEF,SAAQ,OAAO;EACb;EACA,WAAW;EACZ,CAAC;;AAGJ,SAAS,uBAAuB,SAAc,MAAoB;CAChE,MAAM,UAAU,qBAAqB,KAAK;AAC1C,KACE,SAAS,SAAS,qBAClB,SAAS,SAAS,sBAClB,SAAS,SAAS,6BAClB,SAAS,SAAS,qBAElB,QAAO;CAET,MAAM,YAAY,gBAAgB,SAAS,KAAK;AAChD,KAAI,UAAU,WAAW,EACvB,QAAO;AAET,QAAO,UAAU,MAAM,SAAS,sBAAsB,MAAM,IAAI,CAAC,KAAK,wBAAwB,CAAC;;AAGjG,SAAS,wBAAwB,MAAuB;CACtD,MAAM,UAAU,KAAK,MAAM;CAC3B,MAAM,OAAO,iBAAiB,QAAQ;AACtC,KACE,SAAS,YACT,SAAS,YACT,SAAS,YACT,SAAS,aACT,SAAS,aACT,SAAS,SAET,QAAO;AAET,KAAI,YAAY,SACd,QAAO;AAET,KAAI,qBAAqB,IAAI,QAAQ,CACnC,QAAO;AAET,KACE,YAAY,YACZ,YAAY,YACZ,QAAQ,WAAW,IAAI,IACvB,QAAQ,SAAS,KAAK,IACtB,QAAQ,WAAW,IAAI,IACvB,QAAQ,WAAW,SAAS,IAC5B,QAAQ,WAAW,iBAAiB,IACpC,QAAQ,WAAW,OAAO,IAC1B,QAAQ,WAAW,eAAe,IAClC,QAAQ,WAAW,OAAO,IAC1B,QAAQ,WAAW,eAAe,IAClC,QAAQ,WAAW,UAAU,IAC7B,QAAQ,WAAW,WAAW,IAC9B,QAAQ,WAAW,WAAW,IAC9B,QAAQ,WAAW,WAAW,IAC9B,QAAQ,SAAS,KAAK,CAEtB,QAAO;AAET,QAAO"}
@@ -0,0 +1,16 @@
1
+ //#region src/bindings/nodejs/typescript_oxlint/ts/rules/no_floating_promises.d.ts
2
+ declare const noFloatingPromisesRule: {
3
+ defaultOptions: never[];
4
+ meta: {
5
+ docs: {
6
+ requiresTypeChecking: boolean;
7
+ url: string;
8
+ };
9
+ type: "problem";
10
+ schema: never[];
11
+ };
12
+ create: (context: any) => Record<string, (node: any) => void>;
13
+ };
14
+ //#endregion
15
+ export { noFloatingPromisesRule };
16
+ //# sourceMappingURL=no_floating_promises.d.ts.map
@@ -0,0 +1,42 @@
1
+ import { calleePropertyName, memberObject, nearestFunctionAncestors, stripChainExpression } from "./ast.js";
2
+ import { createNativeRule } from "./rule_creator.js";
3
+ import { isPromiseLikeNode } from "./type_utils.js";
4
+ //#region src/bindings/nodejs/typescript_oxlint/ts/rules/no_floating_promises.ts
5
+ const noFloatingPromisesRule = createNativeRule("no-floating-promises", {
6
+ docs: { description: "Require promises to be awaited or otherwise handled." },
7
+ hasSuggestions: true,
8
+ messages: { unexpected: "Promises must be awaited, returned, or explicitly ignored with void." }
9
+ }, (context) => ({ ExpressionStatement(node) {
10
+ const expression = stripChainExpression(node.expression);
11
+ if (expression?.type === "UnaryExpression" && expression.operator === "void") return;
12
+ if (!isPromiseLikeNode(context, expression) || isHandled(expression)) return;
13
+ context.report({
14
+ node,
15
+ messageId: "unexpected",
16
+ suggest: buildSuggestions(context, node)
17
+ });
18
+ } }));
19
+ function isHandled(node) {
20
+ const current = stripChainExpression(node);
21
+ const propertyName = calleePropertyName(current);
22
+ if (!propertyName) return false;
23
+ if (propertyName === "catch") return current.arguments.length > 0;
24
+ if (propertyName === "then") return current.arguments.length > 1;
25
+ if (propertyName === "finally") return isHandled(memberObject(current.callee));
26
+ return false;
27
+ }
28
+ function buildSuggestions(context, node) {
29
+ const suggestions = [{
30
+ desc: "Prefix the expression with void.",
31
+ fix: (fixer) => fixer.insertTextBefore(node.expression, "void ")
32
+ }];
33
+ if (nearestFunctionAncestors(node, context.sourceCode)[0]?.async) suggestions.push({
34
+ desc: "Await the promise.",
35
+ fix: (fixer) => fixer.insertTextBefore(node.expression, "await ")
36
+ });
37
+ return suggestions;
38
+ }
39
+ //#endregion
40
+ export { noFloatingPromisesRule };
41
+
42
+ //# sourceMappingURL=no_floating_promises.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no_floating_promises.js","names":[],"sources":["../../ts/rules/no_floating_promises.ts"],"sourcesContent":["import {\n calleePropertyName,\n memberObject,\n nearestFunctionAncestors,\n stripChainExpression,\n} from \"./ast\";\nimport { createNativeRule } from \"./rule_creator\";\nimport { isPromiseLikeNode } from \"./type_utils\";\n\nexport const noFloatingPromisesRule = createNativeRule(\n \"no-floating-promises\",\n {\n docs: {\n description: \"Require promises to be awaited or otherwise handled.\",\n },\n hasSuggestions: true,\n messages: {\n unexpected: \"Promises must be awaited, returned, or explicitly ignored with void.\",\n },\n },\n (context) => ({\n ExpressionStatement(node: any) {\n const expression = stripChainExpression(node.expression);\n if (expression?.type === \"UnaryExpression\" && expression.operator === \"void\") {\n return;\n }\n if (!isPromiseLikeNode(context, expression) || isHandled(expression)) {\n return;\n }\n context.report({\n node,\n messageId: \"unexpected\",\n suggest: buildSuggestions(context, node),\n });\n },\n }),\n);\n\nfunction isHandled(node: any): boolean {\n const current = stripChainExpression(node);\n const propertyName = calleePropertyName(current);\n if (!propertyName) {\n return false;\n }\n if (propertyName === \"catch\") {\n return current.arguments.length > 0;\n }\n if (propertyName === \"then\") {\n return current.arguments.length > 1;\n }\n if (propertyName === \"finally\") {\n return isHandled(memberObject(current.callee));\n }\n return false;\n}\n\nfunction buildSuggestions(context: any, node: any) {\n const suggestions = [\n {\n desc: \"Prefix the expression with void.\",\n fix: (fixer: any) => fixer.insertTextBefore(node.expression, \"void \"),\n },\n ];\n const nearestFunction = nearestFunctionAncestors(node, context.sourceCode)[0];\n if (nearestFunction?.async) {\n suggestions.push({\n desc: \"Await the promise.\",\n fix: (fixer: any) => fixer.insertTextBefore(node.expression, \"await \"),\n });\n }\n return suggestions;\n}\n"],"mappings":";;;;AASA,MAAa,yBAAyB,iBACpC,wBACA;CACE,MAAM,EACJ,aAAa,wDACd;CACD,gBAAgB;CAChB,UAAU,EACR,YAAY,wEACb;CACF,GACA,aAAa,EACZ,oBAAoB,MAAW;CAC7B,MAAM,aAAa,qBAAqB,KAAK,WAAW;AACxD,KAAI,YAAY,SAAS,qBAAqB,WAAW,aAAa,OACpE;AAEF,KAAI,CAAC,kBAAkB,SAAS,WAAW,IAAI,UAAU,WAAW,CAClE;AAEF,SAAQ,OAAO;EACb;EACA,WAAW;EACX,SAAS,iBAAiB,SAAS,KAAK;EACzC,CAAC;GAEL,EACF;AAED,SAAS,UAAU,MAAoB;CACrC,MAAM,UAAU,qBAAqB,KAAK;CAC1C,MAAM,eAAe,mBAAmB,QAAQ;AAChD,KAAI,CAAC,aACH,QAAO;AAET,KAAI,iBAAiB,QACnB,QAAO,QAAQ,UAAU,SAAS;AAEpC,KAAI,iBAAiB,OACnB,QAAO,QAAQ,UAAU,SAAS;AAEpC,KAAI,iBAAiB,UACnB,QAAO,UAAU,aAAa,QAAQ,OAAO,CAAC;AAEhD,QAAO;;AAGT,SAAS,iBAAiB,SAAc,MAAW;CACjD,MAAM,cAAc,CAClB;EACE,MAAM;EACN,MAAM,UAAe,MAAM,iBAAiB,KAAK,YAAY,QAAQ;EACtE,CACF;AAED,KADwB,yBAAyB,MAAM,QAAQ,WAAW,CAAC,IACtD,MACnB,aAAY,KAAK;EACf,MAAM;EACN,MAAM,UAAe,MAAM,iBAAiB,KAAK,YAAY,SAAS;EACvE,CAAC;AAEJ,QAAO"}
@@ -0,0 +1,16 @@
1
+ //#region src/bindings/nodejs/typescript_oxlint/ts/rules/no_for_in_array.d.ts
2
+ declare const noForInArrayRule: {
3
+ defaultOptions: never[];
4
+ meta: {
5
+ docs: {
6
+ requiresTypeChecking: boolean;
7
+ url: string;
8
+ };
9
+ type: "problem";
10
+ schema: never[];
11
+ };
12
+ create: (context: any) => Record<string, (node: any) => void>;
13
+ };
14
+ //#endregion
15
+ export { noForInArrayRule };
16
+ //# sourceMappingURL=no_for_in_array.d.ts.map
@@ -0,0 +1,16 @@
1
+ import { createNativeRule } from "./rule_creator.js";
2
+ import { isArrayLikeNode } from "./type_utils.js";
3
+ //#region src/bindings/nodejs/typescript_oxlint/ts/rules/no_for_in_array.ts
4
+ const noForInArrayRule = createNativeRule("no-for-in-array", {
5
+ docs: { description: "Disallow for-in iteration over array-like values." },
6
+ messages: { unexpected: "Do not iterate over an array with a for-in loop." }
7
+ }, (context) => ({ ForInStatement(node) {
8
+ if (isArrayLikeNode(context, node.right)) context.report({
9
+ node,
10
+ messageId: "unexpected"
11
+ });
12
+ } }));
13
+ //#endregion
14
+ export { noForInArrayRule };
15
+
16
+ //# sourceMappingURL=no_for_in_array.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no_for_in_array.js","names":[],"sources":["../../ts/rules/no_for_in_array.ts"],"sourcesContent":["import { createNativeRule } from \"./rule_creator\";\nimport { isArrayLikeNode } from \"./type_utils\";\n\nexport const noForInArrayRule = createNativeRule(\n \"no-for-in-array\",\n {\n docs: {\n description: \"Disallow for-in iteration over array-like values.\",\n },\n messages: {\n unexpected: \"Do not iterate over an array with a for-in loop.\",\n },\n },\n (context) => ({\n ForInStatement(node: any) {\n if (isArrayLikeNode(context, node.right)) {\n context.report({ node, messageId: \"unexpected\" });\n }\n },\n }),\n);\n"],"mappings":";;;AAGA,MAAa,mBAAmB,iBAC9B,mBACA;CACE,MAAM,EACJ,aAAa,qDACd;CACD,UAAU,EACR,YAAY,oDACb;CACF,GACA,aAAa,EACZ,eAAe,MAAW;AACxB,KAAI,gBAAgB,SAAS,KAAK,MAAM,CACtC,SAAQ,OAAO;EAAE;EAAM,WAAW;EAAc,CAAC;GAGtD,EACF"}
@@ -0,0 +1,16 @@
1
+ //#region src/bindings/nodejs/typescript_oxlint/ts/rules/no_implied_eval.d.ts
2
+ declare const noImpliedEvalRule: {
3
+ defaultOptions: never[];
4
+ meta: {
5
+ docs: {
6
+ requiresTypeChecking: boolean;
7
+ url: string;
8
+ };
9
+ type: "problem";
10
+ schema: never[];
11
+ };
12
+ create: (context: any) => Record<string, (node: any) => void>;
13
+ };
14
+ //#endregion
15
+ export { noImpliedEvalRule };
16
+ //# sourceMappingURL=no_implied_eval.d.ts.map
@@ -0,0 +1,35 @@
1
+ import { isIdentifierNamed, isLiteralString, memberPropertyName, stripChainExpression } from "./ast.js";
2
+ import { createNativeRule } from "./rule_creator.js";
3
+ import { isStringLikeNode } from "./type_utils.js";
4
+ //#region src/bindings/nodejs/typescript_oxlint/ts/rules/no_implied_eval.ts
5
+ const impliedEvalNames = new Set([
6
+ "execScript",
7
+ "setInterval",
8
+ "setTimeout"
9
+ ]);
10
+ const noImpliedEvalRule = createNativeRule("no-implied-eval", {
11
+ docs: { description: "Disallow string-based dynamic code execution APIs." },
12
+ messages: { unexpected: "Do not pass a string to an implied eval API." }
13
+ }, (context) => ({
14
+ CallExpression(node) {
15
+ const callee = stripChainExpression(node.callee);
16
+ const calleeName = memberPropertyName(callee) ?? (callee?.type === "Identifier" ? callee.name : void 0);
17
+ if (!calleeName || !impliedEvalNames.has(calleeName)) return;
18
+ const [firstArgument] = node.arguments;
19
+ if (firstArgument && !firstArgument.type?.includes("Function") && (isLiteralString(firstArgument) || isStringLikeNode(context, firstArgument))) context.report({
20
+ node,
21
+ messageId: "unexpected"
22
+ });
23
+ },
24
+ NewExpression(node) {
25
+ if (!isIdentifierNamed(node.callee, "Function")) return;
26
+ if (node.arguments.some((argument) => isLiteralString(argument))) context.report({
27
+ node,
28
+ messageId: "unexpected"
29
+ });
30
+ }
31
+ }));
32
+ //#endregion
33
+ export { noImpliedEvalRule };
34
+
35
+ //# sourceMappingURL=no_implied_eval.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no_implied_eval.js","names":[],"sources":["../../ts/rules/no_implied_eval.ts"],"sourcesContent":["import {\n isIdentifierNamed,\n isLiteralString,\n memberPropertyName,\n stripChainExpression,\n} from \"./ast\";\nimport { createNativeRule } from \"./rule_creator\";\nimport { isStringLikeNode } from \"./type_utils\";\n\nconst impliedEvalNames = new Set([\"execScript\", \"setInterval\", \"setTimeout\"]);\n\nexport const noImpliedEvalRule = createNativeRule(\n \"no-implied-eval\",\n {\n docs: {\n description: \"Disallow string-based dynamic code execution APIs.\",\n },\n messages: {\n unexpected: \"Do not pass a string to an implied eval API.\",\n },\n },\n (context) => ({\n CallExpression(node: any) {\n const callee = stripChainExpression(node.callee);\n const calleeName =\n memberPropertyName(callee) ?? (callee?.type === \"Identifier\" ? callee.name : undefined);\n if (!calleeName || !impliedEvalNames.has(calleeName)) {\n return;\n }\n const [firstArgument] = node.arguments;\n if (\n firstArgument &&\n !firstArgument.type?.includes(\"Function\") &&\n (isLiteralString(firstArgument) || isStringLikeNode(context, firstArgument))\n ) {\n context.report({ node, messageId: \"unexpected\" });\n }\n },\n NewExpression(node: any) {\n if (!isIdentifierNamed(node.callee, \"Function\")) {\n return;\n }\n if (node.arguments.some((argument: any) => isLiteralString(argument))) {\n context.report({ node, messageId: \"unexpected\" });\n }\n },\n }),\n);\n"],"mappings":";;;;AASA,MAAM,mBAAmB,IAAI,IAAI;CAAC;CAAc;CAAe;CAAa,CAAC;AAE7E,MAAa,oBAAoB,iBAC/B,mBACA;CACE,MAAM,EACJ,aAAa,sDACd;CACD,UAAU,EACR,YAAY,gDACb;CACF,GACA,aAAa;CACZ,eAAe,MAAW;EACxB,MAAM,SAAS,qBAAqB,KAAK,OAAO;EAChD,MAAM,aACJ,mBAAmB,OAAO,KAAK,QAAQ,SAAS,eAAe,OAAO,OAAO,KAAA;AAC/E,MAAI,CAAC,cAAc,CAAC,iBAAiB,IAAI,WAAW,CAClD;EAEF,MAAM,CAAC,iBAAiB,KAAK;AAC7B,MACE,iBACA,CAAC,cAAc,MAAM,SAAS,WAAW,KACxC,gBAAgB,cAAc,IAAI,iBAAiB,SAAS,cAAc,EAE3E,SAAQ,OAAO;GAAE;GAAM,WAAW;GAAc,CAAC;;CAGrD,cAAc,MAAW;AACvB,MAAI,CAAC,kBAAkB,KAAK,QAAQ,WAAW,CAC7C;AAEF,MAAI,KAAK,UAAU,MAAM,aAAkB,gBAAgB,SAAS,CAAC,CACnE,SAAQ,OAAO;GAAE;GAAM,WAAW;GAAc,CAAC;;CAGtD,EACF"}
@@ -0,0 +1,16 @@
1
+ //#region src/bindings/nodejs/typescript_oxlint/ts/rules/no_mixed_enums.d.ts
2
+ declare const noMixedEnumsRule: {
3
+ defaultOptions: never[];
4
+ meta: {
5
+ docs: {
6
+ requiresTypeChecking: boolean;
7
+ url: string;
8
+ };
9
+ type: "problem";
10
+ schema: never[];
11
+ };
12
+ create: (context: any) => Record<string, (node: any) => void>;
13
+ };
14
+ //#endregion
15
+ export { noMixedEnumsRule };
16
+ //# sourceMappingURL=no_mixed_enums.d.ts.map
@@ -0,0 +1,41 @@
1
+ import { createNativeRule } from "./rule_creator.js";
2
+ import { isNumberLikeNode, isStringLikeNode } from "./type_utils.js";
3
+ //#region src/bindings/nodejs/typescript_oxlint/ts/rules/no_mixed_enums.ts
4
+ const noMixedEnumsRule = createNativeRule("no-mixed-enums", {
5
+ docs: { description: "Disallow mixing string and numeric enum members." },
6
+ messages: { mixed: "Mixing number and string enums can be confusing." }
7
+ }, (context) => ({ TSEnumDeclaration(node) {
8
+ const members = enumMembersOf(node);
9
+ if (members.length === 0) return;
10
+ const desiredKind = enumMemberKind(context, members[0]);
11
+ if (desiredKind === "unknown") return;
12
+ for (const member of members) {
13
+ const currentKind = enumMemberKind(context, member);
14
+ if (currentKind === "unknown") return;
15
+ if (currentKind !== desiredKind) {
16
+ context.report({
17
+ node: member.initializer ?? member,
18
+ messageId: "mixed"
19
+ });
20
+ return;
21
+ }
22
+ }
23
+ } }));
24
+ function enumMembersOf(node) {
25
+ return node.body?.members ?? node.members ?? [];
26
+ }
27
+ function enumMemberKind(context, member) {
28
+ const initializer = member.initializer;
29
+ if (!initializer) return "number";
30
+ if (initializer.type === "Literal") {
31
+ if (typeof initializer.value === "number") return "number";
32
+ if (typeof initializer.value === "string") return "string";
33
+ }
34
+ if (isStringLikeNode(context, initializer)) return "string";
35
+ if (isNumberLikeNode(context, initializer)) return "number";
36
+ return "unknown";
37
+ }
38
+ //#endregion
39
+ export { noMixedEnumsRule };
40
+
41
+ //# sourceMappingURL=no_mixed_enums.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no_mixed_enums.js","names":[],"sources":["../../ts/rules/no_mixed_enums.ts"],"sourcesContent":["import { createNativeRule } from \"./rule_creator\";\nimport { isNumberLikeNode, isStringLikeNode } from \"./type_utils\";\n\nexport const noMixedEnumsRule = createNativeRule(\n \"no-mixed-enums\",\n {\n docs: {\n description: \"Disallow mixing string and numeric enum members.\",\n },\n messages: {\n mixed: \"Mixing number and string enums can be confusing.\",\n },\n },\n (context) => ({\n TSEnumDeclaration(node: any) {\n const members = enumMembersOf(node);\n if (members.length === 0) {\n return;\n }\n const desiredKind = enumMemberKind(context, members[0]);\n if (desiredKind === \"unknown\") {\n return;\n }\n for (const member of members) {\n const currentKind = enumMemberKind(context, member);\n if (currentKind === \"unknown\") {\n return;\n }\n if (currentKind !== desiredKind) {\n context.report({\n node: member.initializer ?? member,\n messageId: \"mixed\",\n });\n return;\n }\n }\n },\n }),\n);\n\nfunction enumMembersOf(node: any): readonly any[] {\n return node.body?.members ?? node.members ?? [];\n}\n\nfunction enumMemberKind(context: any, member: any): \"number\" | \"string\" | \"unknown\" {\n const initializer = member.initializer;\n if (!initializer) {\n return \"number\";\n }\n if (initializer.type === \"Literal\") {\n if (typeof initializer.value === \"number\") {\n return \"number\";\n }\n if (typeof initializer.value === \"string\") {\n return \"string\";\n }\n }\n if (isStringLikeNode(context, initializer)) {\n return \"string\";\n }\n if (isNumberLikeNode(context, initializer)) {\n return \"number\";\n }\n return \"unknown\";\n}\n"],"mappings":";;;AAGA,MAAa,mBAAmB,iBAC9B,kBACA;CACE,MAAM,EACJ,aAAa,oDACd;CACD,UAAU,EACR,OAAO,oDACR;CACF,GACA,aAAa,EACZ,kBAAkB,MAAW;CAC3B,MAAM,UAAU,cAAc,KAAK;AACnC,KAAI,QAAQ,WAAW,EACrB;CAEF,MAAM,cAAc,eAAe,SAAS,QAAQ,GAAG;AACvD,KAAI,gBAAgB,UAClB;AAEF,MAAK,MAAM,UAAU,SAAS;EAC5B,MAAM,cAAc,eAAe,SAAS,OAAO;AACnD,MAAI,gBAAgB,UAClB;AAEF,MAAI,gBAAgB,aAAa;AAC/B,WAAQ,OAAO;IACb,MAAM,OAAO,eAAe;IAC5B,WAAW;IACZ,CAAC;AACF;;;GAIP,EACF;AAED,SAAS,cAAc,MAA2B;AAChD,QAAO,KAAK,MAAM,WAAW,KAAK,WAAW,EAAE;;AAGjD,SAAS,eAAe,SAAc,QAA8C;CAClF,MAAM,cAAc,OAAO;AAC3B,KAAI,CAAC,YACH,QAAO;AAET,KAAI,YAAY,SAAS,WAAW;AAClC,MAAI,OAAO,YAAY,UAAU,SAC/B,QAAO;AAET,MAAI,OAAO,YAAY,UAAU,SAC/B,QAAO;;AAGX,KAAI,iBAAiB,SAAS,YAAY,CACxC,QAAO;AAET,KAAI,iBAAiB,SAAS,YAAY,CACxC,QAAO;AAET,QAAO"}
@@ -0,0 +1,16 @@
1
+ //#region src/bindings/nodejs/typescript_oxlint/ts/rules/no_unsafe_assignment.d.ts
2
+ declare const noUnsafeAssignmentRule: {
3
+ defaultOptions: never[];
4
+ meta: {
5
+ docs: {
6
+ requiresTypeChecking: boolean;
7
+ url: string;
8
+ };
9
+ type: "problem";
10
+ schema: never[];
11
+ };
12
+ create: (context: any) => Record<string, (node: any) => void>;
13
+ };
14
+ //#endregion
15
+ export { noUnsafeAssignmentRule };
16
+ //# sourceMappingURL=no_unsafe_assignment.d.ts.map
@@ -0,0 +1,41 @@
1
+ import { createNativeRule } from "./rule_creator.js";
2
+ import { typeTextsAtNode } from "./type_utils.js";
3
+ import { isUnsafeAssignment } from "@corsa-bind/napi";
4
+ //#region src/bindings/nodejs/typescript_oxlint/ts/rules/no_unsafe_assignment.ts
5
+ const noUnsafeAssignmentRule = createNativeRule("no-unsafe-assignment", {
6
+ docs: { description: "Disallow assigning any-typed values to more specific targets." },
7
+ messages: { unsafe: "Unsafe assignment of an any-typed value." }
8
+ }, (context) => ({
9
+ AssignmentExpression(node) {
10
+ if (node.operator !== "=") return;
11
+ reportIfUnsafe(context, node.right, typeTextsAtNode(context, node.left), node);
12
+ },
13
+ PropertyDefinition(node) {
14
+ if (!node.value) return;
15
+ reportIfUnsafe(context, node.value, targetTypeTextsForNode(context, node), node);
16
+ },
17
+ VariableDeclarator(node) {
18
+ if (!node.init) return;
19
+ reportIfUnsafe(context, node.init, targetTypeTextsForNode(context, node.id), node);
20
+ }
21
+ }));
22
+ function reportIfUnsafe(context, sourceNode, targetTypeTexts, reportNode) {
23
+ if (!isUnsafeAssignment({
24
+ sourceTypeTexts: typeTextsAtNode(context, sourceNode),
25
+ targetTypeTexts
26
+ })) return;
27
+ context.report({
28
+ node: reportNode,
29
+ messageId: "unsafe"
30
+ });
31
+ }
32
+ function targetTypeTextsForNode(context, node) {
33
+ const annotation = node?.typeAnnotation?.typeAnnotation ?? node?.typeAnnotation;
34
+ if (!annotation) return [];
35
+ const text = context.sourceCode.getText(annotation);
36
+ return text ? [text] : [];
37
+ }
38
+ //#endregion
39
+ export { noUnsafeAssignmentRule };
40
+
41
+ //# sourceMappingURL=no_unsafe_assignment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no_unsafe_assignment.js","names":[],"sources":["../../ts/rules/no_unsafe_assignment.ts"],"sourcesContent":["import { isUnsafeAssignment } from \"@corsa-bind/napi\";\n\nimport { createNativeRule } from \"./rule_creator\";\nimport { typeTextsAtNode } from \"./type_utils\";\n\nexport const noUnsafeAssignmentRule = createNativeRule(\n \"no-unsafe-assignment\",\n {\n docs: {\n description: \"Disallow assigning any-typed values to more specific targets.\",\n },\n messages: {\n unsafe: \"Unsafe assignment of an any-typed value.\",\n },\n },\n (context) => ({\n AssignmentExpression(node: any) {\n if (node.operator !== \"=\") {\n return;\n }\n reportIfUnsafe(context, node.right, typeTextsAtNode(context, node.left), node);\n },\n PropertyDefinition(node: any) {\n if (!node.value) {\n return;\n }\n reportIfUnsafe(context, node.value, targetTypeTextsForNode(context, node), node);\n },\n VariableDeclarator(node: any) {\n if (!node.init) {\n return;\n }\n reportIfUnsafe(context, node.init, targetTypeTextsForNode(context, node.id), node);\n },\n }),\n);\n\nfunction reportIfUnsafe(\n context: any,\n sourceNode: any,\n targetTypeTexts: readonly string[],\n reportNode: any,\n): void {\n const sourceTypeTexts = typeTextsAtNode(context, sourceNode);\n if (\n !isUnsafeAssignment({\n sourceTypeTexts,\n targetTypeTexts,\n })\n ) {\n return;\n }\n context.report({\n node: reportNode,\n messageId: \"unsafe\",\n });\n}\n\nfunction targetTypeTextsForNode(context: any, node: any): readonly string[] {\n const annotation = node?.typeAnnotation?.typeAnnotation ?? node?.typeAnnotation;\n if (!annotation) {\n return [];\n }\n const text = context.sourceCode.getText(annotation);\n return text ? [text] : [];\n}\n"],"mappings":";;;;AAKA,MAAa,yBAAyB,iBACpC,wBACA;CACE,MAAM,EACJ,aAAa,iEACd;CACD,UAAU,EACR,QAAQ,4CACT;CACF,GACA,aAAa;CACZ,qBAAqB,MAAW;AAC9B,MAAI,KAAK,aAAa,IACpB;AAEF,iBAAe,SAAS,KAAK,OAAO,gBAAgB,SAAS,KAAK,KAAK,EAAE,KAAK;;CAEhF,mBAAmB,MAAW;AAC5B,MAAI,CAAC,KAAK,MACR;AAEF,iBAAe,SAAS,KAAK,OAAO,uBAAuB,SAAS,KAAK,EAAE,KAAK;;CAElF,mBAAmB,MAAW;AAC5B,MAAI,CAAC,KAAK,KACR;AAEF,iBAAe,SAAS,KAAK,MAAM,uBAAuB,SAAS,KAAK,GAAG,EAAE,KAAK;;CAErF,EACF;AAED,SAAS,eACP,SACA,YACA,iBACA,YACM;AAEN,KACE,CAAC,mBAAmB;EAClB,iBAHoB,gBAAgB,SAAS,WAAW;EAIxD;EACD,CAAC,CAEF;AAEF,SAAQ,OAAO;EACb,MAAM;EACN,WAAW;EACZ,CAAC;;AAGJ,SAAS,uBAAuB,SAAc,MAA8B;CAC1E,MAAM,aAAa,MAAM,gBAAgB,kBAAkB,MAAM;AACjE,KAAI,CAAC,WACH,QAAO,EAAE;CAEX,MAAM,OAAO,QAAQ,WAAW,QAAQ,WAAW;AACnD,QAAO,OAAO,CAAC,KAAK,GAAG,EAAE"}
@@ -0,0 +1,16 @@
1
+ //#region src/bindings/nodejs/typescript_oxlint/ts/rules/no_unsafe_return.d.ts
2
+ declare const noUnsafeReturnRule: {
3
+ defaultOptions: never[];
4
+ meta: {
5
+ docs: {
6
+ requiresTypeChecking: boolean;
7
+ url: string;
8
+ };
9
+ type: "problem";
10
+ schema: never[];
11
+ };
12
+ create: (context: any) => Record<string, (node: any) => void>;
13
+ };
14
+ //#endregion
15
+ export { noUnsafeReturnRule };
16
+ //# sourceMappingURL=no_unsafe_return.d.ts.map
@@ -0,0 +1,56 @@
1
+ import { nearestFunctionAncestors } from "./ast.js";
2
+ import { createNativeRule } from "./rule_creator.js";
3
+ import { checkerFor, typeAtNode, typeTextsAtNode } from "./type_utils.js";
4
+ import { isUnsafeReturn } from "@corsa-bind/napi";
5
+ //#region src/bindings/nodejs/typescript_oxlint/ts/rules/no_unsafe_return.ts
6
+ const callSignatureKind = 0;
7
+ const noUnsafeReturnRule = createNativeRule("no-unsafe-return", {
8
+ docs: { description: "Disallow returning any-typed values from functions." },
9
+ messages: { unsafe: "Unsafe return of an any-typed value." }
10
+ }, (context) => ({
11
+ ArrowFunctionExpression(node) {
12
+ if (node.body?.type === "BlockStatement") return;
13
+ reportIfUnsafeReturn(context, node.body, node);
14
+ },
15
+ ReturnStatement(node) {
16
+ if (!node.argument) return;
17
+ const [owner] = nearestFunctionAncestors(node, context.sourceCode);
18
+ if (!owner) return;
19
+ reportIfUnsafeReturn(context, node.argument, owner);
20
+ }
21
+ }));
22
+ function reportIfUnsafeReturn(context, expression, owner) {
23
+ if (!isUnsafeReturn({
24
+ sourceTypeTexts: typeTextsAtNode(context, expression),
25
+ targetTypeTexts: returnTypeTextsOfFunction(context, owner)
26
+ })) return;
27
+ context.report({
28
+ node: expression,
29
+ messageId: "unsafe"
30
+ });
31
+ }
32
+ function returnTypeTextsOfFunction(context, node) {
33
+ const explicitAnnotation = node.returnType?.typeAnnotation ?? node.returnType;
34
+ if (explicitAnnotation) {
35
+ const text = context.sourceCode.getText(explicitAnnotation);
36
+ if (text) return [text];
37
+ }
38
+ const checker = checkerFor(context);
39
+ const type = typeAtNode(context, node);
40
+ if (!type) return [];
41
+ const texts = /* @__PURE__ */ new Set();
42
+ for (const signature of checker.getSignaturesOfType(type, callSignatureKind)) {
43
+ const returnType = checker.getReturnTypeOfSignature(signature);
44
+ if (!returnType) continue;
45
+ for (const text of [...returnType.texts ?? [], checker.typeToString(returnType)]) if (text) texts.add(text);
46
+ }
47
+ const resolved = [...texts];
48
+ return resolved.every(isPermissiveTypeText) ? [] : resolved;
49
+ }
50
+ function isPermissiveTypeText(text) {
51
+ return text === "any" || text === "unknown" || text === "never";
52
+ }
53
+ //#endregion
54
+ export { noUnsafeReturnRule };
55
+
56
+ //# sourceMappingURL=no_unsafe_return.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no_unsafe_return.js","names":[],"sources":["../../ts/rules/no_unsafe_return.ts"],"sourcesContent":["import { isUnsafeReturn } from \"@corsa-bind/napi\";\n\nimport { nearestFunctionAncestors } from \"./ast\";\nimport { createNativeRule } from \"./rule_creator\";\nimport { checkerFor, typeAtNode, typeTextsAtNode } from \"./type_utils\";\n\nconst callSignatureKind = 0;\n\nexport const noUnsafeReturnRule = createNativeRule(\n \"no-unsafe-return\",\n {\n docs: {\n description: \"Disallow returning any-typed values from functions.\",\n },\n messages: {\n unsafe: \"Unsafe return of an any-typed value.\",\n },\n },\n (context) => ({\n ArrowFunctionExpression(node: any) {\n if (node.body?.type === \"BlockStatement\") {\n return;\n }\n reportIfUnsafeReturn(context, node.body, node);\n },\n ReturnStatement(node: any) {\n if (!node.argument) {\n return;\n }\n const [owner] = nearestFunctionAncestors(node, context.sourceCode);\n if (!owner) {\n return;\n }\n reportIfUnsafeReturn(context, node.argument, owner);\n },\n }),\n);\n\nfunction reportIfUnsafeReturn(context: any, expression: any, owner: any): void {\n const sourceTypeTexts = typeTextsAtNode(context, expression);\n const targetTypeTexts = returnTypeTextsOfFunction(context, owner);\n if (\n !isUnsafeReturn({\n sourceTypeTexts,\n targetTypeTexts,\n })\n ) {\n return;\n }\n context.report({\n node: expression,\n messageId: \"unsafe\",\n });\n}\n\nfunction returnTypeTextsOfFunction(context: any, node: any): readonly string[] {\n const explicitAnnotation = node.returnType?.typeAnnotation ?? node.returnType;\n if (explicitAnnotation) {\n const text = context.sourceCode.getText(explicitAnnotation);\n if (text) {\n return [text];\n }\n }\n\n const checker = checkerFor(context);\n const type = typeAtNode(context, node);\n if (!type) {\n return [];\n }\n\n const texts = new Set<string>();\n for (const signature of checker.getSignaturesOfType(type, callSignatureKind)) {\n const returnType = checker.getReturnTypeOfSignature(signature);\n if (!returnType) {\n continue;\n }\n for (const text of [...(returnType.texts ?? []), checker.typeToString(returnType)]) {\n if (text) {\n texts.add(text);\n }\n }\n }\n\n const resolved = [...texts];\n return resolved.every(isPermissiveTypeText) ? [] : resolved;\n}\n\nfunction isPermissiveTypeText(text: string): boolean {\n return text === \"any\" || text === \"unknown\" || text === \"never\";\n}\n"],"mappings":";;;;;AAMA,MAAM,oBAAoB;AAE1B,MAAa,qBAAqB,iBAChC,oBACA;CACE,MAAM,EACJ,aAAa,uDACd;CACD,UAAU,EACR,QAAQ,wCACT;CACF,GACA,aAAa;CACZ,wBAAwB,MAAW;AACjC,MAAI,KAAK,MAAM,SAAS,iBACtB;AAEF,uBAAqB,SAAS,KAAK,MAAM,KAAK;;CAEhD,gBAAgB,MAAW;AACzB,MAAI,CAAC,KAAK,SACR;EAEF,MAAM,CAAC,SAAS,yBAAyB,MAAM,QAAQ,WAAW;AAClE,MAAI,CAAC,MACH;AAEF,uBAAqB,SAAS,KAAK,UAAU,MAAM;;CAEtD,EACF;AAED,SAAS,qBAAqB,SAAc,YAAiB,OAAkB;AAG7E,KACE,CAAC,eAAe;EACd,iBAJoB,gBAAgB,SAAS,WAAW;EAKxD,iBAJoB,0BAA0B,SAAS,MAAM;EAK9D,CAAC,CAEF;AAEF,SAAQ,OAAO;EACb,MAAM;EACN,WAAW;EACZ,CAAC;;AAGJ,SAAS,0BAA0B,SAAc,MAA8B;CAC7E,MAAM,qBAAqB,KAAK,YAAY,kBAAkB,KAAK;AACnE,KAAI,oBAAoB;EACtB,MAAM,OAAO,QAAQ,WAAW,QAAQ,mBAAmB;AAC3D,MAAI,KACF,QAAO,CAAC,KAAK;;CAIjB,MAAM,UAAU,WAAW,QAAQ;CACnC,MAAM,OAAO,WAAW,SAAS,KAAK;AACtC,KAAI,CAAC,KACH,QAAO,EAAE;CAGX,MAAM,wBAAQ,IAAI,KAAa;AAC/B,MAAK,MAAM,aAAa,QAAQ,oBAAoB,MAAM,kBAAkB,EAAE;EAC5E,MAAM,aAAa,QAAQ,yBAAyB,UAAU;AAC9D,MAAI,CAAC,WACH;AAEF,OAAK,MAAM,QAAQ,CAAC,GAAI,WAAW,SAAS,EAAE,EAAG,QAAQ,aAAa,WAAW,CAAC,CAChF,KAAI,KACF,OAAM,IAAI,KAAK;;CAKrB,MAAM,WAAW,CAAC,GAAG,MAAM;AAC3B,QAAO,SAAS,MAAM,qBAAqB,GAAG,EAAE,GAAG;;AAGrD,SAAS,qBAAqB,MAAuB;AACnD,QAAO,SAAS,SAAS,SAAS,aAAa,SAAS"}
@@ -0,0 +1,16 @@
1
+ //#region src/bindings/nodejs/typescript_oxlint/ts/rules/no_unsafe_unary_minus.d.ts
2
+ declare const noUnsafeUnaryMinusRule: {
3
+ defaultOptions: never[];
4
+ meta: {
5
+ docs: {
6
+ requiresTypeChecking: boolean;
7
+ url: string;
8
+ };
9
+ type: "problem";
10
+ schema: never[];
11
+ };
12
+ create: (context: any) => Record<string, (node: any) => void>;
13
+ };
14
+ //#endregion
15
+ export { noUnsafeUnaryMinusRule };
16
+ //# sourceMappingURL=no_unsafe_unary_minus.d.ts.map
@@ -0,0 +1,28 @@
1
+ import { createNativeRule } from "./rule_creator.js";
2
+ import { classifyTypeText, splitTypeText, typeTextsAtNode } from "./type_utils.js";
3
+ //#region src/bindings/nodejs/typescript_oxlint/ts/rules/no_unsafe_unary_minus.ts
4
+ const noUnsafeUnaryMinusRule = createNativeRule("no-unsafe-unary-minus", {
5
+ docs: { description: "Disallow unary negation on non-number and non-bigint values." },
6
+ messages: { unaryMinus: "Argument of unary negation should be assignable to number | bigint." }
7
+ }, (context) => ({ UnaryExpression(node) {
8
+ if (node.operator !== "-") return;
9
+ if (isSafeLiteral(node.argument)) return;
10
+ const typeTexts = typeTextsAtNode(context, node.argument);
11
+ if (typeTexts.length > 0 && typeTexts.every((text) => {
12
+ return splitTypeText(text).every((part) => {
13
+ const kind = classifyTypeText(part);
14
+ return kind === "any" || kind === "number" || kind === "bigint";
15
+ });
16
+ })) return;
17
+ context.report({
18
+ node,
19
+ messageId: "unaryMinus"
20
+ });
21
+ } }));
22
+ function isSafeLiteral(node) {
23
+ return node?.type === "Literal" && (typeof node.value === "number" || typeof node.bigint === "string");
24
+ }
25
+ //#endregion
26
+ export { noUnsafeUnaryMinusRule };
27
+
28
+ //# sourceMappingURL=no_unsafe_unary_minus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no_unsafe_unary_minus.js","names":[],"sources":["../../ts/rules/no_unsafe_unary_minus.ts"],"sourcesContent":["import { createNativeRule } from \"./rule_creator\";\nimport { classifyTypeText, splitTypeText, typeTextsAtNode } from \"./type_utils\";\n\nexport const noUnsafeUnaryMinusRule = createNativeRule(\n \"no-unsafe-unary-minus\",\n {\n docs: {\n description: \"Disallow unary negation on non-number and non-bigint values.\",\n },\n messages: {\n unaryMinus: \"Argument of unary negation should be assignable to number | bigint.\",\n },\n },\n (context) => ({\n UnaryExpression(node: any) {\n if (node.operator !== \"-\") {\n return;\n }\n if (isSafeLiteral(node.argument)) {\n return;\n }\n const typeTexts = typeTextsAtNode(context, node.argument);\n if (\n typeTexts.length > 0 &&\n typeTexts.every((text) => {\n return splitTypeText(text).every((part) => {\n const kind = classifyTypeText(part);\n return kind === \"any\" || kind === \"number\" || kind === \"bigint\";\n });\n })\n ) {\n return;\n }\n context.report({ node, messageId: \"unaryMinus\" });\n },\n }),\n);\n\nfunction isSafeLiteral(node: any): boolean {\n return (\n node?.type === \"Literal\" && (typeof node.value === \"number\" || typeof node.bigint === \"string\")\n );\n}\n"],"mappings":";;;AAGA,MAAa,yBAAyB,iBACpC,yBACA;CACE,MAAM,EACJ,aAAa,gEACd;CACD,UAAU,EACR,YAAY,uEACb;CACF,GACA,aAAa,EACZ,gBAAgB,MAAW;AACzB,KAAI,KAAK,aAAa,IACpB;AAEF,KAAI,cAAc,KAAK,SAAS,CAC9B;CAEF,MAAM,YAAY,gBAAgB,SAAS,KAAK,SAAS;AACzD,KACE,UAAU,SAAS,KACnB,UAAU,OAAO,SAAS;AACxB,SAAO,cAAc,KAAK,CAAC,OAAO,SAAS;GACzC,MAAM,OAAO,iBAAiB,KAAK;AACnC,UAAO,SAAS,SAAS,SAAS,YAAY,SAAS;IACvD;GACF,CAEF;AAEF,SAAQ,OAAO;EAAE;EAAM,WAAW;EAAc,CAAC;GAEpD,EACF;AAED,SAAS,cAAc,MAAoB;AACzC,QACE,MAAM,SAAS,cAAc,OAAO,KAAK,UAAU,YAAY,OAAO,KAAK,WAAW"}
@@ -0,0 +1,16 @@
1
+ //#region src/bindings/nodejs/typescript_oxlint/ts/rules/only_throw_error.d.ts
2
+ declare const onlyThrowErrorRule: {
3
+ defaultOptions: never[];
4
+ meta: {
5
+ docs: {
6
+ requiresTypeChecking: boolean;
7
+ url: string;
8
+ };
9
+ type: "problem";
10
+ schema: never[];
11
+ };
12
+ create: (context: any) => Record<string, (node: any) => void>;
13
+ };
14
+ //#endregion
15
+ export { onlyThrowErrorRule };
16
+ //# sourceMappingURL=only_throw_error.d.ts.map
@@ -0,0 +1,16 @@
1
+ import { createNativeRule } from "./rule_creator.js";
2
+ import { isErrorLikeNode } from "./type_utils.js";
3
+ //#region src/bindings/nodejs/typescript_oxlint/ts/rules/only_throw_error.ts
4
+ const onlyThrowErrorRule = createNativeRule("only-throw-error", {
5
+ docs: { description: "Require thrown values to be Error-like." },
6
+ messages: { unexpected: "Only Error-like values should be thrown." }
7
+ }, (context) => ({ ThrowStatement(node) {
8
+ if (node.argument && !isErrorLikeNode(context, node.argument)) context.report({
9
+ node,
10
+ messageId: "unexpected"
11
+ });
12
+ } }));
13
+ //#endregion
14
+ export { onlyThrowErrorRule };
15
+
16
+ //# sourceMappingURL=only_throw_error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"only_throw_error.js","names":[],"sources":["../../ts/rules/only_throw_error.ts"],"sourcesContent":["import { createNativeRule } from \"./rule_creator\";\nimport { isErrorLikeNode } from \"./type_utils\";\n\nexport const onlyThrowErrorRule = createNativeRule(\n \"only-throw-error\",\n {\n docs: {\n description: \"Require thrown values to be Error-like.\",\n },\n messages: {\n unexpected: \"Only Error-like values should be thrown.\",\n },\n },\n (context) => ({\n ThrowStatement(node: any) {\n if (node.argument && !isErrorLikeNode(context, node.argument)) {\n context.report({ node, messageId: \"unexpected\" });\n }\n },\n }),\n);\n"],"mappings":";;;AAGA,MAAa,qBAAqB,iBAChC,oBACA;CACE,MAAM,EACJ,aAAa,2CACd;CACD,UAAU,EACR,YAAY,4CACb;CACF,GACA,aAAa,EACZ,eAAe,MAAW;AACxB,KAAI,KAAK,YAAY,CAAC,gBAAgB,SAAS,KAAK,SAAS,CAC3D,SAAQ,OAAO;EAAE;EAAM,WAAW;EAAc,CAAC;GAGtD,EACF"}
@@ -0,0 +1,16 @@
1
+ //#region src/bindings/nodejs/typescript_oxlint/ts/rules/prefer_find.d.ts
2
+ declare const preferFindRule: {
3
+ defaultOptions: never[];
4
+ meta: {
5
+ docs: {
6
+ requiresTypeChecking: boolean;
7
+ url: string;
8
+ };
9
+ type: "problem";
10
+ schema: never[];
11
+ };
12
+ create: (context: any) => Record<string, (node: any) => void>;
13
+ };
14
+ //#endregion
15
+ export { preferFindRule };
16
+ //# sourceMappingURL=prefer_find.d.ts.map
@@ -0,0 +1,25 @@
1
+ import { calleePropertyName, memberObject, memberPropertyName } from "./ast.js";
2
+ import { createNativeRule } from "./rule_creator.js";
3
+ //#region src/bindings/nodejs/typescript_oxlint/ts/rules/prefer_find.ts
4
+ const preferFindRule = createNativeRule("prefer-find", {
5
+ docs: { description: "Prefer find over filtering and taking the first element." },
6
+ messages: { unexpected: "Use .find() instead of filtering and taking the first match." }
7
+ }, (context) => ({
8
+ MemberExpression(node) {
9
+ if (memberPropertyName(node) === "0" && calleePropertyName(node.object) === "filter") context.report({
10
+ node,
11
+ messageId: "unexpected"
12
+ });
13
+ },
14
+ CallExpression(node) {
15
+ if (calleePropertyName(node) !== "at" || node.arguments[0]?.value !== 0) return;
16
+ if (calleePropertyName(memberObject(node.callee)) === "filter") context.report({
17
+ node,
18
+ messageId: "unexpected"
19
+ });
20
+ }
21
+ }));
22
+ //#endregion
23
+ export { preferFindRule };
24
+
25
+ //# sourceMappingURL=prefer_find.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prefer_find.js","names":[],"sources":["../../ts/rules/prefer_find.ts"],"sourcesContent":["import { calleePropertyName, memberObject, memberPropertyName } from \"./ast\";\nimport { createNativeRule } from \"./rule_creator\";\n\nexport const preferFindRule = createNativeRule(\n \"prefer-find\",\n {\n docs: {\n description: \"Prefer find over filtering and taking the first element.\",\n },\n messages: {\n unexpected: \"Use .find() instead of filtering and taking the first match.\",\n },\n },\n (context) => ({\n MemberExpression(node: any) {\n if (memberPropertyName(node) === \"0\" && calleePropertyName(node.object) === \"filter\") {\n context.report({ node, messageId: \"unexpected\" });\n }\n },\n CallExpression(node: any) {\n if (calleePropertyName(node) !== \"at\" || node.arguments[0]?.value !== 0) {\n return;\n }\n if (calleePropertyName(memberObject(node.callee)) === \"filter\") {\n context.report({ node, messageId: \"unexpected\" });\n }\n },\n }),\n);\n"],"mappings":";;;AAGA,MAAa,iBAAiB,iBAC5B,eACA;CACE,MAAM,EACJ,aAAa,4DACd;CACD,UAAU,EACR,YAAY,gEACb;CACF,GACA,aAAa;CACZ,iBAAiB,MAAW;AAC1B,MAAI,mBAAmB,KAAK,KAAK,OAAO,mBAAmB,KAAK,OAAO,KAAK,SAC1E,SAAQ,OAAO;GAAE;GAAM,WAAW;GAAc,CAAC;;CAGrD,eAAe,MAAW;AACxB,MAAI,mBAAmB,KAAK,KAAK,QAAQ,KAAK,UAAU,IAAI,UAAU,EACpE;AAEF,MAAI,mBAAmB,aAAa,KAAK,OAAO,CAAC,KAAK,SACpD,SAAQ,OAAO;GAAE;GAAM,WAAW;GAAc,CAAC;;CAGtD,EACF"}
@@ -0,0 +1,16 @@
1
+ //#region src/bindings/nodejs/typescript_oxlint/ts/rules/prefer_includes.d.ts
2
+ declare const preferIncludesRule: {
3
+ defaultOptions: never[];
4
+ meta: {
5
+ docs: {
6
+ requiresTypeChecking: boolean;
7
+ url: string;
8
+ };
9
+ type: "problem";
10
+ schema: never[];
11
+ };
12
+ create: (context: any) => Record<string, (node: any) => void>;
13
+ };
14
+ //#endregion
15
+ export { preferIncludesRule };
16
+ //# sourceMappingURL=prefer_includes.d.ts.map