Skip to content

Commit

Permalink
Merge pull request #158 from kevsul/fix-reason-string-revert
Browse files Browse the repository at this point in the history
Fix 'revert' case of reason-string
  • Loading branch information
fvictorio authored Sep 9, 2019
2 parents 313d33a + f8807bb commit 8745034
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions lib/rules/best-practises/reason-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ class ReasonStringChecker extends BaseChecker {
const functionName = this.getFunctionName(ctx)

// Throw an error if have no message
if (functionParameters.length <= 1) {
if (
(functionName === 'revert' && functionParameters.length === 0) ||
(functionName === 'require' && functionParameters.length <= 1)
) {
this._errorHaveNoMessage(ctx, functionName)
return
}
Expand Down Expand Up @@ -112,7 +115,7 @@ class ReasonStringChecker extends BaseChecker {
getFunctionParameters(ctx) {
const parent = ctx.parentCtx
const nodes = parent.children[2]
const children = nodes.children[0].children
const children = nodes.children && nodes.children.length > 0 ? nodes.children[0].children : []
const parameters = children
.filter(value => value.getText() !== ',')
.map(value => value.getText())
Expand Down
6 changes: 3 additions & 3 deletions test/rules/best-practises/reason-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('Linter - reason-string', () => {
})

it('should raise reason string is mandatory for revert', () => {
const code = funcWith(`revert(!has(role, account));
const code = funcWith(`revert();
role.bearer[account] = true;role.bearer[account] = true;
`)

Expand Down Expand Up @@ -51,7 +51,7 @@ describe('Linter - reason-string', () => {
})

it('should raise reason string maxLength error for revert', () => {
const code = funcWith(`revert(!has(role, account), "Roles: account already has role");
const code = funcWith(`revert("Roles: account already has role");
role.bearer[account] = true;role.bearer[account] = true;
`)

Expand All @@ -76,7 +76,7 @@ describe('Linter - reason-string', () => {
})

it('should not raise error for revert', () => {
const code = funcWith(`revert(!has(role, account), "Roles: account already has role");
const code = funcWith(`revert("Roles: account already has role");
role.bearer[account] = true;role.bearer[account] = true;
`)

Expand Down

0 comments on commit 8745034

Please sign in to comment.