Skip to content

Commit 8835b03

Browse files
committed
added tests and comments
1 parent e1586b1 commit 8835b03

File tree

8 files changed

+148
-0
lines changed

8 files changed

+148
-0
lines changed

packages/eslint-config-airbnb-base/test/requires.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ test('all entry points parse', (t) => {
88
t.doesNotThrow(() => require('..'), 'index does not throw');
99
t.doesNotThrow(() => require('../legacy'), 'legacy does not throw');
1010
t.doesNotThrow(() => require('../whitespace'), 'whitespace does not throw');
11+
t.doesNotThrow(() => require('../flat'), 'flat does not throw');
1112

1213
t.end();
1314
});
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import test from 'tape';
2+
3+
import flatConfig from '../flat';
4+
5+
import bestPractices from '../rules/best-practices';
6+
import errors from '../rules/errors';
7+
import es6 from '../rules/es6';
8+
import imports from '../rules/imports';
9+
import node from '../rules/node';
10+
import strict from '../rules/strict';
11+
import style from '../rules/style';
12+
import variables from '../rules/variables';
13+
14+
test('flat config includes all rules from rule files', (t) => {
15+
// The flat config is an array with one config object
16+
t.ok(Array.isArray(flatConfig), 'flat config is an array');
17+
t.equal(flatConfig.length, 1, 'flat config has one element');
18+
19+
const flatRules = flatConfig[0].rules;
20+
21+
// Merge rules in the same order as flat.js
22+
const expectedRules = {
23+
...bestPractices.rules,
24+
...errors.rules,
25+
...node.rules,
26+
...style.rules,
27+
...variables.rules,
28+
...es6.rules,
29+
...imports.rules,
30+
...strict.rules,
31+
};
32+
33+
const flatKeys = Object.keys(flatRules).sort();
34+
const expectedKeys = Object.keys(expectedRules).sort();
35+
36+
t.deepEqual(flatKeys, expectedKeys, 'flat config has the same rule keys as combined rule files');
37+
38+
expectedKeys.forEach((key) => {
39+
t.deepEqual(flatRules[key], expectedRules[key], `rule "${key}" has matching config`);
40+
});
41+
42+
t.end();
43+
});
44+
45+
test('flat config has required plugins and settings', (t) => {
46+
const config = flatConfig[0];
47+
48+
t.ok(config.plugins.import, 'import plugin is present');
49+
t.ok(config.settings, 'settings are present');
50+
t.ok(config.languageOptions, 'languageOptions are present');
51+
t.equal(config.languageOptions.sourceType, 'module', 'sourceType is module');
52+
53+
t.end();
54+
});

packages/eslint-config-airbnb-base/whitespace-async.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const { isArray } = Array;
44
const { entries } = Object;
55
const { ESLint } = require('eslint');
66

7+
// ESLint 9 transition-period API; will be moot once eslintrc is fully removed in ESLint 10+
78
const isFlat = ESLint.configType === 'flat';
89
const baseConfig = isFlat ? require('./flat') : require('.');
910
const whitespaceRules = require('./whitespaceRules');

packages/eslint-config-airbnb-base/whitespace.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ if (CLIEngine) {
6060
}
6161
})));
6262

63+
// ESLint 9 transition-period API; will be moot once eslintrc is fully removed in ESLint 10+
6364
if (ESLint.configType === 'flat') {
6465
// In flat mode, whitespace-async.js outputs only { rules: {} } since plugins
6566
// are not JSON-serializable. Merge the rule overrides with the full flat config

packages/eslint-config-airbnb/test/requires.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ test('all entry points parse', (t) => {
1010
t.doesNotThrow(() => require('../legacy'), 'legacy does not throw');
1111
t.doesNotThrow(() => require('../whitespace'), 'whitespace does not throw');
1212
t.doesNotThrow(() => require('../hooks'), 'hooks does not throw');
13+
t.doesNotThrow(() => require('../flat'), 'flat does not throw');
14+
t.doesNotThrow(() => require('../flat-base'), 'flat-base does not throw');
15+
t.doesNotThrow(() => require('../flat-hooks'), 'flat-hooks does not throw');
1316

1417
t.end();
1518
});
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
});

packages/eslint-config-airbnb/whitespace-async.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const { isArray } = Array;
44
const { entries } = Object;
55
const { ESLint } = require('eslint');
66

7+
// ESLint 9 transition-period API; will be moot once eslintrc is fully removed in ESLint 10+
78
const isFlat = ESLint.configType === 'flat';
89
const baseConfig = isFlat ? require('./flat') : require('.');
910
const whitespaceRules = require('./whitespaceRules');

packages/eslint-config-airbnb/whitespace.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ if (CLIEngine) {
6060
}
6161
})));
6262

63+
// ESLint 9 transition-period API; will be moot once eslintrc is fully removed in ESLint 10+
6364
if (ESLint.configType === 'flat') {
6465
// In flat mode, whitespace-async.js outputs only { rules: {} } since plugins
6566
// are not JSON-serializable. Merge the rule overrides with the full flat config

0 commit comments

Comments
 (0)