Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support JS objects for extends config option #6998

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,
Mouvedia marked this conversation as resolved.
Show resolved Hide resolved
};
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') {
Mouvedia marked this conversation as resolved.
Show resolved Hide resolved
extendResult = await loadExtendedConfig(stylelint, configDir, extendLookup);
} else if (typeof extendLookup === 'object' && extendLookup !== null) {
extendResult = { config: extendLookup };
}

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