@eslint-react/kit 4.2.0-beta.2 → 4.2.0-beta.3
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 +58 -1
- package/dist/index.js +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -24,8 +24,8 @@ ESLint React's toolkit for building custom React rules with JavasSript functions
|
|
|
24
24
|
- [Component: Destructure component props](#component-destructure-component-props)
|
|
25
25
|
- [Hooks: Warn on custom hooks that don't call other hooks](#hooks-warn-on-custom-hooks-that-dont-call-other-hooks)
|
|
26
26
|
- [Multiple Collectors: No component/hook factories](#multiple-collectors-no-componenthook-factories)
|
|
27
|
+
- [Override Config: Using spread syntax with `getConfig`](#Override-config-using-spread-syntax-with-getconfig)
|
|
27
28
|
- [Advanced Config: Using `getPlugin` for custom plugin namespace](#advanced-config-using-getplugin-for-custom-plugin-namespace)
|
|
28
|
-
- [More Examples](#more-examples)
|
|
29
29
|
|
|
30
30
|
## Installation
|
|
31
31
|
|
|
@@ -544,6 +544,63 @@ eslintReactKit()
|
|
|
544
544
|
.getConfig();
|
|
545
545
|
```
|
|
546
546
|
|
|
547
|
+
### Override Config: Using spread syntax with `getConfig`
|
|
548
|
+
|
|
549
|
+
`getConfig()` returns a plain config object. You can spread it into a new object to override or supplement its properties — for example, to scope the config to specific files or add extra settings alongside your kit rules.
|
|
550
|
+
|
|
551
|
+
```ts
|
|
552
|
+
import eslintReactKit from "@eslint-react/kit";
|
|
553
|
+
import type { RuleDefinition } from "@eslint-react/kit";
|
|
554
|
+
|
|
555
|
+
function functionComponentDefinition(): RuleDefinition {
|
|
556
|
+
return (context, { collect }) => {
|
|
557
|
+
const { query, visitor } = collect.components(context);
|
|
558
|
+
return {
|
|
559
|
+
...visitor,
|
|
560
|
+
"Program:exit"(program) {
|
|
561
|
+
for (const { name, node } of query.all(program)) {
|
|
562
|
+
if (node.type !== "FunctionDeclaration") {
|
|
563
|
+
context.report({
|
|
564
|
+
node,
|
|
565
|
+
message: `Component "${name ?? "(anonymous)"}" must be a function declaration.`,
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
},
|
|
570
|
+
};
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
function version(major = "19"): RuleDefinition {
|
|
575
|
+
return (context, { settings }) => ({
|
|
576
|
+
Program(program) {
|
|
577
|
+
if (!settings.version.startsWith(`${major}.`)) {
|
|
578
|
+
context.report({
|
|
579
|
+
node: program,
|
|
580
|
+
message: `This project requires React ${major}, but detected version ${settings.version}.`,
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
},
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
// Spread the config into a new object to add or override properties like `files`:
|
|
588
|
+
export default [
|
|
589
|
+
{
|
|
590
|
+
...eslintReactKit()
|
|
591
|
+
.use(functionComponentDefinition)
|
|
592
|
+
.use(version, "19")
|
|
593
|
+
.getConfig(),
|
|
594
|
+
// Override `name` so it shows your own label in config inspector tools
|
|
595
|
+
name: "my-app/kit-rules",
|
|
596
|
+
// Override `files` to scope the kit rules to specific source files
|
|
597
|
+
files: ["src/**/*.ts", "src/**/*.tsx"],
|
|
598
|
+
},
|
|
599
|
+
];
|
|
600
|
+
```
|
|
601
|
+
|
|
602
|
+
This pattern is especially useful when composing kit configs alongside other ESLint configs (e.g. `typescript-eslint`, `eslint-plugin-react-hooks`) via `defineConfig` — you can nest the spread object inside `extends` arrays and attach shared properties like `files` or `languageOptions` at the same level.
|
|
603
|
+
|
|
547
604
|
### Advanced Config: Using `getPlugin` for custom plugin namespace
|
|
548
605
|
|
|
549
606
|
Use `getPlugin()` when you want full control over the plugin namespace and rule severities instead of the all-in-one `getConfig()`.
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/kit",
|
|
3
|
-
"version": "4.2.0-beta.
|
|
3
|
+
"version": "4.2.0-beta.3",
|
|
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.0-beta.
|
|
42
|
-
"@eslint-react/core": "4.2.0-beta.
|
|
43
|
-
"@eslint-react/shared": "4.2.0-beta.
|
|
41
|
+
"@eslint-react/ast": "4.2.0-beta.3",
|
|
42
|
+
"@eslint-react/core": "4.2.0-beta.3",
|
|
43
|
+
"@eslint-react/shared": "4.2.0-beta.3"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"eslint": "^10.1.0",
|