Skip to content

Commit

Permalink
fix(eslint-plugin-template): label-has-associated-control
Browse files Browse the repository at this point in the history
  • Loading branch information
Auke Bruinsma authored and JamesHenry committed May 1, 2024
1 parent 8148966 commit e4a7c4b
Showing 1 changed file with 10 additions and 5 deletions.
@@ -1,4 +1,7 @@
import type { AST, TmplAstElement } from '@angular-eslint/bundled-angular-compiler';
import type {
AST,
TmplAstElement,
} from '@angular-eslint/bundled-angular-compiler';
import { getTemplateParserServices } from '@angular-eslint/utils';
import { createESLintRule } from '../utils/create-eslint-rule';
import { isChildNodeOf } from '../utils/is-child-node-of';
Expand Down Expand Up @@ -78,7 +81,7 @@ export default createESLintRule<Options, MessageIds>({
},
},
defaultOptions: [DEFAULT_OPTIONS],
create(context, [{ controlComponents, labelComponents }]) {
create(context, [{ checkIds, controlComponents, labelComponents }]) {
const parserServices = getTemplateParserServices(context);
const allControlComponents: ReadonlySet<string> = new Set([
...DEFAULT_CONTROL_COMPONENTS,
Expand All @@ -88,8 +91,6 @@ export default createESLintRule<Options, MessageIds>({
...DEFAULT_LABEL_COMPONENTS,
...(labelComponents ?? []),
] as const;
const labelSelectors = allLabelComponents.map(({ selector }) => selector);
const labelComponentsPattern = toPattern(labelSelectors);
let inputItems: TmplAstElement[] = [];
let labelItems: TmplAstElement[] = [];

Expand Down Expand Up @@ -136,7 +137,7 @@ export default createESLintRule<Options, MessageIds>({

context.report({
loc,
messageId: 'accessibilityLabelHasAssociatedControl',
messageId: 'labelHasAssociatedControl',
});
}

Expand Down Expand Up @@ -170,3 +171,7 @@ function hasControlComponentWithId(
}),
);
}

function filterUndefined<T>(value: T | undefined | null): value is T {
return value !== undefined && value !== null;
}

0 comments on commit e4a7c4b

Please sign in to comment.