forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
64 lines (56 loc) · 2.02 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import RulesOfHooks from './rules/RulesOfHooks';
import ExhaustiveDeps from './rules/ExhaustiveDeps';
import type {ESLint, Linter, Rule} from 'eslint';
// All rules
const rules = {
'rules-of-hooks': RulesOfHooks,
'exhaustive-deps': ExhaustiveDeps,
} satisfies Record<string, Rule.RuleModule>;
// Config rules
const configRules = {
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
} satisfies Linter.RulesRecord;
// Legacy config
const legacyRecommendedConfig = {
plugins: ['react-hooks'],
rules: configRules,
} satisfies Linter.LegacyConfig;
// Plugin object
const plugin = {
// TODO: Make this more dynamic to populate version from package.json.
// This can be done by injecting at build time, since importing the package.json isn't an option in Meta
meta: {name: 'eslint-plugin-react-hooks'},
rules,
configs: {
/** Legacy recommended config, to be used with rc-based configurations */
'recommended-legacy': legacyRecommendedConfig,
/**
* 'recommended' is currently aliased to the legacy / rc recommended config) to maintain backwards compatibility.
* This is deprecated and in v6, it will switch to alias the flat recommended config.
*/
recommended: legacyRecommendedConfig,
/** Latest recommended config, to be used with flat configurations */
'recommended-latest': {
name: 'react-hooks/recommended',
plugins: {
get 'react-hooks'(): ESLint.Plugin {
return plugin;
},
},
rules: configRules,
},
},
} satisfies ESLint.Plugin;
const configs = plugin.configs;
const meta = plugin.meta;
export {configs, meta, rules};
// TODO: If the plugin is ever updated to be pure ESM and drops support for rc-based configs, then it should be exporting the plugin as default
// instead of individual named exports.
// export default plugin;