Skip to content

Commit

Permalink
fix: Improve violation reporting location for no-unused-placeholders (
Browse files Browse the repository at this point in the history
#279)

* fix: reporting location for no-unused-placeholders

* improve test
  • Loading branch information
bmish committed Aug 4, 2022
1 parent 31ff45c commit 27c0b65
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/rules/no-unused-placeholders.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ module.exports = {
const key = utils.getKeyName(prop);
if (!placeholdersInMessage.has(key)) {
context.report({
node: message,
node: prop,
messageId: 'placeholderUnused',
data: { unusedKey: key },
});
Expand Down
14 changes: 13 additions & 1 deletion tests/lib/rules/no-missing-placeholders.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,19 @@ ruleTester.run('no-missing-placeholders', rule, {
}
};
`,
errors: [error('bar', 'Literal')],
errors: [
error(
'bar',
'Literal',
// report on `message`
{
line: 6,
endLine: 6,
column: 24,
endColumn: 37,
}
),
],
},
{
code: `
Expand Down
20 changes: 16 additions & 4 deletions tests/lib/rules/no-unused-placeholders.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ const RuleTester = require('eslint').RuleTester;
* @param {string} unusedKey The placeholder that is unused
* @returns {object} An expected error
*/
function error(unusedKey, type = 'Literal') {
function error(unusedKey, extra) {
return {
type,
type: 'Property', // The property in the report's `data` object for the unused placeholder.
message: `The placeholder {{${unusedKey}}} is unused (does not exist in the actual message).`,
...extra,
};
}

Expand Down Expand Up @@ -211,7 +212,18 @@ ruleTester.run('no-unused-placeholders', rule, {
}
};
`,
errors: [error('bar')],
errors: [
error(
'bar',
// report on property in data object
{
line: 7,
endLine: 7,
column: 23,
endColumn: 26,
}
),
],
},
{
// With `create` as variable.
Expand Down Expand Up @@ -241,7 +253,7 @@ ruleTester.run('no-unused-placeholders', rule, {
}
};
`,
errors: [error('bar', 'Identifier')],
errors: [error('bar')],
},
{
code: `
Expand Down

0 comments on commit 27c0b65

Please sign in to comment.