@sapphire/eslint-plugin-result 2.0.2-next.f4ec2624.0 → 2.0.2
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/CHANGELOG.md +7 -0
- package/dist/esm/index.mjs +150 -0
- package/package.json +16 -14
- /package/dist/{index.js → cjs/index.cjs} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
# [@sapphire/eslint-plugin-result@2.0.2](https://github.com/sapphiredev/utilities/compare/@sapphire/eslint-plugin-result@2.0.2...@sapphire/eslint-plugin-result@2.0.2) - (2023-12-04)
|
|
6
|
+
|
|
7
|
+
## 🐛 Bug Fixes
|
|
8
|
+
|
|
9
|
+
- **eslint-plugin-result:** Properly split CJS and ESM ([e357e62](https://github.com/sapphiredev/utilities/commit/e357e629a3932faf827f423736d793c02a495109))
|
|
10
|
+
- **eslint-plugin-result:** Update transitive dependencies ([7878399](https://github.com/sapphiredev/utilities/commit/7878399502917fbb90af1b7c85135b2966dd43b2))
|
|
11
|
+
|
|
5
12
|
# [@sapphire/eslint-plugin-result@2.0.1](https://github.com/sapphiredev/utilities/compare/@sapphire/eslint-plugin-result@2.0.0...@sapphire/eslint-plugin-result@2.0.1) - (2023-08-29)
|
|
6
13
|
|
|
7
14
|
## 🐛 Bug Fixes
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { ESLintUtils, AST_NODE_TYPES } from '@typescript-eslint/utils';
|
|
2
|
+
import { isUnionType, isThenableType } from 'tsutils';
|
|
3
|
+
import ts from 'typescript';
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
9
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
10
|
+
}) : x)(function(x) {
|
|
11
|
+
if (typeof require !== "undefined")
|
|
12
|
+
return require.apply(this, arguments);
|
|
13
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
14
|
+
});
|
|
15
|
+
var __esm = (fn, res) => function __init() {
|
|
16
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
17
|
+
};
|
|
18
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
19
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// src/configs/recommended.ts
|
|
23
|
+
var recommendedConfig;
|
|
24
|
+
var init_recommended = __esm({
|
|
25
|
+
"src/configs/recommended.ts"() {
|
|
26
|
+
recommendedConfig = {
|
|
27
|
+
plugins: ["@sapphire/eslint-plugin-result"],
|
|
28
|
+
rules: {
|
|
29
|
+
"@sapphire/result/no-discard-result": "error"
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
function getSapphireResultType(service, checker) {
|
|
35
|
+
const file = service.program?.getSourceFile(resultPath);
|
|
36
|
+
const resultNode = file?.statements.find((node) => ts.isTypeAliasDeclaration(node) && node.name.getText() === "Result");
|
|
37
|
+
if (resultNode) {
|
|
38
|
+
return checker.getTypeAtLocation(resultNode);
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
function unwrapPotentialPromiseType(checker, node, type = checker.getTypeAtLocation(node)) {
|
|
43
|
+
if (isUnionType(type)) {
|
|
44
|
+
const { ...copy } = type;
|
|
45
|
+
copy.types = type.types.filter((subtype) => Boolean(subtype));
|
|
46
|
+
if (copy.types.length === 1) {
|
|
47
|
+
return unwrapPotentialPromiseType(checker, node, copy.types[0]);
|
|
48
|
+
}
|
|
49
|
+
copy.types = copy.types.map((subtype) => unwrapPotentialPromiseType(checker, node, subtype));
|
|
50
|
+
return copy;
|
|
51
|
+
}
|
|
52
|
+
if (isThenableType(checker, node)) {
|
|
53
|
+
return checker.getTypeArguments(type)[0];
|
|
54
|
+
}
|
|
55
|
+
return type;
|
|
56
|
+
}
|
|
57
|
+
function functionHasResultLikeReturnType(service, checker, node) {
|
|
58
|
+
const functionDeclaration = checker.getResolvedSignature(node);
|
|
59
|
+
if (!functionDeclaration) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
const returnType = unwrapPotentialPromiseType(checker, node);
|
|
63
|
+
const resultType = getSapphireResultType(service, checker);
|
|
64
|
+
if (!returnType.aliasSymbol || !resultType?.aliasSymbol) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
return Reflect.get(returnType.aliasSymbol, "id") === Reflect.get(resultType.aliasSymbol, "id");
|
|
68
|
+
}
|
|
69
|
+
function isDiscardedResult(callExpressionNode) {
|
|
70
|
+
if (callExpressionNode.parent?.type === AST_NODE_TYPES.UnaryExpression && callExpressionNode.parent.operator === "void") {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
if (callExpressionNode.parent?.type === AST_NODE_TYPES.VariableDeclarator) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
if (callExpressionNode.parent?.type === AST_NODE_TYPES.AssignmentExpression) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
if (callExpressionNode.parent?.type === AST_NODE_TYPES.CallExpression) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
if (callExpressionNode.parent?.type === AST_NODE_TYPES.SequenceExpression) {
|
|
83
|
+
return isDiscardedResult(callExpressionNode.parent);
|
|
84
|
+
}
|
|
85
|
+
if (callExpressionNode.parent?.type === AST_NODE_TYPES.AwaitExpression) {
|
|
86
|
+
return isDiscardedResult(callExpressionNode.parent);
|
|
87
|
+
}
|
|
88
|
+
if (callExpressionNode.parent?.type === AST_NODE_TYPES.ConditionalExpression) {
|
|
89
|
+
return isDiscardedResult(callExpressionNode.parent);
|
|
90
|
+
}
|
|
91
|
+
if (callExpressionNode.parent?.type === AST_NODE_TYPES.LogicalExpression) {
|
|
92
|
+
return isDiscardedResult(callExpressionNode.parent);
|
|
93
|
+
}
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
var messages, resultPath, noDiscardResult;
|
|
97
|
+
var init_no_discard_result = __esm({
|
|
98
|
+
"src/rules/no-discard-result.ts"() {
|
|
99
|
+
messages = {
|
|
100
|
+
discardedResult: "This function returns a Result, but its return value is being discarded."
|
|
101
|
+
};
|
|
102
|
+
resultPath = __require.resolve("@sapphire/result").split("/").slice(0, -1).concat("index.d.ts").join("/");
|
|
103
|
+
__name(getSapphireResultType, "getSapphireResultType");
|
|
104
|
+
__name(unwrapPotentialPromiseType, "unwrapPotentialPromiseType");
|
|
105
|
+
__name(functionHasResultLikeReturnType, "functionHasResultLikeReturnType");
|
|
106
|
+
__name(isDiscardedResult, "isDiscardedResult");
|
|
107
|
+
noDiscardResult = ESLintUtils.RuleCreator.withoutDocs({
|
|
108
|
+
meta: {
|
|
109
|
+
messages,
|
|
110
|
+
type: "problem",
|
|
111
|
+
schema: []
|
|
112
|
+
},
|
|
113
|
+
defaultOptions: [],
|
|
114
|
+
create: (context) => {
|
|
115
|
+
return {
|
|
116
|
+
CallExpression(callExpressionNode) {
|
|
117
|
+
const service = ESLintUtils.getParserServices(context);
|
|
118
|
+
const checker = service.program.getTypeChecker();
|
|
119
|
+
if (!functionHasResultLikeReturnType(service, checker, service.esTreeNodeToTSNodeMap.get(callExpressionNode))) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (isDiscardedResult(callExpressionNode)) {
|
|
123
|
+
context.report({ messageId: "discardedResult", node: callExpressionNode });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// src/index.ts
|
|
133
|
+
var require_src = __commonJS({
|
|
134
|
+
"src/index.ts"(exports, module) {
|
|
135
|
+
init_recommended();
|
|
136
|
+
init_no_discard_result();
|
|
137
|
+
var eslintPluginResult = {
|
|
138
|
+
rules: {
|
|
139
|
+
"no-discard-result": noDiscardResult
|
|
140
|
+
},
|
|
141
|
+
configs: {
|
|
142
|
+
recommended: recommendedConfig
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
module.exports = eslintPluginResult;
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
var index = require_src();
|
|
149
|
+
|
|
150
|
+
export { index as default };
|
package/package.json
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sapphire/eslint-plugin-result",
|
|
3
|
-
"version": "2.0.2
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "A TypeScript ESLint plugin for @sapphire/result",
|
|
5
5
|
"author": "@sapphire",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"main": "dist/index.
|
|
8
|
-
"module": "dist/index.
|
|
7
|
+
"main": "dist/cjs/index.cjs",
|
|
8
|
+
"module": "dist/esm/index.mjs",
|
|
9
9
|
"exports": {
|
|
10
|
-
"import":
|
|
11
|
-
|
|
10
|
+
"import": {
|
|
11
|
+
"default": "./dist/esm/index.mjs"
|
|
12
|
+
},
|
|
13
|
+
"require": {
|
|
14
|
+
"default": "./dist/cjs/index.cjs"
|
|
15
|
+
}
|
|
12
16
|
},
|
|
13
17
|
"sideEffects": false,
|
|
14
18
|
"homepage": "https://github.com/sapphiredev/utilities/tree/main/packages/eslint-plugin-result",
|
|
@@ -26,9 +30,7 @@
|
|
|
26
30
|
"directory": "packages/eslint-plugin-result"
|
|
27
31
|
},
|
|
28
32
|
"files": [
|
|
29
|
-
"dist
|
|
30
|
-
"dist/**/*.mjs*",
|
|
31
|
-
"dist/**/*.d*"
|
|
33
|
+
"dist/"
|
|
32
34
|
],
|
|
33
35
|
"engines": {
|
|
34
36
|
"node": ">=v14.0.0",
|
|
@@ -51,17 +53,17 @@
|
|
|
51
53
|
},
|
|
52
54
|
"devDependencies": {
|
|
53
55
|
"@favware/cliff-jumper": "^2.2.3",
|
|
54
|
-
"@typescript-eslint/rule-tester": "^6.
|
|
55
|
-
"@typescript-eslint/typescript-estree": "^6.
|
|
56
|
+
"@typescript-eslint/rule-tester": "^6.13.2",
|
|
57
|
+
"@typescript-eslint/typescript-estree": "^6.13.2",
|
|
56
58
|
"@vitest/coverage-v8": "^0.34.6",
|
|
57
|
-
"tsup": "^
|
|
59
|
+
"tsup": "^8.0.1",
|
|
58
60
|
"typedoc-json-parser": "^9.0.1",
|
|
59
61
|
"vitest": "^0.34.6"
|
|
60
62
|
},
|
|
61
63
|
"dependencies": {
|
|
62
|
-
"@sapphire/result": "^2.6.
|
|
63
|
-
"@typescript-eslint/utils": "^6.
|
|
64
|
+
"@sapphire/result": "^2.6.5",
|
|
65
|
+
"@typescript-eslint/utils": "^6.13.2",
|
|
64
66
|
"tsutils": "^3.21.0",
|
|
65
|
-
"typescript": "^5.
|
|
67
|
+
"typescript": "^5.3.2"
|
|
66
68
|
}
|
|
67
69
|
}
|
|
File without changes
|