Skip to content

Commit

Permalink
Add support for extends in overrides config (#5603)
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Oct 19, 2021
1 parent b6fd2fc commit 67313a3
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
@@ -0,0 +1,8 @@
{
"overrides": [
{
"files": ["*.css"],
"extends": "./extending-simple-rule.json"
}
]
}
33 changes: 33 additions & 0 deletions lib/__tests__/overrides.test.js
Expand Up @@ -83,6 +83,39 @@ describe('single input file. all overrides are matching', () => {
expect(linted.results[0].warnings[2].rule).toBe('block-no-empty');
expect(linted.results[0].warnings[3].rule).toBe('color-named');
});

it('override with extends', async () => {
const linted = await standalone({
files: [path.join(fixturesPath, 'style.css')],
configFile: path.join(fixturesPath, 'extends-in-overrides.json'),
configBasedir: fixturesPath,
});

expect(linted.results).toHaveLength(1);
expect(linted.results[0].warnings).toHaveLength(2);
expect(linted.results[0].warnings[0].rule).toBe('block-no-empty');
expect(linted.results[0].warnings[1].rule).toBe('color-named');
});

it('override with extends in overrides', async () => {
const linted = await standalone({
files: [path.join(fixturesPath, 'style.css')],
config: {
overrides: [
{
files: ['*.css'],
extends: [path.join(fixturesPath, 'extends-in-overrides.json')],
},
],
},
configBasedir: fixturesPath,
});

expect(linted.results).toHaveLength(1);
expect(linted.results[0].warnings).toHaveLength(2);
expect(linted.results[0].warnings[0].rule).toBe('block-no-empty');
expect(linted.results[0].warnings[1].rule).toBe('color-named');
});
});

it('override is not matching', async () => {
Expand Down
5 changes: 4 additions & 1 deletion lib/augmentConfig.js
Expand Up @@ -38,7 +38,10 @@ async function augmentConfigBasic(stylelint, config, configDir, allowOverrides,
augmentedConfig = await extendConfig(stylelint, augmentedConfig, configDir);

if (filePath) {
augmentedConfig = applyOverrides(augmentedConfig, configDir, filePath);
while (augmentedConfig.overrides) {
augmentedConfig = applyOverrides(augmentedConfig, configDir, filePath);
augmentedConfig = await extendConfig(stylelint, augmentedConfig, configDir);
}
}

return absolutizePaths(augmentedConfig, configDir);
Expand Down

0 comments on commit 67313a3

Please sign in to comment.