@@ -23,12 +23,13 @@ module.exports = {
2323 } ,
2424 fixable : 'code' ,
2525 schema : [ ] ,
26+ messages : {
27+ 'message_then' : 'A single expect() in a then() can be rewritten with a should().' ,
28+ 'message_should' : 'A single expect() in a should() can be rewritten with just a should().' ,
29+ } ,
2630 } ,
2731
2832 create ( context ) {
29- const MESSAGE_THEN = 'A single expect() in a then() can be rewritten with a should().'
30- const MESSAGE_SHOULD = 'A single expect() in a should() can be rewritten with just a should().'
31-
3233 //----------------------------------------------------------------------
3334 // Helpers
3435 //----------------------------------------------------------------------
@@ -48,15 +49,15 @@ module.exports = {
4849 }
4950
5051 /**
51- * Report an error with `message ` if both conditions are satisfied:
52+ * Report an error with `messageId ` if both conditions are satisfied:
5253 *
5354 * - `thenOrShouldCallNode` contains as single argument a function
5455 * with a lonely `expect()` statement, and
5556 *
5657 * - the `expect()` must take as argument the same object as the
5758 * one passed to the function.
5859 */
59- function checkThenOrShould ( thenOrShouldCallNode , message ) {
60+ function checkThenOrShould ( thenOrShouldCallNode , messageId ) {
6061 if ( thenOrShouldCallNode . arguments . length !== 1 ) return
6162
6263 let argument = thenOrShouldCallNode . arguments [ 0 ]
@@ -95,7 +96,7 @@ module.exports = {
9596 if ( expectArgument === anonymousFunctionArgumentName ) {
9697 context . report ( {
9798 node : thenOrShouldCallNode ,
98- message ,
99+ messageId ,
99100 fix : ( fixer ) => fixCall ( fixer , thenOrShouldCallNode , thenArgumentBody . expression ) ,
100101 } )
101102 }
@@ -111,10 +112,10 @@ module.exports = {
111112
112113 switch ( node . callee . property . name ) {
113114 case 'then' :
114- checkThenOrShould ( node , MESSAGE_THEN )
115+ checkThenOrShould ( node , 'message_then' )
115116 break
116117 case 'should' :
117- checkThenOrShould ( node , MESSAGE_SHOULD )
118+ checkThenOrShould ( node , 'message_should' )
118119 break
119120 default :
120121 return
0 commit comments