eslint-config-setup 0.4.0 → 0.5.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/dist/modules.js CHANGED
@@ -837,6 +837,8 @@ function prettierCompatConfig() {
837
837
  import eslintReactPlugin2 from "@eslint-react/eslint-plugin";
838
838
  import stylisticPlugin from "@stylistic/eslint-plugin";
839
839
  import jsxA11yPlugin from "eslint-plugin-jsx-a11y";
840
+ import reactHooksPlugin from "eslint-plugin-react-hooks";
841
+ import reactPerfPlugin from "eslint-plugin-react-perf";
840
842
  import reactRefreshPlugin from "eslint-plugin-react-refresh";
841
843
  import globals2 from "globals";
842
844
 
@@ -872,10 +874,6 @@ var LEGACY_ALIASES = {
872
874
  "no-array-index-key": [coreRules, "no-array-index-key"],
873
875
  "no-children-prop": [jsxRules, "no-children-prop"],
874
876
  "no-direct-mutation-state": [coreRules, "no-direct-mutation-state"],
875
- "no-redundant-should-component-update": [
876
- coreRules,
877
- "no-redundant-should-component-update"
878
- ],
879
877
  "no-unused-class-component-members": [
880
878
  coreRules,
881
879
  "no-unused-class-component-members"
@@ -898,7 +896,6 @@ var LEGACY_ALIASES = {
898
896
  ],
899
897
  "display-name": [coreRules, "no-missing-component-display-name"],
900
898
  "forward-ref-uses-ref": [coreRules, "no-forward-ref"],
901
- "destructuring-assignment": [coreRules, "prefer-destructuring-assignment"],
902
899
  "no-did-mount-set-state": [
903
900
  coreRules,
904
901
  "no-set-state-in-component-did-mount"
@@ -1017,17 +1014,49 @@ var reactCompatPlugin = {
1017
1014
 
1018
1015
  // src/configs/react.ts
1019
1016
  var typedConfigs = eslintReactPlugin2.configs;
1020
- var recommendedRules = typedConfigs.recommended.rules;
1021
- var strictRules = typedConfigs.strict.rules;
1022
- var presetRules = translatePresetRules({ ...recommendedRules, ...strictRules });
1017
+ var strictTypeCheckedRules = typedConfigs["strict-type-checked"].rules;
1018
+ var REACT_HOOKS_REPLACED_ESLINT_REACT_RULES = [
1019
+ "error-boundaries",
1020
+ "exhaustive-deps",
1021
+ "purity",
1022
+ "rules-of-hooks",
1023
+ "set-state-in-effect",
1024
+ "set-state-in-render",
1025
+ "static-components",
1026
+ "unsupported-syntax",
1027
+ "use-memo"
1028
+ ];
1029
+ var reactHooksReplacedRules = new Set(
1030
+ REACT_HOOKS_REPLACED_ESLINT_REACT_RULES
1031
+ );
1032
+ function filterReactHooksRules(rules) {
1033
+ const filtered = {};
1034
+ for (const [ruleName, value] of Object.entries(rules)) {
1035
+ const shortName = ruleName.replace(/^@eslint-react\//, "");
1036
+ if (!reactHooksReplacedRules.has(shortName)) {
1037
+ filtered[ruleName] = value;
1038
+ }
1039
+ }
1040
+ return filtered;
1041
+ }
1042
+ var presetRules = translatePresetRules(filterReactHooksRules(strictTypeCheckedRules));
1043
+ var reactHooksRecommendedLatest = reactHooksPlugin.configs.flat["recommended-latest"];
1044
+ var reactHooksPluginForEslint = reactHooksPlugin;
1023
1045
  var EXTRA_REACT_RULES = {
1024
- "react/jsx-no-leaked-render": "error",
1025
1046
  "react/no-duplicate-key": "error",
1026
1047
  "react/no-implicit-key": "error",
1027
- "react/no-unused-props": "warn",
1028
1048
  "react/no-unknown-property": "error",
1029
1049
  "react/style-prop-object": "error"
1030
1050
  };
1051
+ var AI_ADDED_REACT_RULES = {
1052
+ "react/no-unused-state": "error"
1053
+ };
1054
+ var AI_REACT_PERF_RULES = {
1055
+ "react-perf/jsx-no-jsx-as-prop": "error",
1056
+ "react-perf/jsx-no-new-array-as-prop": "error",
1057
+ "react-perf/jsx-no-new-function-as-prop": "error",
1058
+ "react-perf/jsx-no-new-object-as-prop": "error"
1059
+ };
1031
1060
  var JSX_A11Y_ERROR_RULES = {
1032
1061
  "jsx-a11y/alt-text": "error",
1033
1062
  "jsx-a11y/anchor-has-content": "error",
@@ -1059,7 +1088,6 @@ var AI_PROMOTED_REACT_RULES = [
1059
1088
  "react/jsx-no-constructed-context-values",
1060
1089
  "react/no-array-index-key",
1061
1090
  "react/no-object-type-as-default-prop",
1062
- "react/no-unused-state",
1063
1091
  "react/jsx-no-target-blank",
1064
1092
  "react/button-has-type",
1065
1093
  "react/iframe-missing-sandbox",
@@ -1105,6 +1133,8 @@ function applyAiReactRules(builder) {
1105
1133
  for (const ruleName of AI_PROMOTED_REACT_RULES) {
1106
1134
  builder.overrideSeverity(ruleName, "error");
1107
1135
  }
1136
+ addRules2(builder, AI_ADDED_REACT_RULES);
1137
+ addRules2(builder, AI_REACT_PERF_RULES);
1108
1138
  for (const ruleName of AI_A11Y_RULES) {
1109
1139
  builder.addRule(ruleName, "error");
1110
1140
  }
@@ -1126,10 +1156,13 @@ function reactConfig(opts) {
1126
1156
  const isAi = opts?.ai ?? false;
1127
1157
  const builder = createConfig({
1128
1158
  name: "eslint-config-setup/react",
1129
- presets: [{ rules: presetRules }],
1159
+ presets: [{ rules: presetRules }, reactHooksRecommendedLatest],
1130
1160
  plugins: {
1131
1161
  react: reactCompatPlugin,
1132
1162
  "@stylistic": stylisticPlugin,
1163
+ "react-hooks": reactHooksPluginForEslint,
1164
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Plugin from untyped module
1165
+ "react-perf": reactPerfPlugin,
1133
1166
  "react-refresh": reactRefreshPlugin,
1134
1167
  // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Plugin from untyped module
1135
1168
  "jsx-a11y": jsxA11yPlugin
@@ -1187,12 +1220,12 @@ function reactEffectConfig() {
1187
1220
  // Disallow passing fetched data to parent via effect — fetch in parent instead
1188
1221
  // https://github.com/nickjvandyke/eslint-plugin-react-you-might-not-need-an-effect
1189
1222
  "react-you-might-not-need-an-effect/no-pass-data-to-parent": "error",
1190
- // Disallow initializing state in an effect — pass initial value to useState
1223
+ // Disallow external-store subscriptions in an effect — use useSyncExternalStore
1191
1224
  // https://github.com/nickjvandyke/eslint-plugin-react-you-might-not-need-an-effect
1192
- "react-you-might-not-need-an-effect/no-initialize-state": "error",
1193
- // Disallow empty effectsdead code, remove them
1225
+ "react-you-might-not-need-an-effect/no-external-store-subscription": "error",
1226
+ // Disallow initializing state in an effect pass initial value to useState
1194
1227
  // https://github.com/nickjvandyke/eslint-plugin-react-you-might-not-need-an-effect
1195
- "react-you-might-not-need-an-effect/no-empty-effect": "error"
1228
+ "react-you-might-not-need-an-effect/no-initialize-state": "error"
1196
1229
  }
1197
1230
  }
1198
1231
  ];
@@ -1738,7 +1771,8 @@ function unicornConfig(opts) {
1738
1771
  camelCase: true,
1739
1772
  pascalCase: true,
1740
1773
  kebabCase: true
1741
- }
1774
+ },
1775
+ ignore: ["__tests__"]
1742
1776
  }
1743
1777
  ],
1744
1778
  // Discourage Array.reduce() — hard to read for many developers, prefer for...of or other methods
@@ -1844,7 +1878,7 @@ function unicornConfig(opts) {
1844
1878
  "unicorn/numeric-separators-style": "error",
1845
1879
  // Prefer `export { x } from 'y'` over import then re-export
1846
1880
  // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-export-from.md
1847
- "unicorn/prefer-export-from": ["error", { ignoreUsedVariables: true }],
1881
+ "unicorn/prefer-export-from": ["error", { checkUsedVariables: false }],
1848
1882
  // Prefer built-in coercion (String, Number, Boolean) over wrapper functions
1849
1883
  // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-native-coercion-functions.md
1850
1884
  "unicorn/prefer-native-coercion-functions": "error",
@@ -1886,10 +1920,9 @@ function unicornConfig(opts) {
1886
1920
  builder.overrideSeverity("unicorn/consistent-function-scoping", "error");
1887
1921
  builder.overrideSeverity("unicorn/no-array-reduce", "error");
1888
1922
  builder.overrideSeverity("unicorn/no-for-loop", "error");
1889
- builder.addRule("unicorn/no-array-for-each", "error");
1923
+ builder.addRule("unicorn/no-for-each", "error");
1890
1924
  builder.addRule("unicorn/prefer-ternary", ["error", "only-single-line"]);
1891
1925
  builder.addRule("unicorn/prefer-switch", ["error", { minimumCases: 3 }]);
1892
- builder.addRule("unicorn/prevent-abbreviations", "error");
1893
1926
  builder.addRule("unicorn/no-useless-switch-case", "error");
1894
1927
  builder.addRule("unicorn/custom-error-definition", "error");
1895
1928
  builder.addRule("unicorn/prefer-default-parameters", "error");
@@ -2270,28 +2303,37 @@ function testsOverride() {
2270
2303
 
2271
2304
  // src/oxlint/integration.ts
2272
2305
  import oxlintPlugin from "eslint-plugin-oxlint";
2306
+ var typedPlugin = oxlintPlugin;
2307
+ function addOxlintConfig(configs, configName, blockName) {
2308
+ const raw = typedPlugin.configs[configName];
2309
+ const items = Array.isArray(raw) ? raw : [raw];
2310
+ for (const [index, item] of items.entries()) {
2311
+ const suffix = items.length > 1 ? `-${index + 1}` : "";
2312
+ configs.push({ ...item, name: `eslint-config-setup/${blockName}${suffix}` });
2313
+ }
2314
+ }
2315
+ function addReactOxlintConfigs(configs, opts) {
2316
+ if (!opts.react) {
2317
+ return;
2318
+ }
2319
+ addOxlintConfig(configs, "flat/react", "oxlint-react");
2320
+ addOxlintConfig(configs, "flat/jsx-a11y", "oxlint-jsx-a11y");
2321
+ addOxlintConfig(configs, "flat/react-hooks", "oxlint-react-hooks");
2322
+ if (opts.ai) {
2323
+ addOxlintConfig(configs, "flat/react-perf", "oxlint-react-perf");
2324
+ }
2325
+ }
2273
2326
  function oxlintIntegration(opts) {
2274
- const typedPlugin = oxlintPlugin;
2275
2327
  const configs = [];
2276
- const add = (configName, blockName) => {
2277
- const raw = typedPlugin.configs[configName];
2278
- const items = Array.isArray(raw) ? raw : [raw];
2279
- for (const item of items) {
2280
- configs.push({ name: `eslint-config-setup/${blockName}`, ...item });
2281
- }
2282
- };
2283
- add("flat/recommended", "oxlint");
2284
- if (opts.react) {
2285
- add("flat/react", "oxlint-react");
2286
- add("flat/jsx-a11y", "oxlint-jsx-a11y");
2287
- }
2328
+ addOxlintConfig(configs, "flat/recommended", "oxlint");
2329
+ addReactOxlintConfigs(configs, opts);
2288
2330
  if (opts.node) {
2289
- add("flat/node", "oxlint-node");
2331
+ addOxlintConfig(configs, "flat/node", "oxlint-node");
2290
2332
  }
2291
- add("flat/typescript", "oxlint-typescript");
2292
- add("flat/unicorn", "oxlint-unicorn");
2293
- add("flat/import", "oxlint-import");
2294
- add("flat/jsdoc", "oxlint-jsdoc");
2333
+ addOxlintConfig(configs, "flat/typescript", "oxlint-typescript");
2334
+ addOxlintConfig(configs, "flat/unicorn", "oxlint-unicorn");
2335
+ addOxlintConfig(configs, "flat/import", "oxlint-import");
2336
+ addOxlintConfig(configs, "flat/jsdoc", "oxlint-jsdoc");
2295
2337
  return configs;
2296
2338
  }
2297
2339