Skip to content

Commit 6faf549

Browse files
remo5000ning-y
authored andcommitted
Check permitted operators for NoUnspecifiedOps (#14)
* Check permitted operators for NoUnspecifiedOps * Remove duplicate line
1 parent 74098f4 commit 6faf549

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

src/rules/noUnspecifiedOperator.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,30 @@ const noUnspecifiedOperator: Rule<es.BinaryExpression | es.UnaryExpression> = {
2929

3030
checkers: {
3131
BinaryExpression(node: es.BinaryExpression) {
32-
const unspecifiedOperators = [
33-
'==',
34-
'!=',
35-
'<<',
36-
'>>',
37-
'>>>',
38-
'**',
39-
'|',
40-
'^',
41-
'&',
42-
'in',
43-
'instanceof'
32+
const permittedOperators = [
33+
'+',
34+
'-',
35+
'*',
36+
'/',
37+
'%',
38+
'===',
39+
'!==',
40+
'<',
41+
'>',
42+
'<=',
43+
'>=',
44+
'&&',
45+
'||',
4446
]
45-
if (unspecifiedOperators.filter(op => op === node.operator).length > 0) {
47+
if (!permittedOperators.includes(node.operator)) {
4648
return [new NoUnspecifiedOperatorError(node)]
4749
} else {
4850
return []
4951
}
5052
},
5153
UnaryExpression(node: es.UnaryExpression) {
52-
const unspecifiedOperators = ['~', 'typeof', 'void', 'delete']
53-
if (unspecifiedOperators.filter(op => op === node.operator).length > 0) {
54+
const permittedOperators = ['-', '!']
55+
if (!permittedOperators.includes(node.operator)) {
5456
return [new NoUnspecifiedOperatorError(node)]
5557
} else {
5658
return []

0 commit comments

Comments
 (0)