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

source-academy / js-slang / 24840707595

23 Apr 2026 02:22PM UTC coverage: 78.515% (+0.1%) from 78.391%
24840707595

Pull #1893

github

web-flow
Merge 1b47f66fa into 715603479
Pull Request #1893: Error Handling and Stringify Changes

3126 of 4195 branches covered (74.52%)

Branch coverage included in aggregate %.

870 of 1046 new or added lines in 92 files covered. (83.17%)

20 existing lines in 11 files now uncovered.

7033 of 8744 relevant lines covered (80.43%)

176722.37 hits per line

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

89.29
/src/parser/source/rules/noUnspecifiedOperator.ts
1
import type { AssignmentExpression, BinaryExpression, UnaryExpression } from 'estree';
2
import { RuleError } from '../../errors';
3
import { defineRule } from '../../types';
4

5
type ExpressionNodeType = AssignmentExpression | BinaryExpression | UnaryExpression;
6

7
export class NoUnspecifiedOperatorError<T extends ExpressionNodeType> extends RuleError<T> {
8
  public readonly unspecifiedOperator: T['operator'];
9

10
  constructor(node: T) {
11
    super(node);
10✔
12
    this.unspecifiedOperator = node.operator;
10✔
13
  }
14

15
  public override explain() {
16
    return `Operator '${this.unspecifiedOperator}' is not allowed.`;
4✔
17
  }
18

19
  public override elaborate() {
20
    return '';
2✔
21
  }
22
}
23

24
export class StrictEqualityError extends NoUnspecifiedOperatorError<BinaryExpression> {
25
  public override explain() {
26
    if (this.node.operator === '==') {
2✔
27
      return 'Use === instead of ==.';
1✔
28
    } else {
29
      return 'Use !== instead of !=.';
1✔
30
    }
31
  }
32

33
  public override elaborate() {
34
    return '== and != are not valid operators.';
×
35
  }
36
}
37

38
export default defineRule('no-unspecified-operator', {
39
  BinaryExpression(node) {
40
    const permittedOperators: BinaryExpression['operator'][] = [
82,617✔
41
      '+',
42
      '-',
43
      '*',
44
      '/',
45
      '%',
46
      '===',
47
      '!==',
48
      '<',
49
      '>',
50
      '<=',
51
      '>=',
52
      // '&&',
53
      // '||'
54
    ];
55

56
    if (node.operator === '!=' || node.operator === '==') {
82,617✔
57
      return [new StrictEqualityError(node)];
2✔
58
    } else if (!permittedOperators.includes(node.operator)) {
82,615✔
59
      return [new NoUnspecifiedOperatorError(node)];
2✔
60
    } else {
61
      return [];
82,613✔
62
    }
63
  },
64
  UnaryExpression(node) {
65
    const permittedOperators = ['-', '!', 'typeof'];
4,686✔
66
    if (!permittedOperators.includes(node.operator)) {
4,686!
NEW
67
      return [new NoUnspecifiedOperatorError(node)];
×
68
    } else {
69
      return [];
4,686✔
70
    }
71
  },
72
});
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