Cannot configure Eslint rule "@angular-eslint/template/elements-content" in default angular workspace #32677
-
Hi, I do have an issue with configuring the eslint rule To one of the angular templates I have added this HTML code: <button my-label="labelText"></button> When running "npm run lint" I get this linting error:
So I configured that rule to ignore tags which come with a import nx from '@nx/eslint-plugin';
import baseConfig from '../../eslint.config.mjs';
export default [
...baseConfig,
...nx.configs['flat/angular'],
...nx.configs['flat/angular-template'],
{
files: ['**/*.ts'],
rules: {
'@angular-eslint/directive-selector': ... , // omitting details
'@angular-eslint/component-selector': ... , // omitting details
'@angular-eslint/template/elements-content': [
'warn',
{
"allowList": [
"my-label"
]
}
],
},
},
{
files: ['**/*.html'],
// Override or add rules here
rules: {},
},
]; Now linting fails to run and tells me that the configuration is incorrect. But according to official documentation it is configured correctly. So I suspect that the issue is related to how eslint/angular-eslint configuration is set up with Here is the full error message:
Can anyone assist, please? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Solved the issue. :) It's not a nx-specific problem at all. Some rules may only be applied to certain file types/extensions and won't be recognized otherwise. import nx from '@nx/eslint-plugin';
import baseConfig from '../../eslint.config.mjs';
export default [
...baseConfig,
...nx.configs['flat/angular'],
...nx.configs['flat/angular-template'],
{
files: ['**/*.ts'],
rules: {
'@angular-eslint/directive-selector': [
'error',
{
type: 'attribute',
prefix: 'app',
style: 'camelCase',
},
],
'@angular-eslint/component-selector': [
'error',
{
type: 'element',
prefix: 'app',
style: 'kebab-case',
},
],
},
},
{
files: ['**/*.html'],
rules: {
'@angular-eslint/template/elements-content': [
'warn',
{
"allowList": [
"my-label"
]
}
],
},
},
]; |
Beta Was this translation helpful? Give feedback.
Solved the issue. :) It's not a nx-specific problem at all. Some rules may only be applied to certain file types/extensions and won't be recognized otherwise.
Although the HTML template is embedded in a
*.ts
file, I have to apply the rule config to HTML files and then it is working as expected. So the following config is working, although the linted code is inside a*.ts
file: