Skip to content

Commit

Permalink
Chore: use messageId in rule template-curly-spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
aladdin-add committed Aug 19, 2018
1 parent ce644b8 commit 4bd596d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
20 changes: 10 additions & 10 deletions lib/rules/template-curly-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,19 @@ module.exports = {

schema: [
{ enum: ["always", "never"] }
]
],
messages: {
expectedBefore: "Expected space(s) before '}'.",
expectedAfter: "Expected space(s) after '${'.",
unexpectedBefore: "Unexpected space(s) before '}'.",
unexpectedAfter: "Unexpected space(s) after '${'."
}
},

create(context) {
const sourceCode = context.getSourceCode();
const always = context.options[0] === "always";
const prefix = always ? "Expected" : "Unexpected";
const prefix = always ? "expected" : "unexpected";

/**
* Checks spacing before `}` of a given token.
Expand All @@ -58,10 +64,7 @@ module.exports = {
) {
context.report({
loc: token.loc.start,
message: "{{prefix}} space(s) before '}'.",
data: {
prefix
},
messageId: `${prefix}Before`,
fix(fixer) {
if (always) {
return fixer.insertTextBefore(token, " ");
Expand Down Expand Up @@ -93,10 +96,7 @@ module.exports = {
line: token.loc.end.line,
column: token.loc.end.column - 2
},
message: "{{prefix}} space(s) after '${'.",
data: {
prefix
},
messageId: `${prefix}After`,
fix(fixer) {
if (always) {
return fixer.insertTextAfter(token, " ");
Expand Down
48 changes: 24 additions & 24 deletions tests/lib/rules/template-curly-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,64 +33,64 @@ ruleTester.run("template-curly-spacing", rule, {
code: "`${ foo } ${ bar }`",
output: "`${foo} ${bar}`",
errors: [
{ message: "Unexpected space(s) after '${'.", column: 2 },
{ message: "Unexpected space(s) before '}'.", column: 9 },
{ message: "Unexpected space(s) after '${'.", column: 11 },
{ message: "Unexpected space(s) before '}'.", column: 18 }
{ messageId: "unexpectedAfter", column: 2 },
{ messageId: "unexpectedBefore", column: 9 },
{ messageId: "unexpectedAfter", column: 11 },
{ messageId: "unexpectedBefore", column: 18 }
]
},
{
code: "`${ foo } ${ bar }`",
output: "`${foo} ${bar}`",
options: ["never"],
errors: [
{ message: "Unexpected space(s) after '${'.", column: 2 },
{ message: "Unexpected space(s) before '}'.", column: 9 },
{ message: "Unexpected space(s) after '${'.", column: 11 },
{ message: "Unexpected space(s) before '}'.", column: 18 }
{ messageId: "unexpectedAfter", column: 2 },
{ messageId: "unexpectedBefore", column: 9 },
{ messageId: "unexpectedAfter", column: 11 },
{ messageId: "unexpectedBefore", column: 18 }
]
},
{
code: "`${foo} ${bar}`",
output: "`${ foo } ${ bar }`",
options: ["always"],
errors: [
{ message: "Expected space(s) after '${'.", column: 2 },
{ message: "Expected space(s) before '}'.", column: 7 },
{ message: "Expected space(s) after '${'.", column: 9 },
{ message: "Expected space(s) before '}'.", column: 14 }
{ messageId: "expectedAfter", column: 2 },
{ messageId: "expectedBefore", column: 7 },
{ messageId: "expectedAfter", column: 9 },
{ messageId: "expectedBefore", column: 14 }
]
},
{
code: "tag`${ foo } ${ bar }`",
output: "tag`${foo} ${bar}`",
errors: [
{ message: "Unexpected space(s) after '${'.", column: 5 },
{ message: "Unexpected space(s) before '}'.", column: 12 },
{ message: "Unexpected space(s) after '${'.", column: 14 },
{ message: "Unexpected space(s) before '}'.", column: 21 }
{ messageId: "unexpectedAfter", column: 5 },
{ messageId: "unexpectedBefore", column: 12 },
{ messageId: "unexpectedAfter", column: 14 },
{ messageId: "unexpectedBefore", column: 21 }
]
},
{
code: "tag`${ foo } ${ bar }`",
output: "tag`${foo} ${bar}`",
options: ["never"],
errors: [
{ message: "Unexpected space(s) after '${'.", column: 5 },
{ message: "Unexpected space(s) before '}'.", column: 12 },
{ message: "Unexpected space(s) after '${'.", column: 14 },
{ message: "Unexpected space(s) before '}'.", column: 21 }
{ messageId: "unexpectedAfter", column: 5 },
{ messageId: "unexpectedBefore", column: 12 },
{ messageId: "unexpectedAfter", column: 14 },
{ messageId: "unexpectedBefore", column: 21 }
]
},
{
code: "tag`${foo} ${bar}`",
output: "tag`${ foo } ${ bar }`",
options: ["always"],
errors: [
{ message: "Expected space(s) after '${'.", column: 5 },
{ message: "Expected space(s) before '}'.", column: 10 },
{ message: "Expected space(s) after '${'.", column: 12 },
{ message: "Expected space(s) before '}'.", column: 17 }
{ messageId: "expectedAfter", column: 5 },
{ messageId: "expectedBefore", column: 10 },
{ messageId: "expectedAfter", column: 12 },
{ messageId: "expectedBefore", column: 17 }
]
}
]
Expand Down

0 comments on commit 4bd596d

Please sign in to comment.