forked from angular-eslint/angular-eslint
/
no-distracting-elements.ts
45 lines (41 loc) · 1.3 KB
/
no-distracting-elements.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import type { TmplAstElement } from '@angular-eslint/bundled-angular-compiler';
import { getTemplateParserServices } from '@angular-eslint/utils';
import { createESLintRule } from '../utils/create-eslint-rule';
type Options = [];
export type MessageIds = 'noDistractingElements';
export const RULE_NAME = 'no-distracting-elements';
export default createESLintRule<Options, MessageIds>({
name: RULE_NAME,
meta: {
type: 'suggestion',
docs: {
description: 'Enforces that no distracting elements are used',
recommended: false,
},
fixable: 'code',
schema: [],
messages: {
noDistractingElements:
'Do not use <{{element}}> elements as they can create visual accessibility issues and are deprecated',
},
},
defaultOptions: [],
create(context) {
const parserServices = getTemplateParserServices(context);
return {
'Element$1[name=/^(blink|marquee)$/]'({
name: element,
sourceSpan,
}: TmplAstElement) {
const loc = parserServices.convertNodeSourceSpanToLoc(sourceSpan);
context.report({
loc,
messageId: 'noDistractingElements',
data: { element },
fix: (fixer) =>
fixer.removeRange([sourceSpan.start.offset, sourceSpan.end.offset]),
});
},
};
},
});