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

Commit ebf8da8

Browse files
committed
Hotfix: Fix binary rules for "," and "=" operators
Fixes #376
1 parent 5e010a6 commit ebf8da8

8 files changed

+20
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module.exports.prototype = {
4343
if (operators[','] || operators['=']) {
4444
file.iterateTokensByType('Punctuator', function(token, i, tokens) {
4545
var operator = token.value;
46-
if (operator !== ',' && operator !== '=') {
46+
if (operator !== ',' && operator !== '=' || !operators[operator]) {
4747
return;
4848
}
4949

lib/rules/disallow-space-before-binary-operators.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ module.exports.prototype = {
4242
if (operators[','] || operators['=']) {
4343
file.iterateTokensByType('Punctuator', function(token, i, tokens) {
4444
var operator = token.value;
45-
if (operator !== ',' && operator !== '=') {
45+
if (operator !== ',' && operator !== '=' || !operators[operator]) {
4646
return;
4747
}
4848

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module.exports.prototype = {
4343
if (operators[','] || operators['=']) {
4444
file.iterateTokensByType('Punctuator', function(token, i, tokens) {
4545
var operator = token.value;
46-
if (operator !== ',' && operator !== '=') {
46+
if (operator !== ',' && operator !== '=' || !operators[operator]) {
4747
return;
4848
}
4949

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ module.exports.prototype = {
4242
if (operators[','] || operators['=']) {
4343
file.iterateTokensByType('Punctuator', function(token, i, tokens) {
4444
var operator = token.value;
45-
if (operator !== ',' && operator !== '=') {
45+
if (operator !== ',' && operator !== '=' || !operators[operator]) {
4646
return;
4747
}
4848

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,9 @@ describe('rules/disallow-space-after-binary-operators', function() {
4949
checker.configure({ disallowSpaceAfterBinaryOperators: ['='] });
5050
assert(checker.checkString('a=b').isEmpty());
5151
});
52+
it('should not report assignment operator for "a = b" without option', function() {
53+
checker.configure({ disallowSpaceAfterBinaryOperators: [','] });
54+
assert(checker.checkString('a = b').isEmpty());
55+
});
5256

5357
});

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,8 @@ describe('rules/disallow-space-before-binary-operators', function() {
4949
checker.configure({ disallowSpaceBeforeBinaryOperators: ['='] });
5050
assert(checker.checkString('a=b').isEmpty());
5151
});
52+
it('should not report assignment operator for "a = b" without option', function() {
53+
checker.configure({ disallowSpaceBeforeBinaryOperators: [','] });
54+
assert(checker.checkString('a = b').isEmpty());
55+
});
5256
});

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,9 @@ describe('rules/require-space-after-binary-operators', function() {
5353
checker.configure({ requireSpaceAfterBinaryOperators: ['='] });
5454
assert(checker.checkString('a=b').getErrorCount() === 1);
5555
});
56+
it('should not report assignment operator for "a = b" without option', function() {
57+
checker.configure({ requireSpaceAfterBinaryOperators: [','] });
58+
assert(checker.checkString('a=b').isEmpty());
59+
});
5660

5761
});

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,9 @@ describe('rules/require-space-before-binary-operators', function() {
5353
checker.configure({ requireSpaceBeforeBinaryOperators: ['='] });
5454
assert(checker.checkString('a=b').getErrorCount() === 1);
5555
});
56+
it('should not report assignment operator for "a = b" without option', function() {
57+
checker.configure({ requireSpaceBeforeBinaryOperators: [','] });
58+
assert(checker.checkString('a= b').isEmpty());
59+
});
5660

5761
});

0 commit comments

Comments
 (0)