Skip to content

Commit 3391c9c

Browse files
committed
fix: fix ESLint installation and fix linter findings
1 parent 8b0be45 commit 3391c9c

File tree

11 files changed

+96
-98
lines changed

11 files changed

+96
-98
lines changed

.eslintrc.json

Lines changed: 0 additions & 38 deletions
This file was deleted.

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,14 @@ View and edit the live demo Angular app on <a href="https://codesandbox.io/s/ngx
129129
### Recreate project from scratch
130130

131131
```bash
132-
npm install -g @angular/cli@^17
132+
npm install -g @angular/cli@^18
133133
ng new ngx-annotate-text-workspace
134134
cd ngx-annotate-text-workspace/
135135
ng generate library ngx-annotate-text
136-
ng add @angular-eslint/schematics
137-
npm install prettier
136+
ng add angular-eslint@^18
137+
ng g angular-eslint:add-eslint-to-project ngx-annotate-text-workspace
138+
ng g angular-eslint:add-eslint-to-project ngx-annotate-text
139+
npm install prettier --save-dev
138140
ng build ngx-annotate-text
139141
ng lint
140142
ng test ngx-annotate-text

angular.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@
120120
"lint": {
121121
"builder": "@angular-eslint/builder:lint",
122122
"options": {
123-
"lintFilePatterns": ["projects/ngx-annotate-text/**/*.ts", "projects/ngx-annotate-text/**/*.html"]
123+
"lintFilePatterns": ["projects/ngx-annotate-text/**/*.ts", "projects/ngx-annotate-text/**/*.html"],
124+
"eslintConfig": "projects/ngx-annotate-text/eslint.config.js"
124125
}
125126
}
126127
}

eslint.config.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// @ts-check
2+
const eslint = require("@eslint/js");
3+
const tseslint = require("typescript-eslint");
4+
const angular = require("angular-eslint");
5+
6+
module.exports = tseslint.config(
7+
{
8+
files: ["**/*.ts"],
9+
extends: [
10+
eslint.configs.recommended,
11+
...tseslint.configs.recommended,
12+
...tseslint.configs.stylistic,
13+
...angular.configs.tsRecommended,
14+
],
15+
processor: angular.processInlineTemplates,
16+
rules: {
17+
"@angular-eslint/directive-selector": [
18+
"error",
19+
{
20+
type: "attribute",
21+
prefix: "app",
22+
style: "camelCase",
23+
},
24+
],
25+
"@angular-eslint/component-selector": [
26+
"error",
27+
{
28+
type: "element",
29+
prefix: "app",
30+
style: "kebab-case",
31+
},
32+
],
33+
},
34+
},
35+
{
36+
files: ["**/*.html"],
37+
extends: [
38+
...angular.configs.templateRecommended,
39+
...angular.configs.templateAccessibility,
40+
],
41+
rules: {},
42+
}
43+
);

projects/ngx-annotate-text/.eslintrc.json

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// @ts-check
2+
const tseslint = require("typescript-eslint");
3+
const rootConfig = require("../../eslint.config.js");
4+
5+
module.exports = tseslint.config(
6+
...rootConfig,
7+
{
8+
files: ["**/*.ts"],
9+
rules: {
10+
"@angular-eslint/directive-selector": [
11+
"error",
12+
{
13+
type: "attribute",
14+
prefix: "lib",
15+
style: "camelCase",
16+
},
17+
],
18+
"@angular-eslint/component-selector": [
19+
"error",
20+
{
21+
type: "element",
22+
prefix: "lib",
23+
style: "kebab-case",
24+
},
25+
],
26+
},
27+
},
28+
{
29+
files: ["**/*.html"],
30+
rules: {},
31+
}
32+
);

projects/ngx-annotate-text/src/lib/components/annotation-renderer/annotation-renderer.component.spec.ts

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ describe('AnnotationRendererComponent', () => {
1818
beforeEach(() => {
1919
fixture = TestBed.createComponent(NgxAnnotationRendererComponent);
2020
component = fixture.componentInstance;
21-
component.clickAnnotation = () => {};
22-
component.removeAnnotation = () => {};
21+
component.clickAnnotation = jasmine.createSpy('clickAnnotation');
22+
component.removeAnnotation = jasmine.createSpy('removeAnnotation');
2323
fixture.detectChanges();
2424
});
2525

@@ -86,8 +86,6 @@ describe('AnnotationRendererComponent', () => {
8686
});
8787

8888
it("should call the callback function 'removeAnnotation' when a user clicks on the remove button", async () => {
89-
spyOn(component, 'removeAnnotation');
90-
9189
const annotation = new Annotation(0, 13, 'City', 'rgb(60, 65, 75)');
9290
annotation.text = 'San Francisco';
9391
component.annotation = annotation;
@@ -97,14 +95,11 @@ describe('AnnotationRendererComponent', () => {
9795

9896
fixture.nativeElement.querySelector('button.remove-annotation').click();
9997

100-
fixture.whenStable().then(() => {
101-
expect(component.removeAnnotation).toHaveBeenCalledWith(annotation);
102-
});
98+
await fixture.whenStable();
99+
expect(component.removeAnnotation).toHaveBeenCalledWith(annotation);
103100
});
104101

105102
it("should call the callback function 'clickAnnotation' when a user clicks on the annotation's box", async () => {
106-
spyOn(component, 'clickAnnotation');
107-
108103
const annotation = new Annotation(0, 13, 'City', 'rgb(60, 65, 75)');
109104
annotation.text = 'San Francisco';
110105
component.annotation = annotation;
@@ -113,14 +108,11 @@ describe('AnnotationRendererComponent', () => {
113108

114109
fixture.nativeElement.querySelector('button.annotation-parent').click();
115110

116-
fixture.whenStable().then(() => {
117-
expect(component.clickAnnotation).toHaveBeenCalledWith(annotation);
118-
});
111+
await fixture.whenStable();
112+
expect(component.clickAnnotation).toHaveBeenCalledWith(annotation);
119113
});
120114

121115
it("should call the callback function 'clickAnnotation' when the user clicks on the annotation's text", async () => {
122-
spyOn(component, 'clickAnnotation');
123-
124116
const annotation = new Annotation(0, 11, 'City', 'rgb(0, 255, 255)');
125117
annotation.text = 'Los Angeles';
126118
component.annotation = annotation;
@@ -129,14 +121,11 @@ describe('AnnotationRendererComponent', () => {
129121

130122
fixture.nativeElement.querySelector('span.annotation-content').click();
131123

132-
fixture.whenStable().then(() => {
133-
expect(component.clickAnnotation).toHaveBeenCalledWith(annotation);
134-
});
124+
await fixture.whenStable();
125+
expect(component.clickAnnotation).toHaveBeenCalledWith(annotation);
135126
});
136127

137128
it("should call the callback function 'clickAnnotation' when the user clicks on the annotation's label", async () => {
138-
spyOn(component, 'clickAnnotation');
139-
140129
const annotation = new Annotation(0, 9, 'City', 'rgb(255, 255, 0)');
141130
annotation.text = 'Frankfurt';
142131
component.annotation = annotation;
@@ -145,8 +134,7 @@ describe('AnnotationRendererComponent', () => {
145134

146135
fixture.nativeElement.querySelector('span.annotation-label').click();
147136

148-
fixture.whenStable().then(() => {
149-
expect(component.clickAnnotation).toHaveBeenCalledWith(annotation);
150-
});
137+
await fixture.whenStable();
138+
expect(component.clickAnnotation).toHaveBeenCalledWith(annotation);
151139
});
152140
});

projects/ngx-annotate-text/src/lib/components/ngx-annotate-text/ngx-annotate-text.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable @typescript-eslint/no-non-null-assertion */
1+
22
import { SimpleChange } from '@angular/core';
33
import { ComponentFixture, TestBed } from '@angular/core/testing';
44
import { Annotation } from '../../models/annotation.model';

src/app/app.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { FormsModule } from '@angular/forms';
77
import { NgxAnnotationRendererComponentInterface } from '../../projects/ngx-annotate-text/src/lib/models/annotation-renderer-component.model';
88

99
@Component({
10-
// eslint-disable-next-line @angular-eslint/component-selector
1110
selector: 'app-root',
1211
standalone: true,
1312
imports: [NgxAnnotateTextModule, FormsModule],

src/app/my-annotation-renderer/my-annotation-renderer.component.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ describe('MyAnnotationRendererComponent', () => {
1313
fixture = TestBed.createComponent(MyAnnotationRendererComponent);
1414
component = fixture.componentInstance;
1515
component.annotation = new Annotation(7, 12, 'noun', 'red');
16+
// eslint-disable-next-line @typescript-eslint/no-empty-function
1617
component.clickAnnotation = () => {};
18+
// eslint-disable-next-line @typescript-eslint/no-empty-function
1719
component.removeAnnotation = () => {};
1820
fixture.detectChanges();
1921
});

0 commit comments

Comments
 (0)