Skip to content

Commit

Permalink
Chore: use messageId in rule template-tag-spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
aladdin-add committed Aug 19, 2018
1 parent 4bd596d commit e974343
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 90 deletions.
10 changes: 7 additions & 3 deletions lib/rules/template-tag-spacing.js
Expand Up @@ -22,7 +22,11 @@ module.exports = {

schema: [
{ enum: ["always", "never"] }
]
],
messages: {
unexpected: "Unexpected space between template tag and template literal.",
missing: "Missing space between template tag and template literal."
}
},

create(context) {
Expand All @@ -44,7 +48,7 @@ module.exports = {
context.report({
node,
loc: tagToken.loc.start,
message: "Unexpected space between template tag and template literal.",
messageId: "unexpected",
fix(fixer) {
const comments = sourceCode.getCommentsBefore(node.quasi);

Expand All @@ -63,7 +67,7 @@ module.exports = {
context.report({
node,
loc: tagToken.loc.start,
message: "Missing space between template tag and template literal.",
messageId: "missing",
fix(fixer) {
return fixer.insertTextAfter(tagToken, " ");
}
Expand Down
118 changes: 31 additions & 87 deletions tests/lib/rules/template-tag-spacing.js
Expand Up @@ -17,6 +17,8 @@ const rule = require("../../../lib/rules/template-tag-spacing"),
//------------------------------------------------------------------------------

const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } });
const unexpectedError = { messageId: "unexpected" };
const missingError = { messageId: "missing" };

ruleTester.run("template-tag-spacing", rule, {
valid: [
Expand Down Expand Up @@ -53,225 +55,167 @@ ruleTester.run("template-tag-spacing", rule, {
{
code: "tag `name`",
output: "tag`name`",
errors: [
{ message: "Unexpected space between template tag and template literal." }
]
errors: [unexpectedError]
},
{
code: "tag `name`",
output: "tag`name`",
options: ["never"],
errors: [
{ message: "Unexpected space between template tag and template literal." }
]
errors: [unexpectedError]
},
{
code: "tag`name`",
output: "tag `name`",
options: ["always"],
errors: [
{ message: "Missing space between template tag and template literal." }
]
errors: [missingError]
},
{
code: "tag /*here's a comment*/`Hello world`",
output: "tag/*here's a comment*/`Hello world`",
options: ["never"],
errors: [
{ message: "Unexpected space between template tag and template literal." }
]
errors: [unexpectedError]
},
{
code: "tag/*here's a comment*/ `Hello world`",
output: "tag/*here's a comment*/`Hello world`",
options: ["never"],
errors: [
{ message: "Unexpected space between template tag and template literal." }
]
errors: [unexpectedError]
},
{
code: "tag/*here's a comment*/`Hello world`",
output: "tag /*here's a comment*/`Hello world`",
options: ["always"],
errors: [
{ message: "Missing space between template tag and template literal." }
]
errors: [missingError]
},
{
code: "tag // here's a comment \n`bar`",
output: null,
errors: [
{ message: "Unexpected space between template tag and template literal." }
]
errors: [unexpectedError]
},
{
code: "tag // here's a comment \n`bar`",
output: null,
options: ["never"],
errors: [
{ message: "Unexpected space between template tag and template literal." }
]
errors: [unexpectedError]
},
{
code: "tag `hello ${name}`",
output: "tag`hello ${name}`",
errors: [
{ message: "Unexpected space between template tag and template literal." }
]
errors: [unexpectedError]
},
{
code: "tag `hello ${name}`",
output: "tag`hello ${name}`",
options: ["never"],
errors: [
{ message: "Unexpected space between template tag and template literal." }
]
errors: [unexpectedError]
},
{
code: "tag`hello ${name}`",
output: "tag `hello ${name}`",
options: ["always"],
errors: [
{ message: "Missing space between template tag and template literal." }
]
errors: [missingError]
},
{
code: "new tag `name`",
output: "new tag`name`",
errors: [
{ message: "Unexpected space between template tag and template literal." }
]
errors: [unexpectedError]
},
{
code: "new tag `name`",
output: "new tag`name`",
options: ["never"],
errors: [
{ message: "Unexpected space between template tag and template literal." }
]
errors: [unexpectedError]
},
{
code: "new tag`name`",
output: "new tag `name`",
options: ["always"],
errors: [
{ message: "Missing space between template tag and template literal." }
]
errors: [missingError]
},
{
code: "new tag `hello ${name}`",
output: "new tag`hello ${name}`",
errors: [
{ message: "Unexpected space between template tag and template literal." }
]
errors: [unexpectedError]
},
{
code: "new tag `hello ${name}`",
output: "new tag`hello ${name}`",
options: ["never"],
errors: [
{ message: "Unexpected space between template tag and template literal." }
]
errors: [unexpectedError]
},
{
code: "new tag`hello ${name}`",
output: "new tag `hello ${name}`",
options: ["always"],
errors: [
{ message: "Missing space between template tag and template literal." }
]
errors: [missingError]
},
{
code: "(tag) `name`",
output: "(tag)`name`",
errors: [
{ message: "Unexpected space between template tag and template literal." }
]
errors: [unexpectedError]
},
{
code: "(tag) `name`",
output: "(tag)`name`",
options: ["never"],
errors: [
{ message: "Unexpected space between template tag and template literal." }
]
errors: [unexpectedError]
},
{
code: "(tag)`name`",
output: "(tag) `name`",
options: ["always"],
errors: [
{ message: "Missing space between template tag and template literal." }
]
errors: [missingError]
},
{
code: "(tag) `hello ${name}`",
output: "(tag)`hello ${name}`",
errors: [
{ message: "Unexpected space between template tag and template literal." }
]
errors: [unexpectedError]
},
{
code: "(tag) `hello ${name}`",
output: "(tag)`hello ${name}`",
options: ["never"],
errors: [
{ message: "Unexpected space between template tag and template literal." }
]
errors: [unexpectedError]
},
{
code: "(tag)`hello ${name}`",
output: "(tag) `hello ${name}`",
options: ["always"],
errors: [
{ message: "Missing space between template tag and template literal." }
]
errors: [missingError]
},
{
code: "new (tag) `name`",
output: "new (tag)`name`",
errors: [
{ message: "Unexpected space between template tag and template literal." }
]
errors: [unexpectedError]
},
{
code: "new (tag) `name`",
output: "new (tag)`name`",
options: ["never"],
errors: [
{ message: "Unexpected space between template tag and template literal." }
]
errors: [unexpectedError]
},
{
code: "new (tag)`name`",
output: "new (tag) `name`",
options: ["always"],
errors: [
{ message: "Missing space between template tag and template literal." }
]
errors: [missingError]
},
{
code: "new (tag) `hello ${name}`",
output: "new (tag)`hello ${name}`",
errors: [
{ message: "Unexpected space between template tag and template literal." }
]
errors: [unexpectedError]
},
{
code: "new (tag) `hello ${name}`",
output: "new (tag)`hello ${name}`",
options: ["never"],
errors: [
{ message: "Unexpected space between template tag and template literal." }
]
errors: [unexpectedError]
},
{
code: "new (tag)`hello ${name}`",
output: "new (tag) `hello ${name}`",
options: ["always"],
errors: [
{ message: "Missing space between template tag and template literal." }
]
errors: [missingError]
}
]
});

0 comments on commit e974343

Please sign in to comment.