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

Stylelint plugin - fix issue where "customSyntax" property is not recognised as a resolved dependency #802

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading