Skip to content

Commit 2b4e49f

Browse files
authored
docs: improve inline template configuration documentation (#2457)
1 parent ee9f2fe commit 2b4e49f

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

docs/CONFIGURING_FLAT_CONFIG.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,27 @@ Fortunately, however, ESLint has clearly defined points of extensibility that we
2929

3030
Therefore, our flat config will contain two entries, one for TS, one for HTML. We could provide these two entries directly in an exported array, but `typescript-eslint` provides an awesome typed utility function which makes writing our flat configs a lot nicer, so we will instead require the function and pass in multiple objects for our configuration.
3131

32+
## Configuring ESLint for Inline Templates
33+
34+
One of the features of angular-eslint is its ability to lint **inline templates** within your Angular components. This is made possible through ESLint's processor API, which allows us to extract inline template content from your TypeScript component files and apply HTML template rules to them.
35+
36+
### How it works
37+
38+
When you use inline templates in your Angular components (using the `template` property instead of `templateUrl`), angular-eslint can automatically extract these templates and treat them as if they were separate HTML files. This means all your Angular template rules will work seamlessly on both external template files AND inline templates.
39+
40+
The magic happens through the `angular.processInlineTemplates` processor, which:
41+
42+
1. Scans your TypeScript component files for inline templates
43+
2. Extracts the template content
44+
3. Applies your HTML configuration rules to the extracted templates
45+
4. Reports any linting issues with proper line and column mapping back to your original TypeScript file
46+
47+
For more details on how ESLint processors work behind the scenes, see the [ESLint Custom Processors documentation](https://eslint.org/docs/latest/extend/custom-processors).
48+
49+
### Configuration example
50+
51+
The key is to add the `processor: angular.processInlineTemplates` to your TypeScript configuration block:
52+
3253
**Workspace root level eslint.config.js**
3354

3455
```js
@@ -58,8 +79,9 @@ module.exports = tseslint.config(
5879
// Apply the recommended Angular rules
5980
...angular.configs.tsRecommended,
6081
],
61-
// Set the custom processor which will allow us to have our inline Component templates extracted
62-
// and treated as if they are HTML files (and therefore have the .html config below applied to them)
82+
// IMPORTANT: Set the custom processor to enable inline template linting
83+
// This allows your inline Component templates to be extracted and linted with the same
84+
// rules as your external .html template files
6385
processor: angular.processInlineTemplates,
6486
// Override specific rules for TypeScript files (these will take priority over the extended configs above)
6587
rules: {
@@ -82,8 +104,8 @@ module.exports = tseslint.config(
82104
},
83105
},
84106
{
85-
// Everything in this config object targets our HTML files (external templates,
86-
// and inline templates as long as we have the `processor` set on our TypeScript config above)
107+
// Everything in this config object targets our HTML files (both external template files,
108+
// AND inline templates thanks to the processor set in the TypeScript config above)
87109
files: ['**/*.html'],
88110
extends: [
89111
// Apply the recommended Angular template rules
@@ -138,6 +160,7 @@ module.exports = tseslint.config(
138160
},
139161
{
140162
// Any project level overrides or additional rules for HTML files can go here
163+
// (applies to both external template files AND inline templates)
141164
// (we don't need to extend from any angular-eslint configs because
142165
// we already applied the rootConfig above which has them)
143166
files: ['**/*.html'],
@@ -196,6 +219,7 @@ module.exports = tseslint.config([
196219
},
197220
{
198221
// Any project level overrides or additional rules for HTML files can go here
222+
// (applies to both external template files AND inline templates)
199223
// (we don't need to extend from any angular-eslint configs because
200224
// we already applied the rootConfig above which has them)
201225
files: ['**/*.html'],

0 commit comments

Comments
 (0)