eslint-plugin-kaezon 1.1.0 → 1.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/CHANGELOG.md +25 -1
- package/README.md +16 -19
- package/dist/configs/create_config.d.ts.map +1 -1
- package/dist/configs/create_config.js +1 -3
- package/dist/eslint-rules/boolean-is-prefix.d.ts.map +1 -1
- package/dist/eslint-rules/boolean-is-prefix.js +4 -7
- package/dist/eslint-rules/computed-explicit-return-type.d.ts.map +1 -1
- package/dist/eslint-rules/computed-explicit-return-type.js +18 -4
- package/dist/eslint-rules/const-case.d.ts.map +1 -1
- package/dist/eslint-rules/const-case.js +26 -13
- package/dist/eslint-rules/prefer-object-params.d.ts.map +1 -1
- package/dist/eslint-rules/prefer-object-params.js +10 -1
- package/dist/eslint-rules/require-satisfies-with-as-const.d.ts.map +1 -1
- package/dist/eslint-rules/require-satisfies-with-as-const.js +7 -8
- package/dist/eslint-rules/require-typescript-parser.d.ts.map +1 -1
- package/dist/eslint-rules/require-typescript-parser.js +1 -1
- 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 +4 -21
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -8
- package/package.json +15 -3
- package/dist/configs/nuxt.d.ts +0 -3
- package/dist/configs/nuxt.d.ts.map +0 -1
- package/dist/configs/nuxt.js +0 -4
- package/dist/configs/nuxt_house.d.ts +0 -3
- package/dist/configs/nuxt_house.d.ts.map +0 -1
- package/dist/configs/nuxt_house.js +0 -4
- package/dist/configs/ts.d.ts +0 -3
- package/dist/configs/ts.d.ts.map +0 -1
- package/dist/configs/ts.js +0 -4
- package/dist/configs/vue.d.ts +0 -3
- package/dist/configs/vue.d.ts.map +0 -1
- package/dist/configs/vue.js +0 -4
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.2.0] - 2026-11-19
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- `kaezon/const-case` offers a suggestion instead of an autofix when renaming could change behavior: a reader in a shorthand property (`{ page_size }`) or an export specifier (`export { limit }`), a `.vue` file whose template reads the binding, or a new name that already resolves in scope.
|
|
15
|
+
- `kaezon/vue-prop-name-casing-by-type` reports only; its autofix is removed. It renamed the key in `defineProps` but not the usages or the parents that pass the prop. The hint for acronyms is now valid snake_case (`userID` → `user_id`, `URL` → `url`).
|
|
16
|
+
- `kaezon/boolean-is-prefix` accepts an `IS_` prefix, so `const IS_FLAG = false` passes it and `kaezon/const-case` at once. The README no longer claims it matches nothing outside Vue.
|
|
17
|
+
- `kaezon/prefer-object-params` no longer reports a callback passed to `new`, such as `new Promise((resolve, reject) => …)`, whose signature the constructor dictates.
|
|
18
|
+
- `@typescript-eslint/utils` is a dependency instead of a devDependency. The published `dist/types.d.ts` imports and re-exports its types, which did not resolve for consumers.
|
|
19
|
+
- `kaezon/require-satisfies-with-as-const` is only silenced by a `satisfies` on the same expression, not by one on any enclosing expression, and skips `-1 as const` like `1 as const`.
|
|
20
|
+
- `kaezon/computed-explicit-return-type` accepts a type argument (`computed<number>(() => 1)`) and checks the `get` of a writable `computed({ get, set })`.
|
|
21
|
+
|
|
22
|
+
## [1.1.1] - 2026-11-02
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
|
|
26
|
+
- `kaezon/prefer-object-params` no longer reports class methods or class property functions. Their parameter list belongs to the class, not to the body, so asking for a single object parameter would change a public API.
|
|
27
|
+
- `kaezon/vue-prop-name-casing-by-type` no longer reports numeric or symbol keys. `defineProps<{ 42: string }>()` was told to use snake_case, which cannot apply to a key that has no name to case.
|
|
28
|
+
|
|
29
|
+
## [1.1.0] - 2026-11-02
|
|
30
|
+
|
|
10
31
|
### Added
|
|
11
32
|
|
|
12
33
|
- `kaezon/vue-prop-name-casing-by-type` now autofixes prop names, keeping the original quote style for string-literal keys.
|
|
@@ -48,5 +69,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
48
69
|
- `configs.nuxt_house` requires `eslint-plugin-vue` and `@typescript-eslint/eslint-plugin`.
|
|
49
70
|
- The plugin ships no parser. Use `@typescript-eslint/parser` and `vue-eslint-parser` in the consuming project.
|
|
50
71
|
|
|
51
|
-
[Unreleased]: https://github.com/svaldivia12/eslint-plugin-kaezon/compare/v1.
|
|
72
|
+
[Unreleased]: https://github.com/svaldivia12/eslint-plugin-kaezon/compare/v1.2.0...HEAD
|
|
73
|
+
[1.2.0]: https://github.com/svaldivia12/eslint-plugin-kaezon/releases/tag/v1.2.0
|
|
74
|
+
[1.1.1]: https://github.com/svaldivia12/eslint-plugin-kaezon/releases/tag/v1.1.1
|
|
75
|
+
[1.1.0]: https://github.com/svaldivia12/eslint-plugin-kaezon/releases/tag/v1.1.0
|
|
52
76
|
[1.0.0]: https://github.com/svaldivia12/eslint-plugin-kaezon/releases/tag/v1.0.0
|
package/README.md
CHANGED
|
@@ -103,10 +103,7 @@ Override a rule in a following config object:
|
|
|
103
103
|
```js
|
|
104
104
|
import kaezon_plugin from 'eslint-plugin-kaezon'
|
|
105
105
|
|
|
106
|
-
export default [
|
|
107
|
-
kaezon_plugin.configs.nuxt,
|
|
108
|
-
{ rules: { 'kaezon/const-case': 'off' } },
|
|
109
|
-
]
|
|
106
|
+
export default [kaezon_plugin.configs.nuxt, { rules: { 'kaezon/const-case': 'off' } }]
|
|
110
107
|
```
|
|
111
108
|
|
|
112
109
|
`createConfig` keys accept kaezon short names (`const-case`) or prefixed ids (`kaezon/const-case`); those emit prefixed `kaezon/...` ids. Other ESLint rule ids (`curly`, `@typescript-eslint/...`, `vue/...`) are copied through so house style can be overridden without a second config object. Unknown `kaezon/...` names throw.
|
|
@@ -142,29 +139,29 @@ export default [
|
|
|
142
139
|
|
|
143
140
|
## Rules
|
|
144
141
|
|
|
145
|
-
| Rule id
|
|
146
|
-
|
|
147
|
-
| `kaezon/boolean-is-prefix`
|
|
148
|
-
| `kaezon/computed-explicit-return-type`
|
|
149
|
-
| `kaezon/const-case`
|
|
150
|
-
| `kaezon/prefer-object-params`
|
|
151
|
-
| `kaezon/require-satisfies-with-as-const` | Require `as const satisfies SomeType` instead of bare `as const` to validate structure at compile time
|
|
152
|
-
| `kaezon/require-typescript-parser`
|
|
153
|
-
| `kaezon/vue-prop-name-casing-by-type`
|
|
142
|
+
| Rule id | Description | Presets |
|
|
143
|
+
| ---------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- | ------------------------- |
|
|
144
|
+
| `kaezon/boolean-is-prefix` | Require `is_` prefix for booleans and Vue boolean refs (`Ref` / `ShallowRef` / `ComputedRef`); type-aware when typed linting is enabled | vue, nuxt, nuxt_house |
|
|
145
|
+
| `kaezon/computed-explicit-return-type` | Require explicit return types for getters passed to `computed` | vue, nuxt, nuxt_house |
|
|
146
|
+
| `kaezon/const-case` | Require UPPER_CASE for literal and `as const` declarations, and lower case for mutable or computed bindings | ts, nuxt, nuxt_house |
|
|
147
|
+
| `kaezon/prefer-object-params` | Prefer a single object parameter over multiple positional parameters | ts, nuxt, nuxt_house |
|
|
148
|
+
| `kaezon/require-satisfies-with-as-const` | Require `as const satisfies SomeType` instead of bare `as const` to validate structure at compile time | ts, nuxt, nuxt_house |
|
|
149
|
+
| `kaezon/require-typescript-parser` | Require a TypeScript parser for TS files, and `vue-eslint-parser` with a TypeScript parser for Vue files | ts, vue, nuxt, nuxt_house |
|
|
150
|
+
| `kaezon/vue-prop-name-casing-by-type` | Enforce camelCase for function props and snake_case for other props in `defineProps` | vue, nuxt, nuxt_house |
|
|
154
151
|
|
|
155
|
-
`boolean-is-prefix` and `computed-explicit-return-type` target Vue code
|
|
152
|
+
`boolean-is-prefix` and `computed-explicit-return-type` target Vue code, which is why they are left out of the `ts` preset. `computed-explicit-return-type` matches nothing without Vue, but `boolean-is-prefix` also reports plain TypeScript booleans (`const flag: boolean`), so turn it on through the `rules` overlay if you want that outside Vue.
|
|
156
153
|
|
|
157
154
|
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
155
|
|
|
159
156
|
### kaezon/boolean-is-prefix
|
|
160
157
|
|
|
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.
|
|
158
|
+
Requires an `is_` prefix on bindings that hold a boolean or a Vue boolean ref. `IS_` is accepted too, so a literal constant that `const-case` puts in UPPER_CASE (`const IS_FLAG = false`) passes both rules. 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
159
|
|
|
163
160
|
The prefix must read naturally in English. Do not add `is_` to a name where it produces nonsense.
|
|
164
161
|
|
|
165
162
|
### kaezon/computed-explicit-return-type
|
|
166
163
|
|
|
167
|
-
Requires an explicit return type on getters passed to `computed`. Applies to arrow functions
|
|
164
|
+
Requires an explicit return type on getters passed to `computed`, including the `get` of a writable `computed({ get, set })`. Applies to arrow functions, function expressions and methods. A type argument (`computed<number>(…)`) counts as the return type.
|
|
168
165
|
|
|
169
166
|
### kaezon/const-case
|
|
170
167
|
|
|
@@ -172,11 +169,11 @@ UPPER_CASE for `const` bindings initialised with a literal or `as const`, lower
|
|
|
172
169
|
|
|
173
170
|
### kaezon/prefer-object-params
|
|
174
171
|
|
|
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.
|
|
172
|
+
Prefers a single object parameter over multiple positional parameters. Callbacks (functions passed as arguments to a call or `new`, or as properties), object methods, and `computed()` getters are skipped, because their signature is dictated by the caller.
|
|
176
173
|
|
|
177
174
|
### kaezon/require-satisfies-with-as-const
|
|
178
175
|
|
|
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.
|
|
176
|
+
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, negative numbers included, are skipped because they need no structural check. Only a `satisfies` on the same expression counts: one on an enclosing object does not cover an `as const` inside it.
|
|
180
177
|
|
|
181
178
|
### kaezon/require-typescript-parser
|
|
182
179
|
|
|
@@ -224,7 +221,7 @@ Two runnable projects live under `examples/`:
|
|
|
224
221
|
- `examples/nuxt` — `configs.nuxt_house` with the house style and typed linting.
|
|
225
222
|
|
|
226
223
|
Both ship code that fails on purpose, so `npx eslint probe.ts` shows the rules
|
|
227
|
-
in action
|
|
224
|
+
in action.
|
|
228
225
|
|
|
229
226
|
## API
|
|
230
227
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create_config.d.ts","sourceRoot":"","sources":["../../configs/create_config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACT,mBAAmB,EACnB,UAAU,EACV,YAAY,EAGZ,UAAU,EACZ,MAAM,aAAa,CAAA;AAMpB,eAAO,MAAM,aAAa,EAAE,SAAS,MAAM,EAM1C,CAAA;AAED,eAAO,MAAM,QAAQ,EAAE,SAAS,MAAM,EAIrC,CAAA;AAED,eAAO,MAAM,SAAS,EAAE,SAAS,MAAM,EAItC,CAAA;AAED,eAAO,MAAM,YAAY,EAAE,SAAS,MAAM,EAAkC,CAAA;AAE5E;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CA4CjE,CAAA;
|
|
1
|
+
{"version":3,"file":"create_config.d.ts","sourceRoot":"","sources":["../../configs/create_config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACT,mBAAmB,EACnB,UAAU,EACV,YAAY,EAGZ,UAAU,EACZ,MAAM,aAAa,CAAA;AAMpB,eAAO,MAAM,aAAa,EAAE,SAAS,MAAM,EAM1C,CAAA;AAED,eAAO,MAAM,QAAQ,EAAE,SAAS,MAAM,EAIrC,CAAA;AAED,eAAO,MAAM,SAAS,EAAE,SAAS,MAAM,EAItC,CAAA;AAED,eAAO,MAAM,YAAY,EAAE,SAAS,MAAM,EAAkC,CAAA;AAE5E;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CA4CjE,CAAA;AA4GD,wBAAgB,aAAa,CAAC,EAC3B,OAAY,EACZ,MAAM,GACR,EAAE;IACA,OAAO,CAAC,EAAE,mBAAmB,CAAA;IAC7B,MAAM,EAAE,YAAY,CAAA;CACtB,GAAG,UAAU,CAoBb"}
|
|
@@ -150,9 +150,7 @@ export function create_config({ options = {}, plugin, }) {
|
|
|
150
150
|
const files = options.files ?? [...default_files];
|
|
151
151
|
const overlay = options.rules ?? {};
|
|
152
152
|
const is_house = preset === 'nuxt_house';
|
|
153
|
-
const plugins = is_house
|
|
154
|
-
? { ...load_peer_plugins(), kaezon: plugin }
|
|
155
|
-
: { kaezon: plugin };
|
|
153
|
+
const plugins = is_house ? { ...load_peer_plugins(), kaezon: plugin } : { kaezon: plugin };
|
|
156
154
|
return {
|
|
157
155
|
files,
|
|
158
156
|
name: preset_config_names[preset],
|
|
@@ -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;
|
|
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;AAuJvD,QAAA,MAAM,IAAI,EAAE,UAAU,CAAC,iBAAiB,CAwDvC,CAAA;AAED,eAAe,IAAI,CAAA"}
|
|
@@ -17,9 +17,7 @@ function get_node_type({ node, type_services, }) {
|
|
|
17
17
|
return type_services.checker.getTypeAtLocation(ts_node);
|
|
18
18
|
}
|
|
19
19
|
function get_symbol_name(type) {
|
|
20
|
-
const symbol = type.aliasSymbol ??
|
|
21
|
-
type.target?.symbol ??
|
|
22
|
-
type.getSymbol();
|
|
20
|
+
const symbol = type.aliasSymbol ?? type.target?.symbol ?? type.getSymbol();
|
|
23
21
|
return symbol?.getName() ?? null;
|
|
24
22
|
}
|
|
25
23
|
function get_type_arguments({ checker, type, }) {
|
|
@@ -57,8 +55,7 @@ function is_ast_boolean_type(type_node) {
|
|
|
57
55
|
if (type_node.type === 'TSBooleanKeyword')
|
|
58
56
|
return true;
|
|
59
57
|
if (type_node.type === 'TSLiteralType') {
|
|
60
|
-
return
|
|
61
|
-
typeof type_node.literal.value === 'boolean');
|
|
58
|
+
return type_node.literal.type === 'Literal' && typeof type_node.literal.value === 'boolean';
|
|
62
59
|
}
|
|
63
60
|
return false;
|
|
64
61
|
}
|
|
@@ -77,7 +74,7 @@ function is_ast_boolean_ref_call(init) {
|
|
|
77
74
|
if (is_ast_boolean_type(init.typeArguments?.params[0]))
|
|
78
75
|
return true;
|
|
79
76
|
const first_arg = init.arguments[0];
|
|
80
|
-
return
|
|
77
|
+
return first_arg?.type === 'Literal' && typeof first_arg.value === 'boolean';
|
|
81
78
|
}
|
|
82
79
|
function is_ast_boolean_binding({ id, init, }) {
|
|
83
80
|
const annotation = id.typeAnnotation?.typeAnnotation;
|
|
@@ -111,7 +108,7 @@ const rule = {
|
|
|
111
108
|
return;
|
|
112
109
|
if (!is_boolean_binding({ id, init, type_services }))
|
|
113
110
|
return;
|
|
114
|
-
if (id.name.startsWith('is_'))
|
|
111
|
+
if (id.name.startsWith('is_') || id.name.startsWith('IS_'))
|
|
115
112
|
return;
|
|
116
113
|
context.report({
|
|
117
114
|
data: { name: id.name },
|
|
@@ -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;
|
|
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;AAgCvD,QAAA,MAAM,IAAI,EAAE,UAAU,CAAC,mBAAmB,CAiCzC,CAAA;AAED,eAAe,IAAI,CAAA"}
|
|
@@ -5,16 +5,30 @@ function is_computed_call(node) {
|
|
|
5
5
|
return callee.type === 'Identifier' && callee.name === 'computed';
|
|
6
6
|
}
|
|
7
7
|
function is_function_getter(node) {
|
|
8
|
-
return
|
|
9
|
-
|
|
8
|
+
return node?.type === 'ArrowFunctionExpression' || node?.type === 'FunctionExpression';
|
|
9
|
+
}
|
|
10
|
+
/** The getter of `computed(() => …)` or of a writable `computed({ get, set })`. */
|
|
11
|
+
function find_getter(node) {
|
|
12
|
+
if (is_function_getter(node))
|
|
13
|
+
return node;
|
|
14
|
+
if (node?.type !== 'ObjectExpression')
|
|
15
|
+
return null;
|
|
16
|
+
const get = node.properties.find((property) => property.type === 'Property' &&
|
|
17
|
+
!property.computed &&
|
|
18
|
+
property.key.type === 'Identifier' &&
|
|
19
|
+
property.key.name === 'get');
|
|
20
|
+
return is_function_getter(get?.value) ? get.value : null;
|
|
10
21
|
}
|
|
11
22
|
const rule = {
|
|
12
23
|
create(context) {
|
|
13
24
|
function visit_call_expression(node) {
|
|
14
25
|
if (!is_computed_call(node))
|
|
15
26
|
return;
|
|
16
|
-
|
|
17
|
-
if (
|
|
27
|
+
// `computed<T>(…)` types the getter through its type argument.
|
|
28
|
+
if (node.typeArguments)
|
|
29
|
+
return;
|
|
30
|
+
const getter = find_getter(node.arguments[0]);
|
|
31
|
+
if (!getter)
|
|
18
32
|
return;
|
|
19
33
|
if (getter.returnType?.type === 'TSTypeAnnotation')
|
|
20
34
|
return;
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,CAuJ5D,CAAA;AAED,eAAe,IAAI,CAAA"}
|
|
@@ -59,32 +59,45 @@ function to_lower_case(name) {
|
|
|
59
59
|
*/
|
|
60
60
|
function is_exported(declaration) {
|
|
61
61
|
const { parent } = declaration;
|
|
62
|
-
return
|
|
63
|
-
parent?.type === 'ExportDefaultDeclaration');
|
|
62
|
+
return parent?.type === 'ExportNamedDeclaration' || parent?.type === 'ExportDefaultDeclaration';
|
|
64
63
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
/**
|
|
65
|
+
* A rename is only safe when the new name is free in the binding's scope and
|
|
66
|
+
* every scope below it: otherwise a reader would resolve to another binding,
|
|
67
|
+
* or an outer binding would be captured by the renamed one.
|
|
68
|
+
*/
|
|
69
|
+
function is_name_taken({ name, scope }) {
|
|
70
|
+
if (scope.set.has(name))
|
|
71
|
+
return true;
|
|
72
|
+
if (scope.references.some(reference => reference.identifier.name === name))
|
|
73
|
+
return true;
|
|
74
|
+
return scope.childScopes.some(child => is_name_taken({ name, scope: child }));
|
|
75
|
+
}
|
|
76
|
+
/** Renaming a shorthand property or export specifier also renames its key or export. */
|
|
77
|
+
function is_name_bound_elsewhere(identifier) {
|
|
78
|
+
const { parent } = identifier;
|
|
79
|
+
return (parent?.type === 'Property' && parent.shorthand) || parent?.type === 'ExportSpecifier';
|
|
80
|
+
}
|
|
81
|
+
function should_require_lower_case({ init, kind, name }) {
|
|
82
|
+
if (!UPPER_CASE_REGEX.test(name) || is_require_call(init) || has_as_const(init)) {
|
|
69
83
|
return false;
|
|
70
84
|
}
|
|
71
85
|
return kind === 'let' || (kind === 'const' && !is_literal(init));
|
|
72
86
|
}
|
|
73
|
-
function should_require_upper_case({ init, kind, name
|
|
74
|
-
return (kind === 'const' &&
|
|
75
|
-
!UPPER_CASE_REGEX.test(name) &&
|
|
76
|
-
(is_literal(init) || has_as_const(init)));
|
|
87
|
+
function should_require_upper_case({ init, kind, name }) {
|
|
88
|
+
return (kind === 'const' && !UPPER_CASE_REGEX.test(name) && (is_literal(init) || has_as_const(init)));
|
|
77
89
|
}
|
|
78
90
|
const rule = {
|
|
79
91
|
create(context) {
|
|
80
92
|
const source_code = context.sourceCode;
|
|
81
93
|
function build_rename({ declaration, identifier, next_name, }) {
|
|
82
|
-
|
|
94
|
+
// A .vue template reads the binding too, and the script scope cannot see it.
|
|
95
|
+
if (is_exported(declaration) || context.filename.endsWith('.vue'))
|
|
83
96
|
return null;
|
|
84
97
|
const variable = source_code
|
|
85
98
|
.getDeclaredVariables(declaration)
|
|
86
99
|
.find(candidate => candidate.name === identifier.name);
|
|
87
|
-
if (!variable)
|
|
100
|
+
if (!variable || is_name_taken({ name: next_name, scope: variable.scope }))
|
|
88
101
|
return null;
|
|
89
102
|
// Rename every occurrence in the file: the declaration plus all reads.
|
|
90
103
|
// `identifiers` and `references` can share a node, so dedupe by range.
|
|
@@ -101,7 +114,7 @@ const rule = {
|
|
|
101
114
|
seen.add(key);
|
|
102
115
|
targets.push(candidate);
|
|
103
116
|
}
|
|
104
|
-
if (targets.length === 0)
|
|
117
|
+
if (targets.length === 0 || targets.some(is_name_bound_elsewhere))
|
|
105
118
|
return null;
|
|
106
119
|
return fixer => targets.map(target => fixer.replaceText(target, next_name));
|
|
107
120
|
}
|
|
@@ -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;
|
|
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;AA6CvD,QAAA,MAAM,IAAI,EAAE,UAAU,CAAC,oBAAoB,CAsC1C,CAAA;AAED,eAAe,IAAI,CAAA"}
|
|
@@ -8,13 +8,22 @@ function is_computed_getter(node) {
|
|
|
8
8
|
const { callee } = parent;
|
|
9
9
|
return callee.type === 'Identifier' && callee.name === 'computed';
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* A function whose signature is dictated by something other than its body: an
|
|
13
|
+
* object property, a class method, or a callback passed to a call or `new`. Changing
|
|
14
|
+
* their parameters would change a public API or break the caller.
|
|
15
|
+
*/
|
|
11
16
|
function is_external_callback(node) {
|
|
12
17
|
const { parent } = node;
|
|
13
18
|
if (!parent)
|
|
14
19
|
return false;
|
|
15
20
|
if (parent.type === 'Property')
|
|
16
21
|
return true;
|
|
17
|
-
if (parent.type === '
|
|
22
|
+
if (parent.type === 'MethodDefinition')
|
|
23
|
+
return true;
|
|
24
|
+
if (parent.type === 'PropertyDefinition')
|
|
25
|
+
return true;
|
|
26
|
+
if (parent.type === 'CallExpression' || parent.type === 'NewExpression')
|
|
18
27
|
return true;
|
|
19
28
|
return false;
|
|
20
29
|
}
|
|
@@ -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;
|
|
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;AAmCvD,QAAA,MAAM,IAAI,EAAE,UAAU,CAAC,kBAAkB,CA6BxC,CAAA;AAED,eAAe,IAAI,CAAA"}
|
|
@@ -13,16 +13,15 @@ function is_bare_as_const(node) {
|
|
|
13
13
|
typeAnnotation.typeName.name !== 'const') {
|
|
14
14
|
return false;
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (current.type === 'TSSatisfiesExpression')
|
|
19
|
-
return false;
|
|
20
|
-
current = current.parent;
|
|
21
|
-
}
|
|
22
|
-
return true;
|
|
16
|
+
// Only `x as const satisfies T` checks x; a satisfies further out checks something else.
|
|
17
|
+
return node.parent.type !== 'TSSatisfiesExpression' || node.parent.expression !== node;
|
|
23
18
|
}
|
|
24
19
|
function is_primitive_literal(node) {
|
|
25
|
-
|
|
20
|
+
const { expression } = node;
|
|
21
|
+
return (expression.type === 'Literal' ||
|
|
22
|
+
(expression.type === 'UnaryExpression' &&
|
|
23
|
+
expression.operator === '-' &&
|
|
24
|
+
expression.argument.type === 'Literal'));
|
|
26
25
|
}
|
|
27
26
|
const rule = {
|
|
28
27
|
create(context) {
|
|
@@ -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;
|
|
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;AAsG1E,QAAA,MAAM,IAAI,EAAE,UAAU,CAAC,mBAAmB,GAAG,oBAAoB,GAAG,uBAAuB,CA4C1F,CAAA;AAED,eAAe,IAAI,CAAA"}
|
|
@@ -29,7 +29,7 @@ function get_parser_name(parser) {
|
|
|
29
29
|
function is_typescript_parser_name(name) {
|
|
30
30
|
if (!name)
|
|
31
31
|
return false;
|
|
32
|
-
return
|
|
32
|
+
return name === '@typescript-eslint/parser' || name.includes('typescript-eslint');
|
|
33
33
|
}
|
|
34
34
|
function is_vue_parser_name(name) {
|
|
35
35
|
if (!name)
|
|
@@ -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,EAAY,MAAM,aAAa,CAAA;AA8EvD,QAAA,MAAM,IAAI,EAAE,UAAU,CAAC,mBAAmB,GAAG,mBAAmB,CAgE/D,CAAA;AAED,eAAe,IAAI,CAAA"}
|
|
@@ -23,23 +23,9 @@ function extract_define_props_call(node) {
|
|
|
23
23
|
function get_prop_name(node) {
|
|
24
24
|
if (node.key.type === 'Identifier')
|
|
25
25
|
return node.key.name;
|
|
26
|
-
|
|
27
|
-
|
|
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}`);
|
|
26
|
+
// A numeric or symbol literal key has no name to case, so skip it.
|
|
27
|
+
if (node.key.type === 'Literal' && typeof node.key.value === 'string') {
|
|
28
|
+
return node.key.value;
|
|
43
29
|
}
|
|
44
30
|
return null;
|
|
45
31
|
}
|
|
@@ -76,7 +62,7 @@ function to_camel_case(name) {
|
|
|
76
62
|
return name.replaceAll(/_([a-z])/g, (_, char) => char.toUpperCase());
|
|
77
63
|
}
|
|
78
64
|
function to_snake_case(name) {
|
|
79
|
-
return name.replaceAll(/([A-Z])/g,
|
|
65
|
+
return name.replaceAll(/([a-z0-9])([A-Z])/g, '$1_$2').toLowerCase();
|
|
80
66
|
}
|
|
81
67
|
const rule = {
|
|
82
68
|
create(context) {
|
|
@@ -91,7 +77,6 @@ const rule = {
|
|
|
91
77
|
return;
|
|
92
78
|
context.report({
|
|
93
79
|
data: { expected, name },
|
|
94
|
-
fix: build_rename({ next_name: expected, node: prop }),
|
|
95
80
|
messageId: 'variableSnakeCase',
|
|
96
81
|
node: prop.key,
|
|
97
82
|
});
|
|
@@ -103,7 +88,6 @@ const rule = {
|
|
|
103
88
|
return;
|
|
104
89
|
context.report({
|
|
105
90
|
data: { expected, name },
|
|
106
|
-
fix: build_rename({ next_name: expected, node: prop }),
|
|
107
91
|
messageId: 'functionCamelCase',
|
|
108
92
|
node: prop.key,
|
|
109
93
|
});
|
|
@@ -133,7 +117,6 @@ const rule = {
|
|
|
133
117
|
description: 'Enforce camelCase for function props and snake_case for other props in defineProps',
|
|
134
118
|
url: 'https://github.com/svaldivia12/eslint-plugin-kaezon#kaezonvue-prop-name-casing-by-type',
|
|
135
119
|
},
|
|
136
|
-
fixable: 'code',
|
|
137
120
|
messages: {
|
|
138
121
|
functionCamelCase: "Function prop '{{name}}' should be camelCase (e.g. {{expected}}).",
|
|
139
122
|
variableSnakeCase: "Variable prop '{{name}}' should be snake_case (e.g. {{expected}}).",
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAuB,YAAY,EAAE,MAAM,YAAY,CAAA;AA8BnE,QAAA,MAAM,MAAM,EAAE,YAUb,CAAA;AA0BD,eAAe,MAAM,CAAA;AAErB,YAAY,EACT,mBAAmB,EACnB,UAAU,EACV,YAAY,EACZ,UAAU,EACV,iBAAiB,EACjB,aAAa,EACb,UAAU,EACV,UAAU,EACV,YAAY,GACd,MAAM,YAAY,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
import { fileURLToPath } from 'node:url';
|
|
3
3
|
import { create_config } from "./configs/create_config.js";
|
|
4
|
-
import { create_nuxt_config } from "./configs/nuxt.js";
|
|
5
|
-
import { create_nuxt_house_config } from "./configs/nuxt_house.js";
|
|
6
|
-
import { create_ts_config } from "./configs/ts.js";
|
|
7
|
-
import { create_vue_config } from "./configs/vue.js";
|
|
8
4
|
import rules_module from "./eslint-rules/index.js";
|
|
9
5
|
import { to_plugin_rules } from "./types.js";
|
|
10
6
|
/**
|
|
@@ -42,9 +38,9 @@ const plugin = {
|
|
|
42
38
|
},
|
|
43
39
|
rules: to_plugin_rules(rules_module.rules),
|
|
44
40
|
};
|
|
45
|
-
plugin.configs.nuxt =
|
|
46
|
-
plugin.configs.ts =
|
|
47
|
-
plugin.configs.vue =
|
|
41
|
+
plugin.configs.nuxt = create_config({ options: { preset: 'nuxt' }, plugin });
|
|
42
|
+
plugin.configs.ts = create_config({ options: { preset: 'ts' }, plugin });
|
|
43
|
+
plugin.configs.vue = create_config({ options: { preset: 'vue' }, plugin });
|
|
48
44
|
/**
|
|
49
45
|
* Lazily built: the nuxt_house preset needs eslint-plugin-vue and
|
|
50
46
|
* @typescript-eslint/eslint-plugin, and the error should surface when the
|
|
@@ -54,7 +50,7 @@ Object.defineProperty(plugin.configs, 'nuxt_house', {
|
|
|
54
50
|
configurable: true,
|
|
55
51
|
enumerable: true,
|
|
56
52
|
get() {
|
|
57
|
-
const config =
|
|
53
|
+
const config = create_config({ options: { preset: 'nuxt_house' }, plugin });
|
|
58
54
|
Object.defineProperty(plugin.configs, 'nuxt_house', {
|
|
59
55
|
configurable: true,
|
|
60
56
|
enumerable: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-kaezon",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "ESLint 10 flat-config plugin with custom TypeScript and Vue rules.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -51,6 +51,9 @@
|
|
|
51
51
|
"access": "public",
|
|
52
52
|
"provenance": true
|
|
53
53
|
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"@typescript-eslint/utils": "^8.72.1"
|
|
56
|
+
},
|
|
54
57
|
"peerDependencies": {
|
|
55
58
|
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
56
59
|
"eslint": "^10.0.0",
|
|
@@ -67,22 +70,31 @@
|
|
|
67
70
|
},
|
|
68
71
|
"scripts": {
|
|
69
72
|
"build": "tsc --project tsconfig.json",
|
|
73
|
+
"format": "prettier --write .",
|
|
74
|
+
"format:check": "prettier --check .",
|
|
70
75
|
"lint": "eslint .",
|
|
76
|
+
"prepare": "husky",
|
|
71
77
|
"typecheck": "pnpm run build && tsc --project tsconfig.test.json",
|
|
72
78
|
"test": "node --test tests/**/*.test.ts",
|
|
79
|
+
"test:examples": "node scripts/check_examples.ts",
|
|
73
80
|
"check:package": "publint && attw --pack . --profile esm-only",
|
|
74
|
-
"prepublishOnly": "pnpm run build && pnpm run lint && pnpm run test && pnpm run typecheck"
|
|
81
|
+
"prepublishOnly": "pnpm run format:check && pnpm run build && pnpm run lint && pnpm run test && pnpm run typecheck"
|
|
75
82
|
},
|
|
76
83
|
"devDependencies": {
|
|
77
84
|
"@arethetypeswrong/cli": "^0.18.5",
|
|
85
|
+
"@commitlint/cli": "^21.2.4",
|
|
86
|
+
"@commitlint/config-conventional": "^21.2.4",
|
|
78
87
|
"@eslint/js": "^10.0.1",
|
|
79
88
|
"@types/node": "^26.6.6",
|
|
80
89
|
"@typescript-eslint/eslint-plugin": "^8.72.1",
|
|
81
90
|
"@typescript-eslint/parser": "^8.72.1",
|
|
82
|
-
"@typescript-eslint/utils": "^8.72.1",
|
|
83
91
|
"eslint": "^10.14.0",
|
|
92
|
+
"eslint-config-prettier": "^10.1.8",
|
|
84
93
|
"eslint-plugin-vue": "^10.12.0",
|
|
85
94
|
"globals": "^17.13.0",
|
|
95
|
+
"husky": "^9.1.7",
|
|
96
|
+
"lint-staged": "^17.6.0",
|
|
97
|
+
"prettier": "^3.9.10",
|
|
86
98
|
"publint": "^0.3.25",
|
|
87
99
|
"typescript": "~6.0.3",
|
|
88
100
|
"vue-eslint-parser": "^10.4.1"
|
package/dist/configs/nuxt.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nuxt.d.ts","sourceRoot":"","sources":["../../configs/nuxt.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE3D,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,YAAY,GAAG,UAAU,CAEnE"}
|
package/dist/configs/nuxt.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nuxt_house.d.ts","sourceRoot":"","sources":["../../configs/nuxt_house.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE3D,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,YAAY,GAAG,UAAU,CAEzE"}
|
package/dist/configs/ts.d.ts
DELETED
package/dist/configs/ts.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ts.d.ts","sourceRoot":"","sources":["../../configs/ts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE3D,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,YAAY,GAAG,UAAU,CAEjE"}
|
package/dist/configs/ts.js
DELETED
package/dist/configs/vue.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vue.d.ts","sourceRoot":"","sources":["../../configs/vue.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE3D,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,YAAY,GAAG,UAAU,CAElE"}
|
package/dist/configs/vue.js
DELETED