Skip to content

Commit

Permalink
Fix bug where lint was incorrectly counting errors (#781)
Browse files Browse the repository at this point in the history
* Fix bug where it was incorrectly detecting lint errors

* Print the number of lint errors and warnings
  • Loading branch information
clintonfeng-airtasker authored Apr 1, 2020
1 parent 17b7059 commit 1e34364
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 12 deletions.
18 changes: 12 additions & 6 deletions cli/src/commands/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
37 changes: 33 additions & 4 deletions lib/src/linting/find-lint-violations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand All @@ -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 = [
Expand Down
4 changes: 2 additions & 2 deletions lib/src/linting/find-lint-violations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 1e34364

Please sign in to comment.