Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

Commit cf6574d

Browse files
authored
build: switch to eslint (#957)
Switches the repo to use eslint instead of the deprecated tslint. Also adjusts the default config to match our previous setup.
1 parent bdd888a commit cf6574d

File tree

13 files changed

+1026
-346
lines changed

13 files changed

+1026
-346
lines changed

.eslintrc.json

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
{
2+
"root": true,
3+
"ignorePatterns": [
4+
"*.d.ts"
5+
],
6+
"overrides": [
7+
{
8+
"files": ["*.ts"],
9+
"plugins": ["ban"],
10+
"parserOptions": {
11+
"project": [
12+
"tsconfig.json",
13+
"e2e/tsconfig.json"
14+
],
15+
"createDefaultProgram": true
16+
},
17+
"extends": [
18+
"plugin:@angular-eslint/ng-cli-compat",
19+
"plugin:@angular-eslint/ng-cli-compat--formatting-add-on",
20+
"plugin:@angular-eslint/template/process-inline-templates"
21+
],
22+
"rules": {
23+
"@angular-eslint/component-class-suffix": "off",
24+
"@angular-eslint/component-selector": "off",
25+
"@angular-eslint/directive-class-suffix": "off",
26+
"@angular-eslint/directive-selector": "off",
27+
"@typescript-eslint/dot-notation": "off",
28+
"@typescript-eslint/member-delimiter-style": "off",
29+
"@typescript-eslint/explicit-member-accessibility": [
30+
"off",
31+
{
32+
"accessibility": "explicit"
33+
}
34+
],
35+
"@typescript-eslint/no-inferrable-types": "off",
36+
"@typescript-eslint/member-ordering": "off",
37+
"@typescript-eslint/no-unused-vars": "error",
38+
"@typescript-eslint/no-non-null-assertion": "off",
39+
"@typescript-eslint/quotes": [
40+
"error",
41+
"single",
42+
{
43+
"avoidEscape": true,
44+
"allowTemplateLiterals": true
45+
}
46+
],
47+
"@typescript-eslint/semi": [
48+
"error"
49+
],
50+
"arrow-parens": [
51+
"off",
52+
"always"
53+
],
54+
"brace-style": [
55+
"error",
56+
"1tbs"
57+
],
58+
"import/order": "off",
59+
"linebreak-style": [
60+
"error",
61+
"unix"
62+
],
63+
"max-len": [
64+
"error",
65+
{
66+
"code": 100
67+
}
68+
],
69+
"ban/ban": [
70+
"error",
71+
{"name": "fit"},
72+
{"name": "fdescribe"},
73+
{"name": "xit"},
74+
{"name": "xdescribe"},
75+
{"name": ["Object", "assign"], "message": "Use the spread operator instead."}
76+
],
77+
"no-duplicate-imports": "error",
78+
"no-redeclare": "error",
79+
"object-shorthand": "off",
80+
"no-underscore-dangle": "off",
81+
"prefer-arrow/prefer-arrow-functions": "off",
82+
"jsdoc/newline-after-description": "off",
83+
"quote-props": "off"
84+
}
85+
},
86+
{
87+
"files": [
88+
"*.html"
89+
],
90+
"extends": [
91+
"plugin:@angular-eslint/template/recommended"
92+
],
93+
"rules": {
94+
"@angular-eslint/template/accessibility-alt-text": "error",
95+
"@angular-eslint/template/accessibility-elements-content": "error",
96+
"@angular-eslint/template/accessibility-label-for": "error",
97+
"@angular-eslint/template/accessibility-table-scope": "error",
98+
"@angular-eslint/template/accessibility-valid-aria": "error",
99+
"@angular-eslint/template/click-events-have-key-events": "error",
100+
"@angular-eslint/template/mouse-events-have-key-events": "error",
101+
"@angular-eslint/template/no-autofocus": "error",
102+
"@angular-eslint/template/no-distracting-elements": "error",
103+
"@angular-eslint/template/no-positive-tabindex": "error"
104+
}
105+
}
106+
]
107+
}

angular.json

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@
7171
}
7272
],
7373
"stylePreprocessorOptions": {
74-
"includePaths": ["node_modules", "src", "src/styles"]
74+
"includePaths": [
75+
"node_modules",
76+
"src",
77+
"src/styles"
78+
]
7579
},
7680
"scripts": []
7781
},
@@ -155,7 +159,11 @@
155159
}
156160
],
157161
"stylePreprocessorOptions": {
158-
"includePaths": ["node_modules", "src", "src/styles"]
162+
"includePaths": [
163+
"node_modules",
164+
"src",
165+
"src/styles"
166+
]
159167
},
160168
"assets": [
161169
{
@@ -172,15 +180,11 @@
172180
}
173181
},
174182
"lint": {
175-
"builder": "@angular-devkit/build-angular:tslint",
183+
"builder": "@angular-eslint/builder:lint",
176184
"options": {
177-
"tsConfig": [
178-
"tsconfig.app.json",
179-
"tsconfig.spec.json",
180-
"e2e/tsconfig.json"
181-
],
182-
"exclude": [
183-
"**/node_modules/**"
185+
"lintFilePatterns": [
186+
"src/**/*.ts",
187+
"src/**/*.html"
184188
]
185189
}
186190
},
@@ -292,15 +296,11 @@
292296
}
293297
},
294298
"lint": {
295-
"builder": "@angular-devkit/build-angular:tslint",
299+
"builder": "@angular-eslint/builder:lint",
296300
"options": {
297-
"tsConfig": [
298-
"scenes/tsconfig.app.json",
299-
"scenes/tsconfig.spec.json",
300-
"scenes/e2e/tsconfig.json"
301-
],
302-
"exclude": [
303-
"**/node_modules/**"
301+
"lintFilePatterns": [
302+
"scenes/**/*.ts",
303+
"scenes/**/*.html"
304304
]
305305
}
306306
},
@@ -320,6 +320,7 @@
320320
}
321321
},
322322
"cli": {
323-
"analytics": "cf155f04-1636-4df9-9ce2-870ba25ad38d"
323+
"analytics": "cf155f04-1636-4df9-9ce2-870ba25ad38d",
324+
"defaultCollection": "@angular-eslint/schematics"
324325
}
325326
}

package.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,25 @@
5959
},
6060
"devDependencies": {
6161
"@angular-devkit/build-angular": "^12.0.0-next.9",
62+
"@angular-eslint/builder": "4.0.0",
63+
"@angular-eslint/eslint-plugin": "4.0.0",
64+
"@angular-eslint/eslint-plugin-template": "4.0.0",
65+
"@angular-eslint/schematics": "4.0.0",
66+
"@angular-eslint/template-parser": "4.0.0",
6267
"@angular/cli": "^12.0.0-next.9",
6368
"@angular/compiler-cli": "^12.0.0-next.9",
6469
"@angular/localize": "^12.0.0-next.9",
6570
"@types/imagemin": "^7.0.0",
6671
"@types/jasmine": "^3.6.6",
6772
"@types/node": "^14.14.22",
6873
"@types/shelljs": "~0.8.8",
69-
"codelyzer": "^6.0.1",
74+
"@typescript-eslint/eslint-plugin": "4.16.1",
75+
"@typescript-eslint/parser": "4.16.1",
76+
"eslint": "^7.6.0",
77+
"eslint-plugin-ban": "^1.5.2",
78+
"eslint-plugin-import": "^2.22.1",
79+
"eslint-plugin-jsdoc": "^32.3.0",
80+
"eslint-plugin-prefer-arrow": "^1.2.3",
7081
"firebase-tools": "^9.9.0",
7182
"imagemin": "^7.0.1",
7283
"imagemin-pngquant": "^9.0.2",
@@ -86,7 +97,6 @@
8697
"puppeteer": "~8.0.0",
8798
"shelljs": "^0.8.4",
8899
"ts-node": "^8.10.2",
89-
"tslint": "^6.1.3",
90100
"typescript": "~4.2.3"
91101
}
92102
}

scenes/.eslintrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "../.eslintrc.json"
3+
}

scenes/tslint.json

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

src/app/pages/component-sidenav/component-sidenav-can-load-guard.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Injectable} from '@angular/core';
2-
import {CanActivate, ActivatedRouteSnapshot, Router, RouterStateSnapshot} from '@angular/router';
2+
import {CanActivate, ActivatedRouteSnapshot, Router} from '@angular/router';
33
import {SECTIONS} from '../../shared/documentation-items/documentation-items';
44

55
/**
@@ -10,13 +10,14 @@ import {SECTIONS} from '../../shared/documentation-items/documentation-items';
1010
export class CanActivateComponentSidenav implements CanActivate {
1111
constructor(private router: Router) {}
1212

13-
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
13+
canActivate(route: ActivatedRouteSnapshot) {
1414
// Searches if the section defined in the base UrlSegment is a valid section from the
1515
// documentation items. If found, returns true to allow activation, otherwise blocks activation
1616
// and navigates to '/'.
17-
const sectionFound = Object.keys(SECTIONS).find(
18-
(val => val.toLowerCase() === route.url[0].path.toLowerCase()));
19-
if (sectionFound) { return true; }
17+
if (Object.keys(SECTIONS).some((s => s.toLowerCase() === route.url[0].path.toLowerCase()))) {
18+
return true;
19+
}
20+
2021
this.router.navigateByUrl('/');
2122
return false;
2223
}

src/app/pages/component-viewer/component-viewer.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,12 @@ export class ComponentViewer implements OnDestroy {
5454
if (docItemAndSection.doc !== undefined) {
5555
this.componentDocItem.next(docItemAndSection.doc);
5656
this._componentPageTitle.title = `${docItemAndSection.doc.name}`;
57-
docItemAndSection.doc.examples && docItemAndSection.doc.examples.length ?
58-
this.sections.add('examples') :
57+
58+
if (docItemAndSection.doc.examples && docItemAndSection.doc.examples.length) {
59+
this.sections.add('examples');
60+
} else {
5961
this.sections.delete('examples');
62+
}
6063
} else {
6164
this.router.navigate(['/' + docItemAndSection.section]);
6265
}

src/app/pages/page-title/page-title.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ export class ComponentPageTitle {
99
_title = '';
1010
_originalTitle = 'Angular Material UI component library';
1111

12-
get title(): string { return this._title; }
12+
get title(): string {
13+
return this._title;
14+
}
1315

1416
set title(title: string) {
1517
this._title = title;

src/app/routes.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import {Routes} from '@angular/router';
2-
import {CanActivateComponentSidenav} from './pages/component-sidenav/component-sidenav-can-load-guard';
2+
import {
3+
CanActivateComponentSidenav
4+
} from './pages/component-sidenav/component-sidenav-can-load-guard';
35

46
export const MATERIAL_DOCS_ROUTES: Routes = [
57
{

src/app/shared/example-viewer/example-viewer.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ export class ExampleViewer implements OnInit {
5959
/** String key of the currently displayed example. */
6060
@HostBinding('attr.id')
6161
@Input()
62-
get example() { return this._example; }
62+
get example() {
63+
return this._example;
64+
}
6365
set example(exampleName: string | undefined) {
6466
if (exampleName && exampleName !== this._example && EXAMPLE_COMPONENTS[exampleName]) {
6567
this._example = exampleName;
@@ -120,7 +122,7 @@ export class ExampleViewer implements OnInit {
120122
}
121123

122124
toggleSourceView(): void {
123-
this.view === 'full' ? this.view = 'demo' : this.view = 'full';
125+
this.view = this.view === 'full' ? 'demo' : 'full';
124126
}
125127

126128
copySource(snippet: QueryList<CodeSnippet>, selectedIndex: number = 0) {
@@ -154,8 +156,14 @@ export class ExampleViewer implements OnInit {
154156
let indexB = preferredExampleFileOrder.indexOf(b);
155157
// Files which are not part of the preferred example file order should be
156158
// moved after all items with a preferred index.
157-
if (indexA === -1) indexA = preferredExampleFileOrder.length;
158-
if (indexB === -1) indexB = preferredExampleFileOrder.length;
159+
if (indexA === -1) {
160+
indexA = preferredExampleFileOrder.length;
161+
}
162+
163+
if (indexB === -1) {
164+
indexB = preferredExampleFileOrder.length;
165+
}
166+
159167
return (indexA - indexB) || 1;
160168
}) : [];
161169
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy