Skip to content
This repository was archived by the owner on Mar 23, 2024. It is now read-only.

Commit 86e14ae

Browse files
committed
Improve requireSpaceAfterBinaryOperators rule
Add check for assignment to requireSpaceAfterBinaryOperators rule
1 parent cc027af commit 86e14ae

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

lib/rules/require-space-after-binary-operators.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,18 @@ module.exports.prototype = {
3939
}
4040
});
4141

42-
// Comma
43-
if (operators[',']) {
42+
// Comma and assignment
43+
if (operators[','] || operators['=']) {
4444
file.iterateTokensByType('Punctuator', function(token, i, tokens) {
45-
if (token.value !== ',') {
45+
var operator = token.value;
46+
if (operator !== ',' && operator !== '=') {
4647
return;
4748
}
4849

4950
var nextToken = tokens[i + 1];
5051
if (nextToken && nextToken.range[0] === token.range[1]) {
5152
errors.add(
52-
'Operator , should not stick to following expression',
53+
'Operator ' + operator + ' should not stick to following expression',
5354
token.loc.start
5455
);
5556
}

test/rules/require-space-after-binary-operators.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,13 @@ describe('rules/require-space-after-binary-operators', function() {
4545
checker.configure({ requireSpaceAfterBinaryOperators: [','] });
4646
assert(checker.checkString('({a: 1, b: 2})').isEmpty());
4747
});
48+
it('should report assignment operator for "a = b"', function() {
49+
checker.configure({ requireSpaceAfterBinaryOperators: ['='] });
50+
assert(checker.checkString('a = b').isEmpty());
51+
});
52+
it('should not report assignment operator for "a=b"', function() {
53+
checker.configure({ requireSpaceAfterBinaryOperators: ['='] });
54+
assert(checker.checkString('a=b').getErrorCount() === 1);
55+
});
4856

4957
});

0 commit comments

Comments
 (0)