-
Notifications
You must be signed in to change notification settings - Fork 179
/
Copy pathvar-name-mixedcase.js
88 lines (67 loc) · 2.92 KB
/
var-name-mixedcase.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const assert = require('assert')
const linter = require('../../../lib/index')
const contractWith = require('../../common/contract-builder').contractWith
const funcWith = require('../../common/contract-builder').funcWith
describe('Linter - var-name-mixedcase', () => {
it('should raise incorrect var name error', () => {
const code = funcWith('var (a, B);')
const report = linter.processStr(code, {
rules: { 'no-unused-vars': 'error', 'var-name-mixedcase': 'error' },
})
assert.ok(report.errorCount > 0)
assert.ok(report.messages.map((i) => i.message).some((i) => i.includes('name')))
})
it('should raise incorrect var name error for typed declaration', () => {
const code = funcWith('uint B = 1;')
const report = linter.processStr(code, {
rules: { 'no-unused-vars': 'error', 'var-name-mixedcase': 'error' },
})
assert.ok(report.errorCount > 0)
assert.ok(report.messages.map((i) => i.message).some((i) => i.includes('name')))
})
it('should raise incorrect var name error for state declaration', () => {
const code = contractWith('uint32 private D = 10;')
const report = linter.processStr(code, {
rules: { 'no-unused-vars': 'error', 'var-name-mixedcase': 'error' },
})
assert.equal(report.errorCount, 1)
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;')
const report = linter.processStr(code, {
rules: { 'no-unused-vars': 'error', 'var-name-mixedcase': 'error' },
})
assert.equal(report.errorCount, 0)
})
it('should not raise const name error for immutable variables in SNAKE_CASE', () => {
const code = contractWith('uint32 private immutable SNAKE_CASE;')
const report = linter.processStr(code, {
rules: { 'no-unused-vars': 'error', 'var-name-mixedcase': 'error' },
})
assert.equal(report.errorCount, 0)
})
it('should not raise const name error for immutable variables in mixedCase', () => {
const code = contractWith('uint32 private immutable SNAKE_CASE;')
const report = linter.processStr(code, {
rules: { 'no-unused-vars': 'error', 'var-name-mixedcase': 'error' },
})
assert.equal(report.errorCount, 0)
})
describe('with $ character', () => {
const WITH_$ = {
'starting with $': contractWith('uint32 private $D = 10;'),
'containing a $': contractWith('uint32 private testWith$Contained = 10;'),
'ending with $': contractWith('uint32 private testWithEnding$ = 10;'),
'only with $': contractWith('uint32 private $;'),
}
for (const [key, code] of Object.entries(WITH_$)) {
it(`should not raise var name error for variables ${key}`, () => {
const report = linter.processStr(code, {
rules: { 'var-name-mixedcase': 'error' },
})
assert.equal(report.errorCount, 0)
})
}
})
})