@sonsu-lee/eslint-plugin 0.0.0-stage → 0.2.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sonsu Lee
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,34 @@
1
- # Temporary Holding Version
1
+ # @sonsu-lee/eslint-plugin
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Type-aware ESLint rules for TypeScript projects. Use [`@sonsu-lee/eslint-config`](../eslint-config/README.md) to enable these rules together, or configure the plugin directly as shown below.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ pnpm add -D eslint typescript@6 @sonsu-lee/eslint-plugin
9
+ pnpm add -D @typescript-eslint/parser
10
+ ```
11
+
12
+ ## Use
13
+
14
+ In `eslint.config.mjs`, register the plugin for files included in a `tsconfig.json`:
15
+
16
+ ```js
17
+ import plugin from '@sonsu-lee/eslint-plugin';
18
+ import parser from '@typescript-eslint/parser';
19
+
20
+ export default [
21
+ {
22
+ files: ['**/*.{ts,tsx,mts,cts}'],
23
+ languageOptions: { parser, parserOptions: { projectService: true } },
24
+ plugins: { 'sonsu-lee-eslint': plugin },
25
+ rules: { 'sonsu-lee-eslint/no-ignored-rejection': 'error' },
26
+ },
27
+ ];
28
+ ```
29
+
30
+ ## Rules
31
+
32
+ | Rule | Reports |
33
+ | --- | --- |
34
+ | [`sonsu-lee-eslint/no-ignored-rejection`](docs/rules/no-ignored-rejection.md) | Empty rejection handlers and discarded `undefined` or `null` fallbacks. |
@@ -0,0 +1,3 @@
1
+ import { ESLint } from "eslint";
2
+ declare const plugin: ESLint.Plugin;
3
+ export { plugin as default };
package/dist/index.mjs ADDED
@@ -0,0 +1,108 @@
1
+ import { AST_NODE_TYPES, ESLintUtils } from "@typescript-eslint/utils";
2
+ import { isIntrinsicAnyType, isIntrinsicUnknownType, isThenableType } from "ts-api-utils";
3
+ // package.json
4
+ var version = "0.2.0";
5
+ // src/rules/no-ignored-rejection.ts
6
+ function rejectionHandler(name, args) {
7
+ let argument;
8
+ if (name === "catch") argument = args[0];
9
+ else if (name === "then" && args[0]?.type !== AST_NODE_TYPES.SpreadElement) argument = args[1];
10
+ else return null;
11
+ if (argument?.type === AST_NODE_TYPES.ArrowFunctionExpression || argument?.type === AST_NODE_TYPES.FunctionExpression) return argument;
12
+ return null;
13
+ }
14
+ function isTypeWrapper(node) {
15
+ return node.type === AST_NODE_TYPES.TSAsExpression || node.type === AST_NODE_TYPES.TSNonNullExpression || node.type === AST_NODE_TYPES.TSSatisfiesExpression || node.type === AST_NODE_TYPES.TSTypeAssertion;
16
+ }
17
+ function constantFallback(value) {
18
+ if (value === null) return "undefined";
19
+ let expression = value;
20
+ while (isTypeWrapper(expression)) expression = expression.expression;
21
+ if (expression.type === AST_NODE_TYPES.Identifier && expression.name === "undefined") return "undefined";
22
+ if (expression.type === AST_NODE_TYPES.UnaryExpression && expression.operator === "void") return "undefined";
23
+ if (expression.type === AST_NODE_TYPES.Literal && expression.value === null) return "null";
24
+ return null;
25
+ }
26
+ function classifyHandler(handler) {
27
+ const { body } = handler;
28
+ if (body.type !== AST_NODE_TYPES.BlockStatement) return constantFallback(body);
29
+ if (body.body.length === 0) return "empty";
30
+ if (body.body.length === 1 && body.body[0].type === AST_NODE_TYPES.ReturnStatement) return constantFallback(body.body[0].argument);
31
+ return null;
32
+ }
33
+ function isDiscarded(node) {
34
+ let current = node;
35
+ for (;;) {
36
+ const parent = current.parent;
37
+ if (isTypeWrapper(parent) || parent.type === AST_NODE_TYPES.AwaitExpression || parent.type === AST_NODE_TYPES.ChainExpression) {
38
+ current = parent;
39
+ continue;
40
+ }
41
+ if (parent.type === AST_NODE_TYPES.LogicalExpression && parent.right === current) {
42
+ current = parent;
43
+ continue;
44
+ }
45
+ if (parent.type === AST_NODE_TYPES.ConditionalExpression && parent.test !== current) {
46
+ current = parent;
47
+ continue;
48
+ }
49
+ if (parent.type === AST_NODE_TYPES.MemberExpression && parent.object === current) {
50
+ const { property } = parent;
51
+ if (parent.computed || property.type !== AST_NODE_TYPES.Identifier) return false;
52
+ if (property.name !== "finally") return false;
53
+ const call = parent.parent;
54
+ if (call.type !== AST_NODE_TYPES.CallExpression || call.callee !== parent) return false;
55
+ current = call;
56
+ continue;
57
+ }
58
+ if (parent.type === AST_NODE_TYPES.ExpressionStatement) return true;
59
+ return parent.type === AST_NODE_TYPES.UnaryExpression && parent.operator === "void";
60
+ }
61
+ }
62
+ const noIgnoredRejection = ESLintUtils.RuleCreator((name) => `https://github.com/sonsu-lee/style-guide/blob/main/packages/eslint-plugin/docs/rules/${name}.md`)({
63
+ name: "no-ignored-rejection",
64
+ meta: {
65
+ type: "problem",
66
+ docs: { description: "Report rejection handlers that discard failures." },
67
+ schema: [],
68
+ messages: {
69
+ emptyHandler: "This rejection handler does nothing, so the failure is lost. Propagate the error, return a recovery value the caller reads, or report the failure.",
70
+ discardedFallback: "This handler replaces the rejection with {{value}} and nothing reads the result, so the failure is lost."
71
+ }
72
+ },
73
+ create(context) {
74
+ const services = ESLintUtils.getParserServices(context);
75
+ const checker = services.program.getTypeChecker();
76
+ return { CallExpression(node) {
77
+ const { callee } = node;
78
+ if (callee.type !== AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES.Identifier) return;
79
+ const handler = rejectionHandler(callee.property.name, node.arguments);
80
+ if (handler === null) return;
81
+ const fallback = classifyHandler(handler);
82
+ if (fallback === null) return;
83
+ if (fallback !== "empty" && !isDiscarded(node)) return;
84
+ const receiver = services.getTypeAtLocation(callee.object);
85
+ if (isIntrinsicAnyType(receiver) || isIntrinsicUnknownType(receiver)) return;
86
+ const tsNode = services.esTreeNodeToTSNodeMap.get(callee.object);
87
+ if (!isThenableType(checker, tsNode, receiver)) return;
88
+ if (fallback === "empty") context.report({
89
+ node: handler,
90
+ messageId: "emptyHandler"
91
+ });
92
+ else context.report({
93
+ node: handler,
94
+ messageId: "discardedFallback",
95
+ data: { value: fallback }
96
+ });
97
+ } };
98
+ }
99
+ });
100
+ // src/index.ts
101
+ const plugin = {
102
+ meta: {
103
+ name: "@sonsu-lee/eslint-plugin",
104
+ version
105
+ },
106
+ rules: { "no-ignored-rejection": noIgnoredRejection }
107
+ };
108
+ export { plugin as default };
package/package.json CHANGED
@@ -1,6 +1,52 @@
1
1
  {
2
2
  "name": "@sonsu-lee/eslint-plugin",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.0",
4
+ "description": "Type-aware lint rules for ESLint",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/sonsu-lee/style-guide.git",
9
+ "directory": "packages/eslint-plugin"
10
+ },
11
+ "files": [
12
+ "dist"
13
+ ],
14
+ "type": "module",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.mts",
18
+ "default": "./dist/index.mjs"
19
+ }
20
+ },
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "dependencies": {
25
+ "@types/eslint": "9.6.1",
26
+ "@typescript-eslint/utils": "8.74.0",
27
+ "ts-api-utils": "2.5.0"
28
+ },
29
+ "devDependencies": {
30
+ "@sonsu-lee/oxlint-config": "^0.2.0",
31
+ "@types/node": "24.19.2",
32
+ "@typescript-eslint/parser": "8.74.0",
33
+ "@typescript-eslint/rule-tester": "8.74.0",
34
+ "eslint": "10.15.0",
35
+ "oxlint": "1.90.0",
36
+ "oxlint-tsgolint": "7.0.2005",
37
+ "tsdown": "0.23.4",
38
+ "typescript": "6.0.3",
39
+ "vitest": "5.0.5"
40
+ },
41
+ "peerDependencies": {
42
+ "@typescript-eslint/parser": "^8.74.0",
43
+ "eslint": "^9.0.0 || ^10.0.0",
44
+ "typescript": ">=4.8.4 <6.1.0"
45
+ },
46
+ "scripts": {
47
+ "build": "tsdown",
48
+ "test": "vitest run",
49
+ "typecheck": "tsc",
50
+ "lint": "oxlint"
51
+ }
6
52
  }