diff --git a/cli/src/commands/lint.ts b/cli/src/commands/lint.ts index 05313cfcc..66a9a480f 100644 --- a/cli/src/commands/lint.ts +++ b/cli/src/commands/lint.ts @@ -43,12 +43,18 @@ export default class Lint extends Command { const contract = parse(contractPath); const groupedLintErrors = lint(contract); - const { errorCount } = findLintViolations(groupedLintErrors, lintConfig, { - error: (msg: string) => { - this.error(msg, { exit: false }); - }, - warn: this.warn - }); + const { errorCount, warningCount } = findLintViolations( + groupedLintErrors, + lintConfig, + { + error: (msg: string) => { + this.error(msg, { exit: false }); + }, + warn: this.warn + } + ); + + this.log(`Found ${errorCount} errors and ${warningCount} warnings`); if (errorCount > 0) { process.exit(1); diff --git a/lib/src/linting/find-lint-violations.spec.ts b/lib/src/linting/find-lint-violations.spec.ts index 29782d17a..2cdab5fe8 100644 --- a/lib/src/linting/find-lint-violations.spec.ts +++ b/lib/src/linting/find-lint-violations.spec.ts @@ -176,12 +176,10 @@ describe("find lint violations", () => { }); }); - describe("when there are no lint violations", () => { + describe("when there are no lint rules", () => { beforeEach(() => { const spotConfig = { - rules: { - error: "invalid" - } + rules: {} }; findLintViolationsResult = findLintViolations([], spotConfig, { @@ -198,6 +196,37 @@ describe("find lint violations", () => { }); }); + describe("when there are no lint violations", () => { + beforeEach(() => { + const groupedLintErrors = [ + { + name: "error", + violations: [] + } + ]; + + const spotConfig = { + rules: {} + }; + + findLintViolationsResult = findLintViolations( + groupedLintErrors, + spotConfig, + { + error: errorMock, + warn: warnMock + } + ); + }); + + it("should trigger no errors and no warnings", () => { + expect(findLintViolationsResult.errorCount).toBe(0); + expect(findLintViolationsResult.warningCount).toBe(0); + expect(errorMock).not.toBeCalled(); + expect(warnMock).not.toBeCalled(); + }); + }); + describe("when there are multiple errors and warnings", () => { beforeEach(() => { const groupedLintErrors = [ diff --git a/lib/src/linting/find-lint-violations.ts b/lib/src/linting/find-lint-violations.ts index fbfeee19b..aff7f4a21 100644 --- a/lib/src/linting/find-lint-violations.ts +++ b/lib/src/linting/find-lint-violations.ts @@ -33,16 +33,16 @@ export const findLintViolations = ( case "error": { lintingErrors.violations.forEach(lintError => { error(lintError.message); + errorCount++; }); - errorCount++; break; } case "warn": { lintingErrors.violations.forEach(lintWarning => { warn(lintWarning.message); + warningCount++; }); - warningCount++; break; }