@caspeco/eslint-config-react 5.2.1 → 5.4.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
@@ -32,6 +32,24 @@ import config from "@caspeco/eslint-config-react";
32
32
  export default [{ ignores: ["dist/**/*", "build/**/*"] }, ...config];
33
33
  ```
34
34
 
35
+ ### React Compiler (opt-in)
36
+
37
+ If your project has adopted the [React Compiler](https://react.dev/learn/react-compiler), use the
38
+ `/compiler` entry point instead. It is a drop-in replacement that enables the full
39
+ `eslint-plugin-react-hooks` recommended ruleset, including the React Compiler rules
40
+ (`react-hooks/purity`, `react-hooks/static-components`, `react-hooks/use-memo`,
41
+ `react-hooks/immutability`, `react-hooks/set-state-in-render`, and more):
42
+
43
+ ```js
44
+ import config from "@caspeco/eslint-config-react/compiler";
45
+
46
+ export default [{ ignores: ["dist/**/*", "build/**/*"] }, ...config];
47
+ ```
48
+
49
+ The default config (`@caspeco/eslint-config-react`) intentionally enables only
50
+ `react-hooks/rules-of-hooks` and `react-hooks/exhaustive-deps`, so teams that have not
51
+ yet adopted the React Compiler are not flooded with compiler-specific warnings.
52
+
35
53
  ## What's Included
36
54
 
37
55
  This configuration includes everything from our TypeScript config plus React-specific rules:
@@ -0,0 +1,4 @@
1
+ export default flatConfig;
2
+ /** @type {import('typescript-eslint').ConfigArray} */
3
+ declare const flatConfig: import("typescript-eslint").ConfigArray;
4
+ //# sourceMappingURL=compiler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../src/compiler.js"],"names":[],"mappings":";AAGA,sDAAsD;AACtD,0BADW,OAAO,mBAAmB,EAAE,WAAW,CAK/C"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Builds the Caspeco React flat config. The only part that varies between the
3
+ * default and the React Compiler opt-in config is the set of `react-hooks` rules.
4
+ *
5
+ * @param {object} options
6
+ * @param {import('eslint').Linter.RulesRecord} options.reactHooksRules
7
+ * @returns {import('typescript-eslint').ConfigArray}
8
+ */
9
+ export function createConfig({ reactHooksRules }: {
10
+ reactHooksRules: import("eslint").Linter.RulesRecord;
11
+ }): import("typescript-eslint").ConfigArray;
12
+ //# sourceMappingURL=create-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-config.d.ts","sourceRoot":"","sources":["../src/create-config.js"],"names":[],"mappings":"AAOA;;;;;;;GAOG;AACH,kDAHG;IAAqD,eAAe,EAA5D,OAAO,QAAQ,EAAE,MAAM,CAAC,WAAW;CAC3C,GAAU,OAAO,mBAAmB,EAAE,WAAW,CA4DnD"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";AAOA,sDAAsD;AACtD,0BADW,OAAO,mBAAmB,EAAE,WAAW,CAgEhD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";AAEA,sDAAsD;AACtD,0BADW,OAAO,mBAAmB,EAAE,WAAW,CAM/C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caspeco/eslint-config-react",
3
- "version": "5.2.1",
3
+ "version": "5.4.0",
4
4
  "description": "Caspeco ESLint configuration for React projects",
5
5
  "keywords": [
6
6
  "eslint",
@@ -20,6 +20,17 @@
20
20
  },
21
21
  "license": "MIT",
22
22
  "type": "module",
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/index.d.ts",
26
+ "default": "./src/index.js"
27
+ },
28
+ "./compiler": {
29
+ "types": "./dist/compiler.d.ts",
30
+ "default": "./src/compiler.js"
31
+ },
32
+ "./package.json": "./package.json"
33
+ },
23
34
  "main": "src/index.js",
24
35
  "types": "dist/index.d.ts",
25
36
  "bin": {
@@ -32,12 +43,12 @@
32
43
  ],
33
44
  "scripts": {
34
45
  "build": "tsc --project tsconfig.build.json",
35
- "check:types": "attw --pack . --ignore-rules=cjs-resolves-to-esm",
46
+ "check:types": "attw --pack . --ignore-rules=cjs-resolves-to-esm --profile node16",
36
47
  "prepublishOnly": "npm run build",
37
48
  "test": "vitest"
38
49
  },
39
50
  "dependencies": {
40
- "@caspeco/eslint-config-ts": "5.2.1"
51
+ "@caspeco/eslint-config-ts": "5.4.0"
41
52
  },
42
53
  "devDependencies": {
43
54
  "@caspeco/test-utils": "*",
@@ -0,0 +1,11 @@
1
+ import reactHooksPlugin from "eslint-plugin-react-hooks";
2
+ import { createConfig } from "./create-config.js";
3
+
4
+ /** @type {import('typescript-eslint').ConfigArray} */
5
+ const flatConfig = createConfig({
6
+ reactHooksRules: {
7
+ ...reactHooksPlugin.configs.recommended.rules,
8
+ },
9
+ });
10
+
11
+ export default flatConfig;
@@ -0,0 +1,74 @@
1
+ import tsConfig from "@caspeco/eslint-config-ts";
2
+ import reactRefresh from "eslint-plugin-react-refresh";
3
+ import reactPlugin from "eslint-plugin-react";
4
+ import reactHooksPlugin from "eslint-plugin-react-hooks";
5
+ import caspecoReactPlugin from "./plugins/caspeco-react.js";
6
+ import globals from "globals";
7
+
8
+ /**
9
+ * Builds the Caspeco React flat config. The only part that varies between the
10
+ * default and the React Compiler opt-in config is the set of `react-hooks` rules.
11
+ *
12
+ * @param {object} options
13
+ * @param {import('eslint').Linter.RulesRecord} options.reactHooksRules
14
+ * @returns {import('typescript-eslint').ConfigArray}
15
+ */
16
+ export function createConfig({ reactHooksRules }) {
17
+ return [
18
+ // Extend the vanilla TypeScript config
19
+ ...tsConfig,
20
+ // React plugin recommended config
21
+ {
22
+ ...reactPlugin.configs.flat?.recommended,
23
+ files: ["**/*.ts", "**/*.tsx", "**/*.jsx"],
24
+ settings: {
25
+ react: {
26
+ version: "detect",
27
+ },
28
+ },
29
+ languageOptions: {
30
+ ...reactPlugin.configs.flat?.recommended.languageOptions,
31
+ globals: {
32
+ ...globals.serviceworker,
33
+ ...globals.browser,
34
+ },
35
+ parserOptions: {
36
+ ...reactPlugin.configs.flat?.recommended.languageOptions?.parserOptions,
37
+ ecmaVersion: "latest",
38
+ },
39
+ },
40
+ rules: {
41
+ ...reactPlugin.configs.flat?.recommended.rules,
42
+ "react/react-in-jsx-scope": "off",
43
+ "react/prop-types": "off",
44
+ "react/display-name": "off",
45
+ },
46
+ },
47
+ // React hooks plugin config
48
+ {
49
+ ...reactHooksPlugin.configs.recommended,
50
+ plugins: { "react-hooks": reactHooksPlugin },
51
+ files: ["**/*.ts", "**/*.tsx", "**/*.jsx"],
52
+ rules: reactHooksRules,
53
+ },
54
+ // React refresh plugin config
55
+ {
56
+ ...reactRefresh.configs.recommended,
57
+ files: ["**/*.ts", "**/*.tsx", "**/*.jsx"],
58
+ rules: {
59
+ ...reactRefresh.configs.recommended.rules,
60
+ "react-refresh/only-export-components": ["warn", { allowConstantExport: true }],
61
+ },
62
+ },
63
+ // Caspeco React custom rules
64
+ {
65
+ files: ["**/*.ts", "**/*.tsx", "**/*.jsx"],
66
+ plugins: {
67
+ "caspeco-react": caspecoReactPlugin,
68
+ },
69
+ rules: {
70
+ "caspeco-react/discourage-chakra-import": "error",
71
+ },
72
+ },
73
+ ];
74
+ }
package/src/index.js CHANGED
@@ -1,74 +1,11 @@
1
- import tsConfig from "@caspeco/eslint-config-ts";
2
- import reactRefresh from "eslint-plugin-react-refresh";
3
- import reactPlugin from "eslint-plugin-react";
4
- import reactHooksPlugin from "eslint-plugin-react-hooks";
5
- import caspecoReactPlugin from "./plugins/caspeco-react.js";
6
- import globals from "globals";
1
+ import { createConfig } from "./create-config.js";
7
2
 
8
3
  /** @type {import('typescript-eslint').ConfigArray} */
9
- const flatConfig = [
10
- // Extend the vanilla TypeScript config
11
- ...tsConfig,
12
- // React plugin recommended config
13
- {
14
- ...reactPlugin.configs.flat?.recommended,
15
- files: ["**/*.ts", "**/*.tsx", "**/*.jsx"],
16
- settings: {
17
- react: {
18
- version: "detect",
19
- },
20
- },
21
- languageOptions: {
22
- ...reactPlugin.configs.flat?.recommended.languageOptions,
23
- globals: {
24
- ...globals.serviceworker,
25
- ...globals.browser,
26
- },
27
- parserOptions: {
28
- ...reactPlugin.configs.flat?.recommended.languageOptions?.parserOptions,
29
- ecmaVersion: "latest",
30
- },
31
- },
32
- rules: {
33
- ...reactPlugin.configs.flat?.recommended.rules,
34
- "react/react-in-jsx-scope": "off",
35
- "react/prop-types": "off",
36
- "react/display-name": "off",
37
- },
4
+ const flatConfig = createConfig({
5
+ reactHooksRules: {
6
+ "react-hooks/rules-of-hooks": "error",
7
+ "react-hooks/exhaustive-deps": "warn",
38
8
  },
39
- // React hooks plugin recommended config
40
- {
41
- ...reactHooksPlugin.configs.recommended,
42
- plugins: { "react-hooks": reactHooksPlugin },
43
- files: ["**/*.ts", "**/*.tsx", "**/*.jsx"],
44
- rules: {
45
- "react-hooks/rules-of-hooks": "error",
46
- "react-hooks/exhaustive-deps": "warn",
47
- // We ignore the compiler specific rules as we need React 19 for this.
48
- // https://github.com/facebook/react/tree/main/packages/eslint-plugin-react-hooks#flat-config-eslintconfigjsts-1
49
- // When we support this, we can add:
50
- // ...reactHooksPlugin.configs.recommended.rules,
51
- },
52
- },
53
- // React refresh plugin config
54
- {
55
- ...reactRefresh.configs.recommended,
56
- files: ["**/*.ts", "**/*.tsx", "**/*.jsx"],
57
- rules: {
58
- ...reactRefresh.configs.recommended.rules,
59
- "react-refresh/only-export-components": ["warn", { allowConstantExport: true }],
60
- },
61
- },
62
- // Caspeco React custom rules
63
- {
64
- files: ["**/*.ts", "**/*.tsx", "**/*.jsx"],
65
- plugins: {
66
- "caspeco-react": caspecoReactPlugin,
67
- },
68
- rules: {
69
- "caspeco-react/discourage-chakra-import": "error",
70
- },
71
- },
72
- ];
9
+ });
73
10
 
74
11
  export default flatConfig;