diff --git a/lib/rules/template-tag-spacing.js b/lib/rules/template-tag-spacing.js index aee7ac108be1..2cbf1a06c31d 100644 --- a/lib/rules/template-tag-spacing.js +++ b/lib/rules/template-tag-spacing.js @@ -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) { @@ -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); @@ -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, " "); } diff --git a/tests/lib/rules/template-tag-spacing.js b/tests/lib/rules/template-tag-spacing.js index 2475d727ba28..4de2d807184a 100644 --- a/tests/lib/rules/template-tag-spacing.js +++ b/tests/lib/rules/template-tag-spacing.js @@ -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: [ @@ -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] } ] });