diff --git a/.eslint-doc-generatorrc.js b/.eslint-doc-generatorrc.js index 34497c6e7e..e193997169 100644 --- a/.eslint-doc-generatorrc.js +++ b/.eslint-doc-generatorrc.js @@ -7,11 +7,8 @@ const END_HEADER_MARKER = ''; /** @type {import('eslint-doc-generator').GenerateOptions} */ module.exports = { - configEmoji: [ - ['recommended-gjs', '![gjs logo](/docs/svgs/gjs.svg)'], - ['recommended-gts', '![gts logo](/docs/svgs/gts.svg)'], - ['template-lint-migration', 'πŸ“‹'], - ], + configEmoji: [['hbs', 'πŸ“‹']], + ignoreConfig: ['recommended-v13'], ruleDocSectionInclude: ['Examples'], ruleDocTitleFormat: 'prefix-name', ruleListSplit: 'meta.docs.category', diff --git a/README.md b/README.md index 4d61592bee..ccf05154db 100644 --- a/README.md +++ b/README.md @@ -47,21 +47,6 @@ module.exports = { }; ``` -### 3. Set your Ember version (optional) - -Some rules only report when your Ember version supports the fix, and the parser only treats the Ember 7.1 template keywords (such as `eq` and `on`) as defined on 7.1 or newer. Both read the version from the installed `ember-source`. If you lint without `ember-source` installed, set the version in your config. Rules read `settings`, but ESLint doesn't pass `settings` to parsers, so the parser needs its own option: - -```js -// eslint.config.js (flat config) -module.exports = [ - ...eslintPluginEmberRecommended, - { - settings: { ember: { version: '7.3.0' } }, - languageOptions: { parserOptions: { emberSourceVersion: '7.3.0' } }, - }, -]; -``` - ## gts/gjs lint files having `First-Class Component Templates` (fcct) @@ -76,6 +61,8 @@ gjs/gts support is provided by the [ember-eslint-parser](https://github.com/Null > [!NOTE] > if you import .gts files in .ts files, then `ember-eslint-parser` is required for .ts as well to enable typed linting +The `recommended` config covers gjs and gts. It scopes the rules for each with a `files` glob, so a separate config per file type is not necessary. You still need the parser block, because a parser cannot come from a shared config here. + ```js // .eslintrc.js module.exports = { @@ -101,7 +88,6 @@ module.exports = { 'eslint:recommended', 'plugin:@typescript-eslint/recommended', 'plugin:ember/recommended', - 'plugin:ember/recommended-gts', ], }, { @@ -111,7 +97,6 @@ module.exports = { extends: [ 'eslint:recommended', 'plugin:ember/recommended', - 'plugin:ember/recommended-gjs', ], }, { @@ -167,16 +152,18 @@ rules in templates can be disabled with eslint directives with mustache or html ## Migrating from ember-template-lint -If you are replacing `ember-template-lint` with this plugin, use the `template-lint-migration` config to get the equivalent set of rules: +If you are replacing `ember-template-lint` with this plugin, `recommended` already covers `.gjs`/`.gts` files: it enables every template rule from the `ember-template-lint` `recommended` preset that a strict-mode template can violate. + +For `.hbs` files, add the `hbs` config. It keeps the full parity set, including the loose-mode-only rules that `recommended` leaves out. It applies only to `**/*.hbs` and sets the Handlebars parser for those files: ```js // eslint.config.js (flat config) import eslintPluginEmberRecommended from 'eslint-plugin-ember/configs/recommended'; -import eslintPluginEmberTemplateLintMigration from 'eslint-plugin-ember/configs/template-lint-migration'; +import eslintPluginEmberHbs from 'eslint-plugin-ember/configs/hbs'; export default [ ...eslintPluginEmberRecommended, - ...eslintPluginEmberTemplateLintMigration, + ...eslintPluginEmberHbs, { rules: { // Migrate custom overrides from your .template-lintrc.*: @@ -187,31 +174,13 @@ export default [ ]; ``` -`template-lint-migration` mirrors the ember-template-lint `recommended` preset. +`hbs` mirrors the ember-template-lint `recommended` preset. Before v14 it was named `template-lint-migration`. ### Linting `.hbs` files -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: - -```js -// eslint.config.mjs -import { hbsParser, plugin as emberPlugin } from 'eslint-plugin-ember/recommended'; - -export default [ - // ...other blocks... - { - files: ['app/**/*.hbs'], - languageOptions: { parser: hbsParser }, - plugins: { ember: emberPlugin }, - rules: { - 'ember/template-no-bare-strings': 'error', - // ...other template rules... - }, - }, -]; -``` +ESLint flat config only picks up `.hbs` files when a `files` glob names them. The `hbs` config has that glob. -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: +Make sure no `@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 the `hbs` config sets the parser, type-info rules from a matching TS block still layer on and fail with errors like: > Parsing error: `…` was not found by the project service because the extension for the file (`.hbs`) is non-standard. @@ -233,7 +202,7 @@ with: {{!eslint-disable-next-line ember/template-no-invalid-role}} ``` -The [`template-no-template-lint-directives`](docs/rules/template-no-template-lint-directives.md) rule (enabled by the `template-lint-migration` config) does this rewrite for you: run `eslint --fix` once and it converts every `template-lint-disable` / `template-lint-enable` comment in your templates. +The [`template-no-template-lint-directives`](docs/rules/template-no-template-lint-directives.md) rule (enabled by `recommended` and the `hbs` config) does this rewrite for you: run `eslint --fix` once and it converts every `template-lint-disable` / `template-lint-enable` comment in your templates. To disable a rule for an entire `.gjs`/`.gts` file, use a regular ESLint file-level directive in the JS region β€” it applies to the `