From 62e44d39711dc2323e58029993b8f2a16145515f Mon Sep 17 00:00:00 2001 From: dbale-altoros Date: Mon, 13 May 2024 11:04:24 -0300 Subject: [PATCH] fixed retported errors on several contracts --- CHANGELOG.md | 6 ++++++ docker/Dockerfile | 2 +- e2e/test.js | 24 ++++++++++++++++-------- package.json | 2 +- solhint.js | 11 ++++++----- 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51ae795e..ce343433 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## [5.0.1] - 2024-05-13 +### BREAKING CHANGES (refer to v5.0.0) +Fixed an issue on the returining values where only was evaluating the first report instead of all of them. + + +

## [5.0.0] - 2024-05-11 ### BREAKING CHANGES diff --git a/docker/Dockerfile b/docker/Dockerfile index 5c5cb0f1..e5d2f8c0 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,5 +1,5 @@ FROM node:20-alpine LABEL maintainer="diego.bale@protofire.io" -ENV VERSION=5.0.0 +ENV VERSION=5.0.1 RUN npm install -g solhint@"$VERSION" \ No newline at end of file diff --git a/e2e/test.js b/e2e/test.js index e6c69ef0..2d77e757 100644 --- a/e2e/test.js +++ b/e2e/test.js @@ -86,7 +86,7 @@ describe('e2e', function () { it('should show warning when using --init', function () { const { code, stderr } = shell.exec(`${NODE}solhint --init`) - + expect(code).to.equal(EXIT_CODES.BAD_OPTIONS) expect(stderr).to.include('Configuration file already exists') }) @@ -96,12 +96,12 @@ describe('e2e', function () { const PATH = '03-no-empty-blocks' const { PREFIX, SUFFIX } = prepareContext(PATH) - it('No contracts to lint should fail with appropiate message', function () { - const { code, stderr } = shell.exec(`${NODE}solhint Foo1.sol ${SUFFIX}`) - - expect(code).to.equal(EXIT_CODES.BAD_OPTIONS) - expect(stderr).to.include('No files to lint!') - }) + it('No contracts to lint should fail with appropiate message', function () { + const { code, stderr } = shell.exec(`${NODE}solhint Foo1.sol ${SUFFIX}`) + + expect(code).to.equal(EXIT_CODES.BAD_OPTIONS) + expect(stderr).to.include('No files to lint!') + }) it('should end with REPORTED_ERRORS = 1 because report contains errors', function () { const { code, stdout } = shell.exec(`${NODE}solhint ${PREFIX}Foo.sol ${SUFFIX}`) @@ -193,6 +193,14 @@ describe('e2e', function () { expect(code).to.equal(EXIT_CODES.REPORTED_ERRORS) }) + + it('should exit with code 1 if one of evaluated contracts contains errors', function () { + const { code } = shell.exec( + `${NODE}solhint ${PREFIX}contracts/Foo.sol ${PREFIX}contracts/Foo2.sol ${SUFFIX}` + ) + + expect(code).to.equal(EXIT_CODES.REPORTED_ERRORS) + }) }) describe('Linter - foundry-test-functions with shell', () => { @@ -211,7 +219,7 @@ describe('e2e', function () { it(`should raise error for wrongFunctionDefinitionName() only`, () => { const SUFFIX2 = `-c ${PREFIX}test/.solhint.json --disc` - + const { code, stdout } = shell.exec(`${NODE}solhint ${PREFIX}test/FooTest.sol ${SUFFIX2}`) expect(code).to.equal(EXIT_CODES.REPORTED_ERRORS) diff --git a/package.json b/package.json index 5f2783f0..35199efd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "solhint", - "version": "5.0.0", + "version": "5.0.1", "description": "Solidity Code Linter", "main": "lib/index.js", "keywords": [ diff --git a/solhint.js b/solhint.js index 9eb0b95f..bb5b617d 100755 --- a/solhint.js +++ b/solhint.js @@ -180,9 +180,10 @@ function executeMainActionLogic() { printReports(reports, formatterFn) - if (reports[0].errorCount > 0) process.exit(EXIT_CODES.REPORTED_ERRORS) + // check if there's any error reported + const reportedErrors = reports.some((obj) => obj.errorCount > 0) - process.exit(EXIT_CODES.OK) + process.exit(reportedErrors ? EXIT_CODES.REPORTED_ERRORS : EXIT_CODES.OK) } function processStdin(options) { @@ -201,12 +202,12 @@ function processStdin(options) { } const reports = [report] - printReports(reports, formatterFn) - if (reports[0].errorCount > 0) process.exit(EXIT_CODES.REPORTED_ERRORS) + // check if there's any error reported + const reportedErrors = reports.some((obj) => obj.errorCount > 0) - process.exit(EXIT_CODES.OK) + process.exit(reportedErrors ? EXIT_CODES.REPORTED_ERRORS : EXIT_CODES.OK) } function writeSampleConfigFile() {