Skip to content

Commit b40a83e

Browse files
committed
feat: re-export hbs parser and document HBS flat-config setup
Adds `hbsParser` as a named export alongside the existing `parser` (gjs/gts) in `eslint-plugin-ember/recommended`, so consumers don't need a direct `ember-eslint-parser` devDep to wire up `.hbs` linting. README migration section now shows the HBS block and warns about the rule-merging pitfall when a typescript-eslint shared config matches `.hbs` (e.g. `recommendedTypeChecked` without its own `files` glob).
1 parent 24882a3 commit b40a83e

2 files changed

Lines changed: 33 additions & 0 deletions

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:

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)