@siemens/prettier-config 1.0.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,28 @@
1
+ {
2
+ "printWidth": 100,
3
+ "trailingComma": "none",
4
+ "arrowParens": "avoid",
5
+ "htmlWhitespaceSensitivity": "strict",
6
+ "quoteProps": "preserve",
7
+ "singleQuote": true,
8
+ "overrides": [
9
+ {
10
+ "files": "*.html",
11
+ "options": {
12
+ "parser": "angular"
13
+ }
14
+ },
15
+ {
16
+ "files": "index.html",
17
+ "options": {
18
+ "parser": "html"
19
+ }
20
+ },
21
+ {
22
+ "files": "*.json5",
23
+ "options": {
24
+ "singleQuote": false
25
+ }
26
+ }
27
+ ]
28
+ }
package/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License
2
+
3
+ Copyright (c) Siemens 2018 - 2024
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the “Software”), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,316 @@
1
+ # Siemens Lint
2
+
3
+ Siemens Lint helps you to improve and keep the code quality of your project on
4
+ a high level. It provides presets and plugins for various linters used at
5
+ Siemens.
6
+
7
+ We welcome contributions of further linting rules and configs to be added to
8
+ this repo for various other programming languages and frameworks.
9
+
10
+ **Presets available for following linters:**
11
+
12
+ - [typescript-eslint](https://typescript-eslint.io/)
13
+ - [Angular ESLint](https://github.com/angular-eslint/angular-eslint)
14
+ - [stylelint](https://stylelint.io/)
15
+ - [commitlint](https://commitlint.js.org/)
16
+ - [Prettier](https://prettier.io/)
17
+
18
+ **Plugins:**
19
+
20
+ - [eslint-plugin-defaultvalue](./eslint-plugin-defaultvalue/README.md)
21
+ for [typescript-eslint](https://typescript-eslint.io/) to automatically
22
+ annotate the `@defaultValue` TSDoc tag
23
+
24
+ ## Installation
25
+
26
+ Install `@siemens/*-config*` and their peer dependencies in your project (whichever you need):
27
+
28
+ ```bash
29
+ npm install @siemens/stylelint-config-scss --save-dev --save-exact
30
+ npm install @siemens/commitlint-config --save-dev --save-exact
31
+ npm install @siemens/prettier-config --save-dev --save-exact
32
+ npm install @siemens/eslint-config-typescript --save-dev --save-exact
33
+ npm install @siemens/eslint-config-angular --save-dev --save-exact
34
+ ```
35
+
36
+ **_Note_** _You should specify the exact versions of the packages above and
37
+ their peer dependencies like `eslint` and its plugins, `stylelint`,
38
+ `stylelint-config-sass-guidelines` and `@commitlint/config-conventional`. Rules
39
+ will get changed in the patch releases._
40
+
41
+ ### ESLint
42
+
43
+ #### TypeScript
44
+
45
+ Include the ESLint preset in your root `eslint.config.mjs`:
46
+
47
+ ```js
48
+ import path from 'path';
49
+ import { fileURLToPath } from 'url';
50
+ import typescriptEslint from 'typescript-eslint';
51
+ import typescriptConfig from '@siemens/eslint-config-typescript';
52
+
53
+ // mimic CommonJS variables
54
+ const __filename = fileURLToPath(import.meta.url);
55
+ const __dirname = path.dirname(__filename);
56
+
57
+ export default typescriptEslint.config({
58
+ extends: [...baseTypescriptConfig, prettier],
59
+ files: ['**/*.ts'],
60
+ languageOptions: {
61
+ parserOptions: {
62
+ project: ['tsconfig.json', 'tsconfig.app.json', 'tsconfig.spec.json', 'e2e/tsconfig.json']
63
+ tsconfigRootDir: __dirname
64
+ }
65
+ }
66
+ });
67
+ ```
68
+
69
+ > **Note:** to use less strict rules, use the `base` rules, by importing
70
+ > `{ configBase }` instead.
71
+
72
+ #### Angular
73
+
74
+ Include the ESLint preset in your root `eslint.config.js` (not `.mjs`) and make
75
+ sure `"type": "module"` is set in your root `package.json`:
76
+
77
+ ```js
78
+ import path from 'path';
79
+ import { fileURLToPath } from 'url';
80
+ import typescriptEslint from 'typescript-eslint';
81
+ import angularTypescriptConfig from '@siemens/eslint-config-angular';
82
+ import angularTemplateConfig from '@siemens/eslint-config-angular/template';
83
+
84
+ // mimic CommonJS variables
85
+ const __filename = fileURLToPath(import.meta.url);
86
+ const __dirname = path.dirname(__filename);
87
+
88
+ export const tsConfig = typescriptEslint.config({
89
+ extends: [...angularTypescriptConfig, prettier],
90
+ files: ['**/*.ts'],
91
+ languageOptions: {
92
+ parserOptions: {
93
+ project: ['tsconfig.json', 'tsconfig.app.json', 'tsconfig.spec.json', 'e2e/tsconfig.json']
94
+ tsconfigRootDir: __dirname
95
+ }
96
+ },
97
+ rules: {
98
+ '@angular-eslint/directive-selector': [
99
+ 'error',
100
+ {
101
+ type: 'attribute',
102
+ prefix: 'app',
103
+ style: 'camelCase'
104
+ }
105
+ ],
106
+ '@angular-eslint/component-selector': [
107
+ 'error',
108
+ {
109
+ type: 'element',
110
+ prefix: 'app',
111
+ style: 'kebab-case'
112
+ }
113
+ ]
114
+ }
115
+ });
116
+
117
+ export const templateConfig = typescriptEslint.config({
118
+ extends: [...angularTemplateConfig, prettier],
119
+ files: ['**/*.html']
120
+ });
121
+
122
+ export default typescriptEslint.config(...tsConfig, ...templateConfig);
123
+ ```
124
+
125
+ For libraries and other things in the `projects` directory,
126
+ make sure `"type": "module"` is set in the relevant `package.json`
127
+ and create an additional
128
+ `eslint.config.js` for each project that looks like this:
129
+
130
+ ```js
131
+ import typescriptEslint from 'typescript-eslint';
132
+ import { tsConfig, templateConfig } from '../../eslint.config.js';
133
+
134
+ export default typescriptEslint.config(
135
+ {
136
+ extends: [...tsConfig],
137
+ files: ['**/*.ts'],
138
+ languageOptions: {
139
+ parserOptions: {
140
+ project: ['projects/element-ng/tsconfig.lib.json', 'projects/element-ng/tsconfig.spec.json']
141
+ }
142
+ },
143
+ rules: {
144
+ '@angular-eslint/component-selector': [
145
+ 'error',
146
+ {
147
+ type: 'element',
148
+ prefix: 'si',
149
+ style: 'kebab-case'
150
+ }
151
+ ],
152
+ '@angular-eslint/directive-selector': [
153
+ 'error',
154
+ {
155
+ type: 'attribute',
156
+ prefix: 'si',
157
+ style: 'camelCase'
158
+ }
159
+ ]
160
+ }
161
+ },
162
+ ...templateConfig
163
+ );
164
+ ```
165
+
166
+ The `@angular-eslint/builder` will also not automatically pick up the library
167
+ config location, manually provide it in `angular.json`:
168
+
169
+ ```diff
170
+ @@ -122,15 +125,11 @@
171
+ }
172
+ },
173
+ "lint": {
174
+ "builder": "@angular-eslint/builder:lint",
175
+ "options": {
176
+ "lintFilePatterns": [
177
+ "src/**/*.ts",
178
+ "src/**/*.html"
179
+ ],
180
+ + "eslintConfig": "path/to/project/eslint.config.js"
181
+ }
182
+ },
183
+ ```
184
+
185
+ #### Migration from TSLint
186
+
187
+ Also in `angular.json`, make sure to replace the TSLint related entries like
188
+ this:
189
+
190
+ ```diff
191
+ @@ -122,15 +125,11 @@
192
+ }
193
+ },
194
+ "lint": {
195
+ - "builder": "@angular-devkit/build-angular:tslint",
196
+ + "builder": "@angular-eslint/builder:lint",
197
+ "options": {
198
+ - "tsConfig": [
199
+ - "tsconfig.app.json",
200
+ - "tsconfig.spec.json",
201
+ - "e2e/tsconfig.json"
202
+ - ],
203
+ - "exclude": [
204
+ - "**/node_modules/**"
205
+ + "lintFilePatterns": [
206
+ + "src/**/*.ts",
207
+ + "src/**/*.html"
208
+ ]
209
+ }
210
+ },
211
+ ```
212
+
213
+ > **Note:** to use less strict rules, which are derived from the upstream
214
+ > Angular recommendation and more geared towards applications, use the `base`
215
+ > rules, by importing `{ configBase }` instead.
216
+
217
+ ### Stylelint
218
+
219
+ Include the stylelint preset in your `.stylelintrc.yml`:
220
+
221
+ ```yml
222
+ extends:
223
+ - '@siemens/stylelint-config-scss/stylelintrc.yml'
224
+ ```
225
+
226
+ ### Commitlint
227
+
228
+ Include the commitlint preset in your `package.json`:
229
+
230
+ ```json
231
+ "commitlint": {
232
+ "extends": [
233
+ "@siemens/commitlint-config/.commitlintrc.js"
234
+ ]
235
+ },
236
+
237
+ // Optional: Pre-commit hook using husky: https://github.com/typicode/husky
238
+ "husky": {
239
+ "hooks": {
240
+ "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
241
+ }
242
+ },
243
+ ```
244
+
245
+ ### Prettier
246
+
247
+ Include the shared Prettier config in your `package.json`:
248
+
249
+ ```json
250
+ "prettier": "@siemens/prettier-config/.prettierrc.json",
251
+ ```
252
+
253
+ ### ESLint Plugin
254
+
255
+ The usage of the ESLint plugin is documented [here](./eslint-plugin-defaultvalue/README.md).
256
+
257
+ ## Usage
258
+
259
+ The preset will now be automatically used by `eslint` and `ng lint`. Please
260
+ refer to the [Angular ESLint](https://github.com/angular-eslint/angular-eslint) and
261
+ [ng lint](https://angular.io/cli/lint) documentation for more details.
262
+
263
+ Add the commitlint, ESlint and stylelint scripts to your `package.json`:
264
+
265
+ ```json
266
+ "scripts": {
267
+ "lint": "ng lint",
268
+ "lint:sass": "stylelint **.scss",
269
+ "lint:commit": "commitlint --from=origin/main",
270
+ "lint:all": "npm run lint:commit && npm run lint && npm run lint:sass"
271
+ }
272
+ ```
273
+
274
+ To fix ESLint issues automatically use:
275
+
276
+ ```json
277
+ "scripts": {
278
+ "lint:fix": "ng lint --fix"
279
+ }
280
+ ```
281
+
282
+ To fix stylelint issues automatically use:
283
+
284
+ ```json
285
+ "scripts": {
286
+ "lint:sass:fix": "stylelint --fix **.scss"
287
+ }
288
+ ```
289
+
290
+ Make sure to call the linters in your CI build chain in `.gitlab-ci.yml`:
291
+
292
+ ```yml
293
+ lint:
294
+ stage: tests
295
+ script:
296
+ - npm install
297
+ - npm run lint:all
298
+ ```
299
+
300
+ > **Note:** To make commitlint work in Gitlab CI, one needs to set the
301
+ > `Git shallow clone` setting to `0` (found in project `settings` > `CI / CD`).
302
+ > That way GitLab CI fetches all branches and tags each time.
303
+
304
+ ## Contributing
305
+
306
+ Improvements are always welcome! Feel free to log a bug,
307
+ write a suggestion or contribute code by creating a pull request.
308
+ All details are listed in our contribution guide.
309
+
310
+ See [CONTRIBUTING.md](CONTRIBUTING.md).
311
+
312
+ ## License
313
+
314
+ Code and documentation Copyright (c) Siemens 2018 - 2024.
315
+
316
+ See [LICENSE.md](LICENSE.md).
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@siemens/prettier-config",
3
+ "version": "1.0.0-next.1",
4
+ "description": "Configuration for Prettier.",
5
+ "files": [
6
+ "*.json",
7
+ "*.md"
8
+ ],
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+ssh://git@github.com/siemens/lint.git"
12
+ },
13
+ "author": {
14
+ "name": "Siemens",
15
+ "email": "opensource@siemens.com"
16
+ },
17
+ "homepage": "https://github.com/siemens/lint",
18
+ "bugs": "https://github.com/siemens/lint/issues",
19
+ "keywords": [
20
+ "siemens",
21
+ "lint"
22
+ ],
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "license": "MIT",
27
+ "peerDependencies": {
28
+ "prettier": "^3.0.0"
29
+ }
30
+ }