Skip to content

Commit

Permalink
Snake case now allows for a (single) leading underscore. (#93)
Browse files Browse the repository at this point in the history
* Snake case now allows for a (single) leading underscore
* The snake case check now allows for up to two leading underscores.
  • Loading branch information
nventuro authored and pablofullana committed Dec 21, 2018
1 parent f985588 commit e3aa88f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/common/identifier-naming.js
Expand Up @@ -20,7 +20,7 @@ module.exports = {
},

isUpperSnakeCase(text) {
return match(text, /[A-Z0-9]+[_A-Z0-9]*/)
return match(text, /_{0,2}[A-Z0-9]+[_A-Z0-9]*/)
},

isNotUpperSnakeCase(text) {
Expand Down
29 changes: 27 additions & 2 deletions test/naming-rules.js
Expand Up @@ -59,14 +59,39 @@ describe('Linter', () => {
assert.ok(report.messages[0].message.includes('Variable name'))
})

it('should not raise var name error for constants', () => {
const code = contractWith('uint32 private constant D = 10;')
it('should not raise var name error for constants in snake case', () => {
const code = contractWith('uint32 private constant THE_CONSTANT = 10;')

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

assert.equal(report.errorCount, 0)
})

it('should not raise var name error for constants in snake case with single leading underscore', () => {
const code = contractWith('uint32 private constant _THE_CONSTANT = 10;')

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

assert.equal(report.errorCount, 0)
})

it('should not raise var name error for constants in snake case with double leading underscore', () => {
const code = contractWith('uint32 private constant __THE_CONSTANT = 10;')

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

assert.equal(report.errorCount, 0)
})

it('should raise var name error for constants in snake case with more than two leading underscores', () => {
const code = contractWith('uint32 private constant ___THE_CONSTANT = 10;')

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

assert.equal(report.errorCount, 1)
assert.ok(report.messages[0].message.includes('SNAKE_CASE'))
})

it('should raise var name error for event arguments illegal styling', () => {
const code = contractWith('event Event1(uint B);')

Expand Down

0 comments on commit e3aa88f

Please sign in to comment.