-
Notifications
You must be signed in to change notification settings - Fork 179
/
Copy pathgas-named-return-values.js
60 lines (52 loc) · 1.44 KB
/
gas-named-return-values.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
const BaseChecker = require('../base-checker')
const { severityDescription } = require('../../doc/utils')
const DEFAULT_SEVERITY = 'warn'
const ruleId = 'gas-named-return-values'
const meta = {
type: 'gas-consumption',
docs: {
description: `Enforce the return values of a function to be named`,
category: 'Gas Consumption Rules',
options: [
{
description: severityDescription,
default: DEFAULT_SEVERITY,
},
],
examples: {
good: [
{
description: 'Function definition with named return values',
code: 'function checkBalance(address wallet) external view returns(uint256 retBalance) {}',
},
],
bad: [
{
description: 'Function definition with UNNAMED return values',
code: 'function checkBalance(address wallet) external view returns(uint256) {}',
},
],
},
},
isDefault: false,
recommended: false,
defaultSetup: DEFAULT_SEVERITY,
schema: null,
}
class GasNamedReturnValuesChecker extends BaseChecker {
constructor(reporter) {
super(reporter, ruleId, meta)
}
FunctionDefinition(node) {
if (node.returnParameters) {
let index = 0
for (const returnValue of node.returnParameters) {
if (!returnValue.name) {
this.error(node, `GC: Named return value is missing - Index ${index}`)
}
index++
}
}
}
}
module.exports = GasNamedReturnValuesChecker