@@ -28,27 +28,28 @@ module.exports = {
28
28
29
29
create : context => ( {
30
30
JSXOpeningElement : ( node ) => {
31
- // Determine if ignoreNonDOM is set to true
32
- // If true, then do not run rule.
33
31
const options = context . options [ 0 ] || { } ;
34
32
const ignoreNonDOM = ! ! options . ignoreNonDOM ;
33
+
34
+ const autocomplete = getLiteralPropValue ( getProp ( node . attributes , 'autocomplete' ) ) ;
35
35
const elType = elementType ( node ) ;
36
- const isDOMNode = dom . get ( elType ) ;
37
- if ( ignoreNonDOM && ! isDOMNode ) {
36
+ const isNativeDOMNode = ! ! dom . get ( elType ) ;
37
+
38
+ if ( typeof autocomplete !== 'string'
39
+ || ( isNativeDOMNode && elType !== 'input' )
40
+ || ( ! isNativeDOMNode && ignoreNonDOM )
41
+ ) {
38
42
return ;
39
43
}
40
44
41
- const attr = ( attrName ) => {
42
- const value = getLiteralPropValue ( getProp ( node . attributes , attrName ) ) ;
43
- return ( typeof value === 'string' ? value : null ) ;
44
- } ;
45
- const props = {
46
- nodeName : isDOMNode ? elType : 'input' ,
47
- nodeType : 1 ,
48
- } ;
49
- const hasAttr = attrName => attr ( attrName ) !== null ;
50
-
51
- const { violations } = runVirtualRule ( 'autocomplete-valid' , { attr, props, hasAttr } ) ;
45
+ const { violations } = runVirtualRule ( 'autocomplete-valid' , {
46
+ nodeName : 'input' ,
47
+ attributes : {
48
+ autocomplete,
49
+ // Which autocomplete is valid depends on the input type
50
+ type : getLiteralPropValue ( getProp ( node . attributes , 'type' ) ) ,
51
+ } ,
52
+ } ) ;
52
53
53
54
if ( violations . length === 0 ) {
54
55
return ;
0 commit comments