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

added: autofix avoid-suicide #531

Merged
merged 6 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fixed conflicts merge to develop
  • Loading branch information
dbale-altoros committed Dec 22, 2023
commit 0e2d611a6462b74f21a61f416b75e624d76a563f
125 changes: 106 additions & 19 deletions e2e/autofix-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ describe('e2e', function () {
})

it('should execute and compare Foo1 with template AFTER FIX and they should match (2)', () => {
({ code, stdout } = shell.exec(
;({ code, stdout } = shell.exec(
`${params.command} ${params.param1} -c ${currentConfig} ${currentFile} --fix --disc --noPrompt`
))

Expand Down Expand Up @@ -213,7 +213,7 @@ describe('e2e', function () {
})

it('should execute and compare Foo1 with template AFTER FIX and they should match (3)', () => {
({ code, stdout } = shell.exec(
;({ code, stdout } = shell.exec(
`${params.command} ${params.param1} -c ${currentConfig} ${currentFile} --fix --disc --noPrompt`
))

Expand Down Expand Up @@ -259,7 +259,7 @@ describe('e2e', function () {
})

it('should execute and compare Foo1 with template AFTER FIX and they should match (4)', () => {
({ code, stdout } = shell.exec(
;({ code, stdout } = shell.exec(
`${params.command} ${params.param1} -c ${currentConfig} ${currentFile} --fix --disc --noPrompt`
))

Expand Down Expand Up @@ -305,7 +305,7 @@ describe('e2e', function () {
})

it('should execute and compare Foo1 with template AFTER FIX and they should match (5)', () => {
({ code, stdout } = shell.exec(
;({ code, stdout } = shell.exec(
`${params.command} ${params.param1} -c ${currentConfig} ${currentFile} --fix --disc --noPrompt`
))

Expand All @@ -330,50 +330,137 @@ describe('e2e', function () {
})
})

describe('autofix rule: avoid-suicide', () => {
before(function () {
params = retrieveParams('avoid-suicide/')
currentConfig = `${params.path}${params.subpath}.solhint.json`
currentFile = `${params.path}${params.subpath}Foo1.sol`
beforeFixFile = `${params.path}${params.subpath}Foo1BeforeFix.sol`
afterFixFile = `${params.path}${params.subpath}Foo1AfterFix.sol`
describe('autofix rule: quotes', () => {
describe('--fix with noPrompt SINGLE QUOTES', () => {
before(function () {
params = retrieveParams('quotes/')
currentConfig = `${params.path}${params.subpath}.singleQuotes.json`
currentFile = `${params.path}${params.subpath}Foo1.sol`
beforeFixFile = `${params.path}${params.subpath}Foo1BeforeFix.sol`
afterFixFile = `${params.path}${params.subpath}Foo1AfterFixSingle.sol`
})

after(function () {
if (!E2E) {
copyFile(beforeFixFile, currentFile)
}
})

it('should compare Foo1 file with template BEFORE FIX file and they should match (6)', () => {
result = compareTextFiles(currentFile, beforeFixFile)
expect(result).to.be.true
})

it('should execute and compare Foo1 with template AFTER FIX and they should match (6)', () => {
;({ code, stdout } = shell.exec(
`${params.command} ${params.param1} -c ${currentConfig} ${currentFile} --fix --disc --noPrompt`
))

result = compareTextFiles(currentFile, afterFixFile)
expect(result).to.be.true
})

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

it('should get the right report (6)', () => {
const reportLines = stdout.split('\n')
const finalLine = '8 problems (8 errors, 0 warnings)'
expect(reportLines[reportLines.length - 3]).to.contain(finalLine)
})
})
describe('--fix with noPrompt', () => {

describe('--fix with noPrompt DOUBLE QUOTES', () => {
before(function () {
params = retrieveParams('quotes/')
currentConfig = `${params.path}${params.subpath}.doubleQuotes.json`
currentFile = `${params.path}${params.subpath}Foo1.sol`
beforeFixFile = `${params.path}${params.subpath}Foo1BeforeFix.sol`
afterFixFile = `${params.path}${params.subpath}Foo1AfterFixDouble.sol`
})

after(function () {
if (!E2E) {
copyFile(beforeFixFile, currentFile)
}
})

it('should compare Foo1 file with template BEFORE FIX file and they should match (7)', () => {
it('should compare Foo1 file with template BEFORE FIX file and they should match (6)', () => {
result = compareTextFiles(currentFile, beforeFixFile)
expect(result).to.be.true
})

it('should execute and compare Foo1 with template AFTER FIX and they should match (7)', () => {
({ code, stdout } = shell.exec(
it('should execute and compare Foo1 with template AFTER FIX and they should match (6)', () => {
;({ code, stdout } = shell.exec(
`${params.command} ${params.param1} -c ${currentConfig} ${currentFile} --fix --disc --noPrompt`
))

result = compareTextFiles(currentFile, afterFixFile)
expect(result).to.be.true
})

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

it('should get the right report (7)', () => {
it('should get the right report (6)', () => {
const reportLines = stdout.split('\n')
const finalLine = '3 problems (3 errors, 0 warnings)'
const finalLine = '8 problems (8 errors, 0 warnings)'
expect(reportLines[reportLines.length - 3]).to.contain(finalLine)
})
})

it('should check FOO1 does not change after test (7)', () => {
it('should check FOO1 does not change after test (6)', () => {
result = compareTextFiles(currentFile, beforeFixFile)
expect(result).to.be.true
})
})
})

describe('autofix rule: avoid-suicide', () => {
before(function () {
params = retrieveParams('avoid-suicide/')
currentConfig = `${params.path}${params.subpath}.solhint.json`
currentFile = `${params.path}${params.subpath}Foo1.sol`
beforeFixFile = `${params.path}${params.subpath}Foo1BeforeFix.sol`
afterFixFile = `${params.path}${params.subpath}Foo1AfterFix.sol`
})
after(function () {
if (!E2E) {
copyFile(beforeFixFile, currentFile)
}
})

describe('--fix with noPrompt', () => {
it('should compare Foo1 file with template BEFORE FIX file and they should match (7)', () => {
result = compareTextFiles(currentFile, beforeFixFile)
expect(result).to.be.true
})

it('should execute and compare Foo1 with template AFTER FIX and they should match (7)', () => {
;({ code, stdout } = shell.exec(
`${params.command} ${params.param1} -c ${currentConfig} ${currentFile} --fix --disc --noPrompt`
))

result = compareTextFiles(currentFile, afterFixFile)
expect(result).to.be.true
})

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

it('should get the right report (7)', () => {
const reportLines = stdout.split('\n')
const finalLine = '3 problems (3 errors, 0 warnings)'
expect(reportLines[reportLines.length - 3]).to.contain(finalLine)
})
})

it('should check FOO1 does not change after test (7)', () => {
result = compareTextFiles(currentFile, beforeFixFile)
expect(result).to.be.true
})
})
})
Expand Down
5 changes: 5 additions & 0 deletions lib/rules/best-practises/no-console.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ const meta = {
},
],
},
notes: [
{
note: 'Solhint allows this rule to automatically fix the code with `--fix` option',
},
],
},

isDefault: true,
Expand Down
5 changes: 5 additions & 0 deletions lib/rules/best-practises/payable-fallback.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ const meta = {
},
],
},
notes: [
{
note: 'Solhint allows this rule to automatically fix the code with `--fix` option',
},
],
},

isDefault: false,
Expand Down
3 changes: 3 additions & 0 deletions lib/rules/naming/private-vars-leading-underscore.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ const meta = {
{
note: 'See [here](https://docs.soliditylang.org/en/latest/style-guide.html#underscore-prefix-for-non-external-functions-and-variables) for further information',
},
{
note: 'Solhint allows this rule to automatically fix the code with `--fix` option',
},
],
},

Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.