Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: consider comments in object-curly-spacing (fixes #11656) #11657

Merged
merged 1 commit into from Apr 30, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Fix: consider comments in object-curly-spacing (fixes #11656)

  • Loading branch information...
g-plane committed Apr 27, 2019
commit 6bac777596f40d5239fc12937b72f9cc169749fd
@@ -82,7 +82,7 @@ module.exports = {
token: token.value
},
fix(fixer) {
const nextToken = context.getSourceCode().getTokenAfter(token);
const nextToken = context.getSourceCode().getTokenAfter(token, { includeComments: true });

return fixer.removeRange([token.range[1], nextToken.range[0]]);
}
@@ -104,7 +104,7 @@ module.exports = {
token: token.value
},
fix(fixer) {
const previousToken = context.getSourceCode().getTokenBefore(token);
const previousToken = context.getSourceCode().getTokenBefore(token, { includeComments: true });

return fixer.removeRange([previousToken.range[1], token.range[0]]);
}
@@ -225,8 +225,8 @@ module.exports = {

const first = sourceCode.getFirstToken(node),
last = getClosingBraceOfObject(node),
second = sourceCode.getTokenAfter(first),
penultimate = sourceCode.getTokenBefore(last);
second = sourceCode.getTokenAfter(first, { includeComments: true }),
penultimate = sourceCode.getTokenBefore(last, { includeComments: true });

validateBraceSpacing(node, first, second, penultimate, last);
}
@@ -253,8 +253,8 @@ module.exports = {

const first = sourceCode.getTokenBefore(firstSpecifier),
last = sourceCode.getTokenAfter(lastSpecifier, astUtils.isNotCommaToken),
second = sourceCode.getTokenAfter(first),
penultimate = sourceCode.getTokenBefore(last);
second = sourceCode.getTokenAfter(first, { includeComments: true }),
penultimate = sourceCode.getTokenBefore(last, { includeComments: true });

validateBraceSpacing(node, first, second, penultimate, last);
}
@@ -273,8 +273,8 @@ module.exports = {
lastSpecifier = node.specifiers[node.specifiers.length - 1],
first = sourceCode.getTokenBefore(firstSpecifier),
last = sourceCode.getTokenAfter(lastSpecifier, astUtils.isNotCommaToken),
second = sourceCode.getTokenAfter(first),
penultimate = sourceCode.getTokenBefore(last);
second = sourceCode.getTokenAfter(first, { includeComments: true }),
penultimate = sourceCode.getTokenBefore(last, { includeComments: true });

validateBraceSpacing(node, first, second, penultimate, last);
}
@@ -84,6 +84,8 @@ ruleTester.run("object-curly-spacing", rule, {
{ code: "var obj = {foo: {\nbar: quxx}, baz: qux\n};", options: ["never"] },
{ code: "var obj = {foo: {\nbar: quxx\n}, baz: qux};", options: ["never"] },
{ code: "var obj = {\nfoo: bar,\nbaz: qux\n};", options: ["never"] },
{ code: "var obj = {foo: bar, baz: qux /* */};", options: ["never"] },
{ code: "var obj = {/* */ foo: bar, baz: qux};", options: ["never"] },

// never - destructuring
{ code: "var {x} = y", options: ["never"], parserOptions: { ecmaVersion: 6 } },
@@ -97,12 +99,18 @@ ruleTester.run("object-curly-spacing", rule, {
{ code: "var {\ny,\n} = x", options: ["never"], parserOptions: { ecmaVersion: 6 } },
{ code: "var {y,} = x", options: ["never"], parserOptions: { ecmaVersion: 6 } },
{ code: "var {y:x} = x", options: ["never"], parserOptions: { ecmaVersion: 6 } },
{ code: "var {/* */ y} = x", options: ["never"], parserOptions: { ecmaVersion: 6 } },
{ code: "var {y /* */} = x", options: ["never"], parserOptions: { ecmaVersion: 6 } },

// never - import / export
{ code: "import door from 'room'", options: ["never"], parserOptions: { sourceType: "module" } },
{ code: "import * as door from 'room'", options: ["never"], parserOptions: { sourceType: "module" } },
{ code: "import {door} from 'room'", options: ["never"], parserOptions: { sourceType: "module" } },
{ code: "export {door} from 'room'", options: ["never"], parserOptions: { sourceType: "module" } },
{ code: "import {/* */ door} from 'room'", options: ["never"], parserOptions: { sourceType: "module" } },
{ code: "export {/* */ door} from 'room'", options: ["never"], parserOptions: { sourceType: "module" } },
{ code: "import {door /* */} from 'room'", options: ["never"], parserOptions: { sourceType: "module" } },
{ code: "export {door /* */} from 'room'", options: ["never"], parserOptions: { sourceType: "module" } },
{ code: "import {\ndoor} from 'room'", options: ["never"], parserOptions: { sourceType: "module" } },
{ code: "export {\ndoor\n} from 'room'", options: ["never"], parserOptions: { sourceType: "module" } },
{ code: "import {house,mouse} from 'caravan'", options: ["never"], parserOptions: { sourceType: "module" } },
@@ -235,6 +243,34 @@ ruleTester.run("object-curly-spacing", rule, {

]
},
{
code: "import x, { bar/* */} from 'foo';",
output: "import x, { bar/* */ } from 'foo';",
options: ["always"],
parserOptions: { sourceType: "module" },
errors: [
{
message: "A space is required before '}'.",
type: "ImportDeclaration",
line: 1,
column: 21
}
]
},
{
code: "import x, {/* */bar } from 'foo';",
output: "import x, { /* */bar } from 'foo';",
options: ["always"],
parserOptions: { sourceType: "module" },
errors: [
{
message: "A space is required after '{'.",
type: "ImportDeclaration",
line: 1,
column: 11
}
]
},
{
code: "import x, { bar, baz} from 'foo';",
output: "import x, { bar, baz } from 'foo';",
@@ -332,6 +368,26 @@ ruleTester.run("object-curly-spacing", rule, {
}
]
},
{
code: "import { /* */ bar, /* */ } from 'foo';",
output: "import {/* */ bar, /* */} from 'foo';",
options: ["never"],
parserOptions: { sourceType: "module" },
errors: [
{
message: "There should be no space after '{'.",
type: "ImportDeclaration",
line: 1,
column: 8
},
{
message: "There should be no space before '}'.",
type: "ImportDeclaration",
line: 1,
column: 27
}
]
},
{
code: "var bar = 0;\nexport {bar};",
output: "var bar = 0;\nexport { bar };",
@@ -352,6 +408,26 @@ ruleTester.run("object-curly-spacing", rule, {
}
]
},
{
code: "var bar = 0;\nexport { /* */ bar /* */ };",
output: "var bar = 0;\nexport {/* */ bar /* */};",
options: ["never"],
parserOptions: { sourceType: "module" },
errors: [
{
message: "There should be no space after '{'.",
type: "ExportNamedDeclaration",
line: 2,
column: 8
},
{
message: "There should be no space before '}'.",
type: "ExportNamedDeclaration",
line: 2,
column: 26
}
]
},

// always - arraysInObjects
{
@@ -530,6 +606,19 @@ ruleTester.run("object-curly-spacing", rule, {
}
]
},
{
code: "var obj = {/* */foo: bar, baz: qux };",
output: "var obj = { /* */foo: bar, baz: qux };",
options: ["always"],
errors: [
{
message: "A space is required after '{'.",
type: "ObjectExpression",
line: 1,
column: 11
}
]
},
{
code: "var obj = { foo: bar, baz: qux};",
output: "var obj = { foo: bar, baz: qux };",
@@ -543,6 +632,19 @@ ruleTester.run("object-curly-spacing", rule, {
}
]
},
{
code: "var obj = { foo: bar, baz: qux/* */};",
output: "var obj = { foo: bar, baz: qux/* */ };",
options: ["always"],
errors: [
{
message: "A space is required before '}'.",
type: "ObjectExpression",
line: 1,
column: 36
}
]
},
{
code: "var obj = { foo: bar, baz: qux };",
output: "var obj = {foo: bar, baz: qux};",
@@ -575,6 +677,19 @@ ruleTester.run("object-curly-spacing", rule, {
}
]
},
{
code: "var obj = {foo: bar, baz: qux /* */ };",
output: "var obj = {foo: bar, baz: qux /* */};",
options: ["never"],
errors: [
{
message: "There should be no space before '}'.",
type: "ObjectExpression",
line: 1,
column: 37
}
]
},
{
code: "var obj = { foo: bar, baz: qux};",
output: "var obj = {foo: bar, baz: qux};",
@@ -588,6 +703,19 @@ ruleTester.run("object-curly-spacing", rule, {
}
]
},
{
code: "var obj = { /* */ foo: bar, baz: qux};",
output: "var obj = {/* */ foo: bar, baz: qux};",
options: ["never"],
errors: [
{
message: "There should be no space after '{'.",
type: "ObjectExpression",
line: 1,
column: 11
}
]
},
{
code: "var obj = { foo: { bar: quxx}, baz: qux};",
output: "var obj = {foo: {bar: quxx}, baz: qux};",
@@ -676,6 +804,34 @@ ruleTester.run("object-curly-spacing", rule, {
}
]
},
{
code: "var { x, y/* */} = y",
output: "var { x, y/* */ } = y",
options: ["always"],
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "A space is required before '}'.",
type: "ObjectPattern",
line: 1,
column: 16
}
]
},
{
code: "var {/* */x, y } = y",
output: "var { /* */x, y } = y",
options: ["always"],
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "A space is required after '{'.",
type: "ObjectPattern",
line: 1,
column: 5
}
]
},
{
code: "var { x, y } = y",
output: "var {x, y} = y",
@@ -710,6 +866,34 @@ ruleTester.run("object-curly-spacing", rule, {
}
]
},
{
code: "var {x, y/* */ } = y",
output: "var {x, y/* */} = y",
options: ["never"],
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "There should be no space before '}'.",
type: "ObjectPattern",
line: 1,
column: 16
}
]
},
{
code: "var { /* */x, y} = y",
output: "var {/* */x, y} = y",
options: ["never"],
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "There should be no space after '{'.",
type: "ObjectPattern",
line: 1,
column: 5
}
]
},
{
code: "var { x=10} = y",
output: "var { x=10 } = y",
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.