utils

package
v0.5.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultJestVersion = "29.0.0"

DefaultJestVersion is used when the Jest version cannot be resolved from settings or package.json.

Variables

View Source
var EQUALITY_METHOD_NAMES = map[string]bool{
	"toBe":          true,
	"toEqual":       true,
	"toStrictEqual": true,
}
View Source
var EXPECT_MODIFIER_NAMES = map[string]bool{
	"not":      true,
	"rejects":  true,
	"resolves": true,
}
View Source
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,
}
View Source
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.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.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.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.5.3

func ApplyGlobalJestAlias(name string, settings map[string]interface{}) string

ApplyGlobalJestAlias maps settings.jest.globalAliases so that e.g. `context` is treated as `describe`, matching eslint-plugin-jest.

func FindImportDeclaration added in v0.4.0

func FindImportDeclaration(node *ast.Node) *ast.ImportDeclaration

func GetJestVersion added in v0.5.2

func GetJestVersion(ctx rule.RuleContext) string

GetJestVersion returns the effective Jest version: explicit settings, then the nearest package.json, then DefaultJestVersion.

func IsTypeOfJestFnCall

func IsTypeOfJestFnCall(node *ast.Node, ctx rule.RuleContext, kinds ...JestFnType) bool

func JestVersionMajor added in v0.5.2

func JestVersionMajor(v string) int

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.

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 added in v0.4.0

type JestImportMode string
const (
	JEST_GLOBAL_MODE JestImportMode = "global"
	JEST_IMPORT_MODE JestImportMode = "import"
)

type ParsedJestFnCall

type ParsedJestFnCall struct {
	Name            string
	LocalName       string
	Kind            JestFnType
	Members         []string
	MemberEntries   []ParsedJestFnMemberEntry
	Modifiers       []string
	ModifierEntries []ParsedJestFnMemberEntry
	Head            ParsedJestFnCallHead
}

func ParseJestFnCall

func ParseJestFnCall(node *ast.Node, ctx rule.RuleContext) *ParsedJestFnCall

type ParsedJestFnCallHead added in v0.4.0

type ParsedJestFnCallHead struct {
	Type     JestImportMode
	Local    ParsedJestFnCallHeadEntry
	Original ParsedJestFnCallHeadEntry
}

type ParsedJestFnCallHeadEntry added in v0.4.0

type ParsedJestFnCallHeadEntry struct {
	Value string
	Node  *ast.Node
}

type ParsedJestFnMemberEntry added in v0.4.0

type ParsedJestFnMemberEntry struct {
	Name string
	Node *ast.Node
}

func GetJestFnMemberEntries added in v0.4.0

func GetJestFnMemberEntries(node *ast.Node) []ParsedJestFnMemberEntry

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL