Skip to content

Commit 59d5bf9

Browse files
fpetrakovybiquitous
andauthoredJul 4, 2023
Add support JS objects for extends config option (#6998)
Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com>
1 parent 888192d commit 59d5bf9

File tree

5 files changed

+36
-1
lines changed

5 files changed

+36
-1
lines changed
 

‎.changeset/gorgeous-cobras-beam.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"stylelint": minor
3+
---
4+
5+
Added: support for JS objects with `extends` config option

‎lib/__tests__/extends.test.mjs

+14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { fileURLToPath } from 'node:url';
22

3+
import configExtendingWithObject from './fixtures/config-extending-with-object.mjs';
34
import readJSONFile from '../testUtils/readJSONFile.mjs';
45
import safeChdir from '../testUtils/safeChdir.mjs';
56
import standalone from '../standalone.js';
@@ -29,6 +30,19 @@ it('basic extending', async () => {
2930
expect(linted.results[0].warnings[0].rule).toBe('block-no-empty');
3031
});
3132

33+
it('basic extending with object', async () => {
34+
const linted = await standalone({
35+
code: 'a {}',
36+
config: configExtendingWithObject,
37+
configBasedir: fixturesPath,
38+
});
39+
40+
expect(typeof linted.output).toBe('string');
41+
expect(linted.results).toHaveLength(1);
42+
expect(linted.results[0].warnings).toHaveLength(1);
43+
expect(linted.results[0].warnings[0].rule).toBe('block-no-empty');
44+
});
45+
3246
it('recursive extending', async () => {
3347
const linted = await standalone({
3448
code: 'a {}',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default {
2+
rules: {
3+
'block-no-empty': true,
4+
},
5+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import configBlockNoEmpty from './config-block-no-empty.mjs';
2+
3+
export default {
4+
extends: configBlockNoEmpty,
5+
};

‎lib/augmentConfig.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,13 @@ async function extendConfig(stylelint, config, configDir, rootConfigDir, filePat
178178
let resultConfig = originalWithoutExtends;
179179

180180
for (const extendLookup of normalizedExtends) {
181-
const extendResult = await loadExtendedConfig(stylelint, configDir, extendLookup);
181+
let extendResult;
182+
183+
if (typeof extendLookup === 'string') {
184+
extendResult = await loadExtendedConfig(stylelint, configDir, extendLookup);
185+
} else if (typeof extendLookup === 'object' && extendLookup !== null) {
186+
extendResult = { config: extendLookup };
187+
}
182188

183189
if (extendResult) {
184190
let extendResultConfig = extendResult.config;

0 commit comments

Comments
 (0)
Please sign in to comment.