Skip to content

Commit

Permalink
Add support JS objects for extends config option (#6998)
Browse files Browse the repository at this point in the history
Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com>
  • Loading branch information
fpetrakov and ybiquitous committed Jul 4, 2023
1 parent 888192d commit 59d5bf9
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/gorgeous-cobras-beam.md
@@ -0,0 +1,5 @@
---
"stylelint": minor
---

Added: support for JS objects with `extends` config option
14 changes: 14 additions & 0 deletions lib/__tests__/extends.test.mjs
@@ -1,5 +1,6 @@
import { fileURLToPath } from 'node:url';

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

it('basic extending with object', async () => {
const linted = await standalone({
code: 'a {}',
config: configExtendingWithObject,
configBasedir: fixturesPath,
});

expect(typeof linted.output).toBe('string');
expect(linted.results).toHaveLength(1);
expect(linted.results[0].warnings).toHaveLength(1);
expect(linted.results[0].warnings[0].rule).toBe('block-no-empty');
});

it('recursive extending', async () => {
const linted = await standalone({
code: 'a {}',
Expand Down
5 changes: 5 additions & 0 deletions lib/__tests__/fixtures/config-block-no-empty.mjs
@@ -0,0 +1,5 @@
export default {
rules: {
'block-no-empty': true,
},
};
5 changes: 5 additions & 0 deletions lib/__tests__/fixtures/config-extending-with-object.mjs
@@ -0,0 +1,5 @@
import configBlockNoEmpty from './config-block-no-empty.mjs';

export default {
extends: configBlockNoEmpty,
};
8 changes: 7 additions & 1 deletion lib/augmentConfig.js
Expand Up @@ -178,7 +178,13 @@ async function extendConfig(stylelint, config, configDir, rootConfigDir, filePat
let resultConfig = originalWithoutExtends;

for (const extendLookup of normalizedExtends) {
const extendResult = await loadExtendedConfig(stylelint, configDir, extendLookup);
let extendResult;

if (typeof extendLookup === 'string') {
extendResult = await loadExtendedConfig(stylelint, configDir, extendLookup);
} else if (typeof extendLookup === 'object' && extendLookup !== null) {
extendResult = { config: extendLookup };
}

if (extendResult) {
let extendResultConfig = extendResult.config;
Expand Down

0 comments on commit 59d5bf9

Please sign in to comment.