Skip to content

Commit 27c0b65

Browse files
authored
fix: Improve violation reporting location for no-unused-placeholders (#279)
* fix: reporting location for no-unused-placeholders * improve test
1 parent 31ff45c commit 27c0b65

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

Diff for: lib/rules/no-unused-placeholders.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ module.exports = {
108108
const key = utils.getKeyName(prop);
109109
if (!placeholdersInMessage.has(key)) {
110110
context.report({
111-
node: message,
111+
node: prop,
112112
messageId: 'placeholderUnused',
113113
data: { unusedKey: key },
114114
});

Diff for: tests/lib/rules/no-missing-placeholders.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,19 @@ ruleTester.run('no-missing-placeholders', rule, {
236236
}
237237
};
238238
`,
239-
errors: [error('bar', 'Literal')],
239+
errors: [
240+
error(
241+
'bar',
242+
'Literal',
243+
// report on `message`
244+
{
245+
line: 6,
246+
endLine: 6,
247+
column: 24,
248+
endColumn: 37,
249+
}
250+
),
251+
],
240252
},
241253
{
242254
code: `

Diff for: tests/lib/rules/no-unused-placeholders.js

+16-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ const RuleTester = require('eslint').RuleTester;
1717
* @param {string} unusedKey The placeholder that is unused
1818
* @returns {object} An expected error
1919
*/
20-
function error(unusedKey, type = 'Literal') {
20+
function error(unusedKey, extra) {
2121
return {
22-
type,
22+
type: 'Property', // The property in the report's `data` object for the unused placeholder.
2323
message: `The placeholder {{${unusedKey}}} is unused (does not exist in the actual message).`,
24+
...extra,
2425
};
2526
}
2627

@@ -211,7 +212,18 @@ ruleTester.run('no-unused-placeholders', rule, {
211212
}
212213
};
213214
`,
214-
errors: [error('bar')],
215+
errors: [
216+
error(
217+
'bar',
218+
// report on property in data object
219+
{
220+
line: 7,
221+
endLine: 7,
222+
column: 23,
223+
endColumn: 26,
224+
}
225+
),
226+
],
215227
},
216228
{
217229
// With `create` as variable.
@@ -241,7 +253,7 @@ ruleTester.run('no-unused-placeholders', rule, {
241253
}
242254
};
243255
`,
244-
errors: [error('bar', 'Identifier')],
256+
errors: [error('bar')],
245257
},
246258
{
247259
code: `

0 commit comments

Comments
 (0)