33 * @author 薛定谔的猫<[email protected] > 44 */
55
6- // ------------------------------------------------------------------------------
7- // Requirements
8- // ------------------------------------------------------------------------------
9-
10- import * as utils from '../utils.js' ;
116import { getStaticValue } from '@eslint-community/eslint-utils' ;
127
8+ import {
9+ getContextIdentifiers ,
10+ isAutoFixerFunction ,
11+ isSuggestionFixerFunction ,
12+ } from '../utils.js' ;
13+
1314// ------------------------------------------------------------------------------
1415// Rule Definition
1516// ------------------------------------------------------------------------------
@@ -70,15 +71,14 @@ const rule = {
7071 * Check if a returned/yielded node is likely to be a fix or not.
7172 * A fix is an object created by fixer.replaceText() for example and returned by the fix function.
7273 * @param {ASTNode } node - node to check
73- * @param {Context } context
7474 * @returns {boolean }
7575 */
7676 function isFix ( node ) {
7777 if ( node . type === 'ArrayExpression' && node . elements . length === 0 ) {
7878 // An empty array is not a fix.
7979 return false ;
8080 }
81- const scope = utils . getScope ( context ) ;
81+ const scope = context . sourceCode . getScope ( node ) ;
8282 const staticValue = getStaticValue ( node , scope ) ;
8383 if ( ! staticValue ) {
8484 // If we can't find a static value, assume it's a real fix value.
@@ -96,8 +96,8 @@ const rule = {
9696
9797 return {
9898 Program ( ast ) {
99- const sourceCode = utils . getSourceCode ( context ) ;
100- contextIdentifiers = utils . getContextIdentifiers (
99+ const sourceCode = context . sourceCode ;
100+ contextIdentifiers = getContextIdentifiers (
101101 sourceCode . scopeManager ,
102102 ast ,
103103 ) ;
@@ -111,8 +111,8 @@ const rule = {
111111 hasYieldWithFixer : false ,
112112 hasReturnWithFixer : false ,
113113 shouldCheck :
114- utils . isAutoFixerFunction ( node , contextIdentifiers ) ||
115- utils . isSuggestionFixerFunction ( node , contextIdentifiers ) ,
114+ isAutoFixerFunction ( node , contextIdentifiers ) ||
115+ isSuggestionFixerFunction ( node , contextIdentifiers ) ,
116116 node,
117117 } ;
118118 } ,
@@ -146,7 +146,7 @@ const rule = {
146146 // Ensure the current (arrow) fixer function returned a fix.
147147 'ArrowFunctionExpression:exit' ( node ) {
148148 if ( funcInfo . shouldCheck ) {
149- const sourceCode = utils . getSourceCode ( context ) ;
149+ const sourceCode = context . sourceCode ;
150150 const loc = sourceCode . getTokenBefore ( node . body ) . loc ; // Show violation on arrow (=>).
151151 if ( node . expression ) {
152152 // When the return is implied (no curly braces around the body), we have to check the single body node directly.
0 commit comments