-
Notifications
You must be signed in to change notification settings - Fork 439
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2865 from ybnd/poc-eslint-plugin-autofix-selectors
Introduce custom ESLint rules to apply and enforce new themed component selector convention
- Loading branch information
Showing
698 changed files
with
5,404 additions
and
1,556 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[DSpace ESLint plugins](../../../lint/README.md) > HTML rules | ||
_______ | ||
|
||
- [`dspace-angular-html/themed-component-usages`](./rules/themed-component-usages.md): Themeable components should be used via the selector of their `ThemedComponent` wrapper class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
[DSpace ESLint plugins](../../../../lint/README.md) > [HTML rules](../index.md) > `dspace-angular-html/themed-component-usages` | ||
_______ | ||
|
||
Themeable components should be used via the selector of their `ThemedComponent` wrapper class | ||
|
||
This ensures that custom themes can correctly override _all_ instances of this component. | ||
The only exception to this rule are unit tests, where we may want to use the base component in order to keep the test setup simple. | ||
|
||
|
||
_______ | ||
|
||
[Source code](../../../../lint/src/rules/html/themed-component-usages.ts) | ||
|
||
### Examples | ||
|
||
|
||
#### Valid code | ||
|
||
##### use no-prefix selectors in HTML templates | ||
```html | ||
<ds-test-themeable/> | ||
<ds-test-themeable></ds-test-themeable> | ||
<ds-test-themeable [test]="something"></ds-test-themeable> | ||
``` | ||
|
||
##### use no-prefix selectors in TypeScript templates | ||
```html | ||
@Component({ | ||
template: '<ds-test-themeable></ds-test-themeable>' | ||
}) | ||
class Test { | ||
} | ||
``` | ||
|
||
##### use no-prefix selectors in TypeScript test templates | ||
Filename: `lint/test/fixture/src/test.spec.ts` | ||
|
||
```html | ||
@Component({ | ||
template: '<ds-test-themeable></ds-test-themeable>' | ||
}) | ||
class Test { | ||
} | ||
``` | ||
|
||
##### base selectors are also allowed in TypeScript test templates | ||
Filename: `lint/test/fixture/src/test.spec.ts` | ||
|
||
```html | ||
@Component({ | ||
template: '<ds-base-test-themeable></ds-base-test-themeable>' | ||
}) | ||
class Test { | ||
} | ||
``` | ||
|
||
|
||
|
||
|
||
#### Invalid code & automatic fixes | ||
|
||
##### themed override selectors are not allowed in HTML templates | ||
```html | ||
<ds-themed-test-themeable/> | ||
<ds-themed-test-themeable></ds-themed-test-themeable> | ||
<ds-themed-test-themeable [test]="something"></ds-themed-test-themeable> | ||
``` | ||
Will produce the following error(s): | ||
``` | ||
Themeable components should be used via their ThemedComponent wrapper's selector | ||
Themeable components should be used via their ThemedComponent wrapper's selector | ||
Themeable components should be used via their ThemedComponent wrapper's selector | ||
``` | ||
Result of `yarn lint --fix`: | ||
```html | ||
<ds-test-themeable/> | ||
<ds-test-themeable></ds-test-themeable> | ||
<ds-test-themeable [test]="something"></ds-test-themeable> | ||
``` | ||
|
||
##### base selectors are not allowed in HTML templates | ||
```html | ||
<ds-base-test-themeable/> | ||
<ds-base-test-themeable></ds-base-test-themeable> | ||
<ds-base-test-themeable [test]="something"></ds-base-test-themeable> | ||
``` | ||
Will produce the following error(s): | ||
``` | ||
Themeable components should be used via their ThemedComponent wrapper's selector | ||
Themeable components should be used via their ThemedComponent wrapper's selector | ||
Themeable components should be used via their ThemedComponent wrapper's selector | ||
``` | ||
Result of `yarn lint --fix`: | ||
```html | ||
<ds-test-themeable/> | ||
<ds-test-themeable></ds-test-themeable> | ||
<ds-test-themeable [test]="something"></ds-test-themeable> | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[DSpace ESLint plugins](../../../lint/README.md) > TypeScript rules | ||
_______ | ||
|
||
- [`dspace-angular-ts/themed-component-classes`](./rules/themed-component-classes.md): Formatting rules for themeable component classes | ||
- [`dspace-angular-ts/themed-component-selectors`](./rules/themed-component-selectors.md): Themeable component selectors should follow the DSpace convention | ||
- [`dspace-angular-ts/themed-component-usages`](./rules/themed-component-usages.md): Themeable components should be used via their `ThemedComponent` wrapper class |
Oops, something went wrong.