linter

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

README

JSONSchema Linter

This linter helps detect and prevent a common issue with Go struct tags in this project.

The Problem

In Go struct tags using jsonschema, commas in the description field need to be escaped using \\, syntax. If commas aren't properly escaped, the description is silently truncated at the comma.

For example:

// Problematic (description will be truncated at the first comma):
type Example struct {
    Field string `jsonschema:"description=This is a description, but it will be truncated here"`
}

// Correct (commas properly escaped):
type Example struct {
    Field string `jsonschema:"description=This is a description\\, and it will be fully included"`
}

Usage

You can use this linter by running:

make lint-jsonschema

or directly:

go run ./cmd/linters/jsonschema --path .
Auto-fixing issues

The linter can automatically fix unescaped commas in jsonschema descriptions by running:

make lint-jsonschema-fix

or directly:

go run ./cmd/linters/jsonschema --path . --fix

This will scan the codebase for unescaped commas and automatically escape them, then report what was fixed.

Flags

  • --path: Base directory to scan for Go files (default: ".")
  • --fix: Automatically fix unescaped commas
  • --help: Display help information

Integration

This linter is integrated into the default make lint command, ensuring all PRs are checked for this issue.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JSONSchemaError

type JSONSchemaError struct {
	FilePath string
	Line     int
	Column   int
	Offset   int // Byte offset in the file
	Struct   string
	Field    string
	Tag      string
	FixedTag string
}

JSONSchemaError represents a linting error with file position details

type JSONSchemaLinter

type JSONSchemaLinter struct {
	FilePaths []string
	Errors    []JSONSchemaError
	FixMode   bool
	Fixed     map[string]bool
}

JSONSchemaLinter checks for unescaped commas in jsonschema struct tags

func (*JSONSchemaLinter) FindUnescapedCommas

func (l *JSONSchemaLinter) FindUnescapedCommas(baseDir string) error

FindUnescapedCommas scans Go files for jsonschema struct tags with unescaped commas in descriptions

func (*JSONSchemaLinter) PrintErrors

func (l *JSONSchemaLinter) PrintErrors()

PrintErrors outputs all the found errors

Jump to

Keyboard shortcuts

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