Skip to content

Commit db9ff39

Browse files
committed
Update eslint + prettier to latest config combination
Based on documentation at https://github.com/angular-eslint/angular-eslint
1 parent 58cac3f commit db9ff39

File tree

4 files changed

+46
-75
lines changed

4 files changed

+46
-75
lines changed

client/.eslintrc.json

Lines changed: 16 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@
2828
},
2929
"extends": [
3030
"plugin:@angular-eslint/recommended",
31-
"prettier/@typescript-eslint",
32-
"plugin:prettier/recommended",
33-
"plugin:@angular-eslint/recommended--extra"
31+
"plugin:@angular-eslint/template/process-inline-templates",
32+
"plugin:prettier/recommended"
3433
],
3534
"rules": {
3635
/**
@@ -54,13 +53,6 @@
5453
"prefix": "app",
5554
"style": "kebab-case"
5655
}
57-
],
58-
"quotes": [
59-
"error",
60-
"single",
61-
{
62-
"allowTemplateLiterals": true
63-
}
6456
]
6557
}
6658
},
@@ -70,12 +62,14 @@
7062
* COMPONENT TEMPLATES
7163
* -----------------------------------------------------
7264
*
73-
* If you use inline templates, make sure you read the notes on the configuration
74-
* object after this one to understand how they relate to this configuration directly
75-
* below.
65+
* If you use inline templates, make sure you you have read the notes on the extends
66+
* in the "*.ts" overrides above to understand how they relate to this configuration
67+
* directly below.
7668
*/
69+
70+
// NOTE: WE ARE NOT APPLYING PRETTIER IN THIS OVERRIDE, ONLY @ANGULAR-ESLINT/TEMPLATE
7771
{
78-
"files": ["*.component.html"],
72+
"files": ["*.html"],
7973
"extends": ["plugin:@angular-eslint/template/recommended"],
8074
"rules": {
8175
/**
@@ -84,34 +78,15 @@
8478
*/
8579
}
8680
},
87-
88-
/**
89-
* -----------------------------------------------------
90-
* EXTRACT INLINE TEMPLATES (from within .component.ts)
91-
* -----------------------------------------------------
92-
*
93-
* This extra piece of configuration is necessary to extract inline
94-
* templates from within Component metadata, e.g.:
95-
*
96-
* @Component({
97-
* template: `<h1>Hello, World!</h1>`
98-
* })
99-
* ...
100-
*
101-
* It works by extracting the template part of the file and treating it as
102-
* if it were a full .html file, and it will therefore match the configuration
103-
* specific for *.component.html above when it comes to actual rules etc.
104-
*
105-
* NOTE: This processor will skip a lot of work when it runs if you don't use
106-
* inline templates in your projects currently, so there is no great benefit
107-
* in removing it, but you can if you want to.
108-
*
109-
* You won't specify any rules here. As noted above, the rules that are relevant
110-
* to inline templates are the same as the ones defined for *.component.html.
111-
*/
81+
// NOTE: WE ARE NOT APPLYING @ANGULAR-ESLINT/TEMPLATE IN THIS OVERRIDE, ONLY PRETTIER
11282
{
113-
"files": ["*.component.ts"],
114-
"extends": ["plugin:@angular-eslint/template/process-inline-templates"]
83+
"files": ["*.html"],
84+
"excludedFiles": ["*inline-template-*.component.html"],
85+
"extends": ["plugin:prettier/recommended"],
86+
"rules": {
87+
// NOTE: WE ARE OVERRIDING THE DEFAULT CONFIG TO ALWAYS SET THE PARSER TO ANGULAR (SEE BELOW)
88+
"prettier/prettier": ["error", { "parser": "angular" }]
89+
}
11590
}
11691
]
11792
}

client/README.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ This first version of the new frontend stack was introduced as an experimental f
66
([original issue](https://github.com/opendevstack/ods-provisioning-app/issues/518)). It can be activated for users with a
77
`frontend.spa.enabled` feature flag in Spring Boot.
88

9-
OpenDevStack NEXT will include this new frontend activated by default (without featue flag).
9+
OpenDevStack NEXT will include this new frontend activated by default (without feature flag).
1010

1111
To contribute to the further development, see section "Contributions welcome!" further down.
1212

1313
## Stack
1414

15-
- [Angular](https://angular.io/) as single page application framework
16-
- [Jest](https://jestjs.io/) as unit testing framework
17-
- [Prettier](https://prettier.io/) as pre-commit-hook
15+
- [Angular](https://angular.io/)
16+
- [Jest](https://jestjs.io/)
17+
- [ESLint](https://eslint.org/)
18+
- [Prettier](https://prettier.io/)
1819

1920
See package.json for up-to-date version information.
2021

@@ -58,7 +59,8 @@ behaves correctly. Although not ideal, we discovered this as the most effortless
5859

5960
### Build
6061

61-
`npm run build`: The build artifacts will be stored in the `dist/` directory. `yarn build:prod` will be used for the pipeline.
62+
- `npm run build`: The build artifacts will be stored in the `dist/` directory.
63+
- `npm run build:prod` will be used for the pipeline.
6264

6365
### Tests
6466

@@ -67,12 +69,7 @@ behaves correctly. Although not ideal, we discovered this as the most effortless
6769

6870
### Linting
6971

70-
- `npm run lint`: Linting for Typescript and SCSS files.
71-
72-
### Prettier
73-
74-
Prettier is used as a pre-commit hook to format js, json, md, ts files. Formatting of html files has been temporarily removed due to
75-
inflexibility in context of Angular component markup.
72+
- `npm run lint`: Linting for Typescript (using [angular-eslint](https://github.com/angular-eslint/angular-eslint)) incl. Prettier as an eslint rule. This npm task also runs as a pre-commit hook.
7673

7774
## Contributions welcome!
7875

client/package-lock.json

Lines changed: 18 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@
33
"version": "0.0.0",
44
"scripts": {
55
"ng": "ng",
6-
"prettier": "prettier --write \"**/*.{js,json,md,ts,component.html}\"",
7-
"prettier:check": "prettier --check \"**/*.{js,json,css,scss,less,md,ts,html,component.html}\"",
86
"start:dev": "ng serve --proxy-config proxy.conf.json",
97
"start": "ng serve",
108
"build": "ng build --baseHref=/nfe/",
119
"build:prod": "ng build --baseHref=/nfe/ --configuration=production",
1210
"test": "jest",
1311
"test:watch": "jest --watch",
1412
"lint": "ng lint",
15-
"lint:fix": "ng lint --fix",
16-
"format:fix:staged": "pretty-quick --staged --verbose --pattern \"**/*.{js,json,md,ts}\""
13+
"lint:fix": "ng lint --fix"
1714
},
1815
"private": true,
1916
"dependencies": {
@@ -49,9 +46,9 @@
4946
"@typescript-eslint/eslint-plugin": "4.28.2",
5047
"@typescript-eslint/parser": "4.28.2",
5148
"bootstrap": "^4.4.1",
52-
"eslint": "^7.26.0",
49+
"eslint": "^7.31.0",
5350
"eslint-config-prettier": "^8.3.0",
54-
"eslint-plugin-prettier": "^3.1.4",
51+
"eslint-plugin-prettier": "^3.4.0",
5552
"husky": "4.2.3",
5653
"jest": "^25.2.3",
5754
"jest-preset-angular": "8.1.2",
@@ -100,7 +97,7 @@
10097
},
10198
"husky": {
10299
"hooks": {
103-
"pre-commit": "npm run format:fix:staged"
100+
"pre-commit": "npm run lint"
104101
}
105102
}
106103
}

0 commit comments

Comments
 (0)