Skip to content

Commit 0c23c75

Browse files
committed
Update public api and test support
1 parent b62ab66 commit 0c23c75

File tree

9 files changed

+82
-9
lines changed

9 files changed

+82
-9
lines changed

packages/eslint-config-angular/i18n-attributes-ignore.js packages/eslint-config-angular/options.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ const ignoreAttributes = {
6060
'matTooltipClass',
6161
]
6262
};
63+
ignoreAttributes.all = Object.values(ignoreAttributes).flat();
6364

6465
module.exports = {
65-
...ignoreAttributes,
66-
all: [...ignoreAttributes.nimble, ...ignoreAttributes.systemlink, ...ignoreAttributes.jqx, ...ignoreAttributes.material]
66+
ignoreAttributes
6767
};

packages/eslint-config-angular/template.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const ignoreAttributes = require('./i18n-attributes-ignore');
1+
const { ignoreAttributes } = require('./options');
22

33
module.exports = {
44
extends: [
@@ -94,5 +94,18 @@ module.exports = {
9494
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.
9595
*/
9696
'@angular-eslint/template/use-track-by-function': 'off'
97-
}
97+
},
98+
overrides: [
99+
{
100+
// Ignore inline templates in tests using the inline template naming convention
101+
// See naming details: https://github.com/angular-eslint/angular-eslint/releases/tag/v14.0.0
102+
files: ['*.spec.ts*.html'],
103+
rules: {
104+
/*
105+
Tests often define helper components that don't need to be marked for i18n.
106+
*/
107+
'@angular-eslint/template/i18n': 'off'
108+
}
109+
},
110+
]
98111
};

tests/angular/.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Test TypeScript and templates together to process inline templates.
22
module.exports = {
3+
ignorePatterns: ['*.js'],
34
overrides: [{
45
extends: [
56
'@ni/eslint-config-angular',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const {ignoreAttributes} = require('@ni/eslint-config-angular/options');
2+
3+
module.exports = {
4+
overrides: [{
5+
files: ['*.html'],
6+
rules: {
7+
'@angular-eslint/template/i18n': [
8+
'error',
9+
{
10+
checkId: false,
11+
ignoreAttributes: [...ignoreAttributes.all, 'custom-field']
12+
}
13+
],
14+
}
15+
}, {
16+
files: ['*.spec.ts*.html'],
17+
rules: {
18+
'@angular-eslint/template/i18n': 'off'
19+
}
20+
}]
21+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<!-- Angular Template Custom Ignore Attributes Test -->
2+
<span i18n custom-field="test-custom-field">Hello {{name}}</span>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Angular test spec smoke test
2+
import { Component, Input, ViewChild } from '@angular/core';
3+
import { ComponentFixture } from '@angular/core/testing';
4+
5+
@Component({
6+
template: '<div custom-attribute="i18n-should-be-ignored-in-test"></div>'
7+
})
8+
class MyComponent {
9+
@Input() public attr = false;
10+
@ViewChild('div') public div: HTMLDivElement;
11+
public myMethod(): void {}
12+
}
13+
14+
describe('MyComponent', () => {
15+
let hostComponent: MyComponent;
16+
let fixture: ComponentFixture<MyComponent>;
17+
18+
it('should have a div', async () => {
19+
await fixture.whenStable();
20+
21+
expect(hostComponent.div).toBeDefined();
22+
expect(hostComponent.myMethod).not.toHaveBeenCalled();
23+
});
24+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Angular TypeScript and Inline Template Smoke Test
2+
import { Component, Input } from '@angular/core';
3+
4+
@Component({
5+
selector: 'app-root',
6+
template: '<span i18n custom-field="test-custom-field">Hello {{name}}</span>!',
7+
styles: [`
8+
span {
9+
font-weight: bold;
10+
}
11+
`]
12+
})
13+
export class AppComponent {
14+
@Input() public name = 'Angular';
15+
}

tests/angular/index.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Component, Input, ViewChild } from '@angular/core';
33
import { ComponentFixture } from '@angular/core/testing';
44

55
@Component({
6-
template: '<div [(attr)] = true></div>'
6+
template: '<div custom-attribute="i18n-should-be-ignored-in-test">missing i18n should be ignored</div>'
77
})
88
class MyComponent {
99
@Input() public attr = false;

tests/angular/tsconfig.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,5 @@
22
"compilerOptions": {
33
"experimentalDecorators": true
44
},
5-
"files": [
6-
"index.ts",
7-
"index.spec.ts"
8-
]
5+
"include": ["."]
96
}

0 commit comments

Comments
 (0)