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

source-academy / js-slang / 15237418122

25 May 2025 11:31AM UTC coverage: 77.048% (-3.5%) from 80.538%
15237418122

push

github

web-flow
Rewrite: Stepper (#1742)

3433 of 4826 branches covered (71.14%)

Branch coverage included in aggregate %.

1032 of 1260 new or added lines in 27 files covered. (81.9%)

440 existing lines in 29 files now uncovered.

10099 of 12737 relevant lines covered (79.29%)

142411.96 hits per line

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

82.35
/src/parser/source/rules/noDeclareMutable.ts
1
import { generate } from 'astring'
77✔
2
import type { VariableDeclaration } from 'estree'
3
import type { Rule } from '../../types'
4
import { RuleError } from '../../errors'
77✔
5
import { Chapter } from '../../../types'
77✔
6
import { getSourceVariableDeclaration } from '../../../utils/ast/helpers'
77✔
7

8
const mutableDeclarators: VariableDeclaration['kind'][] = ['let', 'var']
77✔
9

10
export class NoDeclareMutableError extends RuleError<VariableDeclaration> {
77✔
11
  public explain() {
12
    return `Mutable variable declaration using keyword '${this.node.kind}' is not allowed.`
11✔
13
  }
14

15
  public elaborate() {
16
    const {
17
      id: { name },
18
      init
UNCOV
19
    } = getSourceVariableDeclaration(this.node)
×
UNCOV
20
    const value = generate(init)
×
21

UNCOV
22
    return `Use keyword "const" instead, to declare a constant:\n\n\tconst ${name} = ${value};`
×
23
  }
24
}
25

26
const noDeclareMutable: Rule<VariableDeclaration> = {
77✔
27
  name: 'no-declare-mutable',
28
  disableFromChapter: Chapter.SOURCE_3,
29

30
  checkers: {
31
    VariableDeclaration(node) {
32
      if (mutableDeclarators.includes(node.kind)) {
5,311✔
33
        return [new NoDeclareMutableError(node)]
11✔
34
      } else {
35
        return []
5,300✔
36
      }
37
    }
38
  }
39
}
40

41
export default noDeclareMutable
77✔
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