-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sdk/skyux-eslint): add
no-radio-group-with-nested-list
rule (#…
- Loading branch information
1 parent
6a3a4c9
commit 7f34a3f
Showing
14 changed files
with
843 additions
and
193 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
libs/sdk/skyux-eslint/docs/rules/template/no-radio-group-with-nested-list.md
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,67 @@ | ||
# `skyux-eslint-template/no-radio-group-with-nested-list` | ||
|
||
Prevents nesting of ordered and unordered lists within `sky-radio-group` components, for accessibility reasons. | ||
|
||
- Type: problem | ||
|
||
<br> | ||
|
||
## Rule Options | ||
|
||
The rule does not have any configuration options. | ||
|
||
<br> | ||
|
||
## Usage Examples | ||
|
||
#### Default Config | ||
|
||
```json | ||
{ | ||
"rules": { | ||
"skyux-eslint-template/no-radio-group-with-nested-list": ["error"] | ||
} | ||
} | ||
``` | ||
|
||
#### ❌ Invalid Code | ||
|
||
```html | ||
<sky-radio-group> | ||
<ul> | ||
~~~~ | ||
<li> | ||
~~~~ | ||
<sky-radio labelText="Foo" /> | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
</li> | ||
~~~~~ | ||
<li> | ||
~~~~ | ||
<sky-radio> | ||
~~~~~~~~~~~ | ||
<sky-radio-label>Foo</sky-radio-label> | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
</sky-radio> | ||
~~~~~~~~~~~~ | ||
</li> | ||
~~~~~ | ||
</ul> | ||
~~~~~ | ||
</sky-radio-group> | ||
``` | ||
|
||
```html | ||
<sky-radio-group> | ||
<ol> | ||
~~~~ | ||
<li *ngFor="let item of items"> | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
<sky-radio labelText="Foo" /> | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
</li> | ||
~~~~~ | ||
</ol> | ||
~~~~~ | ||
</sky-radio-group> | ||
``` |
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
177 changes: 177 additions & 0 deletions
177
libs/sdk/skyux-eslint/src/rules/template/no-radio-group-with-nested-list.spec.ts
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,177 @@ | ||
import { convertAnnotatedSourceToFailureCase } from '@angular-eslint/test-utils'; | ||
|
||
import { createTemplateRuleTester } from '../testing/create-template-rule-tester'; | ||
|
||
import { RULE_NAME, messageId, rule } from './no-radio-group-with-nested-list'; | ||
|
||
const ruleTester = createTemplateRuleTester(); | ||
|
||
ruleTester.run(RULE_NAME, rule, { | ||
valid: [ | ||
`<sky-radio-group></sky-radio-group>`, | ||
`<sky-radio-group> | ||
<sky-radio labelText="Foo" /> | ||
<sky-radio> | ||
<sky-radio-label>Foo</sky-radio-label> | ||
</sky-radio> | ||
</sky-radio-group>`, | ||
`<sky-radio-group> | ||
@for (item of items; track item.name) { | ||
<sky-radio labelText="Foo" /> | ||
} | ||
</sky-radio-group>`, | ||
`<sky-radio-group> | ||
<sky-radio *ngFor="let item of items" labelText="Foo" /> | ||
</sky-radio-group>`, | ||
], | ||
invalid: [ | ||
convertAnnotatedSourceToFailureCase({ | ||
description: 'should fail if radio-group has nested list', | ||
annotatedSource: ` | ||
<sky-radio-group> | ||
<ul> | ||
~~~~ | ||
<li> | ||
~~~~ | ||
<sky-radio labelText="Foo" /> | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
</li> | ||
~~~~~ | ||
<li> | ||
~~~~ | ||
<sky-radio><sky-radio-label>Foo</sky-radio-label></sky-radio> | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
</li> | ||
~~~~~ | ||
</ul> | ||
~~~~~ | ||
</sky-radio-group> | ||
`, | ||
annotatedOutput: ` | ||
<sky-radio-group> | ||
~ | ||
~ | ||
~ | ||
~ | ||
<sky-radio labelText="Foo" /> | ||
~ | ||
~ | ||
~ | ||
~ | ||
~ | ||
<sky-radio><sky-radio-label>Foo</sky-radio-label></sky-radio> | ||
~ | ||
~ | ||
~ | ||
~ | ||
~ | ||
</sky-radio-group> | ||
`, | ||
messageId, | ||
data: {}, | ||
}), | ||
convertAnnotatedSourceToFailureCase({ | ||
description: 'should handle ngFor structural directives', | ||
annotatedSource: ` | ||
<sky-radio-group> | ||
<ul> | ||
~~~~ | ||
<li *ngFor="let item of items"> | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
<sky-radio labelText="Foo" /> | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
</li> | ||
~~~~~ | ||
</ul> | ||
~~~~~ | ||
</sky-radio-group> | ||
`, | ||
annotatedOutput: ` | ||
<sky-radio-group> | ||
~ | ||
~ | ||
<ng-container *ngFor="let item of items"> | ||
~ | ||
<sky-radio labelText="Foo" /> | ||
~ | ||
</ng-container> | ||
~ | ||
~ | ||
~ | ||
</sky-radio-group> | ||
`, | ||
messageId, | ||
data: {}, | ||
}), | ||
convertAnnotatedSourceToFailureCase({ | ||
description: 'should ignore other structural directives', | ||
annotatedSource: ` | ||
<sky-radio-group> | ||
<ul> | ||
~~~~ | ||
<li *ngIf="foobar"> | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
<sky-radio labelText="Foo" /> | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
</li> | ||
~~~~~ | ||
</ul> | ||
~~~~~ | ||
</sky-radio-group> | ||
`, | ||
annotatedOutput: ` | ||
<sky-radio-group> | ||
~ | ||
~ | ||
~ | ||
~ | ||
<sky-radio labelText="Foo" /> | ||
~ | ||
~ | ||
~ | ||
~ | ||
~ | ||
</sky-radio-group> | ||
`, | ||
messageId, | ||
data: {}, | ||
}), | ||
convertAnnotatedSourceToFailureCase({ | ||
description: 'should handle built-in control flow', | ||
annotatedSource: ` | ||
<sky-radio-group> | ||
<ul> | ||
~~~~ | ||
@for (item of items; track item.name) { | ||
<li> | ||
~~~~ | ||
<sky-radio labelText="Foo" /> | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
</li> | ||
~~~~~ | ||
} | ||
</ul> | ||
~~~~~ | ||
</sky-radio-group> | ||
`, | ||
annotatedOutput: ` | ||
<sky-radio-group> | ||
~ | ||
~ | ||
@for (item of items; track item.name) { | ||
~ | ||
~ | ||
<sky-radio labelText="Foo" /> | ||
~ | ||
~ | ||
~ | ||
} | ||
~ | ||
~ | ||
</sky-radio-group> | ||
`, | ||
messageId, | ||
data: {}, | ||
}), | ||
], | ||
}); |
Oops, something went wrong.