Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update @angular-eslint/template/i18n to ignore common nimble and sl-lib attributes #140

Merged
Prev Previous commit
Next Next commit
Update public api and test support
rajsite committed May 10, 2024
commit 0c23c751003211179432c473484b4d3554740907
Original file line number Diff line number Diff line change
@@ -60,8 +60,8 @@ const ignoreAttributes = {
'matTooltipClass',
]
};
ignoreAttributes.all = Object.values(ignoreAttributes).flat();

module.exports = {
...ignoreAttributes,
all: [...ignoreAttributes.nimble, ...ignoreAttributes.systemlink, ...ignoreAttributes.jqx, ...ignoreAttributes.material]
ignoreAttributes
};
17 changes: 15 additions & 2 deletions packages/eslint-config-angular/template.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const ignoreAttributes = require('./i18n-attributes-ignore');
const { ignoreAttributes } = require('./options');

module.exports = {
extends: [
@@ -94,5 +94,18 @@ module.exports = {
Providing a `trackBy` function in `ngFor` loops can improve performance in specific cases where Angular can't track references, but it's overkill to require it for every `ngFor` so this rule is disabled.
*/
'@angular-eslint/template/use-track-by-function': 'off'
}
},
overrides: [
{
// Ignore inline templates in tests using the inline template naming convention
// See naming details: https://github.com/angular-eslint/angular-eslint/releases/tag/v14.0.0
files: ['*.spec.ts*.html'],
rules: {
/*
Tests often define helper components that don't need to be marked for i18n.
*/
'@angular-eslint/template/i18n': 'off'
}
},
]
};
1 change: 1 addition & 0 deletions tests/angular/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Test TypeScript and templates together to process inline templates.
module.exports = {
ignorePatterns: ['*.js'],
overrides: [{
extends: [
'@ni/eslint-config-angular',
21 changes: 21 additions & 0 deletions tests/angular/custom-ignore-attributes/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const {ignoreAttributes} = require('@ni/eslint-config-angular/options');

module.exports = {
overrides: [{
files: ['*.html'],
rules: {
'@angular-eslint/template/i18n': [
'error',
{
checkId: false,
ignoreAttributes: [...ignoreAttributes.all, 'custom-field']
}
],
}
}, {
files: ['*.spec.ts*.html'],
rules: {
'@angular-eslint/template/i18n': 'off'
}
}]
};
2 changes: 2 additions & 0 deletions tests/angular/custom-ignore-attributes/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!-- Angular Template Custom Ignore Attributes Test -->
<span i18n custom-field="test-custom-field">Hello {{name}}</span>
24 changes: 24 additions & 0 deletions tests/angular/custom-ignore-attributes/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Angular test spec smoke test
import { Component, Input, ViewChild } from '@angular/core';
import { ComponentFixture } from '@angular/core/testing';

@Component({
template: '<div custom-attribute="i18n-should-be-ignored-in-test"></div>'
})
class MyComponent {
@Input() public attr = false;
@ViewChild('div') public div: HTMLDivElement;
public myMethod(): void {}
}

describe('MyComponent', () => {
let hostComponent: MyComponent;
let fixture: ComponentFixture<MyComponent>;

it('should have a div', async () => {
await fixture.whenStable();

expect(hostComponent.div).toBeDefined();
expect(hostComponent.myMethod).not.toHaveBeenCalled();
});
});
15 changes: 15 additions & 0 deletions tests/angular/custom-ignore-attributes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Angular TypeScript and Inline Template Smoke Test
import { Component, Input } from '@angular/core';

@Component({
selector: 'app-root',
template: '<span i18n custom-field="test-custom-field">Hello {{name}}</span>!',
styles: [`
span {
font-weight: bold;
}
`]
})
export class AppComponent {
@Input() public name = 'Angular';
}
2 changes: 1 addition & 1 deletion tests/angular/index.spec.ts
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ import { Component, Input, ViewChild } from '@angular/core';
import { ComponentFixture } from '@angular/core/testing';

@Component({
template: '<div [(attr)] = true></div>'
template: '<div custom-attribute="i18n-should-be-ignored-in-test">missing i18n should be ignored</div>'
})
class MyComponent {
@Input() public attr = false;
5 changes: 1 addition & 4 deletions tests/angular/tsconfig.json
Original file line number Diff line number Diff line change
@@ -2,8 +2,5 @@
"compilerOptions": {
"experimentalDecorators": true
},
"files": [
"index.ts",
"index.spec.ts"
]
"include": ["."]
}