linter

package
v1.1.7 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

README

GraphQL Linter Tests

This directory contains comprehensive tests for the main linter functionality.

Test Coverage

The test suite covers all major linter components:

Core Functionality Tests
  • TestNew - Tests linter initialization and rule loading
  • TestGetAvailableRules - Tests rule discovery and listing
  • TestSetRules - Tests rule filtering and enablement
File Processing Tests
  • TestParseSchemaFile - Tests GraphQL schema parsing
    • Valid schema parsing
    • Error handling for non-existent files
    • Error handling for malformed schemas
  • TestLintFile - Tests complete linting workflow
    • Valid schema linting
    • Invalid schema error detection
    • Rule filtering functionality
    • Error handling
Plugin System Tests
  • TestLoadCustomRules - Tests custom rule loading
    • Non-existent directory handling
    • Empty directory handling
    • Non-plugin file handling
  • TestLoadPlugin - Tests individual plugin loading
    • Non-existent plugin handling
    • Invalid plugin file handling
Integration Tests
  • TestLinterIntegration - End-to-end testing with real schemas
    • Multiple rule execution
    • Error aggregation
    • Rule interaction verification
Performance Tests
  • BenchmarkLintFile - Performance testing for complete linting
  • BenchmarkParseSchemaFile - Performance testing for schema parsing

Running Tests

Run all tests
go test -v
Run tests with coverage
go test -cover -v
Run benchmarks
go test -bench=. -benchmem
Run from project root
go test ./pkg/linter -v

Test Schemas

The tests use three predefined schemas:

validSchema

A well-formed schema with proper descriptions and naming conventions.

invalidSchema

A schema with intentional violations:

  • Missing type descriptions
  • Missing field descriptions
  • Query field prefixes (e.g., getUser)
malformedSchema

A schema with syntax errors for testing parser error handling.

Helper Functions

  • createTempSchemaFile(t, content) - Creates temporary GraphQL files for testing
  • Error checking helpers - Validate specific error types and messages

Test Results

Recent test run shows:

  • ✅ All 8 test functions pass
  • ✅ 15 sub-tests pass
  • ✅ Integration test detects 47 violations across 6 rules
  • ✅ Benchmarks show good performance:
    • LintFile: ~180μs per operation
    • ParseSchemaFile: ~95μs per operation

Coverage Areas

The tests provide comprehensive coverage for:

  • Linter initialization and configuration
  • Schema file parsing and validation
  • Rule execution and filtering
  • Custom plugin loading
  • Error handling and edge cases
  • Performance characteristics
  • Integration with all 20 built-in rules

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Linter

type Linter struct {
	// contains filtered or unexported fields
}

Linter provides GraphQL schema linting functionality

func New

func New() *Linter

New creates a new linter instance with all built-in rules

func (*Linter) GetAvailableRules

func (l *Linter) GetAvailableRules() []string

GetAvailableRules returns all available rule names

func (*Linter) LintFile

func (l *Linter) LintFile(filename string) ([]types.LintError, error)

LintFile lints a single GraphQL schema file

func (*Linter) LoadCustomRules

func (l *Linter) LoadCustomRules(customRulesDir string) error

LoadCustomRules loads custom rules from a directory containing Go plugins

func (*Linter) SetRules

func (l *Linter) SetRules(ruleNames []string)

SetRules enables only the specified rules

Jump to

Keyboard shortcuts

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