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

improvement(bit-lint) - show total instead of names for components with no lint issues #8959

Merged
merged 3 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions scopes/defender/eslint/eslint.linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export class ESLintLinter implements Linter {
totalFixableWarningCount,
totalWarningCount,
componentsResults,
isClean,
} = this.computeComponentResultsWithTotals(results);

return {
Expand All @@ -80,6 +81,7 @@ export class ESLintLinter implements Linter {
totalFixableErrorCount,
totalFixableWarningCount,
totalWarningCount,
isClean,
results: componentsResults,
};
});
Expand Down Expand Up @@ -175,13 +177,16 @@ export class ESLintLinter implements Linter {
raw: result,
};
});
const isClean = totalErrorCount === 0 && totalWarningCount === 0 && totalFatalErrorCount === 0;

return {
totalErrorCount,
totalFatalErrorCount,
totalFixableErrorCount,
totalFixableWarningCount,
totalWarningCount,
componentsResults,
isClean,
};
}

Expand All @@ -196,16 +201,19 @@ export class ESLintLinter implements Linter {
let totalComponentsWithFixableErrorCount = 0;
let totalComponentsWithFixableWarningCount = 0;
let totalComponentsWithWarningCount = 0;
let isClean = true;

componentsResults.forEach((result) => {
if (result.totalErrorCount) {
totalErrorCount += result.totalErrorCount;
totalComponentsWithErrorCount += 1;
isClean = false;
}
// @ts-ignore - missing from the @types/eslint lib
if (result.totalFatalErrorCount) {
totalFatalErrorCount += result.totalFatalErrorCount;
totalComponentsWithFatalErrorCount += 1;
isClean = false;
}
if (result.totalFixableErrorCount) {
totalFixableErrorCount += result.totalFixableErrorCount;
Expand All @@ -218,6 +226,7 @@ export class ESLintLinter implements Linter {
if (result.totalWarningCount) {
totalWarningCount += result.totalWarningCount;
totalComponentsWithWarningCount += 1;
isClean = false;
}
});
return {
Expand All @@ -232,6 +241,7 @@ export class ESLintLinter implements Linter {
totalComponentsWithFixableErrorCount,
totalComponentsWithFixableWarningCount,
totalComponentsWithWarningCount,
isClean,
};
}

Expand Down
21 changes: 18 additions & 3 deletions scopes/defender/linter/lint.cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ComponentFactory, ComponentID } from '@teambit/component';
import chalk from 'chalk';
import { EnvsExecutionResult } from '@teambit/envs';
import { Workspace } from '@teambit/workspace';
import { compact, flatten, omit } from 'lodash';
import { compact, flatten, groupBy, omit } from 'lodash';
import { LinterMain } from './linter.main.runtime';
import { ComponentLintResult, LintResults } from './linter';
import { FixTypes, LinterOptions } from './linter-context';
Expand Down Expand Up @@ -63,16 +63,31 @@ export class LintCmd implements Command {
)}'`
);

const componentsOutputs = lintResults.results
const groupedByIsClean = groupBy(lintResults.results, (res) => {
if (res.isClean !== undefined) {
return res.isClean;
}
// The is clean field was added in a later version of the linter, so if it's not there, we will calculate it
// based on the errors/warnings count
return res.totalErrorCount + (res.totalFatalErrorCount || 0) + res.totalWarningCount === 0;
});

const dirtyComponentsOutputs = (groupedByIsClean.false || [])
.map((lintRes) => {
const compTitle = chalk.bold.cyan(lintRes.componentId.toString({ ignoreVersion: true }));
const compOutput = lintRes.output;
return `${compTitle}\n${compOutput}`;
})
.join('\n');

const cleanComponentsCount = groupedByIsClean.true?.length || 0;
const cleanComponentsOutput = cleanComponentsCount
? `total of ${chalk.green(cleanComponentsCount.toString())} component(s) has no linting issues`
: '';

const summary = this.getSummarySection(data);
return { code, data: `${title}\n\n${componentsOutputs}\n\n${summary}` };
const finalOutput = compact([title, dirtyComponentsOutputs, cleanComponentsOutput, summary]).join('\n\n');
return { code, data: finalOutput };
}

private getSummarySection(data: JsonLintResultsData) {
Expand Down
10 changes: 10 additions & 0 deletions scopes/defender/linter/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ export type ComponentLintResult = {
*/
totalWarningCount: number;

/**
* whether the component is clean (have no issues at all)
*/
isClean: boolean;

/**
* lint results for each one of the component files
*/
Expand Down Expand Up @@ -147,6 +152,11 @@ export type LintResults = {
totalComponentsWithFixableWarningCount?: number;
totalComponentsWithWarningCount: number;

/**
* whether all the linted components is clean (have no issues at all)
*/
isClean: boolean;

errors: Error[];
};

Expand Down