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

Commit cc027af

Browse files
committed
Improve disallowSpaceAfterBinaryOperators rule
Add check for assignment to disallowSpaceAfterBinaryOperators rule
1 parent 2fa28e2 commit cc027af

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

lib/rules/disallow-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 ' + token.value + ' should stick to following expression',
53+
'Operator ' + operator + ' should stick to following expression',
5354
token.loc.start
5455
);
5556
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,13 @@ describe('rules/disallow-space-after-binary-operators', function() {
4141
checker.configure({ disallowSpaceAfterBinaryOperators: [','] });
4242
assert(checker.checkString('({a: 1, b: 2})').getErrorCount() === 1);
4343
});
44+
it('should report assignment operator for "a = b"', function() {
45+
checker.configure({ disallowSpaceAfterBinaryOperators: ['='] });
46+
assert(checker.checkString('a = b').getErrorCount() === 1);
47+
});
48+
it('should not report assignment operator for "a=b"', function() {
49+
checker.configure({ disallowSpaceAfterBinaryOperators: ['='] });
50+
assert(checker.checkString('a=b').isEmpty());
51+
});
4452

4553
});

0 commit comments

Comments
 (0)