@eslint-react/kit 4.2.1 → 4.2.3-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -8,7 +8,7 @@ ESLint React's toolkit for building custom React rules with JavasSript functions
8
8
  - [Quick Start](#quick-start)
9
9
  - [API Reference](#api-reference)
10
10
  - [`eslintReactKit` (default export)](#eslintreactkit-default-export)
11
- - [`RuleDefinition`](#ruledefinition)
11
+ - [`RuleFunction`](#rulefunction)
12
12
  - [`Builder`](#builder)
13
13
  - [`getConfig`](#getconfig)
14
14
  - [`getPlugin`](#getplugin)
@@ -26,11 +26,12 @@ ESLint React's toolkit for building custom React rules with JavasSript functions
26
26
  - [Multiple Collectors: No component/hook factories](#multiple-collectors-no-componenthook-factories)
27
27
  - [Override Config: Using spread syntax with `getConfig`](#Override-config-using-spread-syntax-with-getconfig)
28
28
  - [Advanced Config: Using `getPlugin` for custom plugin namespace](#advanced-config-using-getplugin-for-custom-plugin-namespace)
29
+ - [More Examples](#more-examples)
29
30
 
30
31
  ## Installation
31
32
 
32
33
  ```sh
33
- npm install --save-dev @eslint-react/kit@rc
34
+ npm install --save-dev @eslint-react/kit
34
35
  ```
35
36
 
36
37
  ## Quick Start
@@ -38,13 +39,13 @@ npm install --save-dev @eslint-react/kit@rc
38
39
  ```ts
39
40
  import eslintReact from "@eslint-react/eslint-plugin";
40
41
  import eslintReactKit, { merge } from "@eslint-react/kit";
41
- import type { RuleDefinition } from "@eslint-react/kit";
42
+ import type { RuleFunction } from "@eslint-react/kit";
42
43
  import eslintJs from "@eslint/js";
43
44
  import { defineConfig } from "eslint/config";
44
45
  import tseslint from "typescript-eslint";
45
46
 
46
47
  /** Enforce function declarations for function components. */
47
- function functionComponentDefinition(): RuleDefinition {
48
+ function functionComponentDefinition(): RuleFunction {
48
49
  return (context, { collect }) => {
49
50
  const { query, visitor } = collect.components(context);
50
51
  return merge(
@@ -93,27 +94,27 @@ eslintReactKit(): Builder
93
94
 
94
95
  Creates a `Builder` instance for registering custom rules via the chainable `.use()` API.
95
96
 
96
- ### `RuleDefinition`
97
+ ### `RuleFunction`
97
98
 
98
99
  ```ts
99
- import type { RuleDefinition } from "@eslint-react/kit";
100
+ import type { RuleFunction } from "@eslint-react/kit";
100
101
 
101
- type RuleDefinition = (ctx: RuleContext, kit: RuleToolkit) => RuleListener;
102
+ type RuleFunction = (ctx: RuleContext, kit: RuleToolkit) => RuleListener;
102
103
  ```
103
104
 
104
105
  A rule definition is a function that receives the ESLint rule context and the structured `Kit` toolkit, and returns a `RuleListener` (AST visitor object).
105
106
 
106
- Rules are defined as **named functions** that return a `RuleDefinition`. The function name is automatically converted to kebab-case and used as the rule name under the `@eslint-react/kit` plugin namespace.
107
+ Rules are defined as **named functions** that return a `RuleFunction`. The function name is automatically converted to kebab-case and used as the rule name under the `@eslint-react/kit` plugin namespace.
107
108
 
108
109
  ```ts
109
110
  // Function name `noForwardRef` → rule name `no-forward-ref`
110
111
  // Registered as `@eslint-react/kit/no-forward-ref`
111
- function noForwardRef(): RuleDefinition {
112
+ function noForwardRef(): RuleFunction {
112
113
  return (context, { is }) => ({ ... });
113
114
  }
114
115
 
115
116
  // Functions that accept options work the same way
116
- function forbidElements({ forbidden }: ForbidElementsOptions): RuleDefinition {
117
+ function forbidElements({ forbidden }: ForbidElementsOptions): RuleFunction {
117
118
  return (context) => ({ ... });
118
119
  }
119
120
  ```
@@ -122,7 +123,7 @@ function forbidElements({ forbidden }: ForbidElementsOptions): RuleDefinition {
122
123
 
123
124
  ```ts
124
125
  interface Builder {
125
- use<F extends (...args: any[]) => RuleDefinition>(factory: F, ...args: Parameters<F>): Builder;
126
+ use<F extends (...args: any[]) => RuleFunction>(factory: F, ...args: Parameters<F>): Builder;
126
127
  getConfig(): Linter.Config;
127
128
  getPlugin(): ESLint.Plugin;
128
129
  }
@@ -188,7 +189,7 @@ This is essential for combining a collector's `visitor` with your own inspection
188
189
 
189
190
  ### Kit — the toolkit object
190
191
 
191
- The second argument passed to the `RuleDefinition` function is a structured `Kit` object:
192
+ The second argument passed to the `RuleFunction` function is a structured `Kit` object:
192
193
 
193
194
  ```
194
195
  kit
@@ -375,9 +376,9 @@ Exposes the normalized `react-x` settings from the ESLint shared configuration (
375
376
  **Usage:**
376
377
 
377
378
  ```ts
378
- import type { RuleDefinition } from "@eslint-react/kit";
379
+ import type { RuleFunction } from "@eslint-react/kit";
379
380
 
380
- function version(major = "19"): RuleDefinition {
381
+ function version(major = "19"): RuleFunction {
381
382
  return (context, { settings }) => ({
382
383
  Program(program) {
383
384
  if (!settings.version.startsWith(`${major}.`)) {
@@ -400,9 +401,9 @@ function version(major = "19"): RuleDefinition {
400
401
  This is a simplified kit reimplementation of the built-in [`react-x/no-forwardRef`](https://beta.eslint-react.xyz/docs/rules/no-forward-ref) rule.
401
402
 
402
403
  ```ts
403
- import type { RuleDefinition } from "@eslint-react/kit";
404
+ import type { RuleFunction } from "@eslint-react/kit";
404
405
 
405
- function noForwardRef(): RuleDefinition {
406
+ function noForwardRef(): RuleFunction {
406
407
  return (context, { is }) => ({
407
408
  CallExpression(node) {
408
409
  if (is.forwardRefCall(node)) {
@@ -423,10 +424,10 @@ eslintReactKit()
423
424
  This is a simplified kit reimplementation of the built-in [`react-x/prefer-destructuring-assignment`](https://beta.eslint-react.xyz/docs/rules/prefer-destructuring-assignment) rule.
424
425
 
425
426
  ```ts
426
- import type { RuleDefinition } from "@eslint-react/kit";
427
+ import type { RuleFunction } from "@eslint-react/kit";
427
428
  import { merge } from "@eslint-react/kit";
428
429
 
429
- function destructureComponentProps(): RuleDefinition {
430
+ function destructureComponentProps(): RuleFunction {
430
431
  return (context, { collect }) => {
431
432
  const { query, visitor } = collect.components(context);
432
433
 
@@ -464,10 +465,10 @@ eslintReactKit()
464
465
  This is a simplified kit reimplementation of the built-in [`react-x/no-unnecessary-use-prefix`](https://beta.eslint-react.xyz/docs/rules/no-unnecessary-use-prefix) rule.
465
466
 
466
467
  ```ts
467
- import type { RuleDefinition } from "@eslint-react/kit";
468
+ import type { RuleFunction } from "@eslint-react/kit";
468
469
  import { merge } from "@eslint-react/kit";
469
470
 
470
- function noUnnecessaryUsePrefix(): RuleDefinition {
471
+ function noUnnecessaryUsePrefix(): RuleFunction {
471
472
  return (context, { collect }) => {
472
473
  const { query, visitor } = collect.hooks(context);
473
474
 
@@ -498,22 +499,21 @@ Disallow defining components or hooks inside other functions (factory pattern).
498
499
  This is a simplified kit reimplementation of the built-in [`react-x/component-hook-factories`](https://beta.eslint-react.xyz/docs/rules/component-hook-factories) rule.
499
500
 
500
501
  ```ts
501
- import type { RuleDefinition } from "@eslint-react/kit";
502
+ import type { RuleFunction } from "@eslint-react/kit";
502
503
  import { merge } from "@eslint-react/kit";
503
504
  import type { TSESTree } from "@typescript-eslint/utils";
504
505
 
505
- function findParent({ parent }: TSESTree.Node, test: (n: TSESTree.Node) => boolean): TSESTree.Node | null {
506
- if (parent == null) return null;
507
- if (test(parent)) return parent;
508
- if (parent.type === "Program") return null;
509
- return findParent(parent, test);
510
- }
511
-
512
- function isFunction({ type }: TSESTree.Node) {
513
- return type === "FunctionDeclaration" || type === "FunctionExpression" || type === "ArrowFunctionExpression";
514
- }
506
+ function componentHookFactories(): RuleFunction {
507
+ function findParent({ parent }: TSESTree.Node, test: (n: TSESTree.Node) => boolean): TSESTree.Node | null {
508
+ if (parent == null) return null;
509
+ if (test(parent)) return parent;
510
+ if (parent.type === "Program") return null;
511
+ return findParent(parent, test);
512
+ }
515
513
 
516
- function componentHookFactories(): RuleDefinition {
514
+ function isFunction({ type }: TSESTree.Node) {
515
+ return type === "FunctionDeclaration" || type === "FunctionExpression" || type === "ArrowFunctionExpression";
516
+ }
517
517
  return (context, { collect }) => {
518
518
  const fc = collect.components(context);
519
519
  const hk = collect.hooks(context);
@@ -550,7 +550,7 @@ eslintReactKit()
550
550
 
551
551
  ```ts
552
552
  import eslintReactKit from "@eslint-react/kit";
553
- import type { RuleDefinition } from "@eslint-react/kit";
553
+ import type { RuleFunction } from "@eslint-react/kit";
554
554
 
555
555
  // Spread the config into a new object to add or override properties like `files`:
556
556
  export default [
@@ -575,7 +575,7 @@ Use `getPlugin()` when you want full control over the plugin namespace and rule
575
575
 
576
576
  ```ts
577
577
  import eslintReactKit from "@eslint-react/kit";
578
- import type { RuleDefinition } from "@eslint-react/kit";
578
+ import type { RuleFunction } from "@eslint-react/kit";
579
579
 
580
580
  const kit = eslintReactKit()
581
581
  .use(noForwardRef);
@@ -600,6 +600,6 @@ export default [
600
600
  ];
601
601
  ```
602
602
 
603
- <!--## More Examples
603
+ ## More Examples
604
604
 
605
- Please check the [Rule Recipes](https://beta.eslint-react.xyz/docs/configuration/configure-custom-rules#rule-recipes) in the documentation site.-->
605
+ Please check the [Rule Recipes](https://www.eslint-react.xyz/docs/recipes/overview) in the documentation site.
package/dist/index.d.ts CHANGED
@@ -99,11 +99,15 @@ interface RuleToolkit {
99
99
  };
100
100
  settings: ESLintReactSettingsNormalized;
101
101
  }
102
- type RuleDefinition = (context: RuleContext, toolkit: RuleToolkit) => RuleListener;
102
+ type RuleFunction = (context: RuleContext, toolkit: RuleToolkit) => RuleListener;
103
+ /**
104
+ * @deprecated Use `RuleFunction` instead.
105
+ */
106
+ type RuleDefinition = RuleFunction;
103
107
  interface Builder {
104
108
  getConfig(): Linter.Config;
105
109
  getPlugin(): ESLint.Plugin;
106
- use<F extends (...args: any[]) => RuleDefinition>(factory: F, ...args: Parameters<F>): Builder;
110
+ use<F extends (...args: any[]) => RuleFunction>(factory: F, ...args: Parameters<F>): Builder;
107
111
  }
108
112
  declare function build(): Builder;
109
113
  declare module "@typescript-eslint/utils/ts-eslint" {
@@ -123,4 +127,4 @@ declare module "@typescript-eslint/utils/ts-eslint" {
123
127
  }
124
128
  }
125
129
  //#endregion
126
- export { Builder, Collector, CollectorWithContext, RuleDefinition, type RuleFix, type RuleFixer, type RuleListener, build as default, merge };
130
+ export { Builder, Collector, CollectorWithContext, RuleDefinition, type RuleFix, type RuleFixer, RuleFunction, type RuleListener, build as default, merge };
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import { kebabCase } from "string-ts";
4
4
 
5
5
  //#region package.json
6
6
  var name = "@eslint-react/kit";
7
- var version = "4.2.1";
7
+ var version = "4.2.3-beta.0";
8
8
 
9
9
  //#endregion
10
10
  //#region src/index.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/kit",
3
- "version": "4.2.1",
3
+ "version": "4.2.3-beta.0",
4
4
  "description": "ESLint React's utility module for building custom React rules with JavasSript functions.",
5
5
  "keywords": [
6
6
  "react",
@@ -38,9 +38,9 @@
38
38
  "dependencies": {
39
39
  "@typescript-eslint/utils": "^8.58.0",
40
40
  "string-ts": "^2.3.1",
41
- "@eslint-react/ast": "4.2.1",
42
- "@eslint-react/core": "4.2.1",
43
- "@eslint-react/shared": "4.2.1"
41
+ "@eslint-react/core": "4.2.3-beta.0",
42
+ "@eslint-react/ast": "4.2.3-beta.0",
43
+ "@eslint-react/shared": "4.2.3-beta.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "eslint": "^10.1.0",