Skip to content

Commit f211ee4

Browse files
Merge pull request #2715 from johanrd/feat/hbs-parser-reexport
feat: re-export hbs parser and document HBS flat-config setup
2 parents 24882a3 + 85d4f4b commit f211ee4

3 files changed

Lines changed: 34 additions & 1 deletion

File tree

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,36 @@ export default [
174174

175175
`template-lint-migration` mirrors the ember-template-lint `recommended` preset.
176176

177+
### Linting `.hbs` files
178+
179+
ESLint flat config only picks up `.hbs` files when a `files` glob names them. Add a dedicated block so they route to the Handlebars parser:
180+
181+
```js
182+
// eslint.config.mjs
183+
import { hbsParser, plugin as emberPlugin } from 'eslint-plugin-ember/recommended';
184+
185+
export default [
186+
// ...other blocks...
187+
{
188+
files: ['app/**/*.hbs'],
189+
languageOptions: { parser: hbsParser },
190+
plugins: { ember: emberPlugin },
191+
rules: {
192+
'ember/template-no-bare-strings': 'error',
193+
// ...other template rules...
194+
},
195+
},
196+
];
197+
```
198+
199+
Make sure no earlier `@typescript-eslint/parser` block's `files` glob reaches `.hbs` — narrow it to `['**/*.{js,ts,gjs,gts}']` (or similar). Flat config merges rules across every matching block, so even if our HBS block overrides the parser, type-info rules from a matching TS block still layer on and fail with errors like:
200+
201+
> Parsing error: `` was not found by the project service because the extension for the file (`.hbs`) is non-standard.
202+
203+
or
204+
205+
> Error while loading rule `@typescript-eslint/await-thenable`: You have used a rule which requires type information.
206+
177207
### Replacing `template-lint-disable` comments
178208

179209
Inline disable directives need to be rewritten to ESLint's syntax, prefixed with `ember/template-`. For now, only two scopes are supported: the next line, or the rest of the file. For example, replace:

eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ module.exports = [
224224
'import/default': 'off',
225225
'import/no-named-as-default': 'off',
226226
'import/no-named-as-default-member': 'off',
227-
'import/no-unresalved': 'off',
227+
'import/no-unresolved': 'off',
228228
'import/no-missing-import': 'off',
229229

230230
// vite config format does not match regex

lib/recommended.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import baseRules from './recommended-rules.js';
33
import gjsRules from './recommended-rules-gjs.js';
44
import gtsRules from './recommended-rules-gts.js';
55
import emberParser from 'ember-eslint-parser';
6+
import emberHbsParser from 'ember-eslint-parser/hbs';
67

78
export const plugin = emberPlugin;
89
export const parser = emberParser;
10+
export const hbsParser = emberHbsParser;
911

1012
export const base = {
1113
name: 'ember:base',
@@ -57,6 +59,7 @@ export default {
5759
// Helpful utility exports
5860
plugin,
5961
parser,
62+
hbsParser,
6063
// Recommended config sets
6164
configs: {
6265
base,

0 commit comments

Comments
 (0)