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

protofire / solhint / #24682

20 Dec 2018 01:18PM UTC coverage: 99.529% (+0.003%) from 99.526%
#24682

push

web-flow
Merge pull request #89 from nventuro/patch-3

Have --max-warnings better reflect its name

519 of 541 branches covered (95.93%)

2112 of 2122 relevant lines covered (99.53%)

1972.67 hits per line

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

98.31
/lib/comment-directive-parser.js
1
class CommentDirectiveParser {
2
  constructor(tokens) {
3
    this.lastLine = tokens.tokenSource.line
227✔
4
    this.ruleStore = new RuleStore(this.lastLine)
227✔
5

6
    this.parseComments(tokens)
227✔
7
  }
8

9
  parseComments(tokens) {
10
    const items = tokens.filterForChannel(0, tokens.tokens.length - 1, 1)
227✔
11
    if (items) {
227✔
12
      items.forEach(this.onComment.bind(this))
17✔
13
    }
14
  }
15

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

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

27
    if (text.includes('solhint-disable-next-line')) {
28
      const rules = this.parseRuleIds(text, 'solhint-disable-next-line')
2✔
29

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

2✔
34
      return
2✔
35
    }
36

37
    if (text.includes('solhint-disable')) {
17✔
38
      const rules = this.parseRuleIds(text, 'solhint-disable')
3✔
39

40
      ruleStore.disableRulesToEndOfFile(curLine, rules)
3✔
41

2✔
42
      return
43
    }
44

3✔
45
    if (text.includes('solhint-enable')) {
46
      const rules = this.parseRuleIds(text, 'solhint-enable')
47

14✔
48
      ruleStore.enableRulesToEndOfFile(curLine, rules)
5✔
49
    }
50
  }
5✔
51

52
  parseRuleIds(text, start) {
5✔
53
    const ruleIds = text
54
      .replace('//', '')
55
      .replace('/*', '')
9✔
56
      .replace('*/', '')
3✔
57
      .replace(start, '')
58

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

15✔
64
    return rules.length > 0 ? rules : 'all'
65
  }
66

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

15✔
72
class RuleStore {
15✔
73
  constructor(lastLine) {
74
    this.disableRuleByLine = []
15✔
75
    this.disableAllByLine = []
76
    this.lastLine = lastLine
77

78
    this.initRulesTable()
198✔
79
  }
80

81
  initRulesTable() {
82
    for (let i = 1; i <= this.lastLine; i += 1) {
83
      this.disableRuleByLine[i] = new Set()
84
      this.disableAllByLine[i] = false
227✔
85
    }
227✔
86
  }
227✔
87

88
  disableRules(curLine, newRules) {
227✔
89
    if (newRules === 'all') {
90
      this.disableAllByLine[curLine] = true
91
    } else {
92
      const lineRules = this.disableRuleByLine[curLine]
227✔
93
      this.disableRuleByLine[curLine] = new Set([...lineRules, ...newRules])
2,520✔
94
    }
2,520✔
95
  }
96

97
  disableRulesToEndOfFile(startLine, rules) {
98
    this._toEndOfFile(startLine, i => this.disableRules(i, rules))
99
  }
29✔
100

15✔
101
  enableRules(curLine, rules) {
102
    if (rules === 'all') {
14✔
103
      this.disableAllByLine[curLine] = false
14✔
104
    } else {
105
      const lineRules = this.disableRuleByLine[curLine]
106
      rules.forEach(curRule => lineRules.delete(curRule))
107
    }
108
  }
23✔
109

110
  enableRulesToEndOfFile(startLine, rules) {
111
    this._toEndOfFile(startLine, i => this.enableRules(i, rules))
112
  }
9✔
113

3✔
114
  isRuleEnabled(line, ruleId) {
115
    return !this.disableAllByLine[line] && !this.disableRuleByLine[line].has(ruleId)
6✔
116
  }
6✔
117

118
  _toEndOfFile(from, callback) {
119
    if (!callback) {
120
      return
121
    }
9✔
122

123
    for (let i = from; i <= this.lastLine; i += 1) {
124
      callback(i)
125
    }
198✔
126
  }
127
}
128

129
module.exports = CommentDirectiveParser
8!
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

© 2025 Coveralls, Inc