@asd14/eslint-plugin 0.1.0 → 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.
- package/README.md +5 -4
- package/SKILL.md +86 -0
- package/package.json +22 -14
package/README.md
CHANGED
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
npm install @asd14/eslint-plugin --save-dev
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
> NOTE
|
|
23
|
+
> [!NOTE]
|
|
24
|
+
> Works with either `eslint ^9` or `eslint ^10`.
|
|
24
25
|
|
|
25
26
|
## Rules
|
|
26
27
|
|
|
@@ -29,7 +30,7 @@ npm install @asd14/eslint-plugin --save-dev
|
|
|
29
30
|
Enforce consistent error message format in `throw` statements.
|
|
30
31
|
|
|
31
32
|
- Per error class: `Error`, `TypeError` or custom `DBError`
|
|
32
|
-
- Each is an array of `RegExp` patterns
|
|
33
|
+
- Each class is an array of `RegExp` patterns
|
|
33
34
|
- `OR` matching, first match wins
|
|
34
35
|
|
|
35
36
|
```js
|
|
@@ -64,7 +65,7 @@ export default [
|
|
|
64
65
|
]
|
|
65
66
|
```
|
|
66
67
|
|
|
67
|
-
|
|
68
|
+
**Correct** message examples:
|
|
68
69
|
|
|
69
70
|
```js
|
|
70
71
|
// Template literal with interpolation
|
|
@@ -86,7 +87,7 @@ throw new TypeError(
|
|
|
86
87
|
throw new Error("something went wrong")
|
|
87
88
|
```
|
|
88
89
|
|
|
89
|
-
|
|
90
|
+
**Incorrect** message examples:
|
|
90
91
|
|
|
91
92
|
```js
|
|
92
93
|
// Missing @asd14/m/ prefix
|
package/SKILL.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: using-asd14-eslint-plugin
|
|
3
|
+
description:
|
|
4
|
+
Enforces consistent error message formats in throw statements via ESLint. Use
|
|
5
|
+
when configuring @asd14/eslint-plugin or adding error-message linting rules.
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# @asd14/eslint-plugin
|
|
9
|
+
|
|
10
|
+
ESLint rules for opinionated DX patterns not covered by existing plugins.
|
|
11
|
+
Requires `eslint ^9 || ^10` as peer dependency.
|
|
12
|
+
|
|
13
|
+
## error-message-format
|
|
14
|
+
|
|
15
|
+
Enforce consistent error message format in `throw` statements.
|
|
16
|
+
|
|
17
|
+
- Per error class: `Error`, `TypeError` or custom `DBError`
|
|
18
|
+
- Each class is an array of `RegExp` patterns
|
|
19
|
+
- `OR` matching, first match wins
|
|
20
|
+
- Supports string literals, template literals, and string concatenation
|
|
21
|
+
- Variables or function calls as the sole argument are flagged as non-evaluable
|
|
22
|
+
|
|
23
|
+
```js
|
|
24
|
+
// eslint.config.js
|
|
25
|
+
import asd14Plugin from "@asd14/eslint-plugin"
|
|
26
|
+
|
|
27
|
+
export default [
|
|
28
|
+
{
|
|
29
|
+
plugins: { "@asd14": asd14Plugin },
|
|
30
|
+
rules: {
|
|
31
|
+
"@asd14/error-message-format": [
|
|
32
|
+
"error",
|
|
33
|
+
{
|
|
34
|
+
TypeError: [
|
|
35
|
+
{
|
|
36
|
+
pattern: "^myLib/\\w+: expected '\\w+' to be '\\w+', got '\\w+'",
|
|
37
|
+
message:
|
|
38
|
+
"Format: myLib/<fn>: expected '<param>' to be '<Type>', got '<Actual>'"
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Correct
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
// String literal
|
|
52
|
+
throw new TypeError("myLib/sort: expected 'input' to be 'Array', got 'Number'")
|
|
53
|
+
|
|
54
|
+
// Template literal with interpolation
|
|
55
|
+
throw new TypeError(
|
|
56
|
+
`myLib/sort: expected 'input' to be 'Array', got '${type(input)}'`
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
// String concatenation
|
|
60
|
+
throw new TypeError(
|
|
61
|
+
"myLib/sort: expected 'input' to be 'Array', got '" + type(input) + "'"
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
// Unconfigured error classes are ignored
|
|
65
|
+
throw new Error("anything goes")
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Incorrect
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
// Missing prefix
|
|
72
|
+
throw new TypeError("expected 'input' to be 'Array', got 'Number'")
|
|
73
|
+
|
|
74
|
+
// Unquoted types
|
|
75
|
+
throw new TypeError(`myLib/sort: expected Array, got ${type(input)}`)
|
|
76
|
+
|
|
77
|
+
// Non-evaluable — variable reference
|
|
78
|
+
throw new TypeError(message)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Contributing rules
|
|
82
|
+
|
|
83
|
+
- Each rule in its own folder: `src/rules/<rule-name>/`
|
|
84
|
+
- Export from `src/index.ts`
|
|
85
|
+
- Tests: `node:test` + `RuleTester`, split into valid/invalid groups
|
|
86
|
+
- 100% coverage enforced via `c8 --100`
|
package/package.json
CHANGED
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asd14/eslint-plugin",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "ESLint rules for opinionated DX not covered by existing plugins",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/asd-xiv/eslint-plugin.git"
|
|
13
|
+
},
|
|
6
14
|
"author": {
|
|
7
15
|
"name": "Andrei Dumitrescu",
|
|
8
16
|
"url": "https://github.com/andreidmt"
|
|
9
17
|
},
|
|
10
|
-
"type": "module",
|
|
11
|
-
"exports": {
|
|
12
|
-
".": {
|
|
13
|
-
"import": "./dist/index.js",
|
|
14
|
-
"default": "./dist/index.js",
|
|
15
|
-
"types": "./dist/index.d.ts"
|
|
16
|
-
},
|
|
17
|
-
"./package.json": "./package.json"
|
|
18
|
-
},
|
|
19
|
-
"sideEffects": false,
|
|
20
18
|
"files": [
|
|
21
|
-
"/dist"
|
|
19
|
+
"/dist",
|
|
20
|
+
"SKILL.md"
|
|
22
21
|
],
|
|
23
22
|
"nx": {
|
|
24
23
|
"projectType": "library",
|
|
@@ -27,6 +26,15 @@
|
|
|
27
26
|
"target:node"
|
|
28
27
|
]
|
|
29
28
|
},
|
|
29
|
+
"type": "module",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"import": "./dist/index.js",
|
|
33
|
+
"default": "./dist/index.js",
|
|
34
|
+
"types": "./dist/index.d.ts"
|
|
35
|
+
},
|
|
36
|
+
"./package.json": "./package.json"
|
|
37
|
+
},
|
|
30
38
|
"scripts": {
|
|
31
39
|
"----BUNDLE": "",
|
|
32
40
|
"build:code": "swc src -d dist --ignore '**/*.test.ts' --strip-leading-paths",
|
|
@@ -55,13 +63,13 @@
|
|
|
55
63
|
"@commitlint/cli": "^20.4.3",
|
|
56
64
|
"@commitlint/config-conventional": "^20.4.3",
|
|
57
65
|
"@semantic-release/git": "^10.0.1",
|
|
58
|
-
"@swc/cli": "^0.
|
|
66
|
+
"@swc/cli": "^0.8.0",
|
|
59
67
|
"@swc/core": "^1.15.18",
|
|
60
68
|
"c8": "^11.0.0",
|
|
61
69
|
"conventional-changelog-conventionalcommits": "^9.3.0",
|
|
62
70
|
"eslint": "^9.39.2",
|
|
63
71
|
"prettier": "^3.8.1",
|
|
64
|
-
"semantic-release": "^
|
|
72
|
+
"semantic-release": "^25.0.3",
|
|
65
73
|
"tsx": "^4.21.0",
|
|
66
74
|
"typescript": "^5.9.3"
|
|
67
75
|
},
|