You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
main: 'The service `{{name}}` is not referenced in this JS file and might be unused (note: it could still be used in a corresponding handlebars template file, mixin, or parent/child class).',
29
+
main: 'The service `{{name}}` is not referenced in this file and might be unused (note: it could still be used in a corresponding handlebars template file, mixin, or parent/child class).',
28
30
removeServiceInjection: 'Remove the service injection.',
29
31
},
30
32
},
@@ -170,7 +172,22 @@ module.exports = {
170
172
return;
171
173
}
172
174
173
-
if(
175
+
if(node.callee.name===TEMPLATE_TAG_PLACEHOLDER){
176
+
// This is the <template></template> tag placeholder
177
+
// We now have to parse the template elements here to see if the services are used
Copy file name to clipboardExpand all lines: tests/lib/rules-preprocessor/gjs-gts-processor-test.js
+49Lines changed: 49 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -43,6 +43,7 @@ function initESLint(parser = '@babel/eslint-parser') {
43
43
'no-unused-vars': 'error',
44
44
'ember/no-get': 'off',
45
45
'ember/no-array-prototype-extensions': 'error',
46
+
'ember/no-unused-services': 'error',
46
47
},
47
48
},
48
49
});
@@ -116,6 +117,23 @@ const valid = [
116
117
}`,
117
118
parser: '@typescript-eslint/parser',
118
119
},
120
+
{
121
+
filename: 'my-component.gjs',
122
+
code: `
123
+
import Component from '@glimmer/component';
124
+
import { inject as service } from '@ember/service';
125
+
126
+
export default class MyComponent extends Component {
127
+
@service foo;
128
+
129
+
<template>
130
+
{{this.foo}}
131
+
<div></div>
132
+
foobar
133
+
</template>
134
+
}
135
+
`,
136
+
},
119
137
/**
120
138
* TODO: SKIP this scenario. Tracked in https://github.com/ember-cli/eslint-plugin-ember/issues/1685
121
139
{
@@ -285,6 +303,37 @@ const invalid = [
285
303
},
286
304
],
287
305
},
306
+
{
307
+
filename: 'my-component.gjs',
308
+
code: `
309
+
import Component from '@glimmer/component';
310
+
import { inject as service } from '@ember/service';
311
+
312
+
export default class MyComponent extends Component {
313
+
@service foo;
314
+
315
+
@service bar;
316
+
317
+
<template>
318
+
{{this.foo.bar}}
319
+
{{this.bartender}}
320
+
<div>this.bar</div>
321
+
this.bar.foo
322
+
something.bar
323
+
</template>
324
+
}
325
+
`,
326
+
errors: [
327
+
{
328
+
message:
329
+
'The service `bar` is not referenced in this file and might be unused (note: it could still be used in a corresponding handlebars template file, mixin, or parent/child class).',
0 commit comments