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

Fixed reported_errors exit code on several contracts #580

Merged
merged 1 commit into from
May 13, 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.


<br><br>
## [5.0.0] - 2024-05-11
### BREAKING CHANGES

Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM node:20-alpine
LABEL maintainer="[email protected]"
ENV VERSION=5.0.0
ENV VERSION=5.0.1

RUN npm install -g solhint@"$VERSION"
24 changes: 16 additions & 8 deletions e2e/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
Expand All @@ -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}`)
Expand Down Expand Up @@ -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', () => {
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "solhint",
"version": "5.0.0",
"version": "5.0.1",
"description": "Solidity Code Linter",
"main": "lib/index.js",
"keywords": [
Expand Down
11 changes: 6 additions & 5 deletions solhint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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() {
Expand Down
Loading