Skip to content

Commit 2f96ff4

Browse files
Merge pull request #580 from protofire/fix-exit-codes-v2
Fixed reported_errors exit code on several contracts
2 parents 82944cf + 62e44d3 commit 2f96ff4

File tree

5 files changed

+30
-15
lines changed

5 files changed

+30
-15
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## [5.0.1] - 2024-05-13
2+
### BREAKING CHANGES (refer to v5.0.0)
3+
Fixed an issue on the returining values where only was evaluating the first report instead of all of them.
4+
5+
6+
<br><br>
17
## [5.0.0] - 2024-05-11
28
### BREAKING CHANGES
39

docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FROM node:20-alpine
22
LABEL maintainer="[email protected]"
3-
ENV VERSION=5.0.0
3+
ENV VERSION=5.0.1
44

55
RUN npm install -g solhint@"$VERSION"

e2e/test.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ describe('e2e', function () {
8686

8787
it('should show warning when using --init', function () {
8888
const { code, stderr } = shell.exec(`${NODE}solhint --init`)
89-
89+
9090
expect(code).to.equal(EXIT_CODES.BAD_OPTIONS)
9191
expect(stderr).to.include('Configuration file already exists')
9292
})
@@ -96,12 +96,12 @@ describe('e2e', function () {
9696
const PATH = '03-no-empty-blocks'
9797
const { PREFIX, SUFFIX } = prepareContext(PATH)
9898

99-
it('No contracts to lint should fail with appropiate message', function () {
100-
const { code, stderr } = shell.exec(`${NODE}solhint Foo1.sol ${SUFFIX}`)
101-
102-
expect(code).to.equal(EXIT_CODES.BAD_OPTIONS)
103-
expect(stderr).to.include('No files to lint!')
104-
})
99+
it('No contracts to lint should fail with appropiate message', function () {
100+
const { code, stderr } = shell.exec(`${NODE}solhint Foo1.sol ${SUFFIX}`)
101+
102+
expect(code).to.equal(EXIT_CODES.BAD_OPTIONS)
103+
expect(stderr).to.include('No files to lint!')
104+
})
105105

106106
it('should end with REPORTED_ERRORS = 1 because report contains errors', function () {
107107
const { code, stdout } = shell.exec(`${NODE}solhint ${PREFIX}Foo.sol ${SUFFIX}`)
@@ -193,6 +193,14 @@ describe('e2e', function () {
193193

194194
expect(code).to.equal(EXIT_CODES.REPORTED_ERRORS)
195195
})
196+
197+
it('should exit with code 1 if one of evaluated contracts contains errors', function () {
198+
const { code } = shell.exec(
199+
`${NODE}solhint ${PREFIX}contracts/Foo.sol ${PREFIX}contracts/Foo2.sol ${SUFFIX}`
200+
)
201+
202+
expect(code).to.equal(EXIT_CODES.REPORTED_ERRORS)
203+
})
196204
})
197205

198206
describe('Linter - foundry-test-functions with shell', () => {
@@ -211,7 +219,7 @@ describe('e2e', function () {
211219

212220
it(`should raise error for wrongFunctionDefinitionName() only`, () => {
213221
const SUFFIX2 = `-c ${PREFIX}test/.solhint.json --disc`
214-
222+
215223
const { code, stdout } = shell.exec(`${NODE}solhint ${PREFIX}test/FooTest.sol ${SUFFIX2}`)
216224

217225
expect(code).to.equal(EXIT_CODES.REPORTED_ERRORS)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "solhint",
3-
"version": "5.0.0",
3+
"version": "5.0.1",
44
"description": "Solidity Code Linter",
55
"main": "lib/index.js",
66
"keywords": [

solhint.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,10 @@ function executeMainActionLogic() {
180180

181181
printReports(reports, formatterFn)
182182

183-
if (reports[0].errorCount > 0) process.exit(EXIT_CODES.REPORTED_ERRORS)
183+
// check if there's any error reported
184+
const reportedErrors = reports.some((obj) => obj.errorCount > 0)
184185

185-
process.exit(EXIT_CODES.OK)
186+
process.exit(reportedErrors ? EXIT_CODES.REPORTED_ERRORS : EXIT_CODES.OK)
186187
}
187188

188189
function processStdin(options) {
@@ -201,12 +202,12 @@ function processStdin(options) {
201202
}
202203

203204
const reports = [report]
204-
205205
printReports(reports, formatterFn)
206206

207-
if (reports[0].errorCount > 0) process.exit(EXIT_CODES.REPORTED_ERRORS)
207+
// check if there's any error reported
208+
const reportedErrors = reports.some((obj) => obj.errorCount > 0)
208209

209-
process.exit(EXIT_CODES.OK)
210+
process.exit(reportedErrors ? EXIT_CODES.REPORTED_ERRORS : EXIT_CODES.OK)
210211
}
211212

212213
function writeSampleConfigFile() {

0 commit comments

Comments
 (0)