• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tokenhouse / solhint / #401

05 Oct 2017 03:10PM UTC coverage: 99.148% (+29.2%) from 69.948%
#401

push

idrabenia
50-max-states-count-in-contract

461 of 477 branches covered (96.65%)

1745 of 1760 relevant lines covered (99.15%)

432.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.04
/lib/comment-directive-parser.js
1

2

3
class CommentDirectiveParser {
4

5
    constructor (tokens) {
6
        this.lastLine = tokens.tokenSource.line;
186✔
7
        this.ruleStore = new RuleStore(this.lastLine);
186✔
8

9
        this.parseComments(tokens);
186✔
10
    }
11

12
    parseComments(tokens) {
13
        const items = tokens.filterForChannel(0, tokens.tokens.length - 1, 1);
186✔
14
        items && items.forEach(this.onComment.bind(this));
186✔
15
    }
16

17
    onComment(lexema) {
18
        const text = lexema.text;
17✔
19
        const curLine = lexema.line;
17✔
20
        const ruleStore = this.ruleStore;
17✔
21

22
        if (text.includes('solhint-disable-line')) {
17✔
23
            const rules = this.parseRuleIds(text, 'solhint-disable-line');
2✔
24
            ruleStore.disableRules(curLine, rules);
2✔
25
            return;
2✔
26
        }
27

28
        if (text.includes('solhint-disable-next-line')) {
15✔
29
            const rules = this.parseRuleIds(text, 'solhint-disable-next-line');
3✔
30

31
            if (curLine + 1 <= this.lastLine) {
3✔
32
                ruleStore.disableRules(curLine + 1, rules);
2✔
33
            }
34

35
            return;
3✔
36
        }
37

38
        if (text.includes('solhint-disable')) {
12✔
39
            const rules = this.parseRuleIds(text, 'solhint-disable');
4✔
40

41
            ruleStore.disableRulesToEndOfFile(curLine, rules);
4✔
42

43
            return;
4✔
44
        }
45

46
        if (text.includes('solhint-enable')) {
8✔
47
            const rules = this.parseRuleIds(text, 'solhint-enable');
2✔
48

49
            ruleStore.enableRulesToEndOfFile(curLine, rules);
2✔
50
        }
51
    }
52

53
    parseRuleIds(text, start) {
54
        const ruleIds = text
11✔
55
            .replace('//', '')
56
            .replace('/*', '')
57
            .replace('*/', '')
58
            .replace(start, '');
59

60
        const rules = ruleIds
11✔
61
            .split(',')
62
            .map(curRule => curRule.trim())
11✔
63
            .filter(i => i.length > 0);
11✔
64

65
        return (rules.length > 0) ? rules : 'all';
11✔
66
    }
67

68
    isRuleEnabled(line, ruleId) {
69
        return this.ruleStore.isRuleEnabled(line, ruleId);
159✔
70
    }
71

72
}
73

74

75
class RuleStore {
76

77
    constructor (lastLine) {
78
        this.disableRuleByLine = [];
186✔
79
        this.disableAllByLine = [];
186✔
80
        this.lastLine = lastLine;
186✔
81

82
        this.initRulesTable();
186✔
83
    }
84

85
    initRulesTable() {
86
        for (let i = 1; i <= this.lastLine; i += 1) {
186✔
87
            this.disableRuleByLine[i] = new Set();
2,069✔
88
            this.disableAllByLine[i] = false;
2,069✔
89
        }
90
    }
91

92
    disableRules(curLine, newRules) {
93
        if (newRules === 'all') {
22✔
94
            this.disableAllByLine[curLine] = true;
8✔
95
        } else {
96
            const lineRules = this.disableRuleByLine[curLine];
14✔
97
            this.disableRuleByLine[curLine] = new Set([...lineRules, ...newRules]);
14✔
98
        }
99
    }
100

101
    disableRulesToEndOfFile(startLine, rules) {
102
        this._toEndOfFile(startLine, i => this.disableRules(i, rules));
18✔
103
    }
104

105
    enableRules(curLine, rules) {
106
        if (rules === 'all') {
6!
107
            this.disableAllByLine[curLine] = false;
×
108
        } else {
109
            const lineRules = this.disableRuleByLine[curLine];
6✔
110
            rules.forEach(curRule => lineRules.delete(curRule));
6✔
111
        }
112
    }
113

114
    enableRulesToEndOfFile(startLine, rules) {
115
        this._toEndOfFile(startLine, i => this.enableRules(i, rules));
6✔
116
    }
117

118
    isRuleEnabled(line, ruleId) {
119
        return !this.disableAllByLine[line] && !this.disableRuleByLine[line].has(ruleId);
159✔
120
    }
121

122
    _toEndOfFile(from, callback) {
123
        for (let i = from; i <= this.lastLine; i += 1) {
6✔
124
            callback && callback(i);
24✔
125
        }
126
    }
127
}
128

129

130
module.exports = CommentDirectiveParser;
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc