Skip to content

Commit a36e085

Browse files
authored
Merge pull request #3390 from alexandrevryghem/w2p-117616_ported-custom-atmire-eslint-rules
Enforce DSpace-specific coding conventions
2 parents d4aedbb + 443809f commit a36e085

File tree

1,340 files changed

+8270
-4123
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,340 files changed

+8270
-4123
lines changed

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ trim_trailing_whitespace = false
1515

1616
[*.ts]
1717
quote_type = single
18+
ij_typescript_enforce_trailing_comma = whenmultiline
19+
20+
[*.js]
21+
ij_javascript_enforce_trailing_comma = whenmultiline
1822

1923
[*.json5]
2024
ij_json_keep_blank_lines_in_code = 3

.eslintrc.json

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,48 @@
263263
"rxjs/no-nested-subscribe": "off", // todo: go over _all_ cases
264264

265265
// Custom DSpace Angular rules
266+
"dspace-angular-ts/alias-imports": [
267+
"error",
268+
{
269+
"aliases": [
270+
{
271+
"package": "rxjs",
272+
"imported": "of",
273+
"local": "of"
274+
}
275+
]
276+
}
277+
],
266278
"dspace-angular-ts/themed-component-classes": "error",
267279
"dspace-angular-ts/themed-component-selectors": "error",
268-
"dspace-angular-ts/themed-component-usages": "error"
280+
"dspace-angular-ts/themed-component-usages": "error",
281+
"dspace-angular-ts/themed-decorators": [
282+
"off",
283+
{
284+
"decorators": {
285+
"listableObjectComponent": 3,
286+
"rendersSectionForMenu": 2
287+
}
288+
}
289+
],
290+
"dspace-angular-ts/themed-wrapper-no-input-defaults": "error",
291+
"dspace-angular-ts/unique-decorators": [
292+
"off",
293+
{
294+
"decorators": [
295+
"listableObjectComponent"
296+
]
297+
}
298+
],
299+
"dspace-angular-ts/sort-standalone-imports": [
300+
"error",
301+
{
302+
"locale": "en-US",
303+
"maxItems": 0,
304+
"indent": 2,
305+
"trailingComma": true
306+
}
307+
]
269308
}
270309
},
271310
{

docs/lint/html/rules/no-disabled-attribute-on-button.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ _______
99

1010
[Source code](../../../../lint/src/rules/html/no-disabled-attribute-on-button.ts)
1111

12+
13+
1214
### Examples
1315

1416

@@ -19,24 +21,28 @@ _______
1921
```html
2022
<button [dsBtnDisabled]="true">Submit</button>
2123
```
24+
2225

2326
##### disabled attribute is still valid on non-button elements
2427
2528
```html
2629
<input disabled>
2730
```
31+
2832

2933
##### [disabled] attribute is still valid on non-button elements
3034
3135
```html
3236
<input [disabled]="true">
3337
```
38+
3439

3540
##### angular dynamic attributes that use disabled are still valid
3641
3742
```html
3843
<button [class.disabled]="isDisabled">Submit</button>
3944
```
45+
4046

4147

4248

@@ -47,6 +53,9 @@ _______
4753
4854
```html
4955
<button disabled>Submit</button>
56+
57+
58+
5059
```
5160
Will produce the following error(s):
5261
```
@@ -63,6 +72,9 @@ Result of `yarn lint --fix`:
6372
6473
```html
6574
<button [disabled]="true">Submit</button>
75+
76+
77+
6678
```
6779
Will produce the following error(s):
6880
```

docs/lint/html/rules/themed-component-usages.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ _______
1111

1212
[Source code](../../../../lint/src/rules/html/themed-component-usages.ts)
1313

14+
15+
1416
### Examples
1517

1618

@@ -23,6 +25,7 @@ _______
2325
<ds-test-themeable></ds-test-themeable>
2426
<ds-test-themeable [test]="something"></ds-test-themeable>
2527
```
28+
2629

2730
##### use no-prefix selectors in TypeScript templates
2831
@@ -33,6 +36,7 @@ _______
3336
class Test {
3437
}
3538
```
39+
3640

3741
##### use no-prefix selectors in TypeScript test templates
3842
@@ -45,6 +49,7 @@ Filename: `lint/test/fixture/src/test.spec.ts`
4549
class Test {
4650
}
4751
```
52+
4853

4954
##### base selectors are also allowed in TypeScript test templates
5055
@@ -57,6 +62,7 @@ Filename: `lint/test/fixture/src/test.spec.ts`
5762
class Test {
5863
}
5964
```
65+
6066

6167

6268

@@ -69,6 +75,9 @@ class Test {
6975
<ds-themed-test-themeable/>
7076
<ds-themed-test-themeable></ds-themed-test-themeable>
7177
<ds-themed-test-themeable [test]="something"></ds-themed-test-themeable>
78+
79+
80+
7281
```
7382
Will produce the following error(s):
7483
```
@@ -91,6 +100,9 @@ Result of `yarn lint --fix`:
91100
<ds-base-test-themeable/>
92101
<ds-base-test-themeable></ds-base-test-themeable>
93102
<ds-base-test-themeable [test]="something"></ds-base-test-themeable>
103+
104+
105+
94106
```
95107
Will produce the following error(s):
96108
```

docs/lint/ts/index.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
[DSpace ESLint plugins](../../../lint/README.md) > TypeScript rules
22
_______
33

4+
- [`dspace-angular-ts/alias-imports`](./rules/alias-imports.md): Unclear imports should be aliased for clarity
5+
- [`dspace-angular-ts/sort-standalone-imports`](./rules/sort-standalone-imports.md): Sorts the standalone `@Component` imports alphabetically
46
- [`dspace-angular-ts/themed-component-classes`](./rules/themed-component-classes.md): Formatting rules for themeable component classes
57
- [`dspace-angular-ts/themed-component-selectors`](./rules/themed-component-selectors.md): Themeable component selectors should follow the DSpace convention
68
- [`dspace-angular-ts/themed-component-usages`](./rules/themed-component-usages.md): Themeable components should be used via their `ThemedComponent` wrapper class
9+
- [`dspace-angular-ts/themed-decorators`](./rules/themed-decorators.md): Entry components with theme support should declare the correct theme
10+
- [`dspace-angular-ts/themed-wrapper-no-input-defaults`](./rules/themed-wrapper-no-input-defaults.md): ThemedComponent wrappers should not declare input defaults (see [DSpace Angular #2164](https://github.com/DSpace/dspace-angular/pull/2164))
11+
- [`dspace-angular-ts/unique-decorators`](./rules/unique-decorators.md): Some decorators must be called with unique arguments (e.g. when they construct a mapping based on the argument values)
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
[DSpace ESLint plugins](../../../../lint/README.md) > [TypeScript rules](../index.md) > `dspace-angular-ts/alias-imports`
2+
_______
3+
4+
Unclear imports should be aliased for clarity
5+
6+
_______
7+
8+
[Source code](../../../../lint/src/rules/ts/alias-imports.ts)
9+
10+
11+
### Options
12+
13+
#### `aliases`
14+
15+
A list of all the imports that you want to alias for clarity. Every alias should be declared in the following format:
16+
```json
17+
{
18+
"package": "rxjs",
19+
"imported": "of",
20+
"local": "observableOf"
21+
}
22+
```
23+
24+
25+
### Examples
26+
27+
28+
#### Valid code
29+
30+
##### correctly aliased imports
31+
32+
```typescript
33+
import { of as observableOf } from 'rxjs';
34+
```
35+
36+
With options:
37+
38+
```json
39+
{
40+
"aliases": [
41+
{
42+
"package": "rxjs",
43+
"imported": "of",
44+
"local": "observableOf"
45+
}
46+
]
47+
}
48+
```
49+
50+
51+
##### enforce unaliased import
52+
53+
```typescript
54+
import { combineLatest } from 'rxjs';
55+
```
56+
57+
With options:
58+
59+
```json
60+
{
61+
"aliases": [
62+
{
63+
"package": "rxjs",
64+
"imported": "combineLatest",
65+
"local": "combineLatest"
66+
}
67+
]
68+
}
69+
```
70+
71+
72+
73+
74+
75+
#### Invalid code &amp; automatic fixes
76+
77+
##### imports without alias
78+
79+
```typescript
80+
import { of } from 'rxjs';
81+
82+
83+
84+
```
85+
Will produce the following error(s):
86+
```
87+
This import must be aliased
88+
```
89+
90+
Result of `yarn lint --fix`:
91+
```typescript
92+
import { of as observableOf } from 'rxjs';
93+
```
94+
95+
96+
##### imports under the wrong alias
97+
98+
```typescript
99+
import { of as ofSomething } from 'rxjs';
100+
101+
102+
103+
```
104+
Will produce the following error(s):
105+
```
106+
This import uses the wrong alias (should be {{ local }})
107+
```
108+
109+
Result of `yarn lint --fix`:
110+
```typescript
111+
import { of as observableOf } from 'rxjs';
112+
```
113+
114+
115+
##### disallow aliasing import
116+
117+
```typescript
118+
import { combineLatest as observableCombineLatest } from 'rxjs';
119+
120+
121+
With options:
122+
123+
```json
124+
{
125+
"aliases": [
126+
{
127+
"package": "rxjs",
128+
"imported": "combineLatest",
129+
"local": "combineLatest"
130+
}
131+
]
132+
}
133+
```
134+
135+
136+
```
137+
Will produce the following error(s):
138+
```
139+
This import should not use an alias
140+
```
141+
142+
Result of `yarn lint --fix`:
143+
```typescript
144+
import { combineLatest } from 'rxjs';
145+
```
146+
147+
148+

0 commit comments

Comments
 (0)