|
| 1 | +import test from 'tape'; |
| 2 | + |
| 3 | +import flatConfig from '../flat'; |
| 4 | + |
| 5 | +import bestPractices from 'eslint-config-airbnb-base/rules/best-practices'; |
| 6 | +import errors from 'eslint-config-airbnb-base/rules/errors'; |
| 7 | +import es6 from 'eslint-config-airbnb-base/rules/es6'; |
| 8 | +import imports from 'eslint-config-airbnb-base/rules/imports'; |
| 9 | +import node from 'eslint-config-airbnb-base/rules/node'; |
| 10 | +import strict from 'eslint-config-airbnb-base/rules/strict'; |
| 11 | +import style from 'eslint-config-airbnb-base/rules/style'; |
| 12 | +import variables from 'eslint-config-airbnb-base/rules/variables'; |
| 13 | + |
| 14 | +import react from '../rules/react'; |
| 15 | +import reactA11y from '../rules/react-a11y'; |
| 16 | + |
| 17 | +test('flat config structure', (t) => { |
| 18 | + t.ok(Array.isArray(flatConfig), 'flat config is an array'); |
| 19 | + t.equal(flatConfig.length, 2, 'flat config has two elements (base + react)'); |
| 20 | + |
| 21 | + t.notOk(flatConfig[0].files, 'base config has no files scope'); |
| 22 | + t.deepEqual(flatConfig[1].files, ['**/*.{js,jsx,mjs,cjs}'], 'react config is scoped to JS files'); |
| 23 | + |
| 24 | + t.end(); |
| 25 | +}); |
| 26 | + |
| 27 | +test('flat config base rules match rule files', (t) => { |
| 28 | + const baseRules = flatConfig[0].rules; |
| 29 | + |
| 30 | + const expectedBaseRules = { |
| 31 | + ...bestPractices.rules, |
| 32 | + ...errors.rules, |
| 33 | + ...node.rules, |
| 34 | + ...style.rules, |
| 35 | + ...variables.rules, |
| 36 | + ...es6.rules, |
| 37 | + ...imports.rules, |
| 38 | + ...strict.rules, |
| 39 | + }; |
| 40 | + |
| 41 | + const baseKeys = Object.keys(baseRules).sort(); |
| 42 | + const expectedKeys = Object.keys(expectedBaseRules).sort(); |
| 43 | + |
| 44 | + t.deepEqual(baseKeys, expectedKeys, 'base config has the same rule keys as combined base rule files'); |
| 45 | + |
| 46 | + expectedKeys.forEach((key) => { |
| 47 | + t.deepEqual(baseRules[key], expectedBaseRules[key], `base rule "${key}" has matching config`); |
| 48 | + }); |
| 49 | + |
| 50 | + t.end(); |
| 51 | +}); |
| 52 | + |
| 53 | +test('flat config react rules match rule files', (t) => { |
| 54 | + const reactRules = flatConfig[1].rules; |
| 55 | + |
| 56 | + const expectedReactRules = { |
| 57 | + ...react.rules, |
| 58 | + ...reactA11y.rules, |
| 59 | + }; |
| 60 | + |
| 61 | + const reactKeys = Object.keys(reactRules).sort(); |
| 62 | + const expectedKeys = Object.keys(expectedReactRules).sort(); |
| 63 | + |
| 64 | + t.deepEqual(reactKeys, expectedKeys, 'react config has the same rule keys as combined react rule files'); |
| 65 | + |
| 66 | + expectedKeys.forEach((key) => { |
| 67 | + t.deepEqual(reactRules[key], expectedReactRules[key], `react rule "${key}" has matching config`); |
| 68 | + }); |
| 69 | + |
| 70 | + t.end(); |
| 71 | +}); |
| 72 | + |
| 73 | +test('flat config has required plugins and settings', (t) => { |
| 74 | + const baseConfig = flatConfig[0]; |
| 75 | + const reactConfig = flatConfig[1]; |
| 76 | + |
| 77 | + t.ok(baseConfig.plugins.import, 'import plugin is present in base config'); |
| 78 | + t.ok(baseConfig.settings, 'settings are present in base config'); |
| 79 | + t.ok(baseConfig.languageOptions, 'languageOptions are present in base config'); |
| 80 | + |
| 81 | + t.ok(reactConfig.plugins.react, 'react plugin is present in react config'); |
| 82 | + t.ok(reactConfig.plugins['jsx-a11y'], 'jsx-a11y plugin is present in react config'); |
| 83 | + t.ok(reactConfig.settings, 'settings are present in react config'); |
| 84 | + |
| 85 | + t.end(); |
| 86 | +}); |
0 commit comments