-
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(eslint-plugin): complete fix if import already exsists (#845)
- Loading branch information
1 parent
c4d044d
commit 411989e
Showing
4 changed files
with
137 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
import type * as estree from 'estree' | ||
|
||
export const reatomFactoryList = ['atom', 'action', 'reaction'] as const | ||
export const reatomFactoryPattern = new RegExp(`^(reatom\\w+|${reatomFactoryList.join('|')})$`) | ||
|
||
export const patternNames = (pattern: estree.Pattern): estree.Identifier[] => { | ||
if (pattern.type === 'AssignmentPattern') { | ||
return patternNames(pattern.left) | ||
} | ||
if (pattern.type === 'Identifier') { | ||
return [pattern] | ||
} | ||
if (pattern.type === 'ArrayPattern') { | ||
return pattern.elements.flatMap(patternNames) | ||
} | ||
if (pattern.type === 'ObjectPattern') { | ||
return pattern.properties.flatMap((property) => (property.key.type === 'Identifier' ? property.key : [])) | ||
} | ||
return [] | ||
} | ||
|
||
export const checkCallExpressionNode = (node: estree.CallExpression) => | ||
node.callee.type === 'MemberExpression' && | ||
node.callee.object.type === 'Identifier' && | ||
node.callee.property.type === 'Identifier' | ||
import type * as estree from 'estree' | ||
|
||
export const reatomFactoryList = ['atom', 'action', 'reaction'] as const | ||
export const reatomFactoryPattern = new RegExp(`^(reatom\\w+|${reatomFactoryList.join('|')})$`) | ||
|
||
export const patternNames = (pattern: estree.Pattern): estree.Identifier[] => { | ||
if (pattern.type === 'AssignmentPattern') { | ||
return patternNames(pattern.left) | ||
} | ||
if (pattern.type === 'Identifier') { | ||
return [pattern] | ||
} | ||
if (pattern.type === 'ArrayPattern') { | ||
return pattern.elements.flatMap(patternNames) | ||
} | ||
if (pattern.type === 'ObjectPattern') { | ||
return pattern.properties.flatMap((property) => (property.key.type === 'Identifier' ? property.key : [])) | ||
} | ||
return [] | ||
} | ||
|
||
export const checkCallExpressionNodeValid = (node: estree.CallExpression) => | ||
node.callee.type === 'MemberExpression' && | ||
node.callee.object.type === 'Identifier' && | ||
node.callee.property.type === 'Identifier' |