Skip to content

Commit

Permalink
quotes: fixed duplicated test and use a proper error message
Browse files Browse the repository at this point in the history
  • Loading branch information
robclancy committed Dec 22, 2022
1 parent 5496d3b commit dd13d2a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
5 changes: 4 additions & 1 deletion lib/rules/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ export default class Quotes extends Rule {
} else if (goodChars.hbs === chars.double && goodChars.html === chars.double) {
message = 'you must use double quotes in templates';
} else {
message = 'you must use double quotes x and single quotes in y in templates';
const double = goodChars.hbs === chars.double ? 'Handlebars syntax' : 'HTML attributes';
const single = goodChars.hbs === chars.single ? 'Handlebars syntax' : 'HTML attributes';

message = `you must use double quotes for ${double} and single quotes for ${single} in templates`;
}

return {
Expand Down
24 changes: 12 additions & 12 deletions test/unit/rules/quotes-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ generateRuleTests({
"filePath": "layout.hbs",
"isFixable": true,
"line": 1,
"message": "you must use double quotes x and single quotes in y in templates",
"message": "you must use double quotes for Handlebars syntax and single quotes for HTML attributes in templates",
"rule": "quotes",
"severity": 2,
"source": "type=\\"checkbox\\"",
Expand All @@ -303,7 +303,7 @@ generateRuleTests({
"filePath": "layout.hbs",
"isFixable": true,
"line": 1,
"message": "you must use double quotes x and single quotes in y in templates",
"message": "you must use double quotes for Handlebars syntax and single quotes for HTML attributes in templates",
"rule": "quotes",
"severity": 2,
"source": "{{hello 'test' x='test'}}",
Expand All @@ -315,7 +315,7 @@ generateRuleTests({
"filePath": "layout.hbs",
"isFixable": true,
"line": 1,
"message": "you must use double quotes x and single quotes in y in templates",
"message": "you must use double quotes for Handlebars syntax and single quotes for HTML attributes in templates",
"rule": "quotes",
"severity": 2,
"source": "x='test'",
Expand All @@ -325,9 +325,9 @@ generateRuleTests({
},
},
{
config: { hbs: 'double', html: 'single' },
template: `<input type="checkbox"> {{hello 'test' x='test'}}`,
fixedTemplate: `<input type='checkbox'> {{hello "test" x="test"}}`,
config: { hbs: 'single', html: 'double' },
template: `<input type='checkbox'> {{hello "test" x="test"}}`,
fixedTemplate: `<input type="checkbox"> {{hello 'test' x='test'}}`,

verifyResults(results) {
expect(results).toMatchInlineSnapshot(`
Expand All @@ -339,10 +339,10 @@ generateRuleTests({
"filePath": "layout.hbs",
"isFixable": true,
"line": 1,
"message": "you must use double quotes x and single quotes in y in templates",
"message": "you must use double quotes for HTML attributes and single quotes for Handlebars syntax in templates",
"rule": "quotes",
"severity": 2,
"source": "type=\\"checkbox\\"",
"source": "type='checkbox'",
},
{
"column": 32,
Expand All @@ -351,10 +351,10 @@ generateRuleTests({
"filePath": "layout.hbs",
"isFixable": true,
"line": 1,
"message": "you must use double quotes x and single quotes in y in templates",
"message": "you must use double quotes for HTML attributes and single quotes for Handlebars syntax in templates",
"rule": "quotes",
"severity": 2,
"source": "{{hello 'test' x='test'}}",
"source": "{{hello \\"test\\" x=\\"test\\"}}",
},
{
"column": 41,
Expand All @@ -363,10 +363,10 @@ generateRuleTests({
"filePath": "layout.hbs",
"isFixable": true,
"line": 1,
"message": "you must use double quotes x and single quotes in y in templates",
"message": "you must use double quotes for HTML attributes and single quotes for Handlebars syntax in templates",
"rule": "quotes",
"severity": 2,
"source": "x='test'",
"source": "x=\\"test\\"",
},
]
`);
Expand Down

0 comments on commit dd13d2a

Please sign in to comment.