-
Notifications
You must be signed in to change notification settings - Fork 20
/
no-native-attributes.ts
90 lines (81 loc) · 2.08 KB
/
no-native-attributes.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
* @fileoverview Disallows use of native attributes as properties
* @author Pascal Schilp <https://github.com/thepassle>
*/
import {Rule} from 'eslint';
import * as ESTree from 'estree';
import {getPropertyMap} from '../util';
// Taken from https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes
const NATIVE_ATTRS = [
'accesskey',
'autocapitalize',
'autofocus',
'class',
'contenteditable',
'contextmenu',
'dir',
'draggable',
'enterkeyhint',
'exportparts',
'hidden',
'id',
'inert',
'inputmode',
'is',
'itemid',
'itemprop',
'itemref',
'itemscope',
'itemtype',
'lang',
'nonce',
'part',
'popover',
'role',
'slot',
'spellcheck',
'style',
'tabindex',
'title',
'translate',
'virtualkeyboardpolicy'
];
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
const rule: Rule.RuleModule = {
meta: {
docs: {
description: 'Disallows use of native attributes as properties',
recommended: false,
url: 'https://github.com/43081j/eslint-plugin-lit/blob/master/docs/rules/no-native-attributes.md'
},
schema: [],
messages: {
noNativeAttributes:
'The {{ prop }} attribute is a native global attribute. ' +
'Using it as a property could have unintended side-effects.'
}
},
create(context): Rule.RuleListener {
// variables should be defined here
//----------------------------------------------------------------------
// Public
//----------------------------------------------------------------------
return {
'ClassExpression,ClassDeclaration': (node: ESTree.Class): void => {
const propertyMap = getPropertyMap(node);
for (const [prop, {key}] of propertyMap.entries()) {
if (NATIVE_ATTRS.includes(prop)) {
context.report({
node: key,
messageId: 'noNativeAttributes',
data: {prop}
});
}
}
}
};
}
};
export = rule;