@@ -471,4 +471,57 @@ describe('utils', () => {
471471 }
472472 } ) ;
473473 } ) ;
474+
475+ describe ( 'isAutoFixerFunction / isSuggestionFixerFunction' , ( ) => {
476+ const CASES = {
477+ // isAutoFixerFunction
478+ 'context.report({ fix(fixer) {} });' ( ast ) {
479+ return { expected : true , node : ast . body [ 0 ] . expression . arguments [ 0 ] . properties [ 0 ] . value , context : ast . body [ 0 ] . expression . callee . object , fn : utils . isAutoFixerFunction } ;
480+ } ,
481+ 'context.notReport({ fix(fixer) {} });' ( ast ) {
482+ return { expected : false , node : ast . body [ 0 ] . expression . arguments [ 0 ] . properties [ 0 ] . value , context : ast . body [ 0 ] . expression . callee . object , fn : utils . isAutoFixerFunction } ;
483+ } ,
484+ 'context.report({ notFix(fixer) {} });' ( ast ) {
485+ return { expected : false , node : ast . body [ 0 ] . expression . arguments [ 0 ] . properties [ 0 ] . value , context : ast . body [ 0 ] . expression . callee . object , fn : utils . isAutoFixerFunction } ;
486+ } ,
487+ 'notContext.report({ notFix(fixer) {} });' ( ast ) {
488+ return { expected : false , node : ast . body [ 0 ] . expression . arguments [ 0 ] . properties [ 0 ] . value , context : undefined , fn : utils . isAutoFixerFunction } ;
489+ } ,
490+
491+ // isSuggestionFixerFunction
492+ 'context.report({ suggest: [{ fix(fixer) {} }] });' ( ast ) {
493+ return { expected : true , node : ast . body [ 0 ] . expression . arguments [ 0 ] . properties [ 0 ] . value . elements [ 0 ] . properties [ 0 ] . value , context : ast . body [ 0 ] . expression . callee . object , fn : utils . isSuggestionFixerFunction } ;
494+ } ,
495+ 'context.notReport({ suggest: [{ fix(fixer) {} }] });' ( ast ) {
496+ return { expected : false , node : ast . body [ 0 ] . expression . arguments [ 0 ] . properties [ 0 ] . value . elements [ 0 ] . properties [ 0 ] . value , context : ast . body [ 0 ] . expression . callee . object , fn : utils . isSuggestionFixerFunction } ;
497+ } ,
498+ 'context.report({ notSuggest: [{ fix(fixer) {} }] });' ( ast ) {
499+ return { expected : false , node : ast . body [ 0 ] . expression . arguments [ 0 ] . properties [ 0 ] . value . elements [ 0 ] . properties [ 0 ] . value , context : ast . body [ 0 ] . expression . callee . object , fn : utils . isSuggestionFixerFunction } ;
500+ } ,
501+ 'context.report({ suggest: [{ notFix(fixer) {} }] });' ( ast ) {
502+ return { expected : false , node : ast . body [ 0 ] . expression . arguments [ 0 ] . properties [ 0 ] . value . elements [ 0 ] . properties [ 0 ] . value , context : ast . body [ 0 ] . expression . callee . object , fn : utils . isSuggestionFixerFunction } ;
503+ } ,
504+ 'notContext.report({ suggest: [{ fix(fixer) {} }] });' ( ast ) {
505+ return { expected : false , node : ast . body [ 0 ] . expression . arguments [ 0 ] . properties [ 0 ] . value , context : undefined , fn : utils . isSuggestionFixerFunction } ;
506+ } ,
507+ } ;
508+
509+ Object . keys ( CASES ) . forEach ( ruleSource => {
510+ it ( ruleSource , ( ) => {
511+ const ast = espree . parse ( ruleSource , { ecmaVersion : 6 , range : true } ) ;
512+
513+ // Add parent to each node.
514+ estraverse . traverse ( ast , {
515+ enter ( node , parent ) {
516+ node . parent = parent ;
517+ } ,
518+ } ) ;
519+
520+ const testCase = CASES [ ruleSource ] ( ast ) ;
521+ const contextIdentifiers = new Set ( [ testCase . context ] ) ;
522+ const result = testCase . fn ( testCase . node , contextIdentifiers ) ;
523+ assert . strictEqual ( result , testCase . expected ) ;
524+ } ) ;
525+ } ) ;
526+ } ) ;
474527} ) ;
0 commit comments