@@ -29,40 +29,101 @@ const parserOptions = {
29
29
const ruleTester = new RuleTester ( { parserOptions } ) ;
30
30
ruleTester . run ( 'no-unknown-property' , rule , {
31
31
valid : parsers . all ( [
32
+ // React components and their props/attributes should be fine
32
33
{ code : '<App class="bar" />;' } ,
33
34
{ code : '<App for="bar" />;' } ,
35
+ { code : '<App someProp="bar" />;' } ,
34
36
{ code : '<Foo.bar for="bar" />;' } ,
35
37
{ code : '<App accept-charset="bar" />;' } ,
36
- { code : '<meta charset="utf-8" />;' } ,
37
- { code : '<meta charSet="utf-8" />;' } ,
38
38
{ code : '<App http-equiv="bar" />;' } ,
39
39
{
40
40
code : '<App xlink:href="bar" />;' ,
41
41
features : [ 'jsx namespace' ] ,
42
42
} ,
43
43
{ code : '<App clip-path="bar" />;' } ,
44
+ // Some HTML/DOM elements with common attributes should work
44
45
{ code : '<div className="bar"></div>;' } ,
45
46
{ code : '<div onMouseDown={this._onMouseDown}></div>;' } ,
46
- // data attributes should work
47
+ { code : '<a href="someLink">Read more</a>' } ,
48
+ { code : '<img src="cat_keyboard.jpeg" alt="A cat sleeping on a keyboard" />' } ,
49
+ { code : '<input type="password" required />' } ,
50
+ { code : '<input ref={this.input} type="radio" />' } ,
51
+ { code : '<button disabled>You cannot click me</button>;' } ,
52
+ // Case ignored attributes, for `charset` discussion see https://github.com/jsx-eslint/eslint-plugin-react/pull/1863
53
+ { code : '<meta charset="utf-8" />;' } ,
54
+ { code : '<meta charSet="utf-8" />;' } ,
55
+ // Some custom web components that are allowed to use `class` instead of `className`
56
+ { code : '<div class="foo" is="my-elem"></div>;' } ,
57
+ { code : '<div {...this.props} class="foo" is="my-elem"></div>;' } ,
58
+ { code : '<atom-panel class="foo"></atom-panel>;' } ,
59
+ // data-* attributes should work
47
60
{ code : '<div data-foo="bar"></div>;' } ,
48
61
{ code : '<div data-foo-bar="baz"></div>;' } ,
49
62
{ code : '<div data-parent="parent"></div>;' } ,
50
63
{ code : '<div data-index-number="1234"></div>;' } ,
51
- { code : '<div class="foo" is="my-elem"></div>;' } ,
52
- { code : '<div {...this.props} class="foo" is="my-elem"></div>;' } ,
53
- { code : '<atom-panel class="foo"></atom-panel>;' } , {
64
+ // Ignoring should work
65
+ {
54
66
code : '<div class="bar"></div>;' ,
55
67
options : [ { ignore : [ 'class' ] } ] ,
56
68
} ,
57
- // aria attributes should work
69
+ {
70
+ code : '<div someProp="bar"></div>;' ,
71
+ options : [ { ignore : [ 'someProp' ] } ] ,
72
+ } ,
73
+
74
+ // aria-* attributes should work
58
75
{ code : '<button aria-haspopup="true">Click me to open pop up</button>;' } ,
59
76
{ code : '<button aria-label="Close" onClick={someThing.close} />;' } ,
77
+ // Attributes on allowed elements should work
60
78
{ code : '<script crossOrigin />' } ,
61
79
{ code : '<audio crossOrigin />' } ,
62
- { code : '<div hasOwnProperty="should not be allowed tag" />' } ,
63
80
{ code : '<svg><image crossOrigin /></svg>' } ,
64
81
] ) ,
65
82
invalid : parsers . all ( [
83
+ {
84
+ code : '<div hasOwnProperty="should not be allowed property"></div>;' ,
85
+ errors : [
86
+ {
87
+ messageId : 'unknownProp' ,
88
+ data : {
89
+ name : 'hasOwnProperty' ,
90
+ } ,
91
+ } ,
92
+ ] ,
93
+ } ,
94
+ {
95
+ code : '<div abc="should not be allowed property"></div>;' ,
96
+ errors : [
97
+ {
98
+ messageId : 'unknownProp' ,
99
+ data : {
100
+ name : 'abc' ,
101
+ } ,
102
+ } ,
103
+ ] ,
104
+ } ,
105
+ {
106
+ code : '<div aria-fake="should not be allowed property"></div>;' ,
107
+ errors : [
108
+ {
109
+ messageId : 'unknownProp' ,
110
+ data : {
111
+ name : 'aria-fake' ,
112
+ } ,
113
+ } ,
114
+ ] ,
115
+ } ,
116
+ {
117
+ code : '<div someProp="bar"></div>;' ,
118
+ errors : [
119
+ {
120
+ messageId : 'unknownProp' ,
121
+ data : {
122
+ name : 'someProp' ,
123
+ } ,
124
+ } ,
125
+ ] ,
126
+ } ,
66
127
{
67
128
code : '<div class="bar"></div>;' ,
68
129
output : '<div className="bar"></div>;' ,
0 commit comments