-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from sutrkiller/features/state-and-props-access…
…-within-setstate Features/state and props access within setstate
- Loading branch information
Showing
11 changed files
with
221 additions
and
59 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export const OPTION_UPDATER_ONLY = "updater-only"; | ||
|
||
export interface IOptions { | ||
readonly updaterOnly: boolean; | ||
} | ||
|
||
export function parseOptions(ruleArguments: any[]): IOptions { | ||
const updaterOnly = ruleArguments[0] as string; | ||
|
||
return { | ||
updaterOnly: updaterOnly === OPTION_UPDATER_ONLY, | ||
}; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import * as ts from "typescript"; | ||
|
||
export const isThisKeyword = (expression: ts.Expression) => expression.kind === ts.SyntaxKind.ThisKeyword; |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import * as ts from "typescript"; | ||
import { | ||
isCallExpression, | ||
isPropertyAccessExpression, | ||
isParenthesizedExpression, | ||
} from "tsutils"; | ||
|
||
import { isThisKeyword } from "./syntaxKindUtils"; | ||
|
||
export const isThisPropertyAccess = (node: ts.Node): node is ts.PropertyAccessExpression => | ||
isPropertyAccessExpression(node) && isThisKeyword(node.expression); | ||
|
||
export const isThisSetState = (node: ts.Node): node is ts.CallExpression => | ||
isCallExpression(node) | ||
&& isPropertyAccessExpression(node.expression) | ||
&& isThisKeyword(node.expression.expression) | ||
&& node.expression.name.text === "setState"; | ||
|
||
export function getFirstSetStateAncestor(node: ts.Node): ts.CallExpression { | ||
if (node.kind === ts.SyntaxKind.SourceFile) { | ||
return null; | ||
} | ||
|
||
if (isThisSetState(node)) { | ||
return node as ts.CallExpression; | ||
} | ||
|
||
return getFirstSetStateAncestor(node.parent); | ||
} | ||
|
||
export const removeParentheses = (node: ts.Node) => isParenthesizedExpression(node) | ||
? removeParentheses(node.expression) | ||
: node; |
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
Oops, something went wrong.