eslint-plugin-react-hooks 6.2.0-canary-85c427d8-20251003 → 6.2.0-canary-c7862584-20251006

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
@@ -1,8 +1,6 @@
1
1
  # `eslint-plugin-react-hooks`
2
2
 
3
- This ESLint plugin enforces the [Rules of Hooks](https://react.dev/reference/rules/rules-of-hooks).
4
-
5
- It is a part of the [Hooks API](https://react.dev/reference/react/hooks) for React.
3
+ The official ESLint plugin for [React](https://react.dev) which enforces the [Rules of React](https://react.dev/reference/eslint-plugin-react-hooks) and other best practices.
6
4
 
7
5
  ## Installation
8
6
 
@@ -89,7 +87,7 @@ If you're using a version earlier than 5.2.0, the legacy config was simply `reco
89
87
 
90
88
  ### Custom Configuration
91
89
 
92
- If you want more fine-grained configuration, you can instead add a snippet like this to your ESLint configuration file:
90
+ If you want more fine-grained configuration, you can instead choose to enable specific rules. However, we strongly encourage using the recommended presets — see above — so that you will automatically receive new recommended rules as we add them in future versions of the plugin.
93
91
 
94
92
  #### Flat Config (eslint.config.js|ts)
95
93
 
@@ -1,6 +1,10 @@
1
1
  import * as estree from 'estree';
2
2
  import { Rule, Linter } from 'eslint';
3
3
 
4
+ type FlatConfig = {
5
+ plugins: Record<string, any>;
6
+ rules: Linter.RulesRecord;
7
+ };
4
8
  declare const plugin: {
5
9
  meta: {
6
10
  name: string;
@@ -81,9 +85,9 @@ declare const plugin: {
81
85
  plugins: Array<string>;
82
86
  rules: Linter.RulesRecord;
83
87
  };
84
- "flat/recommended": Array<Linter.Config>;
85
- "recommended-latest": Array<Linter.Config>;
86
- recommended: Array<Linter.Config>;
88
+ "flat/recommended": Array<FlatConfig>;
89
+ "recommended-latest": Array<FlatConfig>;
90
+ recommended: Array<FlatConfig>;
87
91
  };
88
92
  };
89
93
 
@@ -19,7 +19,6 @@ var BabelParser = require('@babel/parser');
19
19
  var zod = require('zod');
20
20
  var zodValidationError = require('zod-validation-error');
21
21
  var crypto = require('crypto');
22
- var HermesParser = require('hermes-parser');
23
22
  var util = require('util');
24
23
 
25
24
  const SETTINGS_KEY = 'react-hooks';
@@ -32071,7 +32070,7 @@ const HookSchema = zod.z.object({
32071
32070
  });
32072
32071
  const EnvironmentConfigSchema = zod.z.object({
32073
32072
  customHooks: zod.z.map(zod.z.string(), HookSchema).default(new Map()),
32074
- moduleTypeProvider: zod.z.nullable(zod.z.function().args(zod.z.string())).default(null),
32073
+ moduleTypeProvider: zod.z.nullable(zod.z.any()).default(null),
32075
32074
  customMacros: zod.z.nullable(zod.z.array(MacroSchema)).default(null),
32076
32075
  enableResetCacheOnSourceFileChanges: zod.z.nullable(zod.z.boolean()).default(null),
32077
32076
  enablePreserveExistingMemoizationGuarantees: zod.z.boolean().default(true),
@@ -32079,7 +32078,7 @@ const EnvironmentConfigSchema = zod.z.object({
32079
32078
  enablePreserveExistingManualUseMemo: zod.z.boolean().default(false),
32080
32079
  enableForest: zod.z.boolean().default(false),
32081
32080
  enableUseTypeAnnotations: zod.z.boolean().default(false),
32082
- flowTypeProvider: zod.z.nullable(zod.z.function().args(zod.z.string())).default(null),
32081
+ flowTypeProvider: zod.z.nullable(zod.z.any()).default(null),
32083
32082
  enableOptionalDependencies: zod.z.boolean().default(true),
32084
32083
  enableFire: zod.z.boolean().default(false),
32085
32084
  enableNameAnonymousFunctions: zod.z.boolean().default(false),
@@ -32444,6 +32443,12 @@ _Environment_globals = new WeakMap(), _Environment_shapes = new WeakMap(), _Envi
32444
32443
  if (moduleTypeProvider == null) {
32445
32444
  return null;
32446
32445
  }
32446
+ if (typeof moduleTypeProvider !== 'function') {
32447
+ CompilerError.throwInvalidConfig({
32448
+ reason: `Expected a function for \`moduleTypeProvider\``,
32449
+ loc,
32450
+ });
32451
+ }
32447
32452
  const unparsedModuleConfig = moduleTypeProvider(moduleName);
32448
32453
  if (unparsedModuleConfig != null) {
32449
32454
  const parsedModuleConfig = TypeSchema.safeParse(unparsedModuleConfig);
@@ -54173,28 +54178,14 @@ function runReactCompilerImpl({ sourceCode, filename, userOpts, }) {
54173
54178
  (_b = options.logger) === null || _b === void 0 ? void 0 : _b.logEvent(filename, err);
54174
54179
  }
54175
54180
  let babelAST = null;
54176
- if (filename.endsWith('.tsx') || filename.endsWith('.ts')) {
54177
- try {
54178
- babelAST = BabelParser.parse(sourceCode.text, {
54179
- sourceFilename: filename,
54180
- sourceType: 'unambiguous',
54181
- plugins: ['typescript', 'jsx'],
54182
- });
54183
- }
54184
- catch (_c) {
54185
- }
54181
+ try {
54182
+ babelAST = BabelParser.parse(sourceCode.text, {
54183
+ sourceFilename: filename,
54184
+ sourceType: 'unambiguous',
54185
+ plugins: ['typescript', 'jsx'],
54186
+ });
54186
54187
  }
54187
- else {
54188
- try {
54189
- babelAST = HermesParser.parse(sourceCode.text, {
54190
- babel: true,
54191
- enableExperimentalComponentSyntax: true,
54192
- sourceFilename: filename,
54193
- sourceType: 'module',
54194
- });
54195
- }
54196
- catch (_d) {
54197
- }
54188
+ catch (err) {
54198
54189
  }
54199
54190
  if (babelAST != null) {
54200
54191
  results.flowSuppressions = getFlowSuppressions(sourceCode);
@@ -15,7 +15,6 @@ var BabelParser = require('@babel/parser');
15
15
  var zod = require('zod');
16
16
  var zodValidationError = require('zod-validation-error');
17
17
  var crypto = require('crypto');
18
- var HermesParser = require('hermes-parser');
19
18
  var util = require('util');
20
19
 
21
20
  const SETTINGS_KEY = 'react-hooks';
@@ -31898,7 +31897,7 @@ const HookSchema = zod.z.object({
31898
31897
  });
31899
31898
  const EnvironmentConfigSchema = zod.z.object({
31900
31899
  customHooks: zod.z.map(zod.z.string(), HookSchema).default(new Map()),
31901
- moduleTypeProvider: zod.z.nullable(zod.z.function().args(zod.z.string())).default(null),
31900
+ moduleTypeProvider: zod.z.nullable(zod.z.any()).default(null),
31902
31901
  customMacros: zod.z.nullable(zod.z.array(MacroSchema)).default(null),
31903
31902
  enableResetCacheOnSourceFileChanges: zod.z.nullable(zod.z.boolean()).default(null),
31904
31903
  enablePreserveExistingMemoizationGuarantees: zod.z.boolean().default(true),
@@ -31906,7 +31905,7 @@ const EnvironmentConfigSchema = zod.z.object({
31906
31905
  enablePreserveExistingManualUseMemo: zod.z.boolean().default(false),
31907
31906
  enableForest: zod.z.boolean().default(false),
31908
31907
  enableUseTypeAnnotations: zod.z.boolean().default(false),
31909
- flowTypeProvider: zod.z.nullable(zod.z.function().args(zod.z.string())).default(null),
31908
+ flowTypeProvider: zod.z.nullable(zod.z.any()).default(null),
31910
31909
  enableOptionalDependencies: zod.z.boolean().default(true),
31911
31910
  enableFire: zod.z.boolean().default(false),
31912
31911
  enableNameAnonymousFunctions: zod.z.boolean().default(false),
@@ -32271,6 +32270,12 @@ _Environment_globals = new WeakMap(), _Environment_shapes = new WeakMap(), _Envi
32271
32270
  if (moduleTypeProvider == null) {
32272
32271
  return null;
32273
32272
  }
32273
+ if (typeof moduleTypeProvider !== 'function') {
32274
+ CompilerError.throwInvalidConfig({
32275
+ reason: `Expected a function for \`moduleTypeProvider\``,
32276
+ loc,
32277
+ });
32278
+ }
32274
32279
  const unparsedModuleConfig = moduleTypeProvider(moduleName);
32275
32280
  if (unparsedModuleConfig != null) {
32276
32281
  const parsedModuleConfig = TypeSchema.safeParse(unparsedModuleConfig);
@@ -54000,28 +54005,14 @@ function runReactCompilerImpl({ sourceCode, filename, userOpts, }) {
54000
54005
  (_b = options.logger) === null || _b === void 0 ? void 0 : _b.logEvent(filename, err);
54001
54006
  }
54002
54007
  let babelAST = null;
54003
- if (filename.endsWith('.tsx') || filename.endsWith('.ts')) {
54004
- try {
54005
- babelAST = BabelParser.parse(sourceCode.text, {
54006
- sourceFilename: filename,
54007
- sourceType: 'unambiguous',
54008
- plugins: ['typescript', 'jsx'],
54009
- });
54010
- }
54011
- catch (_c) {
54012
- }
54008
+ try {
54009
+ babelAST = BabelParser.parse(sourceCode.text, {
54010
+ sourceFilename: filename,
54011
+ sourceType: 'unambiguous',
54012
+ plugins: ['typescript', 'jsx'],
54013
+ });
54013
54014
  }
54014
- else {
54015
- try {
54016
- babelAST = HermesParser.parse(sourceCode.text, {
54017
- babel: true,
54018
- enableExperimentalComponentSyntax: true,
54019
- sourceFilename: filename,
54020
- sourceType: 'module',
54021
- });
54022
- }
54023
- catch (_d) {
54024
- }
54015
+ catch (err) {
54025
54016
  }
54026
54017
  if (babelAST != null) {
54027
54018
  results.flowSuppressions = getFlowSuppressions(sourceCode);
package/index.d.ts CHANGED
@@ -5,4 +5,4 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- export * from './cjs/eslint-plugin-react-hooks';
8
+ export {default} from './cjs/eslint-plugin-react-hooks';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-hooks",
3
3
  "description": "ESLint rules for React Hooks",
4
- "version": "6.2.0-canary-85c427d8-20251003",
4
+ "version": "6.2.0-canary-c7862584-20251006",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/facebook/react.git",
@@ -41,23 +41,22 @@
41
41
  "dependencies": {
42
42
  "@babel/core": "^7.24.4",
43
43
  "@babel/parser": "^7.24.4",
44
- "hermes-parser": "^0.25.1",
45
- "zod": "^3.22.4",
46
- "zod-validation-error": "^3.0.3"
44
+ "zod": "^3.22.4 || ^4.0.0",
45
+ "zod-validation-error": "^3.0.3 || ^4.0.0"
47
46
  },
48
47
  "devDependencies": {
49
48
  "@babel/eslint-parser": "^7.11.4",
50
49
  "@babel/preset-typescript": "^7.26.0",
51
50
  "@babel/types": "^7.19.0",
52
51
  "@tsconfig/strictest": "^2.0.5",
53
- "@typescript-eslint/parser-v2": "npm:@typescript-eslint/parser@^2.26.0",
54
- "@typescript-eslint/parser-v3": "npm:@typescript-eslint/parser@^3.10.0",
55
- "@typescript-eslint/parser-v4": "npm:@typescript-eslint/parser@^4.1.0",
56
- "@typescript-eslint/parser-v5": "npm:@typescript-eslint/parser@^5.62.0",
57
52
  "@types/eslint": "^8.56.12",
58
53
  "@types/estree": "^1.0.6",
59
54
  "@types/estree-jsx": "^1.0.5",
60
55
  "@types/node": "^20.2.5",
56
+ "@typescript-eslint/parser-v2": "npm:@typescript-eslint/parser@^2.26.0",
57
+ "@typescript-eslint/parser-v3": "npm:@typescript-eslint/parser@^3.10.0",
58
+ "@typescript-eslint/parser-v4": "npm:@typescript-eslint/parser@^4.1.0",
59
+ "@typescript-eslint/parser-v5": "npm:@typescript-eslint/parser@^5.62.0",
61
60
  "babel-eslint": "^10.0.3",
62
61
  "eslint-v7": "npm:eslint@^7.7.0",
63
62
  "eslint-v8": "npm:eslint@^8.57.1",