@@ -2,6 +2,7 @@ export default ({ preferred, negatedPreferred, attributes }) => (context) => {
22 const getCorrectFunctionFor = ( node , negated = false ) =>
33 ( node . arguments . length === 1 ||
44 node . arguments [ 1 ] . value === true ||
5+ node . arguments [ 1 ] . type !== "Literal" ||
56 ( typeof node . arguments [ 1 ] . value === "string" &&
67 node . arguments [ 1 ] . value . toLowerCase ( ) === "true" ) ||
78 node . arguments [ 1 ] . value === "" ) &&
@@ -34,7 +35,7 @@ export default ({ preferred, negatedPreferred, attributes }) => (context) => {
3435 ) ,
3536 } ) ;
3637 } ,
37- [ ` CallExpression[callee.property.name=/toBe(Truthy|Falsy)?|toEqual/][callee.object.callee.name='expect']` ] (
38+ " CallExpression[callee.property.name=/toBe(Truthy|Falsy)?|toEqual/][callee.object.callee.name='expect']" (
3839 node
3940 ) {
4041 const {
@@ -65,7 +66,7 @@ export default ({ preferred, negatedPreferred, attributes }) => (context) => {
6566 ] ,
6667 } ) ;
6768 } ,
68- [ ` CallExpression[callee.property.name=/toHaveProperty|toHaveAttribute/][callee.object.property.name='not'][callee.object.object.callee.name='expect']` ] (
69+ " CallExpression[callee.property.name=/toHaveProperty|toHaveAttribute/][callee.object.property.name='not'][callee.object.object.callee.name='expect']" (
6970 node
7071 ) {
7172 const arg = node . arguments [ 0 ] . value ;
@@ -86,7 +87,7 @@ export default ({ preferred, negatedPreferred, attributes }) => (context) => {
8687 ) ,
8788 } ) ;
8889 } ,
89- [ ` CallExpression[callee.object.callee.name='expect'][callee.property.name=/toHaveProperty|toHaveAttribute/]` ] (
90+ " CallExpression[callee.object.callee.name='expect'][callee.property.name=/toHaveProperty|toHaveAttribute/]" (
9091 node
9192 ) {
9293 if ( ! isBannedArg ( node ) ) {
@@ -98,17 +99,27 @@ export default ({ preferred, negatedPreferred, attributes }) => (context) => {
9899 const incorrectFunction = node . callee . property . name ;
99100
100101 const message = `Use ${ correctFunction } () instead of ${ incorrectFunction } (${ node . arguments
101- . map ( ( { raw } ) => raw )
102+ . map ( ( { raw, name } ) => raw || name )
102103 . join ( ", " ) } )`;
104+
105+ const secondArgIsLiteral =
106+ node . arguments . length === 2 && node . arguments [ 1 ] . type === "Literal" ;
107+
103108 context . report ( {
104109 node : node . callee . property ,
105110 message,
106- fix : ( fixer ) => [
107- fixer . replaceTextRange (
108- [ node . callee . property . range [ 0 ] , node . range [ 1 ] ] ,
109- `${ correctFunction } ()`
110- ) ,
111- ] ,
111+ fix : ( fixer ) => {
112+ if ( node . arguments . length === 1 || secondArgIsLiteral ) {
113+ return [
114+ fixer . replaceTextRange (
115+ [ node . callee . property . range [ 0 ] , node . range [ 1 ] ] ,
116+ `${ correctFunction } ()`
117+ ) ,
118+ ] ;
119+ }
120+
121+ return null ;
122+ } ,
112123 } ) ;
113124 } ,
114125 } ;
0 commit comments