@asd14/eslint-plugin 0.1.0 → 1.0.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/SKILL.md +87 -0
- package/package.json +22 -14
package/SKILL.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
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
|
+
Enforces consistent format in `throw new Error(...)` statements.
|
|
16
|
+
|
|
17
|
+
- Configured per error class (`TypeError`, `Error`, custom classes)
|
|
18
|
+
- Each class: array of `{ pattern, message }` checks
|
|
19
|
+
- `pattern`: plain regex string, no `/` delimiters, passed to `new RegExp()`
|
|
20
|
+
- OR matching: first match wins, reports if none match
|
|
21
|
+
- Supports string literals, template literals, and string concatenation
|
|
22
|
+
- Variables or function calls as the sole argument are flagged as non-evaluable
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
// eslint.config.js
|
|
26
|
+
import asd14Plugin from "@asd14/eslint-plugin"
|
|
27
|
+
|
|
28
|
+
export default [
|
|
29
|
+
{
|
|
30
|
+
plugins: { "@asd14": asd14Plugin },
|
|
31
|
+
rules: {
|
|
32
|
+
"@asd14/error-message-format": [
|
|
33
|
+
"error",
|
|
34
|
+
{
|
|
35
|
+
TypeError: [
|
|
36
|
+
{
|
|
37
|
+
pattern: "^myLib/\\w+: expected '\\w+' to be '\\w+', got '\\w+'",
|
|
38
|
+
message:
|
|
39
|
+
"Format: myLib/<fn>: expected '<param>' to be '<Type>', got '<Actual>'"
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Correct
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
// String literal
|
|
53
|
+
throw new TypeError("myLib/sort: expected 'input' to be 'Array', got 'Number'")
|
|
54
|
+
|
|
55
|
+
// Template literal with interpolation
|
|
56
|
+
throw new TypeError(
|
|
57
|
+
`myLib/sort: expected 'input' to be 'Array', got '${type(input)}'`
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
// String concatenation
|
|
61
|
+
throw new TypeError(
|
|
62
|
+
"myLib/sort: expected 'input' to be 'Array', got '" + type(input) + "'"
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
// Unconfigured error classes are ignored
|
|
66
|
+
throw new Error("anything goes")
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Incorrect
|
|
70
|
+
|
|
71
|
+
```js
|
|
72
|
+
// Missing prefix
|
|
73
|
+
throw new TypeError("expected 'input' to be 'Array', got 'Number'")
|
|
74
|
+
|
|
75
|
+
// Unquoted types
|
|
76
|
+
throw new TypeError(`myLib/sort: expected Array, got ${type(input)}`)
|
|
77
|
+
|
|
78
|
+
// Non-evaluable — variable reference
|
|
79
|
+
throw new TypeError(message)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Contributing rules
|
|
83
|
+
|
|
84
|
+
- Each rule in its own folder: `src/rules/<rule-name>/`
|
|
85
|
+
- Export from `src/index.ts`
|
|
86
|
+
- Tests: `node:test` + `RuleTester`, split into valid/invalid groups
|
|
87
|
+
- 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.0.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
|
},
|