rule_tester

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunRuleTester

func RunRuleTester(rootDir string, tsconfigPath string, t *testing.T, r *rule.Rule, validTestCases []ValidTestCase, invalidTestCases []InvalidTestCase)

func RunRuleTesterFromESLintJSON added in v0.1.14

func RunRuleTesterFromESLintJSON(rootDir string, tsconfigPath string, testFilePath string, t *testing.T, r *rule.Rule) error

RunRuleTesterFromESLintJSON loads and runs ESLint-format tests from a JSON file

func RunRuleTesterFromJSON added in v0.1.14

func RunRuleTesterFromJSON(rootDir string, tsconfigPath string, testFilePath string, t *testing.T, r *rule.Rule) error

RunRuleTesterFromJSON loads and runs tests from a JSON file

Types

type BatchTestBuilder added in v0.1.14

type BatchTestBuilder struct {
	Valid   []ValidTestCase
	Invalid []InvalidTestCase
}

BatchTestBuilder helps build large test suites programmatically

func NewBatchTestBuilder added in v0.1.14

func NewBatchTestBuilder() *BatchTestBuilder

NewBatchTestBuilder creates a new BatchTestBuilder

func (*BatchTestBuilder) AddInvalid added in v0.1.14

func (b *BatchTestBuilder) AddInvalid(code string, messageId string, line int, column int, output string) *BatchTestBuilder

AddInvalid adds an invalid test case

func (*BatchTestBuilder) AddInvalidWithErrors added in v0.1.14

func (b *BatchTestBuilder) AddInvalidWithErrors(code string, errors []InvalidTestCaseError, output string) *BatchTestBuilder

AddInvalidWithErrors adds an invalid test case with multiple errors

func (*BatchTestBuilder) AddInvalidWithOptions added in v0.1.14

func (b *BatchTestBuilder) AddInvalidWithOptions(code string, messageId string, line int, column int, output string, options any) *BatchTestBuilder

AddInvalidWithOptions adds an invalid test case with options

func (*BatchTestBuilder) AddValid added in v0.1.14

func (b *BatchTestBuilder) AddValid(code string) *BatchTestBuilder

AddValid adds a valid test case

func (*BatchTestBuilder) AddValidWithFileName added in v0.1.14

func (b *BatchTestBuilder) AddValidWithFileName(code string, fileName string) *BatchTestBuilder

AddValidWithFileName adds a valid test case with a specific filename

func (*BatchTestBuilder) AddValidWithOptions added in v0.1.14

func (b *BatchTestBuilder) AddValidWithOptions(code string, options any) *BatchTestBuilder

AddValidWithOptions adds a valid test case with options

func (*BatchTestBuilder) Build added in v0.1.14

Build returns the built test cases

func (*BatchTestBuilder) GetSuite added in v0.1.14

func (b *BatchTestBuilder) GetSuite() *TestSuite

GetSuite returns a TestSuite

type CommonFixtures added in v0.1.14

type CommonFixtures struct{}

CommonFixtures provides common test code patterns

func NewCommonFixtures added in v0.1.14

func NewCommonFixtures() *CommonFixtures

NewCommonFixtures creates a new CommonFixtures instance

func (*CommonFixtures) ArrowFunction added in v0.1.14

func (f *CommonFixtures) ArrowFunction(params string, returnType string, body string) string

ArrowFunction generates an arrow function

func (*CommonFixtures) Class added in v0.1.14

func (f *CommonFixtures) Class(name string, body string) string

Class generates a class declaration

func (*CommonFixtures) Const added in v0.1.14

func (f *CommonFixtures) Const(name string, type_ string, value string) string

Const generates a const declaration

func (*CommonFixtures) Enum added in v0.1.14

func (f *CommonFixtures) Enum(name string, members string) string

Enum generates an enum declaration

func (*CommonFixtures) Export added in v0.1.14

func (f *CommonFixtures) Export(what string) string

Export generates an export statement

func (*CommonFixtures) Function added in v0.1.14

func (f *CommonFixtures) Function(name string, params string, returnType string, body string) string

Function generates a function declaration

func (*CommonFixtures) Import added in v0.1.14

func (f *CommonFixtures) Import(specifiers string, from string) string

Import generates an import statement

func (*CommonFixtures) Interface added in v0.1.14

func (f *CommonFixtures) Interface(name string, body string) string

Interface generates an interface declaration

func (*CommonFixtures) Let added in v0.1.14

func (f *CommonFixtures) Let(name string, type_ string, value string) string

Let generates a let declaration

func (*CommonFixtures) Method added in v0.1.14

func (f *CommonFixtures) Method(name string, params string, returnType string, body string) string

Method generates a method declaration

func (*CommonFixtures) Module added in v0.1.14

func (f *CommonFixtures) Module(name string, body string) string

Module generates a module declaration

func (*CommonFixtures) Namespace added in v0.1.14

func (f *CommonFixtures) Namespace(name string, body string) string

Namespace generates a namespace declaration

func (*CommonFixtures) Property added in v0.1.14

func (f *CommonFixtures) Property(name string, type_ string, value string) string

Property generates a property declaration

func (*CommonFixtures) Type added in v0.1.14

func (f *CommonFixtures) Type(name string, definition string) string

Type generates a type alias

func (*CommonFixtures) Var added in v0.1.14

func (f *CommonFixtures) Var(name string, type_ string, value string) string

Var generates a var declaration

type DiagnosticAssertion added in v0.1.14

type DiagnosticAssertion struct{}

DiagnosticAssertion provides utilities for asserting diagnostic properties

func NewDiagnosticAssertion added in v0.1.14

func NewDiagnosticAssertion() *DiagnosticAssertion

NewDiagnosticAssertion creates a new DiagnosticAssertion

func (*DiagnosticAssertion) FormatDiagnosticError added in v0.1.14

func (a *DiagnosticAssertion) FormatDiagnosticError(messageId string, line int, column int, endLine int, endColumn int) InvalidTestCaseError

FormatDiagnosticError formats a diagnostic error for testing output

func (*DiagnosticAssertion) FormatDiagnosticErrorWithSuggestions added in v0.1.14

func (a *DiagnosticAssertion) FormatDiagnosticErrorWithSuggestions(messageId string, line int, column int, suggestions []InvalidTestCaseSuggestion) InvalidTestCaseError

FormatDiagnosticErrorWithSuggestions formats a diagnostic error with suggestions

type ESLintError added in v0.1.14

type ESLintError struct {
	Message     string             `json:"message,omitempty"`
	MessageId   string             `json:"messageId,omitempty"`
	Type        string             `json:"type,omitempty"`
	Line        int                `json:"line,omitempty"`
	Column      int                `json:"column,omitempty"`
	EndLine     int                `json:"endLine,omitempty"`
	EndColumn   int                `json:"endColumn,omitempty"`
	Suggestions []ESLintSuggestion `json:"suggestions,omitempty"`
}

ESLintError represents an error in ESLint format

type ESLintInvalidTestCase added in v0.1.14

type ESLintInvalidTestCase struct {
	ESLintTestCase
	Output      string             `json:"output,omitempty"`
	Errors      []ESLintError      `json:"errors"`
	Suggestions []ESLintSuggestion `json:"suggestions,omitempty"`
}

ESLintInvalidTestCase represents invalid test cases from ESLint format

type ESLintSuggestion added in v0.1.14

type ESLintSuggestion struct {
	MessageId string `json:"messageId,omitempty"`
	Desc      string `json:"desc,omitempty"`
	Output    string `json:"output,omitempty"`
}

ESLintSuggestion represents a suggestion in ESLint format

type ESLintTestCase added in v0.1.14

type ESLintTestCase struct {
	Code     string                 `json:"code"`
	Filename string                 `json:"filename,omitempty"`
	Options  []interface{}          `json:"options,omitempty"`
	Settings map[string]interface{} `json:"settings,omitempty"`
	Only     bool                   `json:"only,omitempty"`
	Skip     bool                   `json:"skip,omitempty"`
	Parser   string                 `json:"parser,omitempty"`
}

ESLintTestCase represents test cases from ESLint format

type ESLintTestSuite added in v0.1.14

type ESLintTestSuite struct {
	Valid   []ESLintTestCase        `json:"valid"`
	Invalid []ESLintInvalidTestCase `json:"invalid"`
}

ESLintTestSuite represents a complete ESLint test suite

func LoadESLintTestSuiteFromJSON added in v0.1.14

func LoadESLintTestSuiteFromJSON(filePath string) (*ESLintTestSuite, error)

LoadESLintTestSuiteFromJSON loads ESLint-format test cases from a JSON file

type InvalidTestCase

type InvalidTestCase struct {
	Code     string                 `json:"code"`
	FileName string                 `json:"fileName"`
	Only     bool                   `json:"only"`
	Skip     bool                   `json:"skip"`
	Output   []string               `json:"output"`
	Errors   []InvalidTestCaseError `json:"errors"`
	TSConfig string                 `json:"tsConfig"`
	Options  any                    `json:"options"`
	Tsx      bool                   `json:"tsx"`
}

func ConvertESLintInvalidTestCase added in v0.1.14

func ConvertESLintInvalidTestCase(tc ESLintInvalidTestCase) InvalidTestCase

ConvertESLintInvalidTestCase converts an ESLint invalid test case to our internal format

type InvalidTestCaseError

type InvalidTestCaseError struct {
	MessageId   string                      `json:"messageId"`
	Line        int                         `json:"line"`
	Column      int                         `json:"column"`
	EndLine     int                         `json:"endLine"`
	EndColumn   int                         `json:"endColumn"`
	Suggestions []InvalidTestCaseSuggestion `json:"suggestions"`
}

type InvalidTestCaseSuggestion

type InvalidTestCaseSuggestion struct {
	MessageId string `json:"messageId"`
	Output    string `json:"output"`
}

type ProgramHelper added in v0.1.14

type ProgramHelper struct {
	RootDir string
}

ProgramHelper provides utilities for creating TypeScript programs for testing

func NewProgramHelper added in v0.1.14

func NewProgramHelper(rootDir string) *ProgramHelper

NewProgramHelper creates a new ProgramHelper

func (*ProgramHelper) CreateTestProgram added in v0.1.14

func (h *ProgramHelper) CreateTestProgram(code string, fileName string, tsconfigPath string) (*compiler.Program, *ast.SourceFile, error)

CreateTestProgram creates a TypeScript program from source code

type TestHelpers added in v0.1.14

type TestHelpers struct {
	RootDir string
}

TestHelpers provides utility functions for rule testing

func NewTestHelpers added in v0.1.14

func NewTestHelpers(rootDir string) *TestHelpers

NewTestHelpers creates a new TestHelpers instance

type TestSuite added in v0.1.14

type TestSuite struct {
	Valid   []ValidTestCase   `json:"valid"`
	Invalid []InvalidTestCase `json:"invalid"`
}

TestSuite represents a complete test suite that can be loaded from JSON

func ConvertESLintTestSuite added in v0.1.14

func ConvertESLintTestSuite(suite *ESLintTestSuite) *TestSuite

ConvertESLintTestSuite converts an entire ESLint test suite to our internal format

func LoadTestSuiteFromJSON added in v0.1.14

func LoadTestSuiteFromJSON(filePath string) (*TestSuite, error)

LoadTestSuiteFromJSON loads test cases from a JSON file

type ValidTestCase

type ValidTestCase struct {
	Code     string `json:"code"`
	FileName string `json:"fileName"`
	Only     bool   `json:"only"`
	Skip     bool   `json:"skip"`
	Options  any    `json:"options"`
	TSConfig string `json:"tsConfig"`
	Tsx      bool   `json:"tsx"`
}

func ConvertESLintTestCase added in v0.1.14

func ConvertESLintTestCase(tc ESLintTestCase) ValidTestCase

ConvertESLintTestCase converts an ESLint test case to our internal format

Jump to

Keyboard shortcuts

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