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

Commit bdf0e99

Browse files
Alexej Yaroshevichmikesherov
authored andcommitted
Object Key rules: ignore method syntax
Fixes #1013 Closes gh-1020
1 parent 3beb93d commit bdf0e99

12 files changed

Lines changed: 36 additions & 6 deletions

lib/rules/disallow-space-after-object-keys.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module.exports.prototype = {
4141
check: function(file, errors) {
4242
file.iterateNodesByType('ObjectExpression', function(node) {
4343
node.properties.forEach(function(property) {
44-
if (property.shorthand) {
44+
if (property.shorthand || property.method) {
4545
return;
4646
}
4747

lib/rules/disallow-space-before-object-values.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module.exports.prototype = {
4141
check: function(file, errors) {
4242
file.iterateNodesByType('ObjectExpression', function(node) {
4343
node.properties.forEach(function(property) {
44-
if (property.shorthand) {
44+
if (property.shorthand || property.method) {
4545
return;
4646
}
4747

lib/rules/require-aligned-object-values.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ module.exports.prototype = {
6767

6868
var maxKeyEndPos = 0;
6969
var skip = node.properties.some(function(property, index) {
70-
if (property.shorthand) {
70+
if (property.shorthand || property.method) {
7171
return true;
7272
}
7373

lib/rules/require-quoted-keys-in-objects.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ module.exports.prototype = {
4444
check: function(file, errors) {
4545
file.iterateNodesByType('ObjectExpression', function(node) {
4646
node.properties.forEach(function(prop) {
47-
if (prop.shorthand) {
47+
if (prop.shorthand || prop.method) {
4848
return;
4949
}
5050

lib/rules/require-space-after-object-keys.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module.exports.prototype = {
4141
check: function(file, errors) {
4242
file.iterateNodesByType('ObjectExpression', function(node) {
4343
node.properties.forEach(function(property) {
44-
if (property.shorthand) {
44+
if (property.shorthand || property.method) {
4545
return;
4646
}
4747

lib/rules/require-space-before-object-values.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module.exports.prototype = {
4141
check: function(file, errors) {
4242
file.iterateNodesByType('ObjectExpression', function(node) {
4343
node.properties.forEach(function(property) {
44-
if (property.shorthand) {
44+
if (property.shorthand || property.method) {
4545
return;
4646
}
4747

test/rules/disallow-space-after-object-keys.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,9 @@ describe('rules/disallow-space-after-object-keys', function() {
3939
checker.configure({ esnext: true });
4040
assert.equal(checker.checkString('var x = { a : 1, b };').getErrorCount(), 1);
4141
});
42+
43+
it('should not report es6-methods. #1013', function() {
44+
checker.configure({ esnext: true });
45+
assert(checker.checkString('var x = { a() { } };').isEmpty());
46+
});
4247
});

test/rules/disallow-space-before-object-values.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,9 @@ describe('rules/disallow-space-before-object-values', function() {
5151
checker.configure({ esnext: true });
5252
assert.equal(checker.checkString('var x = { a : 1, b };').getErrorCount(), 1);
5353
});
54+
55+
it('should not report es6-methods. #1013', function() {
56+
checker.configure({ esnext: true });
57+
assert(checker.checkString('var x = { a() { } };').isEmpty());
58+
});
5459
});

test/rules/require-aligned-object-values.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ describe('rules/require-aligned-object-values', function() {
4646
);
4747
});
4848

49+
it('should not report es6-methods. #1013', function() {
50+
checker.configure({ esnext: true });
51+
assert(checker.checkString('var x = { a() { } };').isEmpty());
52+
});
53+
4954
it('should report invalid alignment', function() {
5055
assert(
5156
checker.checkString(

test/rules/require-quoted-keys-in-objects.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,9 @@ describe('rules/require-quoted-keys-in-objects', function() {
6767
checker.configure({ esnext: true });
6868
assert(checker.checkString('var x = { a, b };').isEmpty());
6969
});
70+
71+
it('should not report es6-methods. #1013', function() {
72+
checker.configure({ esnext: true });
73+
assert(checker.checkString('var x = { a() { } };').isEmpty());
74+
});
7075
});

0 commit comments

Comments
 (0)