Skip to content

Commit 01ed208

Browse files
authored
Merge branch 'main' into codex/edit-error-string-in-eslint-utils.ts
2 parents 3aaa2a5 + 61f631c commit 01ed208

File tree

4 files changed

+182
-14
lines changed

4 files changed

+182
-14
lines changed

AGENTS.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ This repository uses Nx as the task runner. Nx Cloud requires internet access, w
44

55
## Required checks
66

7-
When modifying rule implementations or documentation, run the following commands and ensure they pass:
7+
When modifying rule implementations or documentation, run the following commands and ensure they pass (noting the comments that explain what to do if any of these checks fail):
88

99
```bash
10-
pnpm format-check
11-
NX_NO_CLOUD=true pnpm nx sync:check
12-
NX_NO_CLOUD=true pnpm nx run-many -t check-rule-docs
13-
NX_NO_CLOUD=true pnpm nx run-many -t check-rule-lists
14-
NX_NO_CLOUD=true pnpm nx run-many -t check-rule-configs
10+
pnpm format-check # run pnpm nx format and commit the result if this check fails
11+
pnpm nx sync:check # run pnpm nx sync and commit the result if this check fails
12+
NX_NO_CLOUD=true pnpm nx run-many -t check-rule-docs # run NX_NO_CLOUD=true pnpm nx run-many -t update-rule-docs and commit the result if this check fails
13+
NX_NO_CLOUD=true pnpm nx run-many -t check-rule-lists # run NX_NO_CLOUD=true pnpm nx run-many -t update-rule-lists and commit the result if this check fails
14+
NX_NO_CLOUD=true pnpm nx run-many -t check-rule-configs # run NX_NO_CLOUD=true pnpm nx run-many -t update-rule-configs and commit the result if this check fails
1515
```
1616

1717
Additionally, run tests and lints for any affected project. For example, changes to `eslint-plugin-template` require:
@@ -21,9 +21,13 @@ NX_NO_CLOUD=true pnpm nx test eslint-plugin-template
2121
NX_NO_CLOUD=true pnpm nx lint eslint-plugin-template
2222
```
2323

24+
If there are memory issues with jest tests, try passing `--runInBand` to the test command.
25+
2426
## Commit conventions
2527

2628
Use [Conventional Commits](https://www.conventionalcommits.org/) for commit messages and PR titles.
2729

2830
- When a change affects a single project, include its name as the scope: `feat(eslint-plugin-template): add new rule`.
2931
- When multiple projects are affected, omit the scope: `fix: correct lint configuration`.
32+
33+
By convention, if only updating a single rule within a single project, for example the `alt-text` rule within the `eslint-plugin-template` project, the commit message should be `fix(eslint-plugin-template): [alt-text] description of the change`.

packages/eslint-plugin-template/docs/rules/alt-text.md

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,32 @@ The rule does not have any configuration options.
408408

409409
#### ✅ Valid Code
410410

411+
```html
412+
<object aria-label="foo" id="bar"></object>
413+
```
414+
415+
<br>
416+
417+
---
418+
419+
<br>
420+
421+
#### Default Config
422+
423+
```json
424+
{
425+
"rules": {
426+
"@angular-eslint/template/alt-text": [
427+
"error"
428+
]
429+
}
430+
}
431+
```
432+
433+
<br>
434+
435+
#### ✅ Valid Code
436+
411437
```html
412438
<area aria-label="foo" />
413439
```
@@ -486,6 +512,32 @@ The rule does not have any configuration options.
486512

487513
#### ✅ Valid Code
488514

515+
```html
516+
<area alt="desc" href="path">
517+
```
518+
519+
<br>
520+
521+
---
522+
523+
<br>
524+
525+
#### Default Config
526+
527+
```json
528+
{
529+
"rules": {
530+
"@angular-eslint/template/alt-text": [
531+
"error"
532+
]
533+
}
534+
}
535+
```
536+
537+
<br>
538+
539+
#### ✅ Valid Code
540+
489541
```html
490542
<input type="text">
491543
```
@@ -568,6 +620,110 @@ The rule does not have any configuration options.
568620
<input type="image" aria-labelledby="id1">
569621
```
570622

623+
<br>
624+
625+
---
626+
627+
<br>
628+
629+
#### Default Config
630+
631+
```json
632+
{
633+
"rules": {
634+
"@angular-eslint/template/alt-text": [
635+
"error"
636+
]
637+
}
638+
}
639+
```
640+
641+
<br>
642+
643+
#### ✅ Valid Code
644+
645+
```html
646+
<object [title]="title" [other]="val"></object>
647+
```
648+
649+
<br>
650+
651+
---
652+
653+
<br>
654+
655+
#### Default Config
656+
657+
```json
658+
{
659+
"rules": {
660+
"@angular-eslint/template/alt-text": [
661+
"error"
662+
]
663+
}
664+
}
665+
```
666+
667+
<br>
668+
669+
#### ✅ Valid Code
670+
671+
```html
672+
<object [attr.aria-label]="desc" [custom]="x"></object>
673+
```
674+
675+
<br>
676+
677+
---
678+
679+
<br>
680+
681+
#### Default Config
682+
683+
```json
684+
{
685+
"rules": {
686+
"@angular-eslint/template/alt-text": [
687+
"error"
688+
]
689+
}
690+
}
691+
```
692+
693+
<br>
694+
695+
#### ✅ Valid Code
696+
697+
```html
698+
<area [alt]="altText" [id]="itemId">
699+
```
700+
701+
<br>
702+
703+
---
704+
705+
<br>
706+
707+
#### Default Config
708+
709+
```json
710+
{
711+
"rules": {
712+
"@angular-eslint/template/alt-text": [
713+
"error"
714+
]
715+
}
716+
}
717+
```
718+
719+
<br>
720+
721+
#### ✅ Valid Code
722+
723+
```html
724+
<area [attr.aria-label]="label" [prop]="p">
725+
```
726+
571727
</details>
572728

573729
<br>

packages/eslint-plugin-template/src/rules/alt-text.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ function isValidObjectNode(node: TmplAstElement): boolean {
8181
hasAriaLabelAttribute = false;
8282

8383
for (const attribute of node.attributes) {
84-
hasTitleAttribute = attribute.name === 'title';
85-
hasAriaLabelAttribute = isAriaLabel(attribute.name);
84+
hasTitleAttribute = hasTitleAttribute || attribute.name === 'title';
85+
hasAriaLabelAttribute =
86+
hasAriaLabelAttribute || isAriaLabel(attribute.name);
8687
}
8788

8889
// Note that we return "early" before looping through `element.inputs`.
@@ -96,8 +97,8 @@ function isValidObjectNode(node: TmplAstElement): boolean {
9697
hasAriaLabelBinding = false;
9798

9899
for (const input of node.inputs) {
99-
hasTitleBinding = input.name === 'title';
100-
hasAriaLabelBinding = isAriaLabel(input.name);
100+
hasTitleBinding = hasTitleBinding || input.name === 'title';
101+
hasAriaLabelBinding = hasAriaLabelBinding || isAriaLabel(input.name);
101102
}
102103

103104
if (hasTitleBinding || hasAriaLabelBinding) {
@@ -119,8 +120,9 @@ function isValidAreaNode(node: TmplAstElement): boolean {
119120
hasAriaLabelAttribute = false;
120121

121122
for (const attribute of node.attributes) {
122-
hasAltAttribute = isAlt(attribute.name);
123-
hasAriaLabelAttribute = isAriaLabel(attribute.name);
123+
hasAltAttribute = hasAltAttribute || isAlt(attribute.name);
124+
hasAriaLabelAttribute =
125+
hasAriaLabelAttribute || isAriaLabel(attribute.name);
124126
}
125127

126128
// Note that we return "early" before looping through `element.inputs`.
@@ -134,8 +136,8 @@ function isValidAreaNode(node: TmplAstElement): boolean {
134136
hasAriaLabelBinding = false;
135137

136138
for (const input of node.inputs) {
137-
hasAltBinding = isAlt(input.name);
138-
hasAriaLabelBinding = isAriaLabel(input.name);
139+
hasAltBinding = hasAltBinding || isAlt(input.name);
140+
hasAriaLabelBinding = hasAriaLabelBinding || isAriaLabel(input.name);
139141
}
140142

141143
return hasAltBinding || hasAriaLabelBinding;

packages/eslint-plugin-template/tests/rules/alt-text/cases.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@ export const valid: readonly (string | ValidTestCase<Options>)[] = [
1616
'<object aria-labelledby="id1">',
1717
'<object>Meaningful description</object>',
1818
'<object title="An object">',
19+
'<object aria-label="foo" id="bar"></object>',
1920
'<area aria-label="foo" />',
2021
'<area aria-labelledby="id1" />',
2122
'<area alt="This is descriptive!" />',
23+
'<area alt="desc" href="path">',
2224
'<input type="text">',
2325
'<input type="image" alt="This is descriptive!">',
2426
'<input type="image" aria-label="foo">',
2527
'<input type="image" aria-labelledby="id1">',
28+
'<object [title]="title" [other]="val"></object>',
29+
'<object [attr.aria-label]="desc" [custom]="x"></object>',
30+
'<area [alt]="altText" [id]="itemId">',
31+
'<area [attr.aria-label]="label" [prop]="p">',
2632
];
2733

2834
export const invalid: readonly InvalidTestCase<MessageIds, Options>[] = [

0 commit comments

Comments
 (0)