3
3
* @author 薛定谔的猫<[email protected] >
4
4
*/
5
5
6
- // ------------------------------------------------------------------------------
7
- // Requirements
8
- // ------------------------------------------------------------------------------
9
-
10
- import * as utils from '../utils.js' ;
11
6
import { getStaticValue } from '@eslint-community/eslint-utils' ;
12
7
8
+ import {
9
+ getContextIdentifiers ,
10
+ isAutoFixerFunction ,
11
+ isSuggestionFixerFunction ,
12
+ } from '../utils.js' ;
13
+
13
14
// ------------------------------------------------------------------------------
14
15
// Rule Definition
15
16
// ------------------------------------------------------------------------------
@@ -70,15 +71,14 @@ const rule = {
70
71
* Check if a returned/yielded node is likely to be a fix or not.
71
72
* A fix is an object created by fixer.replaceText() for example and returned by the fix function.
72
73
* @param {ASTNode } node - node to check
73
- * @param {Context } context
74
74
* @returns {boolean }
75
75
*/
76
76
function isFix ( node ) {
77
77
if ( node . type === 'ArrayExpression' && node . elements . length === 0 ) {
78
78
// An empty array is not a fix.
79
79
return false ;
80
80
}
81
- const scope = utils . getScope ( context ) ;
81
+ const scope = context . sourceCode . getScope ( node ) ;
82
82
const staticValue = getStaticValue ( node , scope ) ;
83
83
if ( ! staticValue ) {
84
84
// If we can't find a static value, assume it's a real fix value.
@@ -96,8 +96,8 @@ const rule = {
96
96
97
97
return {
98
98
Program ( ast ) {
99
- const sourceCode = utils . getSourceCode ( context ) ;
100
- contextIdentifiers = utils . getContextIdentifiers (
99
+ const sourceCode = context . sourceCode ;
100
+ contextIdentifiers = getContextIdentifiers (
101
101
sourceCode . scopeManager ,
102
102
ast ,
103
103
) ;
@@ -111,8 +111,8 @@ const rule = {
111
111
hasYieldWithFixer : false ,
112
112
hasReturnWithFixer : false ,
113
113
shouldCheck :
114
- utils . isAutoFixerFunction ( node , contextIdentifiers ) ||
115
- utils . isSuggestionFixerFunction ( node , contextIdentifiers ) ,
114
+ isAutoFixerFunction ( node , contextIdentifiers ) ||
115
+ isSuggestionFixerFunction ( node , contextIdentifiers ) ,
116
116
node,
117
117
} ;
118
118
} ,
@@ -146,7 +146,7 @@ const rule = {
146
146
// Ensure the current (arrow) fixer function returned a fix.
147
147
'ArrowFunctionExpression:exit' ( node ) {
148
148
if ( funcInfo . shouldCheck ) {
149
- const sourceCode = utils . getSourceCode ( context ) ;
149
+ const sourceCode = context . sourceCode ;
150
150
const loc = sourceCode . getTokenBefore ( node . body ) . loc ; // Show violation on arrow (=>).
151
151
if ( node . expression ) {
152
152
// When the return is implied (no curly braces around the body), we have to check the single body node directly.
0 commit comments