Skip to content

Commit

Permalink
Merge 7ef5fb9 into f389547
Browse files Browse the repository at this point in the history
  • Loading branch information
nventuro committed Dec 20, 2018
2 parents f389547 + 7ef5fb9 commit 78e0dd5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
22 changes: 21 additions & 1 deletion lib/rules/order/function-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const STATES = {
{ on: 'external', goTo: 'AFTER_EXTERNAL' },
{ on: 'external_const', goTo: 'AFTER_EXTERNAL_CONSTANT' },
{ on: 'public', goTo: 'AFTER_PUBLIC' },
{ on: 'public_const', goTo: 'AFTER_PUBLIC_CONSTANT' },
{ on: 'internal', goTo: 'AFTER_INTERNAL' },
{ on: 'private', goTo: 'AFTER_PRIVATE' }
]
Expand All @@ -65,6 +66,7 @@ const STATES = {
{ on: 'external', goTo: 'AFTER_EXTERNAL' },
{ on: 'external_const', goTo: 'AFTER_EXTERNAL_CONSTANT' },
{ on: 'public', goTo: 'AFTER_PUBLIC' },
{ on: 'public_const', goTo: 'AFTER_PUBLIC_CONSTANT' },
{ on: 'internal', goTo: 'AFTER_INTERNAL' },
{ on: 'private', goTo: 'AFTER_PRIVATE' }
]
Expand All @@ -77,6 +79,7 @@ const STATES = {
{ on: 'external', goTo: 'AFTER_EXTERNAL' },
{ on: 'external_const', goTo: 'AFTER_EXTERNAL_CONSTANT' },
{ on: 'public', goTo: 'AFTER_PUBLIC' },
{ on: 'public_const', goTo: 'AFTER_PUBLIC_CONSTANT' },
{ on: 'internal', goTo: 'AFTER_INTERNAL' },
{ on: 'private', goTo: 'AFTER_PRIVATE' }
]
Expand All @@ -89,6 +92,7 @@ const STATES = {
{ on: 'external', goTo: 'AFTER_EXTERNAL' },
{ on: 'external_const', goTo: 'AFTER_EXTERNAL_CONSTANT' },
{ on: 'public', goTo: 'AFTER_PUBLIC' },
{ on: 'public_const', goTo: 'AFTER_PUBLIC_CONSTANT' },
{ on: 'internal', goTo: 'AFTER_INTERNAL' },
{ on: 'private', goTo: 'AFTER_PRIVATE' }
]
Expand All @@ -100,6 +104,7 @@ const STATES = {
rules: [
{ on: 'external_const', goTo: 'AFTER_EXTERNAL_CONSTANT' },
{ on: 'public', goTo: 'AFTER_PUBLIC' },
{ on: 'public_const', goTo: 'AFTER_PUBLIC_CONSTANT' },
{ on: 'internal', goTo: 'AFTER_INTERNAL' },
{ on: 'private', goTo: 'AFTER_PRIVATE' }
]
Expand All @@ -110,6 +115,17 @@ const STATES = {
after: 'public',
rules: [
{ on: 'public', goTo: 'AFTER_PUBLIC' },
{ on: 'public_const', goTo: 'AFTER_PUBLIC_CONSTANT' },
{ on: 'internal', goTo: 'AFTER_INTERNAL' },
{ on: 'private', goTo: 'AFTER_PRIVATE' }
]
}),

AFTER_PUBLIC_CONSTANT: new State({
name: 'AFTER_PUBLIC_CONSTANT',
after: 'public constant',
rules: [
{ on: 'public_const', goTo: 'AFTER_PUBLIC_CONSTANT' },
{ on: 'internal', goTo: 'AFTER_INTERNAL' },
{ on: 'private', goTo: 'AFTER_PRIVATE' }
]
Expand Down Expand Up @@ -191,7 +207,11 @@ class FuncTypeParser {
return 'internal'
}

return 'public'
if (includesAnyOf(text, ['pure', 'view', 'constant'])) {
return 'public_const'
} else {
return 'public'
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions test/ordering-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ describe('Linter', () => {
assert.ok(report.messages[0].message.includes('Function order is incorrect'))
})

it('should raise incorrect function order error for public constant funcs', () => {
const code = contractWith(`
function b() public pure {}
function c() public {}
`)

const report = linter.processStr(code, noIndent())

assert.equal(report.errorCount, 1)
assert.ok(report.messages[0].message.includes('Function order is incorrect'))
})

it('should raise incorrect function order error for internal function', () => {
const code = contractWith(`
function c() internal {}
Expand Down

0 comments on commit 78e0dd5

Please sign in to comment.