Skip to content

Commit 67e9085

Browse files
committedOct 30, 2024
Minor refactors
1 parent 1ecf821 commit 67e9085

File tree

7 files changed

+24
-25
lines changed

7 files changed

+24
-25
lines changed
 

‎.github/ISSUE_TEMPLATE/02-regression.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ body:
66
- type: markdown
77
attributes:
88
value: |
9-
Please make sure you have read the docs and are using the latest version of Knip. Use common sense and provide the necessary information that helps me or others to help you.
9+
Please make sure you have read the docs and are using the latest version of Knip.
10+
Use common sense and provide the necessary information that helps me or others to help you.
1011
1112
A minimal reproduction is mandatory: only the code and configuration required to demonstrate the issue.
1213
- type: checkboxes

‎packages/docs/src/content/docs/guides/writing-a-plugin.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ const isEnabled: IsPluginEnabled = ({ dependencies }) =>
101101
const config = ['.nycrc', '.nycrc.json', '.nycrc.{yml,yaml}', 'nyc.config.js'];
102102

103103
const resolveConfig: ResolveConfig<NycConfig> = config => {
104-
return config?.extends ? [config.extends].flat() : [];
104+
const extend = config?.extends ?? [];
105+
const requires = config?.require ?? [];
106+
return [extend, requires].flat().map(toDeferResolve);
105107
};
106108

107109
export default {
@@ -141,10 +143,10 @@ without an extension are provided as plain text strings.
141143

142144
:::tip[Should I implement resolveConfig?]
143145

144-
You should implement `resolveConfig` if:
146+
You should implement `resolveConfig` if any of these are true:
145147

146-
- The tool supports a `config` file in JSON or YAML format, and/or
147-
- The `config` file reference dependencies as strings
148+
- The tool supports a `config` file in JSON or YAML format
149+
- The `config` file references dependencies as strings
148150

149151
:::
150152

@@ -165,7 +167,7 @@ Here's an example from the Ava test runner plugin:
165167

166168
```ts
167169
const resolveEntryPaths: ResolveEntryPaths<AvaConfig> = localConfig => {
168-
return localConfig?.files ?? [];
170+
return (localConfig?.files ?? []).map(toEntry);
169171
};
170172
```
171173

‎packages/knip/src/plugins/linthtml/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ const isEnabled: IsPluginEnabled = ({ dependencies }) => hasDependency(dependenc
1717
const config: string[] = ['package.json', ...toCosmiconfig('linthtml')];
1818

1919
const resolveConfig: ResolveConfig<PluginConfig> = config => {
20-
const extensions = [config.extends ?? []].flat();
21-
const plugins = [config.plugins ?? []].flat();
22-
return [...extensions, ...plugins].map(toDeferResolve);
20+
const extensions = config.extends ?? [];
21+
const plugins = config.plugins ?? [];
22+
return [extensions, plugins].flat().map(toDeferResolve);
2323
};
2424

2525
export default {

‎packages/knip/src/plugins/nyc/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ const isEnabled: IsPluginEnabled = ({ dependencies }) => hasDependency(dependenc
1414
const config = ['.nycrc', '.nycrc.json', '.nycrc.{yml,yaml}', 'nyc.config.js', 'package.json'];
1515

1616
const resolveConfig: ResolveConfig<NycConfig> = config => {
17-
const extend = config?.extends ? [config?.extends].flat() : [];
18-
const requires = config?.require ? [config?.require].flat() : [];
19-
return [...extend, ...requires].flat().map(toDeferResolve);
17+
const extend = config?.extends ?? [];
18+
const requires = config?.require ?? [];
19+
return [extend, requires].flat().map(toDeferResolve);
2020
};
2121

2222
export default {

‎packages/knip/src/plugins/stylelint/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ const isEnabled: IsPluginEnabled = ({ dependencies }) => hasDependency(dependenc
1515
const config = ['package.json', ...toCosmiconfig('stylelint')];
1616

1717
const resolve = (config: StyleLintConfig | BaseStyleLintConfig): Input[] => {
18-
const extend = config.extends ? [config.extends].flat() : [];
19-
const plugins = config.plugins ? [config.plugins].flat() : [];
18+
const extend = config.extends ?? [];
19+
const plugins = config.plugins ?? [];
2020
const customSyntax = config.customSyntax ? [config.customSyntax] : [];
2121
const overrideConfigs = 'overrides' in config ? config.overrides.flatMap(resolve) : [];
22-
return [...[...extend, ...plugins, ...customSyntax].map(toDeferResolve), ...overrideConfigs];
22+
return [...[extend, plugins, customSyntax].flat().map(toDeferResolve), ...overrideConfigs];
2323
};
2424

2525
const resolveConfig: ResolveConfig<StyleLintConfig> = config => resolve(config);

‎packages/knip/src/plugins/travis/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ const config = ['.travis.yml'];
1414
const resolveConfig: ResolveConfig = async (config, options) => {
1515
if (!config) return [];
1616

17-
const beforeDeploy = [config.before_deploy ?? []].flat();
18-
const beforeInstall = [config.before_install ?? []].flat();
19-
const beforeScript = [config.before_script ?? []].flat();
17+
const beforeDeploy = config.before_deploy ?? [];
18+
const beforeInstall = config.before_install ?? [];
19+
const beforeScript = config.before_script ?? [];
2020

21-
const scripts = [...beforeDeploy, ...beforeInstall, ...beforeScript];
21+
const scripts = [beforeDeploy, beforeInstall, beforeScript].flat();
2222

2323
return options.getInputsFromScripts(scripts, { knownBinsOnly: true });
2424
};

‎packages/knip/src/plugins/vitest/index.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,8 @@ const findConfigDependencies = (localConfig: ViteConfig, options: PluginOptions)
4242
const coverage = hasCoverageEnabled ? [`@vitest/coverage-${testConfig.coverage?.provider ?? 'v8'}`] : [];
4343

4444
const dir = join(configFileDir, testConfig.root ?? '.');
45-
const setupFiles = [testConfig.setupFiles ?? []].flat().map(specifier => {
46-
return { ...toDeferResolve(specifier), dir };
47-
});
48-
const globalSetup = [testConfig.globalSetup ?? []].flat().map(specifier => {
49-
return { ...toDeferResolve(specifier), dir };
50-
});
45+
const setupFiles = [testConfig.setupFiles ?? []].flat().map(specifier => ({ ...toDeferResolve(specifier), dir }));
46+
const globalSetup = [testConfig.globalSetup ?? []].flat().map(specifier => ({ ...toDeferResolve(specifier), dir }));
5147

5248
return [...[...environments, ...reporters, ...coverage].map(toDependency), ...setupFiles, ...globalSetup];
5349
};

0 commit comments

Comments
 (0)
Please sign in to comment.