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

fix: ret error 0 when executed correctly #554

Merged
merged 3 commits into from
Mar 11, 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
24 changes: 12 additions & 12 deletions e2e/autofix-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe('e2e', function () {
}
)

expect(solhintProcess.status).to.equal(1)
expect(solhintProcess.status).to.equal(0)
expect(solhintProcess.stdout.toString().includes('5 problems (5 errors, 0 warnings)'))
})
})
Expand All @@ -129,7 +129,7 @@ describe('e2e', function () {
`${params.command} ${params.param1} -c ${currentConfig} ${currentFile} --fix --disc --noPrompt`
)

expect(code).to.equal(1)
expect(code).to.equal(0)

const reportLines = stdout.split('\n')
const finalLine = '5 problems (5 errors, 0 warnings)'
Expand Down Expand Up @@ -175,8 +175,8 @@ describe('e2e', function () {
expect(result).to.be.true
})

it('should execute and exit with code 1 (2)', () => {
expect(code).to.equal(1)
it('should execute and exit with code 0 (2)', () => {
expect(code).to.equal(0)
})

it('should get the right report (2)', () => {
Expand Down Expand Up @@ -222,7 +222,7 @@ describe('e2e', function () {
})

it('should execute and exit with code 1 (3)', () => {
expect(code).to.equal(1)
expect(code).to.equal(0)
})

it('should get the right report (3)', () => {
Expand Down Expand Up @@ -268,7 +268,7 @@ describe('e2e', function () {
})

it('should execute and exit with code 1 (4)', () => {
expect(code).to.equal(1)
expect(code).to.equal(0)
})

it('should get the right report (4)', () => {
Expand Down Expand Up @@ -314,7 +314,7 @@ describe('e2e', function () {
})

it('should execute and exit with code 1 (5)', () => {
expect(code).to.equal(1)
expect(code).to.equal(0)
})

it('should get the right report (5)', () => {
Expand Down Expand Up @@ -361,7 +361,7 @@ describe('e2e', function () {
})

it('should execute and exit with code 1 (6)', () => {
expect(code).to.equal(1)
expect(code).to.equal(0)
})

it('should get the right report (6)', () => {
Expand Down Expand Up @@ -401,7 +401,7 @@ describe('e2e', function () {
})

it('should execute and exit with code 1 (6)', () => {
expect(code).to.equal(1)
expect(code).to.equal(0)
})

it('should get the right report (6)', () => {
Expand Down Expand Up @@ -448,7 +448,7 @@ describe('e2e', function () {
})

it('should execute and exit with code 1 (7)', () => {
expect(code).to.equal(1)
expect(code).to.equal(0)
})

it('should get the right report (7)', () => {
Expand Down Expand Up @@ -494,7 +494,7 @@ describe('e2e', function () {
})

it('should execute and exit with code 1 (8)', () => {
expect(code).to.equal(1)
expect(code).to.equal(0)
})

it('should get the right report (8)', () => {
Expand Down Expand Up @@ -540,7 +540,7 @@ describe('e2e', function () {
})

it('should execute and exit with code 1 (8)', () => {
expect(code).to.equal(1)
expect(code).to.equal(0)
})

it('should get the right report (8)', () => {
Expand Down
12 changes: 6 additions & 6 deletions e2e/formatters-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('e2e', function () {
expect(reportLines[i]).to.equal(expectedLine)
}
// because there's an error
expect(code).to.equal(1)
expect(code).to.equal(0)

const finalLine = '10 problem/s (1 error/s, 9 warning/s)'
expect(reportLines[reportLines.length - 2]).to.contain(finalLine)
Expand Down Expand Up @@ -128,7 +128,7 @@ describe('e2e', function () {
const strExpected = JSON.stringify(expectedFinalOutput)
expect(strExpected).to.equal(strOutput)
// There's an error, that is why exit code is 1
expect(code).to.equal(1)
expect(code).to.equal(0)
})
})

Expand Down Expand Up @@ -175,7 +175,7 @@ describe('e2e', function () {
expect(reportLines[i]).to.equal(expectedLine)
}
// because there's an error
expect(code).to.equal(1)
expect(code).to.equal(0)

const finalLine = '10 problem/s (1 error/s, 9 warning/s)'
expect(reportLines[reportLines.length - 2]).to.contain(finalLine)
Expand Down Expand Up @@ -240,7 +240,7 @@ describe('e2e', function () {

expect(reportLines[i].replace(/\s/g, '')).to.equal(expectedLine.replace(/\s/g, ''))
}
expect(code).to.equal(1)
expect(code).to.equal(0)

const finalLine = '\u2716 10 problems (1 error, 9 warnings)'
expect(reportLines[reportLines.length - 3]).to.equal(finalLine)
Expand Down Expand Up @@ -342,7 +342,7 @@ describe('e2e', function () {
expect(reportLines[3]).to.eq(tableHeader1)
expect(reportLines[4]).to.eq(tableHeader2)

expect(code).to.equal(1)
expect(code).to.equal(0)
})
})

Expand Down Expand Up @@ -670,7 +670,7 @@ describe('e2e', function () {
]

// There's an error, that is why exit code is 1
expect(code).to.equal(1)
expect(code).to.equal(0)
expect(sarifOutput.runs[0].artifacts[0].location.uri).to.eq(expectedUriPathFoo)
expect(sarifOutput.runs[0].artifacts[1].location.uri).to.eq(expectedUriPathFoo2)
expect(sarifOutput.runs[0].artifacts[2].location.uri).to.eq(expectedUriPathFoo3)
Expand Down
16 changes: 8 additions & 8 deletions e2e/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ describe('e2e', function () {
describe('no-empty-blocks', function () {
useFixture('03-no-empty-blocks')

it('should exit with 1', function () {
it('should end correctly (exit w/0), found 1 error', function () {
const { code, stdout } = shell.exec('solhint Foo.sol')

expect(code).to.equal(1)
expect(code).to.equal(0)
expect(stdout.trim()).to.contain('Code contains empty blocks')
})

it('should work with stdin', async function () {
it('should work with stdin, exit 0, found 1 error', async function () {
const child = cp.exec('solhint stdin')

const stdoutPromise = getStream(child.stdout)
Expand All @@ -96,7 +96,7 @@ describe('e2e', function () {

const code = await codePromise

expect(code).to.equal(1)
expect(code).to.equal(0)

const stdout = await stdoutPromise

Expand Down Expand Up @@ -127,7 +127,7 @@ describe('e2e', function () {
expect(stdout.trim()).to.not.contain(warningExceededMsg)
})

it('should display [warnings exceeded] for max 3 warnings and exit error 1', function () {
it('should display [warnings exceeded] for max 3 warnings and exit with 0', function () {
const { code, stdout } = shell.exec('solhint contracts/Foo.sol --max-warnings 3')

expect(code).to.equal(1)
Expand All @@ -137,13 +137,13 @@ describe('e2e', function () {
it('should return error for Compiler version rule, ignoring 3 --max-warnings', function () {
const { code, stdout } = shell.exec('solhint contracts/Foo2.sol --max-warnings 3')

expect(code).to.equal(1)
expect(code).to.equal(0)
expect(stdout.trim()).to.contain(errorFound)
})

it('should return error for Compiler version rule. No message for max-warnings', function () {
const { code, stdout } = shell.exec('solhint contracts/Foo2.sol --max-warnings 27')
expect(code).to.equal(1)
expect(code).to.equal(0)
expect(stdout.trim()).to.not.contain(errorFound)
})
})
Expand All @@ -163,7 +163,7 @@ describe('e2e', function () {
it(`should raise error for wrongFunctionDefinitionName() only`, () => {
const { code, stdout } = shell.exec('solhint -c test/.solhint.json test/FooTest.sol')

expect(code).to.equal(1)
expect(code).to.equal(0)
expect(stdout.trim()).to.contain(
'Function wrongFunctionDefinitionName() must match Foundry test naming convention'
)
Expand Down
17 changes: 8 additions & 9 deletions solhint.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ function init() {
.option('-q, --quiet', 'report errors only - default: false')
.option('--ignore-path [file_name]', 'file to use as your .solhintignore')
.option('--fix', 'automatically fix problems. Skips fixes in report')
// .option('--fixShow', 'automatically fix problems. Show fixes in report')
.option('--noPrompt', 'do not suggest to backup files when any `fix` option is selected')
.option('--init', 'create configuration file for solhint')
.option('--disc', 'do not check for solhint updates')
Expand Down Expand Up @@ -81,7 +80,6 @@ function askUserToContinue(callback) {
}

function execMainAction() {
// if ((program.opts().fix || program.opts().fixShow) && !program.opts().noPrompt) {
if (program.opts().fix && !program.opts().noPrompt) {
askUserToContinue((userAnswer) => {
if (userAnswer !== 'y') {
Expand Down Expand Up @@ -162,7 +160,8 @@ function executeMainActionLogic() {

printReports(reports, formatterFn)

exitWithCode(reports)
// exitWithCode(reports)
process.exit(0)
}

function processStdin(options) {
Expand All @@ -183,8 +182,8 @@ function processStdin(options) {
const reports = [report]

printReports(reports, formatterFn)

exitWithCode(reports)
process.exit(0)
// exitWithCode(reports)
}

function writeSampleConfigFile() {
Expand Down Expand Up @@ -364,10 +363,10 @@ function listRules() {
}
}

function exitWithCode(reports) {
const errorsCount = reports.reduce((acc, i) => acc + i.errorCount, 0)
process.exit(errorsCount > 0 ? 1 : 0)
}
// function exitWithCode(reports) {
// const errorsCount = reports.reduce((acc, i) => acc + i.errorCount, 0)
// process.exit(errorsCount > 0 ? 1 : 0)
// }

function checkForUpdate() {
// eslint-disable-next-line import/no-extraneous-dependencies
Expand Down
Loading