Skip to content

Commit

Permalink
Stylelint plugin - fix issue where "customSyntax" property is not rec…
Browse files Browse the repository at this point in the history
…ognised as a resolved dependency (#802)
  • Loading branch information
duncan-thacker authored Oct 4, 2024
1 parent d9ae5dc commit fdb0246
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/knip/fixtures/plugins/stylelint/.stylelintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"customSyntax": "postcss-less",
"extends": ["stylelint-config-standard", "./myExtendableConfig"],
"plugins": ["stylelint-order"],
"rules": {
Expand Down
7 changes: 4 additions & 3 deletions packages/knip/src/plugins/stylelint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ const isEnabled: IsPluginEnabled = ({ dependencies }) => hasDependency(dependenc
const config = ['package.json', ...toCosmiconfig('stylelint')];

const resolve = (config: StyleLintConfig | BaseStyleLintConfig): string[] => {
const extend = config.extends ? [config.extends].flat().filter(id => !isInternal(id)) : [];
const plugins = config.plugins ? [config.plugins].flat().filter(id => !isInternal(id)) : [];
const extend = config.extends ? [config.extends].flat() : [];
const plugins = config.plugins ? [config.plugins].flat() : [];
const customSyntax = config.customSyntax ? [config.customSyntax] : [];
const overrideConfigs = 'overrides' in config ? config.overrides.flatMap(resolve) : [];
return [...extend, ...plugins, ...overrideConfigs];
return [...extend, ...plugins, ...overrideConfigs, ...customSyntax].filter(id => !isInternal(id));
};

const resolveConfig: ResolveConfig<StyleLintConfig> = config => resolve(config);
Expand Down
1 change: 1 addition & 0 deletions packages/knip/src/plugins/stylelint/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export type BaseStyleLintConfig = {
customSyntax?: string;
extends?: string | string[];
plugins?: string[];
};
Expand Down
3 changes: 2 additions & 1 deletion packages/knip/test/plugins/stylelint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ test('Find dependencies with the stylelint plugin', async () => {
});

assert(issues.devDependencies['package.json']['stylelint']);
assert(issues.unlisted['.stylelintrc']['postcss-less']);
assert(issues.unlisted['.stylelintrc']['stylelint-config-standard']);
assert(issues.unlisted['.stylelintrc']['stylelint-order']);
assert(issues.unlisted['.stylelintrc']['stylelint-config-html/html']);

assert.deepEqual(counters, {
...baseCounters,
devDependencies: 1,
unlisted: 3,
unlisted: 4,
processed: 0,
total: 0,
});
Expand Down

0 comments on commit fdb0246

Please sign in to comment.