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

protofire / solhint / #913

pending completion
#913

push

web-flow
Merge pull request #416 from juanpcapurro/fix-error-on-named-global-import

 Do not raise error on named global import

581 of 665 branches covered (87.37%)

1 of 1 new or added line in 1 file covered. (100.0%)

1278 of 1368 relevant lines covered (93.42%)

202.93 hits per line

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

91.3
/lib/comment-directive-parser.js
1
class CommentDirectiveParser {
2
  constructor(tokens) {
3
    const lastToken = tokens[tokens.length - 1]
365✔
4
    this.lastLine = lastToken ? lastToken.loc.end.line : 0
365✔
5
    this.ruleStore = new RuleStore(this.lastLine)
365✔
6

7
    this.parseComments(tokens)
365✔
8
  }
9

10
  parseComments(tokens) {
11
    const items = tokens.filter(
365✔
12
      (token) => token.type === 'Keyword' && /^(\/\/|\/\*)/.test(token.value)
8,432✔
13
    )
14
    items.forEach((item) => this.onComment(item))
365✔
15
  }
16

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

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

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

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

35
      return
2✔
36
    }
37

38
    if (text.includes('solhint-disable-previous-line')) {
19✔
39
      const rules = this.parseRuleIds(text, 'solhint-disable-previous-line')
2✔
40

41
      if (curLine > 0) {
2!
42
        ruleStore.disableRules(curLine - 1, rules)
2✔
43
      }
44

45
      return
2✔
46
    }
47

48
    if (text.includes('solhint-disable')) {
17✔
49
      const rules = this.parseRuleIds(text, 'solhint-disable')
3✔
50

51
      ruleStore.disableRulesToEndOfFile(curLine, rules)
3✔
52

53
      return
3✔
54
    }
55

56
    if (text.includes('solhint-enable')) {
14✔
57
      const rules = this.parseRuleIds(text, 'solhint-enable')
2✔
58

59
      ruleStore.enableRulesToEndOfFile(curLine, rules)
2✔
60
    }
61
  }
62

63
  parseRuleIds(text, start) {
64
    const ruleIds = text.replace('//', '').replace('/*', '').replace('*/', '').replace(start, '')
9✔
65

66
    const rules = ruleIds
9✔
67
      .split(',')
68
      .map((curRule) => curRule.trim())
9✔
69
      .filter((i) => i.length > 0)
9✔
70

71
    return rules.length > 0 ? rules : 'all'
9✔
72
  }
73

74
  isRuleEnabled(line, ruleId) {
75
    return this.ruleStore.isRuleEnabled(line, ruleId)
206✔
76
  }
77
}
78

79
class RuleStore {
80
  constructor(lastLine) {
81
    this.disableRuleByLine = []
365✔
82
    this.disableAllByLine = []
365✔
83
    this.lastLine = lastLine
365✔
84

85
    this.initRulesTable()
365✔
86
  }
87

88
  initRulesTable() {
89
    for (let i = 1; i <= this.lastLine; i += 1) {
365✔
90
      this.disableRuleByLine[i] = new Set()
3,439✔
91
      this.disableAllByLine[i] = false
3,439✔
92
    }
93
  }
94

95
  disableRules(curLine, newRules) {
96
    if (newRules === 'all') {
15✔
97
      this.disableAllByLine[curLine] = true
11✔
98
    } else {
99
      const lineRules = this.disableRuleByLine[curLine]
4✔
100
      this.disableRuleByLine[curLine] = new Set([...lineRules, ...newRules])
4✔
101
    }
102
  }
103

104
  disableRulesToEndOfFile(startLine, rules) {
105
    this._toEndOfFile(startLine, (i) => this.disableRules(i, rules))
11✔
106
  }
107

108
  enableRules(curLine, rules) {
109
    if (rules === 'all') {
4✔
110
      this.disableAllByLine[curLine] = false
2✔
111
    } else {
112
      const lineRules = this.disableRuleByLine[curLine]
2✔
113
      rules.forEach((curRule) => lineRules.delete(curRule))
2✔
114
    }
115
  }
116

117
  enableRulesToEndOfFile(startLine, rules) {
118
    this._toEndOfFile(startLine, (i) => this.enableRules(i, rules))
4✔
119
  }
120

121
  isRuleEnabled(line, ruleId) {
122
    const allRulesDisabled = this.disableAllByLine[line]
206✔
123
    const ruleDisabled = this.disableRuleByLine[line] && this.disableRuleByLine[line].has(ruleId)
206✔
124
    return !allRulesDisabled && !ruleDisabled
206✔
125
  }
126

127
  _toEndOfFile(from, callback) {
128
    if (!callback) {
5!
129
      return
×
130
    }
131

132
    for (let i = from; i <= this.lastLine; i += 1) {
5✔
133
      callback(i)
15✔
134
    }
135
  }
136
}
137

138
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