[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | const fromEntries = require('object.fromentries');
|
---|
| 4 | const entries = require('object.entries');
|
---|
| 5 |
|
---|
| 6 | const allRules = require('./lib/rules');
|
---|
| 7 |
|
---|
| 8 | function filterRules(rules, predicate) {
|
---|
| 9 | return fromEntries(entries(rules).filter((entry) => predicate(entry[1])));
|
---|
| 10 | }
|
---|
| 11 |
|
---|
| 12 | /**
|
---|
| 13 | * @param {object} rules - rules object mapping rule name to rule module
|
---|
| 14 | * @returns {Record<string, 2>}
|
---|
| 15 | */
|
---|
| 16 | function configureAsError(rules) {
|
---|
| 17 | return fromEntries(Object.keys(rules).map((key) => [`react/${key}`, 2]));
|
---|
| 18 | }
|
---|
| 19 |
|
---|
| 20 | const activeRules = filterRules(allRules, (rule) => !rule.meta.deprecated);
|
---|
| 21 | const activeRulesConfig = configureAsError(activeRules);
|
---|
| 22 |
|
---|
| 23 | const deprecatedRules = filterRules(allRules, (rule) => rule.meta.deprecated);
|
---|
| 24 |
|
---|
| 25 | // for legacy config system
|
---|
| 26 | const plugins = [
|
---|
| 27 | 'react',
|
---|
| 28 | ];
|
---|
| 29 |
|
---|
| 30 | const plugin = {
|
---|
| 31 | deprecatedRules,
|
---|
| 32 | rules: allRules,
|
---|
| 33 | configs: {
|
---|
| 34 | recommended: {
|
---|
| 35 | plugins,
|
---|
| 36 | parserOptions: {
|
---|
| 37 | ecmaFeatures: {
|
---|
| 38 | jsx: true,
|
---|
| 39 | },
|
---|
| 40 | },
|
---|
| 41 | rules: {
|
---|
| 42 | 'react/display-name': 2,
|
---|
| 43 | 'react/jsx-key': 2,
|
---|
| 44 | 'react/jsx-no-comment-textnodes': 2,
|
---|
| 45 | 'react/jsx-no-duplicate-props': 2,
|
---|
| 46 | 'react/jsx-no-target-blank': 2,
|
---|
| 47 | 'react/jsx-no-undef': 2,
|
---|
| 48 | 'react/jsx-uses-react': 2,
|
---|
| 49 | 'react/jsx-uses-vars': 2,
|
---|
| 50 | 'react/no-children-prop': 2,
|
---|
| 51 | 'react/no-danger-with-children': 2,
|
---|
| 52 | 'react/no-deprecated': 2,
|
---|
| 53 | 'react/no-direct-mutation-state': 2,
|
---|
| 54 | 'react/no-find-dom-node': 2,
|
---|
| 55 | 'react/no-is-mounted': 2,
|
---|
| 56 | 'react/no-render-return-value': 2,
|
---|
| 57 | 'react/no-string-refs': 2,
|
---|
| 58 | 'react/no-unescaped-entities': 2,
|
---|
| 59 | 'react/no-unknown-property': 2,
|
---|
| 60 | 'react/no-unsafe': 0,
|
---|
| 61 | 'react/prop-types': 2,
|
---|
| 62 | 'react/react-in-jsx-scope': 2,
|
---|
| 63 | 'react/require-render-return': 2,
|
---|
| 64 | },
|
---|
| 65 | },
|
---|
| 66 | all: {
|
---|
| 67 | plugins,
|
---|
| 68 | parserOptions: {
|
---|
| 69 | ecmaFeatures: {
|
---|
| 70 | jsx: true,
|
---|
| 71 | },
|
---|
| 72 | },
|
---|
| 73 | rules: activeRulesConfig,
|
---|
| 74 | },
|
---|
| 75 | 'jsx-runtime': {
|
---|
| 76 | plugins,
|
---|
| 77 | parserOptions: {
|
---|
| 78 | ecmaFeatures: {
|
---|
| 79 | jsx: true,
|
---|
| 80 | },
|
---|
| 81 | jsxPragma: null, // for @typescript/eslint-parser
|
---|
| 82 | },
|
---|
| 83 | rules: {
|
---|
| 84 | 'react/react-in-jsx-scope': 0,
|
---|
| 85 | 'react/jsx-uses-react': 0,
|
---|
| 86 | },
|
---|
| 87 | },
|
---|
| 88 | },
|
---|
| 89 | };
|
---|
| 90 |
|
---|
| 91 | plugin.configs.flat = {
|
---|
| 92 | recommended: {
|
---|
| 93 | plugins: { react: plugin },
|
---|
| 94 | rules: plugin.configs.recommended.rules,
|
---|
| 95 | languageOptions: { parserOptions: plugin.configs.recommended.parserOptions },
|
---|
| 96 | },
|
---|
| 97 | all: {
|
---|
| 98 | plugins: { react: plugin },
|
---|
| 99 | rules: plugin.configs.all.rules,
|
---|
| 100 | languageOptions: { parserOptions: plugin.configs.all.parserOptions },
|
---|
| 101 | },
|
---|
| 102 | 'jsx-runtime': {
|
---|
| 103 | plugins: { react: plugin },
|
---|
| 104 | rules: plugin.configs['jsx-runtime'].rules,
|
---|
| 105 | languageOptions: { parserOptions: plugin.configs['jsx-runtime'].parserOptions },
|
---|
| 106 | },
|
---|
| 107 | };
|
---|
| 108 |
|
---|
| 109 | module.exports = plugin;
|
---|