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

feat(linter): add error and warning statistics #18313

Merged
merged 1 commit into from
Feb 1, 2024
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
4 changes: 2 additions & 2 deletions e2e/angular-core/src/ng-add.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,14 +411,14 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {

let output = runCLI(`lint ${project}`);
expect(output).toContain(`> nx run ${project}:lint`);
expect(output).toContain('All files pass linting.');
expect(output).toContain('All files pass linting');
expect(output).toContain(
`Successfully ran target lint for project ${project}`
);

output = runCLI(`lint ${project}`);
expect(output).toContain(`> nx run ${project}:lint [local cache]`);
expect(output).toContain('All files pass linting.');
expect(output).toContain('All files pass linting');
expect(output).toContain(
`Successfully ran target lint for project ${project}`
);
Expand Down
4 changes: 2 additions & 2 deletions e2e/expo/src/expo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ describe('expo', () => {
expectTestsPass(await runCLIAsync(`test ${libName}`));

const appLintResults = await runCLIAsync(`lint ${appName}`);
expect(appLintResults.combinedOutput).toContain('All files pass linting.');
expect(appLintResults.combinedOutput).toContain('All files pass linting');

const libLintResults = await runCLIAsync(`lint ${libName}`);
expect(libLintResults.combinedOutput).toContain('All files pass linting.');
expect(libLintResults.combinedOutput).toContain('All files pass linting');
});

it('should serve with metro', async () => {
Expand Down
2 changes: 1 addition & 1 deletion e2e/js/src/js-generators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('js e2e', () => {
const result = runCLI(`lint ${dirName}-${libName}`);

expect(result).toContain(`Linting "${dirName}-${libName}"...`);
expect(result).toContain('All files pass linting.');
expect(result).toContain('All files pass linting');

// Test
const testResult = await runCLIAsync(`test ${dirName}-${libName}`);
Expand Down
2 changes: 1 addition & 1 deletion e2e/next-core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function checkApp(

if (opts.checkLint) {
const lintResults = runCLI(`lint ${appName}`);
expect(lintResults).toContain('All files pass linting.');
expect(lintResults).toContain('All files pass linting');
}

if (opts.checkUnitTest) {
Expand Down
2 changes: 1 addition & 1 deletion e2e/next-extensions/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function checkApp(

if (opts.checkLint) {
const lintResults = runCLI(`lint ${appName}`);
expect(lintResults).toContain('All files pass linting.');
expect(lintResults).toContain('All files pass linting');
}

if (opts.checkUnitTest) {
Expand Down
16 changes: 8 additions & 8 deletions e2e/node/src/node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('Node Applications', () => {
setMaxWorkers(join('apps', nodeapp, 'project.json'));

const lintResults = runCLI(`lint ${nodeapp}`);
expect(lintResults).toContain('All files pass linting.');
expect(lintResults).toContain('All files pass linting');

updateFile(`apps/${nodeapp}/src/main.ts`, `console.log('Hello World!');`);
await runCLIAsync(`build ${nodeapp}`);
Expand Down Expand Up @@ -100,7 +100,7 @@ describe('Node Applications', () => {
setMaxWorkers(join('apps', nodeapp, 'project.json'));

const lintResults = runCLI(`lint ${nodeapp}`);
expect(lintResults).toContain('All files pass linting.');
expect(lintResults).toContain('All files pass linting');

updateJson(join('apps', nodeapp, 'project.json'), (config) => {
config.targets.build.options.additionalEntryPoints = [
Expand Down Expand Up @@ -194,7 +194,7 @@ describe('Node Applications', () => {
runCLI(`generate @nx/express:app ${nodeapp} --linter=eslint`);
setMaxWorkers(join('apps', nodeapp, 'project.json'));
const lintResults = runCLI(`lint ${nodeapp}`);
expect(lintResults).toContain('All files pass linting.');
expect(lintResults).toContain('All files pass linting');

updateFile(
`apps/${nodeapp}/src/app/test.spec.ts`,
Expand Down Expand Up @@ -237,7 +237,7 @@ describe('Node Applications', () => {
setMaxWorkers(join('apps', nestapp, 'project.json'));

const lintResults = runCLI(`lint ${nestapp}`);
expect(lintResults).toContain('All files pass linting.');
expect(lintResults).toContain('All files pass linting');

updateFile(`apps/${nestapp}/src/assets/file.txt`, ``);
const jestResult = await runCLIAsync(`test ${nestapp}`);
Expand Down Expand Up @@ -590,7 +590,7 @@ ${jslib}();
runCLI(`generate @nx/nest:lib ${nestlib}`);

const lintResults = runCLI(`lint ${nestlib}`);
expect(lintResults).toContain('All files pass linting.');
expect(lintResults).toContain('All files pass linting');

const testResults = runCLI(`test ${nestlib}`);
expect(testResults).toContain(
Expand All @@ -604,7 +604,7 @@ ${jslib}();
runCLI(`generate @nx/nest:lib ${nestlib} --service`);

const lintResults = runCLI(`lint ${nestlib}`);
expect(lintResults).toContain('All files pass linting.');
expect(lintResults).toContain('All files pass linting');

const jestResult = await runCLIAsync(`test ${nestlib}`);
expect(jestResult.combinedOutput).toContain(
Expand All @@ -618,7 +618,7 @@ ${jslib}();
runCLI(`generate @nx/nest:lib ${nestlib} --controller`);

const lintResults = runCLI(`lint ${nestlib}`);
expect(lintResults).toContain('All files pass linting.');
expect(lintResults).toContain('All files pass linting');

const jestResult = await runCLIAsync(`test ${nestlib}`);
expect(jestResult.combinedOutput).toContain(
Expand All @@ -632,7 +632,7 @@ ${jslib}();
runCLI(`generate @nx/nest:lib ${nestlib} --controller --service`);

const lintResults = runCLI(`lint ${nestlib}`);
expect(lintResults).toContain('All files pass linting.');
expect(lintResults).toContain('All files pass linting');

const jestResult = await runCLIAsync(`test ${nestlib}`);
expect(jestResult.combinedOutput).toContain(
Expand Down
8 changes: 4 additions & 4 deletions e2e/plugin/src/nx-plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('Nx Plugin', () => {
`generate @nx/plugin:plugin ${plugin} --linter=eslint --e2eTestRunner=jest --publishable`
);
const lintResults = runCLI(`lint ${plugin}`);
expect(lintResults).toContain('All files pass linting.');
expect(lintResults).toContain('All files pass linting');

const buildResults = runCLI(`build ${plugin}`);
expect(buildResults).toContain('Done compiling TypeScript files');
Expand All @@ -63,7 +63,7 @@ describe('Nx Plugin', () => {
);

const lintResults = runCLI(`lint ${plugin}`);
expect(lintResults).toContain('All files pass linting.');
expect(lintResults).toContain('All files pass linting');

expectTestsPass(await runCLIAsync(`test ${plugin}`));

Expand Down Expand Up @@ -93,7 +93,7 @@ describe('Nx Plugin', () => {
runCLI(`generate @nx/plugin:generator ${generator} --project=${plugin}`);

const lintResults = runCLI(`lint ${plugin}`);
expect(lintResults).toContain('All files pass linting.');
expect(lintResults).toContain('All files pass linting');

expectTestsPass(await runCLIAsync(`test ${plugin}`));

Expand Down Expand Up @@ -130,7 +130,7 @@ describe('Nx Plugin', () => {
);

const lintResults = runCLI(`lint ${plugin}`);
expect(lintResults).toContain('All files pass linting.');
expect(lintResults).toContain('All files pass linting');

expectTestsPass(await runCLIAsync(`test ${plugin}`));

Expand Down
6 changes: 3 additions & 3 deletions e2e/react-core/src/react.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,14 @@ describe('React Applications', () => {
runCLI(`g @nx/react:redux orange --project=${libName} --skipFormat`);

let lintResults = runCLI(`lint ${appName}`);
expect(lintResults).toContain('All files pass linting.');
expect(lintResults).toContain('All files pass linting');
const appTestResults = await runCLIAsync(`test ${appName}`);
expect(appTestResults.combinedOutput).toContain(
'Test Suites: 2 passed, 2 total'
);

lintResults = runCLI(`lint ${libName}`);
expect(lintResults).toContain('All files pass linting.');
expect(lintResults).toContain('All files pass linting');
const libTestResults = await runCLIAsync(`test ${libName}`);
expect(libTestResults.combinedOutput).toContain(
'Test Suites: 2 passed, 2 total'
Expand Down Expand Up @@ -443,7 +443,7 @@ async function testGeneratedApp(
) {
if (opts.checkLinter) {
const lintResults = runCLI(`lint ${appName}`);
expect(lintResults).toContain('All files pass linting.');
expect(lintResults).toContain('All files pass linting');
}

runCLI(
Expand Down
4 changes: 2 additions & 2 deletions e2e/react-native/src/react-native.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ describe('react native', () => {
expectTestsPass(await runCLIAsync(`test ${libName}`));

const appLintResults = await runCLIAsync(`lint ${appName}`);
expect(appLintResults.combinedOutput).toContain('All files pass linting.');
expect(appLintResults.combinedOutput).toContain('All files pass linting');

const libLintResults = await runCLIAsync(`lint ${libName}`);
expect(libLintResults.combinedOutput).toContain('All files pass linting.');
expect(libLintResults.combinedOutput).toContain('All files pass linting');
});

it('should run e2e for cypress', async () => {
Expand Down
4 changes: 2 additions & 2 deletions e2e/web/src/web-vite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('Web Components Applications with bundler set as vite', () => {
setMaxWorkers(join('apps', appName, 'project.json'));

const lintResults = runCLI(`lint ${appName}`);
expect(lintResults).toContain('All files pass linting.');
expect(lintResults).toContain('All files pass linting');

runCLI(`build ${appName}`);
checkFilesExist(`dist/apps/${appName}/index.html`);
Expand All @@ -35,7 +35,7 @@ describe('Web Components Applications with bundler set as vite', () => {

const lintE2eResults = runCLI(`lint ${appName}-e2e`);

expect(lintE2eResults).toContain('All files pass linting.');
expect(lintE2eResults).toContain('All files pass linting');

if (isNotWindows() && runE2ETests()) {
const e2eResults = runCLI(`e2e ${appName}-e2e --no-watch`);
Expand Down
6 changes: 3 additions & 3 deletions e2e/web/src/web.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('Web Components Applications', () => {
setMaxWorkers(join('apps', appName, 'project.json'));

const lintResults = runCLI(`lint ${appName}`);
expect(lintResults).toContain('All files pass linting.');
expect(lintResults).toContain('All files pass linting');

const testResults = await runCLIAsync(`test ${appName}`);

Expand All @@ -42,7 +42,7 @@ describe('Web Components Applications', () => {
);
const lintE2eResults = runCLI(`lint ${appName}-e2e`);

expect(lintE2eResults).toContain('All files pass linting.');
expect(lintE2eResults).toContain('All files pass linting');

if (isNotWindows() && runE2ETests()) {
const e2eResults = runCLI(`e2e ${appName}-e2e --no-watch`);
Expand Down Expand Up @@ -110,7 +110,7 @@ describe('Web Components Applications', () => {

const lintE2eResults = runCLI(`lint ${appName}-e2e`);

expect(lintE2eResults).toContain('All files pass linting.');
expect(lintE2eResults).toContain('All files pass linting');

if (isNotWindows() && runE2ETests()) {
ensurePlaywrightBrowsersInstallation();
Expand Down
66 changes: 47 additions & 19 deletions packages/eslint/src/executors/lint/lint.impl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,45 @@ describe('Linter Builder', () => {
}),
mockContext
);
expect(console.error).toHaveBeenCalledWith(
'Lint errors found in the listed files.\n'
expect(console.info).toHaveBeenCalledWith(
'✖ 14 problems (4 errors, 10 warnings)\n'
);
});

it('should log fixable errors or warnings', async () => {
mockReports = [
{
errorCount: 2,
warningCount: 4,
fixableErrorCount: 1,
fixableWarningCount: 2,
results: [],
usedDeprecatedRules: [],
},
{
errorCount: 3,
warningCount: 6,
fixableErrorCount: 2,
fixableWarningCount: 4,
results: [],
usedDeprecatedRules: [],
},
];
setupMocks();
await lintExecutor(
createValidRunBuilderOptions({
eslintConfig: './.eslintrc.json',
lintFilePatterns: ['includedFile1'],
format: 'json',
silent: false,
}),
mockContext
);
expect(console.info).toHaveBeenCalledWith(
'✖ 15 problems (5 errors, 10 warnings)\n'
);
expect(console.warn).toHaveBeenCalledWith(
'Lint warnings found in the listed files.\n'
expect(console.info).toHaveBeenCalledWith(
' 3 errors and 6 warnings are potentially fixable with the `--fix` option.\n'
);
});

Expand Down Expand Up @@ -375,13 +409,13 @@ Please see https://nx.dev/guides/eslint for full guidance on how to resolve this
}),
mockContext
);
expect(console.error).not.toHaveBeenCalledWith(
'Lint errors found in the listed files.\n'
expect(console.info).not.toHaveBeenCalledWith(
'✖ 0 problems (0 errors, 0 warnings)\n'
);
expect(console.warn).not.toHaveBeenCalledWith(
'Lint warnings found in the listed files.\n'
expect(console.info).not.toHaveBeenCalledWith(
' 0 errors and 0 warnings are potentially fixable with the `--fix` option.\n'
);
expect(console.info).toHaveBeenCalledWith('All files pass linting.\n');
expect(console.info).toHaveBeenCalledWith('All files pass linting\n');
});

it('should not log warnings if the quiet flag was passed', async () => {
Expand Down Expand Up @@ -486,11 +520,8 @@ Please see https://nx.dev/guides/eslint for full guidance on how to resolve this
}),
mockContext
);
expect(console.error).toHaveBeenCalledWith(
'Lint errors found in the listed files.\n'
);
expect(console.warn).not.toHaveBeenCalledWith(
'Lint warnings found in the listed files.\n'
expect(console.info).toHaveBeenCalledWith(
'✖ 4 problems (4 errors, 0 warnings)\n'
);
});
it('should not log if the silent flag was passed', async () => {
Expand Down Expand Up @@ -518,11 +549,8 @@ Please see https://nx.dev/guides/eslint for full guidance on how to resolve this
}),
mockContext
);
expect(console.error).not.toHaveBeenCalledWith(
'Lint errors found in the listed files.\n'
);
expect(console.warn).not.toHaveBeenCalledWith(
'Lint warnings found in the listed files.\n'
expect(console.info).not.toHaveBeenCalledWith(
'✖ 14 problems (4 errors, 10 warnings)\n'
);
});
});
Expand Down
Loading