eslint-plugin-kaezon 1.0.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/CHANGELOG.md +21 -0
- package/README.md +46 -4
- package/dist/eslint-rules/boolean-is-prefix.d.ts.map +1 -1
- package/dist/eslint-rules/boolean-is-prefix.js +1 -0
- package/dist/eslint-rules/computed-explicit-return-type.d.ts.map +1 -1
- package/dist/eslint-rules/computed-explicit-return-type.js +1 -0
- package/dist/eslint-rules/const-case.d.ts +1 -1
- package/dist/eslint-rules/const-case.d.ts.map +1 -1
- package/dist/eslint-rules/const-case.js +113 -12
- package/dist/eslint-rules/prefer-object-params.d.ts.map +1 -1
- package/dist/eslint-rules/prefer-object-params.js +1 -0
- package/dist/eslint-rules/require-satisfies-with-as-const.d.ts.map +1 -1
- package/dist/eslint-rules/require-satisfies-with-as-const.js +1 -0
- package/dist/eslint-rules/require-typescript-parser.d.ts.map +1 -1
- package/dist/eslint-rules/require-typescript-parser.js +1 -0
- package/dist/eslint-rules/vue-prop-name-casing-by-type.d.ts.map +1 -1
- package/dist/eslint-rules/vue-prop-name-casing-by-type.js +79 -41
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- `kaezon/vue-prop-name-casing-by-type` now autofixes prop names, keeping the original quote style for string-literal keys.
|
|
13
|
+
- `kaezon/const-case` now autofixes names that are not exported, renaming the declaration and every reference in the file. Exported bindings get a suggestion instead, because renaming them would break importers.
|
|
14
|
+
- `meta.docs.url` on every rule, pointing at its section in the README.
|
|
15
|
+
- Per-rule documentation in the README.
|
|
16
|
+
- `examples/ts` and `examples/nuxt`, both runnable.
|
|
17
|
+
- A CI job that checks the built package on every Node version `engines` claims to support.
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
- `engines.node` is now `^20.19.0 || ^22.13.0 || >=24`, matching ESLint 10. The published code only needs `node:fs`, `node:url`, and `Object.hasOwn`, so the previous `>=26` was stricter than necessary.
|
|
22
|
+
- Rule messages now name the offending identifier and the expected name.
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
|
|
26
|
+
- Removed a regular expression in `const-case` that backtracked on long runs of underscores.
|
|
27
|
+
|
|
10
28
|
## [1.0.0] - 2026-11-02
|
|
11
29
|
|
|
12
30
|
### Added
|
|
@@ -23,6 +41,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
23
41
|
|
|
24
42
|
### Notes
|
|
25
43
|
|
|
44
|
+
- Written in TypeScript and published as compiled ESM in `dist/`, with `.d.ts` files generated from the source.
|
|
45
|
+
- Requires Node.js `>=26` and ESLint `^10.0.0` (flat config only).
|
|
46
|
+
- The public types (`PresetName`, `CreateConfigOptions`, `KaezonPlugin`, `KaezonRule`, `KaezonRuleContext`, `KaezonRuleMap`, `RuleConfig`, `RuleSeverity`, `FlatConfig`) are exported from the package root.
|
|
26
47
|
- `configs.nuxt` contains kaezon rules only and works with ESLint installed.
|
|
27
48
|
- `configs.nuxt_house` requires `eslint-plugin-vue` and `@typescript-eslint/eslint-plugin`.
|
|
28
49
|
- The plugin ships no parser. Use `@typescript-eslint/parser` and `vue-eslint-parser` in the consuming project.
|
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# eslint-plugin-kaezon
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/eslint-plugin-kaezon)
|
|
4
|
-
[](https://github.com/svaldivia12/eslint-plugin-kaezon/actions/workflows/ci.yml)
|
|
5
|
-
[](./LICENSE)
|
|
3
|
+
[](https://www.npmjs.com/package/eslint-plugin-kaezon)
|
|
4
|
+
[](https://github.com/svaldivia12/eslint-plugin-kaezon/actions/workflows/ci.yml)
|
|
5
|
+
[](./LICENSE)
|
|
6
6
|
|
|
7
7
|
ESLint 10 flat-config plugin with custom TypeScript and Vue rules.
|
|
8
8
|
|
|
@@ -154,6 +154,38 @@ export default [
|
|
|
154
154
|
|
|
155
155
|
`boolean-is-prefix` and `computed-explicit-return-type` target Vue code. In a project without Vue they match nothing, which is why they are left out of the `ts` preset.
|
|
156
156
|
|
|
157
|
+
None of the rules accept options: every one declares an empty `schema`, so there is nothing to configure beyond on, off, or warn. Configure them through the preset and the `rules` overlay of `createConfig`.
|
|
158
|
+
|
|
159
|
+
### kaezon/boolean-is-prefix
|
|
160
|
+
|
|
161
|
+
Requires an `is_` prefix on bindings that hold a boolean or a Vue boolean ref. Without typed linting it reads the AST: `boolean` annotations, `Ref<boolean>`, and boolean literals. With typed linting it asks the type checker, so an inferred `shallowRef(getFlag())` is caught too.
|
|
162
|
+
|
|
163
|
+
The prefix must read naturally in English. Do not add `is_` to a name where it produces nonsense.
|
|
164
|
+
|
|
165
|
+
### kaezon/computed-explicit-return-type
|
|
166
|
+
|
|
167
|
+
Requires an explicit return type on getters passed to `computed`. Applies to arrow functions and function expressions.
|
|
168
|
+
|
|
169
|
+
### kaezon/const-case
|
|
170
|
+
|
|
171
|
+
UPPER_CASE for `const` bindings initialised with a literal or `as const`, lower case for anything mutable or computed. `let` must be lower case, `var` is ignored, and `require(...)` calls keep their name. Destructuring is not checked.
|
|
172
|
+
|
|
173
|
+
### kaezon/prefer-object-params
|
|
174
|
+
|
|
175
|
+
Prefers a single object parameter over multiple positional parameters. Callbacks (functions passed as arguments or properties), object methods, and `computed()` getters are skipped, because their signature is dictated by the caller.
|
|
176
|
+
|
|
177
|
+
### kaezon/require-satisfies-with-as-const
|
|
178
|
+
|
|
179
|
+
Requires `as const satisfies SomeType` instead of bare `as const`, so the object shape is validated at compile time while literal inference is preserved. Primitive literals are skipped because they need no structural check.
|
|
180
|
+
|
|
181
|
+
### kaezon/require-typescript-parser
|
|
182
|
+
|
|
183
|
+
Reports when a `.ts`, `.tsx`, `.mts`, or `.cts` file is parsed without a TypeScript-capable parser, or when a `.vue` file lacks `vue-eslint-parser` or a TypeScript parser for its `<script>`. Without the right parser the other rules silently do nothing, so this rule turns that misconfiguration into a visible error. It does not require typed linting.
|
|
184
|
+
|
|
185
|
+
### kaezon/vue-prop-name-casing-by-type
|
|
186
|
+
|
|
187
|
+
camelCase for props whose type is a function, snake_case for every other prop in `defineProps`. Replaces `vue/prop-name-casing`, which cannot tell the two apart. Skips names containing `:` and `update:`.
|
|
188
|
+
|
|
157
189
|
## Nuxt house style
|
|
158
190
|
|
|
159
191
|
`configs.nuxt_house` enables every `kaezon/*` rule above that applies to Vue + TypeScript, plus this house style:
|
|
@@ -184,6 +216,16 @@ Without `parserOptions.project` or `parserOptions.projectService`, ESLint report
|
|
|
184
216
|
|
|
185
217
|
`ts`, `vue`, and `nuxt` do not include house style and do not need typed linting.
|
|
186
218
|
|
|
219
|
+
## Examples
|
|
220
|
+
|
|
221
|
+
Two runnable projects live under `examples/`:
|
|
222
|
+
|
|
223
|
+
- `examples/ts` — `configs.ts` with only the kaezon rules.
|
|
224
|
+
- `examples/nuxt` — `configs.nuxt_house` with the house style and typed linting.
|
|
225
|
+
|
|
226
|
+
Both ship code that fails on purpose, so `npx eslint probe.ts` shows the rules
|
|
227
|
+
in action and `npx eslint probe.ts --fix` shows the automatic renames.
|
|
228
|
+
|
|
187
229
|
## API
|
|
188
230
|
|
|
189
231
|
Default export:
|
|
@@ -205,7 +247,7 @@ TypeScript types ship with the package (`dist/index.d.ts`), including `PresetNam
|
|
|
205
247
|
|
|
206
248
|
## Requirements
|
|
207
249
|
|
|
208
|
-
- Node.js
|
|
250
|
+
- Node.js `^20.19.0 || ^22.13.0 || >=24`
|
|
209
251
|
- ESLint `^10.0.0`
|
|
210
252
|
- TypeScript `>=5` (peer, for the type-aware checks)
|
|
211
253
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"boolean-is-prefix.d.ts","sourceRoot":"","sources":["../../eslint-rules/boolean-is-prefix.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAY,MAAM,aAAa,CAAA;AAgKvD,QAAA,MAAM,IAAI,EAAE,UAAU,CAAC,iBAAiB,
|
|
1
|
+
{"version":3,"file":"boolean-is-prefix.d.ts","sourceRoot":"","sources":["../../eslint-rules/boolean-is-prefix.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAY,MAAM,aAAa,CAAA;AAgKvD,QAAA,MAAM,IAAI,EAAE,UAAU,CAAC,iBAAiB,CA2DvC,CAAA;AAED,eAAe,IAAI,CAAA"}
|
|
@@ -137,6 +137,7 @@ const rule = {
|
|
|
137
137
|
meta: {
|
|
138
138
|
docs: {
|
|
139
139
|
description: 'Require is_ prefix for boolean and Vue boolean-ref bindings',
|
|
140
|
+
url: 'https://github.com/svaldivia12/eslint-plugin-kaezon#kaezonboolean-is-prefix',
|
|
140
141
|
},
|
|
141
142
|
messages: {
|
|
142
143
|
missingIsPrefix: "Boolean '{{name}}' should use an is_ prefix that reads naturally in English (e.g. is_{{name}}); do not add is_ only to satisfy the rule.",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"computed-explicit-return-type.d.ts","sourceRoot":"","sources":["../../eslint-rules/computed-explicit-return-type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAY,MAAM,aAAa,CAAA;AAkBvD,QAAA,MAAM,IAAI,EAAE,UAAU,CAAC,mBAAmB,
|
|
1
|
+
{"version":3,"file":"computed-explicit-return-type.d.ts","sourceRoot":"","sources":["../../eslint-rules/computed-explicit-return-type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAY,MAAM,aAAa,CAAA;AAkBvD,QAAA,MAAM,IAAI,EAAE,UAAU,CAAC,mBAAmB,CAgCzC,CAAA;AAED,eAAe,IAAI,CAAA"}
|
|
@@ -30,6 +30,7 @@ const rule = {
|
|
|
30
30
|
meta: {
|
|
31
31
|
docs: {
|
|
32
32
|
description: 'Require explicit return types for getters passed to computed',
|
|
33
|
+
url: 'https://github.com/svaldivia12/eslint-plugin-kaezon#kaezoncomputed-explicit-return-type',
|
|
33
34
|
},
|
|
34
35
|
messages: {
|
|
35
36
|
missingReturnType: 'Computed getters must declare an explicit return type.',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"const-case.d.ts","sourceRoot":"","sources":["../../eslint-rules/const-case.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"const-case.d.ts","sourceRoot":"","sources":["../../eslint-rules/const-case.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAsB,MAAM,aAAa,CAAA;AAwHjE,QAAA,MAAM,IAAI,EAAE,UAAU,CAAC,WAAW,GAAG,UAAU,GAAG,WAAW,CAyJ5D,CAAA;AAED,eAAe,IAAI,CAAA"}
|
|
@@ -27,6 +27,41 @@ function is_require_call(init) {
|
|
|
27
27
|
function is_special_name(name) {
|
|
28
28
|
return SPECIAL_CHAR_REGEX.test(name);
|
|
29
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Trims leading and trailing underscores without a regex. An alternation like
|
|
32
|
+
* /^_+|_+$/g backtracks from every position on a long run of underscores, so a
|
|
33
|
+
* scan is both linear and easier to reason about.
|
|
34
|
+
*/
|
|
35
|
+
function trim_underscores(name) {
|
|
36
|
+
let start = 0;
|
|
37
|
+
let end = name.length;
|
|
38
|
+
while (start < end && name[start] === '_')
|
|
39
|
+
start += 1;
|
|
40
|
+
while (end > start && name[end - 1] === '_')
|
|
41
|
+
end -= 1;
|
|
42
|
+
return name.slice(start, end);
|
|
43
|
+
}
|
|
44
|
+
function to_upper_case(name) {
|
|
45
|
+
return trim_underscores(name
|
|
46
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1_$2')
|
|
47
|
+
.replace(/[^A-Za-z0-9]+/g, '_')
|
|
48
|
+
.toUpperCase());
|
|
49
|
+
}
|
|
50
|
+
function to_lower_case(name) {
|
|
51
|
+
return trim_underscores(name
|
|
52
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1_$2')
|
|
53
|
+
.replace(/[^A-Za-z0-9]+/g, '_')
|
|
54
|
+
.toLowerCase());
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* An exported binding can be imported elsewhere, so renaming it automatically
|
|
58
|
+
* would break call sites we cannot see. Those get a suggestion instead of a fix.
|
|
59
|
+
*/
|
|
60
|
+
function is_exported(declaration) {
|
|
61
|
+
const { parent } = declaration;
|
|
62
|
+
return (parent?.type === 'ExportNamedDeclaration' ||
|
|
63
|
+
parent?.type === 'ExportDefaultDeclaration');
|
|
64
|
+
}
|
|
30
65
|
function should_require_lower_case({ init, kind, name, }) {
|
|
31
66
|
if (!UPPER_CASE_REGEX.test(name) ||
|
|
32
67
|
is_require_call(init) ||
|
|
@@ -42,17 +77,79 @@ function should_require_upper_case({ init, kind, name, }) {
|
|
|
42
77
|
}
|
|
43
78
|
const rule = {
|
|
44
79
|
create(context) {
|
|
45
|
-
|
|
46
|
-
|
|
80
|
+
const source_code = context.sourceCode;
|
|
81
|
+
function build_rename({ declaration, identifier, next_name, }) {
|
|
82
|
+
if (is_exported(declaration))
|
|
83
|
+
return null;
|
|
84
|
+
const variable = source_code
|
|
85
|
+
.getDeclaredVariables(declaration)
|
|
86
|
+
.find(candidate => candidate.name === identifier.name);
|
|
87
|
+
if (!variable)
|
|
88
|
+
return null;
|
|
89
|
+
// Rename every occurrence in the file: the declaration plus all reads.
|
|
90
|
+
// `identifiers` and `references` can share a node, so dedupe by range.
|
|
91
|
+
const seen = new Set();
|
|
92
|
+
const targets = [];
|
|
93
|
+
const candidates = [
|
|
94
|
+
...variable.identifiers,
|
|
95
|
+
...variable.references.map(reference => reference.identifier),
|
|
96
|
+
];
|
|
97
|
+
for (const candidate of candidates) {
|
|
98
|
+
const key = `${candidate.range[0]}:${candidate.range[1]}`;
|
|
99
|
+
if (seen.has(key))
|
|
100
|
+
continue;
|
|
101
|
+
seen.add(key);
|
|
102
|
+
targets.push(candidate);
|
|
103
|
+
}
|
|
104
|
+
if (targets.length === 0)
|
|
105
|
+
return null;
|
|
106
|
+
return fixer => targets.map(target => fixer.replaceText(target, next_name));
|
|
107
|
+
}
|
|
108
|
+
function report_lower_case({ declaration, identifier, }) {
|
|
109
|
+
const next_name = to_lower_case(identifier.name);
|
|
110
|
+
if (!next_name || next_name === identifier.name)
|
|
111
|
+
return;
|
|
112
|
+
const fix = build_rename({ declaration, identifier, next_name });
|
|
113
|
+
const descriptor = {
|
|
114
|
+
data: { name: identifier.name, next: next_name },
|
|
47
115
|
messageId: 'lowerCase',
|
|
48
|
-
node,
|
|
49
|
-
}
|
|
116
|
+
node: identifier,
|
|
117
|
+
};
|
|
118
|
+
context.report(fix
|
|
119
|
+
? { ...descriptor, fix }
|
|
120
|
+
: {
|
|
121
|
+
...descriptor,
|
|
122
|
+
suggest: [
|
|
123
|
+
{
|
|
124
|
+
data: descriptor.data,
|
|
125
|
+
fix: fixer => fixer.replaceText(identifier, next_name),
|
|
126
|
+
messageId: 'renameTo',
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
});
|
|
50
130
|
}
|
|
51
|
-
function report_upper_case(
|
|
52
|
-
|
|
131
|
+
function report_upper_case({ declaration, identifier, }) {
|
|
132
|
+
const next_name = to_upper_case(identifier.name);
|
|
133
|
+
if (!next_name || next_name === identifier.name)
|
|
134
|
+
return;
|
|
135
|
+
const fix = build_rename({ declaration, identifier, next_name });
|
|
136
|
+
const descriptor = {
|
|
137
|
+
data: { name: identifier.name, next: next_name },
|
|
53
138
|
messageId: 'upperCase',
|
|
54
|
-
node,
|
|
55
|
-
}
|
|
139
|
+
node: identifier,
|
|
140
|
+
};
|
|
141
|
+
context.report(fix
|
|
142
|
+
? { ...descriptor, fix }
|
|
143
|
+
: {
|
|
144
|
+
...descriptor,
|
|
145
|
+
suggest: [
|
|
146
|
+
{
|
|
147
|
+
data: descriptor.data,
|
|
148
|
+
fix: fixer => fixer.replaceText(identifier, next_name),
|
|
149
|
+
messageId: 'renameTo',
|
|
150
|
+
},
|
|
151
|
+
],
|
|
152
|
+
});
|
|
56
153
|
}
|
|
57
154
|
function visit_variable_declaration(node) {
|
|
58
155
|
for (const declaration of node.declarations) {
|
|
@@ -66,10 +163,10 @@ const rule = {
|
|
|
66
163
|
if (is_special_name(shape.name))
|
|
67
164
|
continue;
|
|
68
165
|
if (should_require_upper_case(shape)) {
|
|
69
|
-
report_upper_case(declaration.id);
|
|
166
|
+
report_upper_case({ declaration: node, identifier: declaration.id });
|
|
70
167
|
}
|
|
71
168
|
if (should_require_lower_case(shape)) {
|
|
72
|
-
report_lower_case(declaration.id);
|
|
169
|
+
report_lower_case({ declaration: node, identifier: declaration.id });
|
|
73
170
|
}
|
|
74
171
|
}
|
|
75
172
|
}
|
|
@@ -80,10 +177,14 @@ const rule = {
|
|
|
80
177
|
meta: {
|
|
81
178
|
docs: {
|
|
82
179
|
description: 'Require UPPER_CASE for literal and "as const" declarations, and lower case for mutable or computed bindings',
|
|
180
|
+
url: 'https://github.com/svaldivia12/eslint-plugin-kaezon#kaezonconst-case',
|
|
83
181
|
},
|
|
182
|
+
fixable: 'code',
|
|
183
|
+
hasSuggestions: true,
|
|
84
184
|
messages: {
|
|
85
|
-
lowerCase: 'const/let should be in lower case.',
|
|
86
|
-
|
|
185
|
+
lowerCase: 'const/let "{{name}}" should be in lower case, not UPPER_CASE.',
|
|
186
|
+
renameTo: 'Rename to "{{next}}".',
|
|
187
|
+
upperCase: 'const "{{name}}" should be in UPPER_CASE.',
|
|
87
188
|
},
|
|
88
189
|
schema: [],
|
|
89
190
|
type: 'suggestion',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prefer-object-params.d.ts","sourceRoot":"","sources":["../../eslint-rules/prefer-object-params.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAY,MAAM,aAAa,CAAA;AA0CvD,QAAA,MAAM,IAAI,EAAE,UAAU,CAAC,oBAAoB,
|
|
1
|
+
{"version":3,"file":"prefer-object-params.d.ts","sourceRoot":"","sources":["../../eslint-rules/prefer-object-params.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAY,MAAM,aAAa,CAAA;AA0CvD,QAAA,MAAM,IAAI,EAAE,UAAU,CAAC,oBAAoB,CAuC1C,CAAA;AAED,eAAe,IAAI,CAAA"}
|
|
@@ -52,6 +52,7 @@ const rule = {
|
|
|
52
52
|
meta: {
|
|
53
53
|
docs: {
|
|
54
54
|
description: 'Prefer a single object parameter over multiple positional parameters.',
|
|
55
|
+
url: 'https://github.com/svaldivia12/eslint-plugin-kaezon#kaezonprefer-object-params',
|
|
55
56
|
},
|
|
56
57
|
messages: {
|
|
57
58
|
preferObjectParams: 'Use a single object parameter instead of {{count}} positional parameters. Example: (a, b, c) -> ({ a, b, c })',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"require-satisfies-with-as-const.d.ts","sourceRoot":"","sources":["../../eslint-rules/require-satisfies-with-as-const.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAY,MAAM,aAAa,CAAA;AAkCvD,QAAA,MAAM,IAAI,EAAE,UAAU,CAAC,kBAAkB,
|
|
1
|
+
{"version":3,"file":"require-satisfies-with-as-const.d.ts","sourceRoot":"","sources":["../../eslint-rules/require-satisfies-with-as-const.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAY,MAAM,aAAa,CAAA;AAkCvD,QAAA,MAAM,IAAI,EAAE,UAAU,CAAC,kBAAkB,CA6BxC,CAAA;AAED,eAAe,IAAI,CAAA"}
|
|
@@ -43,6 +43,7 @@ const rule = {
|
|
|
43
43
|
meta: {
|
|
44
44
|
docs: {
|
|
45
45
|
description: 'Require "as const satisfies SomeType" instead of bare "as const" to validate structure at compile time.',
|
|
46
|
+
url: 'https://github.com/svaldivia12/eslint-plugin-kaezon#kaezonrequire-satisfies-with-as-const',
|
|
46
47
|
},
|
|
47
48
|
messages: {
|
|
48
49
|
requireSatisfies: 'Use "as const satisfies SomeType" to validate the type. Bare "as const" does not check structure.',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"require-typescript-parser.d.ts","sourceRoot":"","sources":["../../eslint-rules/require-typescript-parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA+B,MAAM,aAAa,CAAA;AAgH1E,QAAA,MAAM,IAAI,EAAE,UAAU,CACnB,mBAAmB,GAAG,oBAAoB,GAAG,uBAAuB,
|
|
1
|
+
{"version":3,"file":"require-typescript-parser.d.ts","sourceRoot":"","sources":["../../eslint-rules/require-typescript-parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA+B,MAAM,aAAa,CAAA;AAgH1E,QAAA,MAAM,IAAI,EAAE,UAAU,CACnB,mBAAmB,GAAG,oBAAoB,GAAG,uBAAuB,CA6CtE,CAAA;AAED,eAAe,IAAI,CAAA"}
|
|
@@ -103,6 +103,7 @@ const rule = {
|
|
|
103
103
|
meta: {
|
|
104
104
|
docs: {
|
|
105
105
|
description: 'Require a TypeScript parser for TS files, and vue-eslint-parser with a TypeScript parser for Vue files',
|
|
106
|
+
url: 'https://github.com/svaldivia12/eslint-plugin-kaezon#kaezonrequire-typescript-parser',
|
|
106
107
|
},
|
|
107
108
|
messages: {
|
|
108
109
|
missing_ts_parser: 'This TypeScript file is not using a TypeScript parser (for example @typescript-eslint/parser). kaezon rules that inspect TypeScript AST nodes will not run. This plugin does not ship a parser.',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vue-prop-name-casing-by-type.d.ts","sourceRoot":"","sources":["../../eslint-rules/vue-prop-name-casing-by-type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"vue-prop-name-casing-by-type.d.ts","sourceRoot":"","sources":["../../eslint-rules/vue-prop-name-casing-by-type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAsB,MAAM,aAAa,CAAA;AAuGjE,QAAA,MAAM,IAAI,EAAE,UAAU,CAAC,mBAAmB,GAAG,mBAAmB,CAqE/D,CAAA;AAED,eAAe,IAAI,CAAA"}
|
|
@@ -4,20 +4,21 @@
|
|
|
4
4
|
*/
|
|
5
5
|
const CAMEL_CASE = /^[a-z][a-zA-Z0-9]*$/;
|
|
6
6
|
const SNAKE_CASE = /^[a-z][a-z0-9]*(_[a-z0-9]+)*$/;
|
|
7
|
-
function
|
|
7
|
+
function is_defines_props(node) {
|
|
8
8
|
const { callee } = node;
|
|
9
|
-
|
|
9
|
+
return callee.type === 'Identifier' && callee.name === 'defineProps';
|
|
10
|
+
}
|
|
11
|
+
function extract_define_props_call(node) {
|
|
12
|
+
if (is_defines_props(node))
|
|
10
13
|
return node;
|
|
14
|
+
const { callee } = node;
|
|
15
|
+
if (callee.type !== 'Identifier' || callee.name !== 'withDefaults') {
|
|
16
|
+
return null;
|
|
11
17
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
first_arg.callee.name === 'defineProps') {
|
|
17
|
-
return first_arg;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return null;
|
|
18
|
+
const first_arg = node.arguments[0];
|
|
19
|
+
if (first_arg?.type !== 'CallExpression')
|
|
20
|
+
return null;
|
|
21
|
+
return is_defines_props(first_arg) ? first_arg : null;
|
|
21
22
|
}
|
|
22
23
|
function get_prop_name(node) {
|
|
23
24
|
if (node.key.type === 'Identifier')
|
|
@@ -26,6 +27,22 @@ function get_prop_name(node) {
|
|
|
26
27
|
return String(node.key.value);
|
|
27
28
|
return null;
|
|
28
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Renaming an identifier key is safe: the prop name is the identifier itself.
|
|
32
|
+
* A string-literal key has to keep its quotes, otherwise the fix would emit
|
|
33
|
+
* invalid syntax. Computed keys and template literals return null and get no fix.
|
|
34
|
+
*/
|
|
35
|
+
function build_rename({ node, next_name, }) {
|
|
36
|
+
const { key } = node;
|
|
37
|
+
if (key.type === 'Identifier') {
|
|
38
|
+
return fixer => fixer.replaceText(key, next_name);
|
|
39
|
+
}
|
|
40
|
+
if (key.type === 'Literal' && typeof key.value === 'string') {
|
|
41
|
+
const quote = key.raw.startsWith('"') ? '"' : "'";
|
|
42
|
+
return fixer => fixer.replaceText(key, `${quote}${next_name}${quote}`);
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
29
46
|
function get_props_from_type_literal(type_literal) {
|
|
30
47
|
if (type_literal?.type !== 'TSTypeLiteral')
|
|
31
48
|
return [];
|
|
@@ -45,47 +62,66 @@ function is_function_type(node) {
|
|
|
45
62
|
}
|
|
46
63
|
return false;
|
|
47
64
|
}
|
|
65
|
+
function is_wrapped_in_with_defaults(node) {
|
|
66
|
+
const { parent } = node;
|
|
67
|
+
if (parent?.type !== 'CallExpression')
|
|
68
|
+
return false;
|
|
69
|
+
const { callee } = parent;
|
|
70
|
+
return callee.type === 'Identifier' && callee.name === 'withDefaults';
|
|
71
|
+
}
|
|
72
|
+
function has_update_prefix(name) {
|
|
73
|
+
return name.includes(':') || name.startsWith('update:');
|
|
74
|
+
}
|
|
75
|
+
function to_camel_case(name) {
|
|
76
|
+
return name.replaceAll(/_([a-z])/g, (_, char) => char.toUpperCase());
|
|
77
|
+
}
|
|
78
|
+
function to_snake_case(name) {
|
|
79
|
+
return name.replaceAll(/([A-Z])/g, (_, char) => `_${char.toLowerCase()}`);
|
|
80
|
+
}
|
|
48
81
|
const rule = {
|
|
49
82
|
create(context) {
|
|
83
|
+
function check_prop(prop) {
|
|
84
|
+
const name = get_prop_name(prop);
|
|
85
|
+
if (!name || has_update_prefix(name))
|
|
86
|
+
return;
|
|
87
|
+
const is_function = is_function_type(prop);
|
|
88
|
+
if (!is_function && !SNAKE_CASE.test(name)) {
|
|
89
|
+
const expected = to_snake_case(name);
|
|
90
|
+
if (!expected)
|
|
91
|
+
return;
|
|
92
|
+
context.report({
|
|
93
|
+
data: { expected, name },
|
|
94
|
+
fix: build_rename({ next_name: expected, node: prop }),
|
|
95
|
+
messageId: 'variableSnakeCase',
|
|
96
|
+
node: prop.key,
|
|
97
|
+
});
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (is_function && !CAMEL_CASE.test(name)) {
|
|
101
|
+
const expected = to_camel_case(name);
|
|
102
|
+
if (!expected)
|
|
103
|
+
return;
|
|
104
|
+
context.report({
|
|
105
|
+
data: { expected, name },
|
|
106
|
+
fix: build_rename({ next_name: expected, node: prop }),
|
|
107
|
+
messageId: 'functionCamelCase',
|
|
108
|
+
node: prop.key,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
50
112
|
function visit_call_expression(node) {
|
|
51
113
|
const define_props_call = extract_define_props_call(node);
|
|
52
114
|
if (!define_props_call)
|
|
53
115
|
return;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
node.parent.callee.type === 'Identifier' &&
|
|
57
|
-
node.parent.callee.name === 'withDefaults') {
|
|
116
|
+
// withDefaults(defineProps<...>()) would otherwise report on both calls.
|
|
117
|
+
if (define_props_call === node && is_wrapped_in_with_defaults(node)) {
|
|
58
118
|
return;
|
|
59
119
|
}
|
|
60
120
|
const type_param = define_props_call.typeArguments?.params[0];
|
|
61
121
|
if (!type_param)
|
|
62
122
|
return;
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
const name = get_prop_name(prop);
|
|
66
|
-
if (!name)
|
|
67
|
-
continue;
|
|
68
|
-
if (name.includes(':') || name.startsWith('update:'))
|
|
69
|
-
continue;
|
|
70
|
-
const is_function = is_function_type(prop);
|
|
71
|
-
const is_camel_case = CAMEL_CASE.test(name);
|
|
72
|
-
const is_snake_case = SNAKE_CASE.test(name);
|
|
73
|
-
if (is_function && !is_camel_case) {
|
|
74
|
-
const expected = name.replaceAll(/_([a-z])/g, (_, char) => char.toUpperCase());
|
|
75
|
-
context.report({
|
|
76
|
-
data: { expected: expected || 'myFunction', name },
|
|
77
|
-
messageId: 'functionCamelCase',
|
|
78
|
-
node: prop.key,
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
else if (!is_function && !is_snake_case) {
|
|
82
|
-
const expected = name.replaceAll(/([A-Z])/g, (_, char) => `_${char.toLowerCase()}`);
|
|
83
|
-
context.report({
|
|
84
|
-
data: { expected: expected || 'total_records', name },
|
|
85
|
-
messageId: 'variableSnakeCase',
|
|
86
|
-
node: prop.key,
|
|
87
|
-
});
|
|
88
|
-
}
|
|
123
|
+
for (const prop of get_props_from_type_literal(type_param)) {
|
|
124
|
+
check_prop(prop);
|
|
89
125
|
}
|
|
90
126
|
}
|
|
91
127
|
return {
|
|
@@ -95,7 +131,9 @@ const rule = {
|
|
|
95
131
|
meta: {
|
|
96
132
|
docs: {
|
|
97
133
|
description: 'Enforce camelCase for function props and snake_case for other props in defineProps',
|
|
134
|
+
url: 'https://github.com/svaldivia12/eslint-plugin-kaezon#kaezonvue-prop-name-casing-by-type',
|
|
98
135
|
},
|
|
136
|
+
fixable: 'code',
|
|
99
137
|
messages: {
|
|
100
138
|
functionCamelCase: "Function prop '{{name}}' should be camelCase (e.g. {{expected}}).",
|
|
101
139
|
variableSnakeCase: "Variable prop '{{name}}' should be snake_case (e.g. {{expected}}).",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-kaezon",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "ESLint 10 flat-config plugin with custom TypeScript and Vue rules.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
],
|
|
46
46
|
"packageManager": "pnpm@12.16.1",
|
|
47
47
|
"engines": {
|
|
48
|
-
"node": ">=
|
|
48
|
+
"node": "^20.19.0 || ^22.13.0 || >=24"
|
|
49
49
|
},
|
|
50
50
|
"publishConfig": {
|
|
51
51
|
"access": "public",
|