Skip to content

Commit

Permalink
Only show any config hints in non-production mode
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Nov 5, 2024
1 parent 0a4c302 commit a138388
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
11 changes: 7 additions & 4 deletions packages/knip/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export const main = async (unresolvedConfiguration: CommandLineOptions) => {
const isReportTypes = report.types || report.nsTypes || report.enumMembers;
const isReportClassMembers = report.classMembers;
const isSkipLibs = !(isIncludeLibs || isReportClassMembers);
const isShowConfigHints = !workspace && !isProduction && !isHideConfigHints;

const collector = new IssueCollector({ cwd, rules, filters });

Expand Down Expand Up @@ -617,15 +618,17 @@ export const main = async (unresolvedConfiguration: CommandLineOptions) => {
deputy.removeIgnoredIssues(collector.getIssues());

// Hints about ignored dependencies/binaries can be confusing/annoying/incorrect in production/strict mode
if (!workspace && !isProduction && !isHideConfigHints) {
if (isShowConfigHints) {
const configurationHints = deputy.getConfigurationHints();
for (const hint of configurationHints) collector.addConfigurationHint(hint);
}
}

const unusedIgnoredWorkspaces = chief.getUnusedIgnoredWorkspaces();
for (const identifier of unusedIgnoredWorkspaces) {
collector.addConfigurationHint({ type: 'ignoreWorkspaces', identifier });
if (isShowConfigHints) {
const unusedIgnoredWorkspaces = chief.getUnusedIgnoredWorkspaces();
for (const identifier of unusedIgnoredWorkspaces) {
collector.addConfigurationHint({ type: 'ignoreWorkspaces', identifier });
}
}
};

Expand Down
10 changes: 3 additions & 7 deletions packages/knip/test/workspaces-nested.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@ import baseCounters from './helpers/baseCounters.js';

const cwd = resolve('fixtures/workspaces-nested');

const expectedConfigurationHintsProduction = new Set([
{ type: 'ignoreWorkspaces', identifier: 'unused-ignored-workspace' },
]);

const expectedConfigurationHints = new Set([
...expectedConfigurationHintsProduction,
{ type: 'ignoreWorkspaces', identifier: 'unused-ignored-workspace' },
{ type: 'ignoreBinaries', identifier: 'unused-ignored-bin-global', workspaceName: '.' },
{ type: 'ignoreBinaries', identifier: 'unused-ignored-bin-L-2', workspaceName: 'L-1-1/L-1-2' },
{ type: 'ignoreDependencies', identifier: 'ignored-dep-global', workspaceName: '.' },
Expand Down Expand Up @@ -68,7 +64,7 @@ test('Find unused dependencies in nested workspaces with default config in produ
total: 3,
});

assert.deepEqual(configurationHints, expectedConfigurationHintsProduction);
assert.deepEqual(configurationHints, new Set());
});

test('Find unused dependencies in nested workspaces with default config in production mode (strict)', async () => {
Expand All @@ -93,5 +89,5 @@ test('Find unused dependencies in nested workspaces with default config in produ
total: 3,
});

assert.deepEqual(configurationHints, expectedConfigurationHintsProduction);
assert.deepEqual(configurationHints, new Set());
});

0 comments on commit a138388

Please sign in to comment.