@@ -29,40 +29,101 @@ const parserOptions = {
2929const ruleTester = new RuleTester ( { parserOptions } ) ;
3030ruleTester . run ( 'no-unknown-property' , rule , {
3131 valid : parsers . all ( [
32+ // React components and their props/attributes should be fine
3233 { code : '<App class="bar" />;' } ,
3334 { code : '<App for="bar" />;' } ,
35+ { code : '<App someProp="bar" />;' } ,
3436 { code : '<Foo.bar for="bar" />;' } ,
3537 { code : '<App accept-charset="bar" />;' } ,
36- { code : '<meta charset="utf-8" />;' } ,
37- { code : '<meta charSet="utf-8" />;' } ,
3838 { code : '<App http-equiv="bar" />;' } ,
3939 {
4040 code : '<App xlink:href="bar" />;' ,
4141 features : [ 'jsx namespace' ] ,
4242 } ,
4343 { code : '<App clip-path="bar" />;' } ,
44+ // Some HTML/DOM elements with common attributes should work
4445 { code : '<div className="bar"></div>;' } ,
4546 { 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
4760 { code : '<div data-foo="bar"></div>;' } ,
4861 { code : '<div data-foo-bar="baz"></div>;' } ,
4962 { code : '<div data-parent="parent"></div>;' } ,
5063 { 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+ {
5466 code : '<div class="bar"></div>;' ,
5567 options : [ { ignore : [ 'class' ] } ] ,
5668 } ,
57- // aria attributes should work
69+ {
70+ code : '<div someProp="bar"></div>;' ,
71+ options : [ { ignore : [ 'someProp' ] } ] ,
72+ } ,
73+
74+ // aria-* attributes should work
5875 { code : '<button aria-haspopup="true">Click me to open pop up</button>;' } ,
5976 { code : '<button aria-label="Close" onClick={someThing.close} />;' } ,
77+ // Attributes on allowed elements should work
6078 { code : '<script crossOrigin />' } ,
6179 { code : '<audio crossOrigin />' } ,
62- { code : '<div hasOwnProperty="should not be allowed tag" />' } ,
6380 { code : '<svg><image crossOrigin /></svg>' } ,
6481 ] ) ,
6582 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+ } ,
66127 {
67128 code : '<div class="bar"></div>;' ,
68129 output : '<div className="bar"></div>;' ,
0 commit comments