@open-turo/eslint-config-react 15.0.0-pr-320.2.1.1 → 15.0.0-pr-320.3.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/README.md CHANGED
@@ -20,28 +20,24 @@ Install the package and all of its peer dependencies:
20
20
  npx install-peerdeps --dev @open-turo/eslint-config-react
21
21
  ```
22
22
 
23
- Then in your `.eslintrc` file, extend from the default configuration of this package, which is the recommended eslint
24
- configuration for our existing front-end projects.
23
+ ### [`eslint.config.js`](https://eslint.org/docs/latest/use/configure/configuration-files-new) (requires eslint>=v8.23.0)
25
24
 
26
- To use this config, just add to your `.eslintrc` the following:
25
+ ```js
26
+ const turoConfig = require("@open-turo/eslint-config-react");
27
27
 
28
+ module.exports = turoConfig();
28
29
  ```
29
- "extends": "@open-turo/eslint-config-typescript"
30
- ```
31
-
32
- ### Legacy preset
33
30
 
34
- There is a `legacy` preset that extends `@open-turo/eslint-config-typescript/legacy`. This only exists for backwards
35
- compatibility with existing projects. It is strongly recommended to use the standard preset.
31
+ ### **[.eslintrc](https://eslint.org/docs/latest/use/configure/configuration-files)** (legacy example)
36
32
 
37
- To use the `legacy` preset, update your `.eslintrc` file to be:
38
-
39
- ```json
33
+ ```jsonc
40
34
  {
41
- "extends": "@open-turo/eslint-config-react/legacy"
35
+ "extends": "@open-turo/eslint-config-react/recommended",
42
36
  }
43
37
  ```
44
38
 
39
+ You will have to set the `ESLINT_USE_FLAT_CONFIG` env var to true.
40
+
45
41
  ## Development
46
42
 
47
43
  ### Pre-commit
@@ -45,10 +45,5 @@ Will become a `eslint.config.js` file like this:
45
45
  ```js
46
46
  const turoConfig = require("@open-turo/eslint-config-react");
47
47
 
48
- module.exports = [
49
- ...turoConfig,
50
- {
51
- ignores: ["/lib"],
52
- },
53
- ];
48
+ module.exports = turoConfig({ turo: { ignores: ["/lib"] } });
54
49
  ```
package/index.cjs CHANGED
@@ -7,98 +7,106 @@ const globals = require("globals");
7
7
  // TODO We can't do this because this function is not here directly technically
8
8
  const tseslint = require("typescript-eslint");
9
9
 
10
- module.exports = tseslint.config(
11
- {
12
- extends: turoConfig({
13
- allowModules: [
14
- "@jest/globals",
15
- "@testing-library/dom",
16
- "@testing-library/react",
17
- "@testing-library/user-event",
18
- "nock",
19
- ],
20
- }),
21
- rules: {
22
- /*
23
- * Rules that significantly impact performance time of eslint, and are not
24
- * necessarily relevant for react applications.
25
- */
26
- "sonarjs/aws-apigateway-public-api": "off",
27
- "sonarjs/aws-ec2-rds-dms-public": "off",
28
- "sonarjs/aws-iam-all-privileges": "off",
29
- "sonarjs/aws-iam-privilege-escalation": "off",
30
- "sonarjs/aws-iam-public-access": "off",
31
- "sonarjs/aws-restricted-ip-admin-access": "off",
32
- "sonarjs/jsx-no-useless-fragment": "off",
33
- // Already covered with react/no-array-index-key
34
- "sonarjs/no-array-index-key": "off",
35
- // Already covered with react/no-unknown-property
36
- "sonarjs/no-unknown-property": "off",
37
- "sonarjs/no-unstable-nested-components": "off",
38
- // Allow file names to match a component name
39
- "unicorn/filename-case": "off",
40
- },
41
- },
42
- {
43
- extends: [
44
- reactPlugin.configs.flat.recommended,
45
- reactPlugin.configs.flat["jsx-runtime"],
46
- jsxA11yPlugin.flatConfigs.recommended,
47
- reactCompilerPlugin.configs.recommended,
48
- ],
49
- files: ["**/*.{jsx,tsx,mjsx,cjsx}"],
50
- languageOptions: {
51
- globals: {
52
- ...globals.browser,
10
+ /**
11
+ *
12
+ * @param {object} options ESLint configuration options
13
+ * @param {object} options.turo ESLing configuration options for open-turo/eslint-config-typescript. See their documentation for available options.
14
+ * @returns Configuration Array
15
+ */
16
+ module.exports = (options = {}) =>
17
+ tseslint.config(
18
+ {
19
+ extends: turoConfig({
20
+ ...options.turo,
21
+ allowModules: [
22
+ "@jest/globals",
23
+ "@testing-library/dom",
24
+ "@testing-library/react",
25
+ "@testing-library/user-event",
26
+ "nock",
27
+ ].concat(options.turo?.allowModules ?? []),
28
+ }),
29
+ rules: {
30
+ /*
31
+ * Rules that significantly impact performance time of eslint, and are not
32
+ * necessarily relevant for react applications.
33
+ */
34
+ "sonarjs/aws-apigateway-public-api": "off",
35
+ "sonarjs/aws-ec2-rds-dms-public": "off",
36
+ "sonarjs/aws-iam-all-privileges": "off",
37
+ "sonarjs/aws-iam-privilege-escalation": "off",
38
+ "sonarjs/aws-iam-public-access": "off",
39
+ "sonarjs/aws-restricted-ip-admin-access": "off",
40
+ "sonarjs/jsx-no-useless-fragment": "off",
41
+ // Already covered with react/no-array-index-key
42
+ "sonarjs/no-array-index-key": "off",
43
+ // Already covered with react/no-unknown-property
44
+ "sonarjs/no-unknown-property": "off",
45
+ "sonarjs/no-unstable-nested-components": "off",
46
+ // Allow file names to match a component name
47
+ "unicorn/filename-case": "off",
53
48
  },
54
49
  },
55
- plugins: {
56
- "react-hooks": reactHooksPlugin,
57
- },
58
- rules: {
59
- ...reactHooksPlugin.configs.recommended.rules,
60
- "jsx-a11y/anchor-is-valid": [
61
- "warn",
62
- {
63
- specialLink: ["to"],
64
- },
50
+ {
51
+ extends: [
52
+ reactPlugin.configs.flat.recommended,
53
+ reactPlugin.configs.flat["jsx-runtime"],
54
+ jsxA11yPlugin.flatConfigs.recommended,
55
+ reactCompilerPlugin.configs.recommended,
65
56
  ],
66
- /** ESLint plugin for the React Compiler, to enforce rules that make adopting it easier/more effective */
67
- "react-compiler/react-compiler": [
68
- "error",
69
- {
70
- environment: {
71
- /**
72
- * At the time of writing, `eslint-plugin-react-compiler` errors on ref usages in render paths. This rule is noisy,
73
- * since it currently reports false positives. We can remove this in the future when the rule is more accurate.
74
- * {@link https://github.com/facebook/react/pull/30843 PR that disables this rule in the default config}
75
- */
76
- validateRefAccessDuringRender: false,
57
+ files: ["**/*.{jsx,tsx,mjsx,cjsx}"],
58
+ languageOptions: {
59
+ globals: {
60
+ ...globals.browser,
61
+ },
62
+ },
63
+ plugins: {
64
+ "react-hooks": reactHooksPlugin,
65
+ },
66
+ rules: {
67
+ ...reactHooksPlugin.configs.recommended.rules,
68
+ "jsx-a11y/anchor-is-valid": [
69
+ "warn",
70
+ {
71
+ specialLink: ["to"],
72
+ },
73
+ ],
74
+ /** ESLint plugin for the React Compiler, to enforce rules that make adopting it easier/more effective */
75
+ "react-compiler/react-compiler": [
76
+ "error",
77
+ {
78
+ environment: {
79
+ /**
80
+ * At the time of writing, `eslint-plugin-react-compiler` errors on ref usages in render paths. This rule is noisy,
81
+ * since it currently reports false positives. We can remove this in the future when the rule is more accurate.
82
+ * {@link https://github.com/facebook/react/pull/30843 PR that disables this rule in the default config}
83
+ */
84
+ validateRefAccessDuringRender: false,
85
+ },
77
86
  },
87
+ ],
88
+ // don't force .jsx extension
89
+ "react/jsx-filename-extension": "off",
90
+ // In TS you must use the Fragment syntax instead of the shorthand
91
+ "react/jsx-fragments": "off",
92
+ // This allows props to be spread in JSX
93
+ "react/jsx-props-no-spreading": "off",
94
+ // ensure props are alphabetical
95
+ "react/jsx-sort-props": "error",
96
+ // Allow emotion css prop
97
+ "react/no-unknown-property": ["error", { ignore: ["css"] }],
98
+ // We don't need default props on TS components
99
+ "react/require-default-props": "off",
100
+ "react/sort-prop-types": "error",
101
+ // State initialization can be in the constructor or via class fields
102
+ "react/state-in-constructor": "off",
103
+ // This allows static properties to be placed within the class declaration
104
+ "react/static-property-placement": "off",
105
+ },
106
+ settings: {
107
+ react: {
108
+ version: "detect",
78
109
  },
79
- ],
80
- // don't force .jsx extension
81
- "react/jsx-filename-extension": "off",
82
- // In TS you must use the Fragment syntax instead of the shorthand
83
- "react/jsx-fragments": "off",
84
- // This allows props to be spread in JSX
85
- "react/jsx-props-no-spreading": "off",
86
- // ensure props are alphabetical
87
- "react/jsx-sort-props": "error",
88
- // Allow emotion css prop
89
- "react/no-unknown-property": ["error", { ignore: ["css"] }],
90
- // We don't need default props on TS components
91
- "react/require-default-props": "off",
92
- "react/sort-prop-types": "error",
93
- // State initialization can be in the constructor or via class fields
94
- "react/state-in-constructor": "off",
95
- // This allows static properties to be placed within the class declaration
96
- "react/static-property-placement": "off",
97
- },
98
- settings: {
99
- react: {
100
- version: "detect",
101
110
  },
102
111
  },
103
- },
104
- );
112
+ );
package/package.json CHANGED
@@ -49,5 +49,5 @@
49
49
  "access": "public"
50
50
  },
51
51
  "repository": "https://github.com/open-turo/eslint-config-react",
52
- "version": "15.0.0-pr-320.2.1.1"
52
+ "version": "15.0.0-pr-320.3.1.1"
53
53
  }
package/test/test.spec.js CHANGED
@@ -44,7 +44,7 @@ describe("validate config", () => {
44
44
  });
45
45
  const { default: config } = await import(`../${configFile}`);
46
46
  const linter = new ESLint({
47
- baseConfig: config,
47
+ baseConfig: config(),
48
48
  overrideConfig: [
49
49
  {
50
50
  files: [testFileName],