Documentation
¶
Index ¶
- Constants
- Variables
- func ApplyGlobalJestAlias(name string, settings map[string]interface{}) string
- func CalleeChainName(expr *ast.Node) string
- func FindExpectModifiersAndMatcher(entries []ParsedJestFnMemberEntry) ([]ParsedJestFnMemberEntry, *ParsedJestFnMemberEntry, string)
- func FindImportDeclaration(node *ast.Node) *ast.ImportDeclaration
- func FindTopMostCallExpression(node *ast.Node) *ast.Node
- func GetAccessorReceiverAndParent(entry *ParsedJestFnMemberEntry) (*ast.Node, *ast.Node)
- func GetJestVersion(ctx rule.RuleContext) string
- func IsBooleanLiteral(node *ast.Node) (value bool, ok bool)
- func IsFunction(node *ast.Node) bool
- func IsMemberAccessNode(node *ast.Node) bool
- func IsNamedMember(node *ast.Node, name string) bool
- func IsStaticExpectMatcher(matcher string, headNode *ast.Node) bool
- func IsTypeOfJestFnCall(node *ast.Node, ctx rule.RuleContext, kinds ...JestFnType) bool
- func JestFnMemberEntriesRange(entries []ParsedJestFnMemberEntry) (core.TextRange, bool)
- func JestHookOrderIndex(name string) int
- func JestVersionMajor(v string) int
- func JoinJestFnMemberEntries(entries []ParsedJestFnMemberEntry) string
- func ReceiverBeforeInvocation(matcherCall *ast.Node) *ast.Node
- func ResolveFirstIdentifier(node *ast.Node) *ast.Node
- func ResolveNamedFunctionCallback(ctx rule.RuleContext, callExpr *ast.CallExpression) (*ast.Node, string)
- func UnwrapBasicTypeAssertions(node *ast.Node) *ast.Node
- func UnwrapTypeAssertions(node *ast.Node) *ast.Node
- type JestFnType
- type JestImportMode
- type ParsedJestFnCall
- type ParsedJestFnCallHead
- type ParsedJestFnCallHeadEntry
- type ParsedJestFnMemberEntry
- type TestCallbackInfo
Constants ¶
const ( ExpectParseReasonNone = "" ExpectParseReasonMatcherNotFound = "matcher-not-found" ExpectParseReasonModifierUnknown = "modifier-unknown" )
const DefaultJestVersion = "29.0.0"
DefaultJestVersion is used when the Jest version cannot be resolved from settings or package.json.
Variables ¶
var EQUALITY_METHOD_NAMES = map[string]bool{ "toBe": true, "toEqual": true, "toStrictEqual": true, }
var EXPECT_MODIFIER_NAMES = map[string]bool{ "not": true, "rejects": true, "resolves": true, }
var JEST_HOOKS_ORDER = []string{"beforeAll", "beforeEach", "afterEach", "afterAll"}
var JEST_METHOD_NAMES = map[string]bool{ "afterAll": true, "afterEach": true, "beforeAll": true, "beforeEach": true, "describe": true, "expect": true, "fdescribe": true, "fit": true, "it": true, "jest": true, "test": true, "xdescribe": true, "xit": true, "xtest": true, }
var VALID_JEST_FN_CALL_CHAINS = map[string]bool{ "afterAll": true, "afterEach": true, "beforeAll": true, "beforeEach": true, "describe": true, "describe.each": true, "describe.only": true, "describe.only.each": true, "describe.skip": true, "describe.skip.each": true, "fdescribe": true, "fdescribe.each": true, "fit": true, "fit.concurrent": true, "fit.each": true, "fit.failing": true, "fit.fails": true, "it": true, "it.concurrent": true, "it.concurrent.each": true, "it.concurrent.only.each": true, "it.concurrent.skip.each": true, "it.each": true, "it.failing": true, "it.failing.each": true, "it.fails": true, "it.only": true, "it.only.each": true, "it.only.failing": true, "it.only.fails": true, "it.skip": true, "it.skip.each": true, "it.skip.failing": true, "it.skip.fails": true, "it.todo": true, "test": true, "test.concurrent": true, "test.concurrent.each": true, "test.concurrent.only.each": true, "test.concurrent.skip.each": true, "test.each": true, "test.failing": true, "test.fails": true, "test.only": true, "test.only.each": true, "test.only.failing": true, "test.only.fails": true, "test.skip": true, "test.skip.each": true, "test.skip.failing": true, "test.skip.fails": true, "test.todo": true, "xdescribe": true, "xdescribe.each": true, "xit": true, "xit.concurrent": true, "xit.each": true, "xit.failing": true, "xit.fails": true, "xtest": true, "xtest.each": true, "xtest.failing": true, "xtest.fails": true, }
Functions ¶
func ApplyGlobalJestAlias ¶ added in v0.22.0
ApplyGlobalJestAlias maps settings.jest.globalAliases so that e.g. `context` is treated as `describe`, matching eslint-plugin-jest.
func CalleeChainName ¶ added in v0.22.0
CalleeChainName returns a dotted name for a call callee expression, mirroring eslint-plugin-jest getNodeName for CallExpression callees (used by expect-expect assertFunctionNames matching).
It differs from GetJestFnMemberEntries / getElementAccessName: bracket notation contributes a segment only when the index matches eslint-plugin-jest's supported accessor names (identifier, string literal, or no-substitution template). Unsupported keys break the chain entirely. NewExpression is peeled so e.g. new (require('x')).y becomes a chain.
func FindExpectModifiersAndMatcher ¶ added in v0.22.0
func FindExpectModifiersAndMatcher(entries []ParsedJestFnMemberEntry) ( []ParsedJestFnMemberEntry, *ParsedJestFnMemberEntry, string, )
func FindImportDeclaration ¶
func FindImportDeclaration(node *ast.Node) *ast.ImportDeclaration
func FindTopMostCallExpression ¶ added in v0.22.0
FindTopMostCallExpression walks up member/call chains to the outermost CallExpression, matching eslint-plugin-jest's findTopMostCallExpression.
func GetAccessorReceiverAndParent ¶ added in v0.22.0
func GetAccessorReceiverAndParent(entry *ParsedJestFnMemberEntry) (*ast.Node, *ast.Node)
func GetJestVersion ¶ added in v0.22.0
func GetJestVersion(ctx rule.RuleContext) string
GetJestVersion returns the effective Jest version: explicit settings, then the nearest package.json, then DefaultJestVersion.
func IsBooleanLiteral ¶ added in v0.22.0
IsBooleanLiteral reports whether node is a `true`/`false` literal after stripping parentheses and basic TS type assertions, and returns its value.
func IsFunction ¶ added in v0.22.0
func IsMemberAccessNode ¶ added in v0.22.0
func IsStaticExpectMatcher ¶ added in v0.22.0
IsStaticExpectMatcher reports static expect APIs such as expect.any(...) or expect.not.stringContaining(...), but not assertion matchers like toBe.
func IsTypeOfJestFnCall ¶
func IsTypeOfJestFnCall(node *ast.Node, ctx rule.RuleContext, kinds ...JestFnType) bool
func JestFnMemberEntriesRange ¶ added in v0.22.0
func JestFnMemberEntriesRange(entries []ParsedJestFnMemberEntry) (core.TextRange, bool)
JestFnMemberEntriesRange returns the source range spanning the first through last member entry nodes in a parsed jest/expect call chain.
func JestHookOrderIndex ¶ added in v0.22.0
JestHookOrderIndex returns the expected declaration order index for a Jest hook name, or -1 if unknown.
func JestVersionMajor ¶ added in v0.22.0
JestVersionMajor extracts the major version number from an npm version or range (e.g. "^29.0.0", "~27.1.0"). It returns 29 when the version cannot be parsed, matching the historical default of Jest 29.
func JoinJestFnMemberEntries ¶ added in v0.22.0
func JoinJestFnMemberEntries(entries []ParsedJestFnMemberEntry) string
func ReceiverBeforeInvocation ¶ added in v0.22.0
ReceiverBeforeInvocation returns the expression before .m() or ["m"]() on a call, such as `expect(x).not` before `.toBe()`.
func ResolveFirstIdentifier ¶ added in v0.22.0
ResolveFirstIdentifier walks the left side of a call/member chain and returns the first identifier it finds, if any.
func ResolveNamedFunctionCallback ¶ added in v0.22.0
func ResolveNamedFunctionCallback(ctx rule.RuleContext, callExpr *ast.CallExpression) (*ast.Node, string)
ResolveNamedFunctionCallback returns the function declaration node and name when a Jest test call uses a named function reference as its callback (e.g. it('foo', getValue)).
func UnwrapBasicTypeAssertions ¶ added in v0.22.0
Types ¶
type JestFnType ¶
type JestFnType string
const ( JestFnTypeExpect JestFnType = "expect" JestFnTypeDescribe JestFnType = "describe" JestFnTypeHook JestFnType = "hook" JestFnTypeJest JestFnType = "jest" JestFnTypeTest JestFnType = "test" JestFnTypeUnknown JestFnType = "unknown" )
func GetJestKind ¶
func GetJestKind(name string) JestFnType
type JestImportMode ¶
type JestImportMode string
const ( JEST_GLOBAL_MODE JestImportMode = "global" JEST_IMPORT_MODE JestImportMode = "import" )
func ResolveJestFunctionReference ¶ added in v0.22.0
type ParsedJestFnCall ¶
type ParsedJestFnCall struct {
Name string
LocalName string
Kind JestFnType
Members []string
MemberEntries []ParsedJestFnMemberEntry
Modifiers []string
ModifierEntries []ParsedJestFnMemberEntry
Matcher string
MatcherEntry *ParsedJestFnMemberEntry
Head ParsedJestFnCallHead
}
func ParseJestFnCall ¶
func ParseJestFnCall(node *ast.Node, ctx rule.RuleContext) *ParsedJestFnCall
type ParsedJestFnCallHead ¶
type ParsedJestFnCallHead struct {
Type JestImportMode
Local ParsedJestFnCallHeadEntry
Original ParsedJestFnCallHeadEntry
}
type ParsedJestFnMemberEntry ¶
func GetJestFnMemberEntries ¶
func GetJestFnMemberEntries(node *ast.Node) []ParsedJestFnMemberEntry
type TestCallbackInfo ¶ added in v0.22.0
TestCallbackInfo describes a Jest test callback passed by reference (e.g. it('foo', getValue)).
func ResolveTestCallbackFunction ¶ added in v0.22.0
func ResolveTestCallbackFunction(ctx rule.RuleContext, callExpr *ast.CallExpression) TestCallbackInfo
ResolveTestCallbackFunction resolves the callback function node for a Jest test call. Inline callbacks are not returned; they are tracked via the enclosing test call.