From e39550002da63ab8639cd8bf1016fa1a9da6921b Mon Sep 17 00:00:00 2001 From: Duncan Thacker Date: Fri, 4 Oct 2024 20:29:50 +0100 Subject: [PATCH 1/4] #799 stylelint customSyntax config field indicates dependency usage --- packages/knip/src/plugins/stylelint/index.ts | 7 ++++--- packages/knip/src/plugins/stylelint/types.ts | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/knip/src/plugins/stylelint/index.ts b/packages/knip/src/plugins/stylelint/index.ts index 794611228..119988172 100644 --- a/packages/knip/src/plugins/stylelint/index.ts +++ b/packages/knip/src/plugins/stylelint/index.ts @@ -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 = config => resolve(config); diff --git a/packages/knip/src/plugins/stylelint/types.ts b/packages/knip/src/plugins/stylelint/types.ts index 4bae02528..10e37c971 100644 --- a/packages/knip/src/plugins/stylelint/types.ts +++ b/packages/knip/src/plugins/stylelint/types.ts @@ -1,4 +1,5 @@ export type BaseStyleLintConfig = { + customSyntax?: string; extends?: string | string[]; plugins?: string[]; }; From 64788839222cbef73f47952d36acd6696fd37740 Mon Sep 17 00:00:00 2001 From: Duncan Thacker Date: Fri, 4 Oct 2024 20:37:44 +0100 Subject: [PATCH 2/4] #799 add test case for customSyntax field --- packages/knip/fixtures/plugins/stylelint/.stylelintrc | 1 + packages/knip/test/plugins/stylelint.test.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/knip/fixtures/plugins/stylelint/.stylelintrc b/packages/knip/fixtures/plugins/stylelint/.stylelintrc index a8f56ffc5..bf1e4f402 100644 --- a/packages/knip/fixtures/plugins/stylelint/.stylelintrc +++ b/packages/knip/fixtures/plugins/stylelint/.stylelintrc @@ -1,4 +1,5 @@ { + "customsyntax": "postcss-less", "extends": ["stylelint-config-standard", "./myExtendableConfig"], "plugins": ["stylelint-order"], "rules": { diff --git a/packages/knip/test/plugins/stylelint.test.ts b/packages/knip/test/plugins/stylelint.test.ts index 8066a7219..f1036de5b 100644 --- a/packages/knip/test/plugins/stylelint.test.ts +++ b/packages/knip/test/plugins/stylelint.test.ts @@ -14,6 +14,7 @@ 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']); From 503119216280186f37789fb40821cfad5350ebf3 Mon Sep 17 00:00:00 2001 From: Duncan Thacker Date: Fri, 4 Oct 2024 20:38:44 +0100 Subject: [PATCH 3/4] #799 fix incorrect test fixture --- packages/knip/fixtures/plugins/stylelint/.stylelintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/knip/fixtures/plugins/stylelint/.stylelintrc b/packages/knip/fixtures/plugins/stylelint/.stylelintrc index bf1e4f402..d226d0bc9 100644 --- a/packages/knip/fixtures/plugins/stylelint/.stylelintrc +++ b/packages/knip/fixtures/plugins/stylelint/.stylelintrc @@ -1,5 +1,5 @@ { - "customsyntax": "postcss-less", + "customSyntax": "postcss-less", "extends": ["stylelint-config-standard", "./myExtendableConfig"], "plugins": ["stylelint-order"], "rules": { From 32acb885928e28b74eeb258a67e7f40c7409956e Mon Sep 17 00:00:00 2001 From: Duncan Thacker Date: Fri, 4 Oct 2024 20:52:45 +0100 Subject: [PATCH 4/4] fix incorrect test --- packages/knip/test/plugins/stylelint.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/knip/test/plugins/stylelint.test.ts b/packages/knip/test/plugins/stylelint.test.ts index f1036de5b..f0b86a921 100644 --- a/packages/knip/test/plugins/stylelint.test.ts +++ b/packages/knip/test/plugins/stylelint.test.ts @@ -22,7 +22,7 @@ test('Find dependencies with the stylelint plugin', async () => { assert.deepEqual(counters, { ...baseCounters, devDependencies: 1, - unlisted: 3, + unlisted: 4, processed: 0, total: 0, });