eslint-plugin-kaezon 1.0.0 → 1.1.1

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 CHANGED
@@ -7,6 +7,33 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.1.1] - 2026-11-02
11
+
12
+ ### Fixed
13
+
14
+ - `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.
15
+ - `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.
16
+
17
+ ## [1.1.0] - 2026-11-02
18
+
19
+ ### Added
20
+
21
+ - `kaezon/vue-prop-name-casing-by-type` now autofixes prop names, keeping the original quote style for string-literal keys.
22
+ - `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.
23
+ - `meta.docs.url` on every rule, pointing at its section in the README.
24
+ - Per-rule documentation in the README.
25
+ - `examples/ts` and `examples/nuxt`, both runnable.
26
+ - A CI job that checks the built package on every Node version `engines` claims to support.
27
+
28
+ ### Changed
29
+
30
+ - `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.
31
+ - Rule messages now name the offending identifier and the expected name.
32
+
33
+ ### Fixed
34
+
35
+ - Removed a regular expression in `const-case` that backtracked on long runs of underscores.
36
+
10
37
  ## [1.0.0] - 2026-11-02
11
38
 
12
39
  ### Added
@@ -23,9 +50,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
23
50
 
24
51
  ### Notes
25
52
 
53
+ - Written in TypeScript and published as compiled ESM in `dist/`, with `.d.ts` files generated from the source.
54
+ - Requires Node.js `>=26` and ESLint `^10.0.0` (flat config only).
55
+ - The public types (`PresetName`, `CreateConfigOptions`, `KaezonPlugin`, `KaezonRule`, `KaezonRuleContext`, `KaezonRuleMap`, `RuleConfig`, `RuleSeverity`, `FlatConfig`) are exported from the package root.
26
56
  - `configs.nuxt` contains kaezon rules only and works with ESLint installed.
27
57
  - `configs.nuxt_house` requires `eslint-plugin-vue` and `@typescript-eslint/eslint-plugin`.
28
58
  - The plugin ships no parser. Use `@typescript-eslint/parser` and `vue-eslint-parser` in the consuming project.
29
59
 
30
- [Unreleased]: https://github.com/svaldivia12/eslint-plugin-kaezon/compare/v1.0.0...HEAD
60
+ [Unreleased]: https://github.com/svaldivia12/eslint-plugin-kaezon/compare/v1.1.1...HEAD
61
+ [1.1.1]: https://github.com/svaldivia12/eslint-plugin-kaezon/releases/tag/v1.1.1
62
+ [1.1.0]: https://github.com/svaldivia12/eslint-plugin-kaezon/releases/tag/v1.1.0
31
63
  [1.0.0]: https://github.com/svaldivia12/eslint-plugin-kaezon/releases/tag/v1.0.0
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # eslint-plugin-kaezon
2
2
 
3
- [![npm version](https://img.shields.io/npm/v/eslint-plugin-kaezon.svg)](https://www.npmjs.com/package/eslint-plugin-kaezon)
4
- [![CI](https://github.com/svaldivia12/eslint-plugin-kaezon/actions/workflows/ci.yml/badge.svg)](https://github.com/svaldivia12/eslint-plugin-kaezon/actions/workflows/ci.yml)
5
- [![License: MIT](https://img.shields.io/npm/l/eslint-plugin-kaezon.svg)](./LICENSE)
3
+ [![npm version](https://img.shields.io/npm/v/eslint-plugin-kaezon.svg?cacheSeconds=0)](https://www.npmjs.com/package/eslint-plugin-kaezon)
4
+ [![CI](https://github.com/svaldivia12/eslint-plugin-kaezon/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/svaldivia12/eslint-plugin-kaezon/actions/workflows/ci.yml)
5
+ [![License: MIT](https://img.shields.io/npm/l/eslint-plugin-kaezon.svg?cacheSeconds=0)](./LICENSE)
6
6
 
7
7
  ESLint 10 flat-config plugin with custom TypeScript and Vue rules.
8
8
 
@@ -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,18 +139,50 @@ export default [
142
139
 
143
140
  ## Rules
144
141
 
145
- | Rule id | Description | Presets |
146
- |---|---|---|
147
- | `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 |
148
- | `kaezon/computed-explicit-return-type` | Require explicit return types for getters passed to `computed` | vue, nuxt, nuxt_house |
149
- | `kaezon/const-case` | Require UPPER_CASE for literal and `as const` declarations, and lower case for mutable or computed bindings | ts, nuxt, nuxt_house |
150
- | `kaezon/prefer-object-params` | Prefer a single object parameter over multiple positional parameters | ts, nuxt, nuxt_house |
151
- | `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 |
152
- | `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 |
153
- | `kaezon/vue-prop-name-casing-by-type` | Enforce camelCase for function props and snake_case for other props in `defineProps` | vue, nuxt, nuxt_house |
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
152
  `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
153
 
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`.
155
+
156
+ ### kaezon/boolean-is-prefix
157
+
158
+ 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.
159
+
160
+ The prefix must read naturally in English. Do not add `is_` to a name where it produces nonsense.
161
+
162
+ ### kaezon/computed-explicit-return-type
163
+
164
+ Requires an explicit return type on getters passed to `computed`. Applies to arrow functions and function expressions.
165
+
166
+ ### kaezon/const-case
167
+
168
+ 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.
169
+
170
+ ### kaezon/prefer-object-params
171
+
172
+ 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.
173
+
174
+ ### kaezon/require-satisfies-with-as-const
175
+
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 are skipped because they need no structural check.
177
+
178
+ ### kaezon/require-typescript-parser
179
+
180
+ 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.
181
+
182
+ ### kaezon/vue-prop-name-casing-by-type
183
+
184
+ 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:`.
185
+
157
186
  ## Nuxt house style
158
187
 
159
188
  `configs.nuxt_house` enables every `kaezon/*` rule above that applies to Vue + TypeScript, plus this house style:
@@ -184,6 +213,16 @@ Without `parserOptions.project` or `parserOptions.projectService`, ESLint report
184
213
 
185
214
  `ts`, `vue`, and `nuxt` do not include house style and do not need typed linting.
186
215
 
216
+ ## Examples
217
+
218
+ Two runnable projects live under `examples/`:
219
+
220
+ - `examples/ts` — `configs.ts` with only the kaezon rules.
221
+ - `examples/nuxt` — `configs.nuxt_house` with the house style and typed linting.
222
+
223
+ Both ship code that fails on purpose, so `npx eslint probe.ts` shows the rules
224
+ in action and `npx eslint probe.ts --fix` shows the automatic renames.
225
+
187
226
  ## API
188
227
 
189
228
  Default export:
@@ -205,7 +244,7 @@ TypeScript types ship with the package (`dist/index.d.ts`), including `PresetNam
205
244
 
206
245
  ## Requirements
207
246
 
208
- - Node.js `>=26`
247
+ - Node.js `^20.19.0 || ^22.13.0 || >=24`
209
248
  - ESLint `^10.0.0`
210
249
  - TypeScript `>=5` (peer, for the type-aware checks)
211
250
 
@@ -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;AAgHD,wBAAgB,aAAa,CAAC,EAC3B,OAAY,EACZ,MAAM,GACR,EAAE;IACA,OAAO,CAAC,EAAE,mBAAmB,CAAA;IAC7B,MAAM,EAAE,YAAY,CAAA;CACtB,GAAG,UAAU,CAsBb"}
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;AAgKvD,QAAA,MAAM,IAAI,EAAE,UAAU,CAAC,iBAAiB,CA0DvC,CAAA;AAED,eAAe,IAAI,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 (type_node.literal.type === 'Literal' &&
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 (first_arg?.type === 'Literal' && typeof first_arg.value === 'boolean');
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;
@@ -137,6 +134,7 @@ const rule = {
137
134
  meta: {
138
135
  docs: {
139
136
  description: 'Require is_ prefix for boolean and Vue boolean-ref bindings',
137
+ url: 'https://github.com/svaldivia12/eslint-plugin-kaezon#kaezonboolean-is-prefix',
140
138
  },
141
139
  messages: {
142
140
  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,CA+BzC,CAAA;AAED,eAAe,IAAI,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;AAevD,QAAA,MAAM,IAAI,EAAE,UAAU,CAAC,mBAAmB,CA8BzC,CAAA;AAED,eAAe,IAAI,CAAA"}
@@ -5,8 +5,7 @@ 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 (node?.type === 'ArrowFunctionExpression' ||
9
- node?.type === 'FunctionExpression');
8
+ return node?.type === 'ArrowFunctionExpression' || node?.type === 'FunctionExpression';
10
9
  }
11
10
  const rule = {
12
11
  create(context) {
@@ -30,6 +29,7 @@ const rule = {
30
29
  meta: {
31
30
  docs: {
32
31
  description: 'Require explicit return types for getters passed to computed',
32
+ url: 'https://github.com/svaldivia12/eslint-plugin-kaezon#kaezoncomputed-explicit-return-type',
33
33
  },
34
34
  messages: {
35
35
  missingReturnType: 'Computed getters must declare an explicit return type.',
@@ -1,4 +1,4 @@
1
1
  import type { KaezonRule } from '../types.ts';
2
- declare const rule: KaezonRule<'lowerCase' | 'upperCase'>;
2
+ declare const rule: KaezonRule<'lowerCase' | 'renameTo' | 'upperCase'>;
3
3
  export default rule;
4
4
  //# sourceMappingURL=const-case.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"const-case.d.ts","sourceRoot":"","sources":["../../eslint-rules/const-case.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAY,MAAM,aAAa,CAAA;AA2EvD,QAAA,MAAM,IAAI,EAAE,UAAU,CAAC,WAAW,GAAG,WAAW,CAwD/C,CAAA;AAED,eAAe,IAAI,CAAA"}
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;AAuGjE,QAAA,MAAM,IAAI,EAAE,UAAU,CAAC,WAAW,GAAG,UAAU,GAAG,WAAW,CAsJ5D,CAAA;AAED,eAAe,IAAI,CAAA"}
@@ -27,32 +27,124 @@ function is_require_call(init) {
27
27
  function is_special_name(name) {
28
28
  return SPECIAL_CHAR_REGEX.test(name);
29
29
  }
30
- function should_require_lower_case({ init, kind, name, }) {
31
- if (!UPPER_CASE_REGEX.test(name) ||
32
- is_require_call(init) ||
33
- has_as_const(init)) {
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' || parent?.type === 'ExportDefaultDeclaration';
63
+ }
64
+ function should_require_lower_case({ init, kind, name }) {
65
+ if (!UPPER_CASE_REGEX.test(name) || is_require_call(init) || has_as_const(init)) {
34
66
  return false;
35
67
  }
36
68
  return kind === 'let' || (kind === 'const' && !is_literal(init));
37
69
  }
38
- function should_require_upper_case({ init, kind, name, }) {
39
- return (kind === 'const' &&
40
- !UPPER_CASE_REGEX.test(name) &&
41
- (is_literal(init) || has_as_const(init)));
70
+ function should_require_upper_case({ init, kind, name }) {
71
+ return (kind === 'const' && !UPPER_CASE_REGEX.test(name) && (is_literal(init) || has_as_const(init)));
42
72
  }
43
73
  const rule = {
44
74
  create(context) {
45
- function report_lower_case(node) {
46
- context.report({
75
+ const source_code = context.sourceCode;
76
+ function build_rename({ declaration, identifier, next_name, }) {
77
+ if (is_exported(declaration))
78
+ return null;
79
+ const variable = source_code
80
+ .getDeclaredVariables(declaration)
81
+ .find(candidate => candidate.name === identifier.name);
82
+ if (!variable)
83
+ return null;
84
+ // Rename every occurrence in the file: the declaration plus all reads.
85
+ // `identifiers` and `references` can share a node, so dedupe by range.
86
+ const seen = new Set();
87
+ const targets = [];
88
+ const candidates = [
89
+ ...variable.identifiers,
90
+ ...variable.references.map(reference => reference.identifier),
91
+ ];
92
+ for (const candidate of candidates) {
93
+ const key = `${candidate.range[0]}:${candidate.range[1]}`;
94
+ if (seen.has(key))
95
+ continue;
96
+ seen.add(key);
97
+ targets.push(candidate);
98
+ }
99
+ if (targets.length === 0)
100
+ return null;
101
+ return fixer => targets.map(target => fixer.replaceText(target, next_name));
102
+ }
103
+ function report_lower_case({ declaration, identifier, }) {
104
+ const next_name = to_lower_case(identifier.name);
105
+ if (!next_name || next_name === identifier.name)
106
+ return;
107
+ const fix = build_rename({ declaration, identifier, next_name });
108
+ const descriptor = {
109
+ data: { name: identifier.name, next: next_name },
47
110
  messageId: 'lowerCase',
48
- node,
49
- });
111
+ node: identifier,
112
+ };
113
+ context.report(fix
114
+ ? { ...descriptor, fix }
115
+ : {
116
+ ...descriptor,
117
+ suggest: [
118
+ {
119
+ data: descriptor.data,
120
+ fix: fixer => fixer.replaceText(identifier, next_name),
121
+ messageId: 'renameTo',
122
+ },
123
+ ],
124
+ });
50
125
  }
51
- function report_upper_case(node) {
52
- context.report({
126
+ function report_upper_case({ declaration, identifier, }) {
127
+ const next_name = to_upper_case(identifier.name);
128
+ if (!next_name || next_name === identifier.name)
129
+ return;
130
+ const fix = build_rename({ declaration, identifier, next_name });
131
+ const descriptor = {
132
+ data: { name: identifier.name, next: next_name },
53
133
  messageId: 'upperCase',
54
- node,
55
- });
134
+ node: identifier,
135
+ };
136
+ context.report(fix
137
+ ? { ...descriptor, fix }
138
+ : {
139
+ ...descriptor,
140
+ suggest: [
141
+ {
142
+ data: descriptor.data,
143
+ fix: fixer => fixer.replaceText(identifier, next_name),
144
+ messageId: 'renameTo',
145
+ },
146
+ ],
147
+ });
56
148
  }
57
149
  function visit_variable_declaration(node) {
58
150
  for (const declaration of node.declarations) {
@@ -66,10 +158,10 @@ const rule = {
66
158
  if (is_special_name(shape.name))
67
159
  continue;
68
160
  if (should_require_upper_case(shape)) {
69
- report_upper_case(declaration.id);
161
+ report_upper_case({ declaration: node, identifier: declaration.id });
70
162
  }
71
163
  if (should_require_lower_case(shape)) {
72
- report_lower_case(declaration.id);
164
+ report_lower_case({ declaration: node, identifier: declaration.id });
73
165
  }
74
166
  }
75
167
  }
@@ -80,10 +172,14 @@ const rule = {
80
172
  meta: {
81
173
  docs: {
82
174
  description: 'Require UPPER_CASE for literal and "as const" declarations, and lower case for mutable or computed bindings',
175
+ url: 'https://github.com/svaldivia12/eslint-plugin-kaezon#kaezonconst-case',
83
176
  },
177
+ fixable: 'code',
178
+ hasSuggestions: true,
84
179
  messages: {
85
- lowerCase: 'const/let should be in lower case.',
86
- upperCase: 'const should be in upper case.',
180
+ lowerCase: 'const/let "{{name}}" should be in lower case, not UPPER_CASE.',
181
+ renameTo: 'Rename to "{{next}}".',
182
+ upperCase: 'const "{{name}}" should be in UPPER_CASE.',
87
183
  },
88
184
  schema: [],
89
185
  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,CAsC1C,CAAA;AAED,eAAe,IAAI,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,12 +8,21 @@ 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. 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;
22
+ if (parent.type === 'MethodDefinition')
23
+ return true;
24
+ if (parent.type === 'PropertyDefinition')
25
+ return true;
17
26
  if (parent.type === 'CallExpression')
18
27
  return true;
19
28
  return false;
@@ -52,6 +61,7 @@ const rule = {
52
61
  meta: {
53
62
  docs: {
54
63
  description: 'Prefer a single object parameter over multiple positional parameters.',
64
+ url: 'https://github.com/svaldivia12/eslint-plugin-kaezon#kaezonprefer-object-params',
55
65
  },
56
66
  messages: {
57
67
  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,CA4BxC,CAAA;AAED,eAAe,IAAI,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;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,CA4CtE,CAAA;AAED,eAAe,IAAI,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 (name === '@typescript-eslint/parser' || name.includes('typescript-eslint'));
32
+ return name === '@typescript-eslint/parser' || name.includes('typescript-eslint');
33
33
  }
34
34
  function is_vue_parser_name(name) {
35
35
  if (!name)
@@ -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,EAAY,MAAM,aAAa,CAAA;AA2DvD,QAAA,MAAM,IAAI,EAAE,UAAU,CAAC,mBAAmB,GAAG,mBAAmB,CAmE/D,CAAA;AAED,eAAe,IAAI,CAAA"}
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;AAsGjE,QAAA,MAAM,IAAI,EAAE,UAAU,CAAC,mBAAmB,GAAG,mBAAmB,CAmE/D,CAAA;AAED,eAAe,IAAI,CAAA"}
@@ -4,26 +4,46 @@
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 extract_define_props_call(node) {
7
+ function is_defines_props(node) {
8
8
  const { callee } = node;
9
- if (callee.type === 'Identifier' && callee.name === 'defineProps') {
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
- if (callee.type === 'Identifier' && callee.name === 'withDefaults') {
13
- const first_arg = node.arguments[0];
14
- if (first_arg?.type === 'CallExpression' &&
15
- first_arg.callee.type === 'Identifier' &&
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')
24
25
  return node.key.name;
25
- if (node.key.type === 'Literal')
26
- return String(node.key.value);
26
+ // A numeric or symbol literal key cannot be camelCase or snake_case, and
27
+ // renaming it would change the prop name the consumer must pass, so skip it.
28
+ if (node.key.type === 'Literal' && typeof node.key.value === 'string') {
29
+ return node.key.value;
30
+ }
31
+ return null;
32
+ }
33
+ /**
34
+ * Renaming an identifier key is safe: the prop name is the identifier itself.
35
+ * A string-literal key has to keep its quotes, otherwise the fix would emit
36
+ * invalid syntax. Computed keys and template literals return null and get no fix.
37
+ */
38
+ function build_rename({ node, next_name, }) {
39
+ const { key } = node;
40
+ if (key.type === 'Identifier') {
41
+ return fixer => fixer.replaceText(key, next_name);
42
+ }
43
+ if (key.type === 'Literal' && typeof key.value === 'string') {
44
+ const quote = key.raw.startsWith('"') ? '"' : "'";
45
+ return fixer => fixer.replaceText(key, `${quote}${next_name}${quote}`);
46
+ }
27
47
  return null;
28
48
  }
29
49
  function get_props_from_type_literal(type_literal) {
@@ -45,47 +65,66 @@ function is_function_type(node) {
45
65
  }
46
66
  return false;
47
67
  }
68
+ function is_wrapped_in_with_defaults(node) {
69
+ const { parent } = node;
70
+ if (parent?.type !== 'CallExpression')
71
+ return false;
72
+ const { callee } = parent;
73
+ return callee.type === 'Identifier' && callee.name === 'withDefaults';
74
+ }
75
+ function has_update_prefix(name) {
76
+ return name.includes(':') || name.startsWith('update:');
77
+ }
78
+ function to_camel_case(name) {
79
+ return name.replaceAll(/_([a-z])/g, (_, char) => char.toUpperCase());
80
+ }
81
+ function to_snake_case(name) {
82
+ return name.replaceAll(/([A-Z])/g, (_, char) => `_${char.toLowerCase()}`);
83
+ }
48
84
  const rule = {
49
85
  create(context) {
86
+ function check_prop(prop) {
87
+ const name = get_prop_name(prop);
88
+ if (!name || has_update_prefix(name))
89
+ return;
90
+ const is_function = is_function_type(prop);
91
+ if (!is_function && !SNAKE_CASE.test(name)) {
92
+ const expected = to_snake_case(name);
93
+ if (!expected)
94
+ return;
95
+ context.report({
96
+ data: { expected, name },
97
+ fix: build_rename({ next_name: expected, node: prop }),
98
+ messageId: 'variableSnakeCase',
99
+ node: prop.key,
100
+ });
101
+ return;
102
+ }
103
+ if (is_function && !CAMEL_CASE.test(name)) {
104
+ const expected = to_camel_case(name);
105
+ if (!expected)
106
+ return;
107
+ context.report({
108
+ data: { expected, name },
109
+ fix: build_rename({ next_name: expected, node: prop }),
110
+ messageId: 'functionCamelCase',
111
+ node: prop.key,
112
+ });
113
+ }
114
+ }
50
115
  function visit_call_expression(node) {
51
116
  const define_props_call = extract_define_props_call(node);
52
117
  if (!define_props_call)
53
118
  return;
54
- if (define_props_call === node &&
55
- node.parent?.type === 'CallExpression' &&
56
- node.parent.callee.type === 'Identifier' &&
57
- node.parent.callee.name === 'withDefaults') {
119
+ // withDefaults(defineProps<...>()) would otherwise report on both calls.
120
+ if (define_props_call === node && is_wrapped_in_with_defaults(node)) {
58
121
  return;
59
122
  }
60
123
  const type_param = define_props_call.typeArguments?.params[0];
61
124
  if (!type_param)
62
125
  return;
63
- const props = get_props_from_type_literal(type_param);
64
- for (const prop of props) {
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
- }
126
+ for (const prop of get_props_from_type_literal(type_param)) {
127
+ check_prop(prop);
89
128
  }
90
129
  }
91
130
  return {
@@ -95,7 +134,9 @@ const rule = {
95
134
  meta: {
96
135
  docs: {
97
136
  description: 'Enforce camelCase for function props and snake_case for other props in defineProps',
137
+ url: 'https://github.com/svaldivia12/eslint-plugin-kaezon#kaezonvue-prop-name-casing-by-type',
98
138
  },
139
+ fixable: 'code',
99
140
  messages: {
100
141
  functionCamelCase: "Function prop '{{name}}' should be camelCase (e.g. {{expected}}).",
101
142
  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.0.0",
3
+ "version": "1.1.1",
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": ">=26"
48
+ "node": "^20.19.0 || ^22.13.0 || >=24"
49
49
  },
50
50
  "publishConfig": {
51
51
  "access": "public",
@@ -67,22 +67,32 @@
67
67
  },
68
68
  "scripts": {
69
69
  "build": "tsc --project tsconfig.json",
70
+ "format": "prettier --write .",
71
+ "format:check": "prettier --check .",
70
72
  "lint": "eslint .",
73
+ "prepare": "husky",
71
74
  "typecheck": "pnpm run build && tsc --project tsconfig.test.json",
72
75
  "test": "node --test tests/**/*.test.ts",
76
+ "test:examples": "node scripts/check_examples.ts",
73
77
  "check:package": "publint && attw --pack . --profile esm-only",
74
- "prepublishOnly": "pnpm run build && pnpm run lint && pnpm run test && pnpm run typecheck"
78
+ "prepublishOnly": "pnpm run format:check && pnpm run build && pnpm run lint && pnpm run test && pnpm run typecheck"
75
79
  },
76
80
  "devDependencies": {
77
81
  "@arethetypeswrong/cli": "^0.18.5",
82
+ "@commitlint/cli": "^21.2.4",
83
+ "@commitlint/config-conventional": "^21.2.4",
78
84
  "@eslint/js": "^10.0.1",
79
85
  "@types/node": "^26.6.6",
80
86
  "@typescript-eslint/eslint-plugin": "^8.72.1",
81
87
  "@typescript-eslint/parser": "^8.72.1",
82
88
  "@typescript-eslint/utils": "^8.72.1",
83
89
  "eslint": "^10.14.0",
90
+ "eslint-config-prettier": "^10.1.8",
84
91
  "eslint-plugin-vue": "^10.12.0",
85
92
  "globals": "^17.13.0",
93
+ "husky": "^9.1.7",
94
+ "lint-staged": "^17.6.0",
95
+ "prettier": "^3.9.10",
86
96
  "publint": "^0.3.25",
87
97
  "typescript": "~6.0.3",
88
98
  "vue-eslint-parser": "^10.4.1"