Skip to content

Add Justfile Validation#447

Draft
kehoecj wants to merge 16 commits intomainfrom
feat/justfile-support
Draft

Add Justfile Validation#447
kehoecj wants to merge 16 commits intomainfrom
feat/justfile-support

Conversation

@kehoecj
Copy link
Copy Markdown
Collaborator

@kehoecj kehoecj commented Apr 15, 2026

Implements the Justfile part of #347 and #301 using a custom go-just project (to be released shortly)

kehoecj added 16 commits April 10, 2026 13:35
- Refactor CLI struct to use unexported fields with With* options
- Embed SchemaStore catalog with remote fetching and local caching (24h TTL)
- Add --schemastore (bool) and --schemastore-path (string) flags
- Add .cfv.toml config file support with schema validation
- Add --config and --no-config flags
- Add JSONC file type support using hujson
- Add .tf and .tfvars extensions to HCL
- Add JSONC note on failed JSON files that are valid JSONC
- Add stdin support via - search path with --file-types
- Add exit code granularity (0=clean, 1=validation errors, 2=runtime errors)
- Add pre-commit hook support (.pre-commit-hooks.yaml)
- Add context.Context with timeout to schema fetching
- Rename schemastore Lookup to Resolve
- Remove configfile dependency on validator package
- Deduplicate isGlobPattern into tools.IsGlobPattern
- Extract resolveConfig/buildCLI in cmd/validator
- Extract Go API docs to docs/go-api.md
- Add Notes field to Report for non-error supplementary info
- Fix --depth=0 with trailing slash on search path
- Update README with TOC, JSON vs JSONC section, stronger About
- Update release workflow to refresh SchemaStore catalog

BREAKING: --schemastore is now a boolean flag (was string path).
Use --schemastore-path for local clones.
BREAKING: schemastore.Lookup renamed to schemastore.Resolve.
BREAKING: CLI struct fields are now unexported (use With* options).
- Update PKGBUILD to 2.2.0
- Update CHANGELOG from Unreleased to 2.2.0
- Add httptest-based tests for schema fetch/cache (200, 404, 500, network error, cache hit, unwritable dir)
- Add txtar tests for config file keys, stdin, and JSONC features
- Add unit tests for SchemaErrors, JSONC edge cases, stdin with quiet
- Fix config file depth not applying via flagSet.Set
- Coverage: 87.3% -> 92.8% (schemastore: 82.5% -> 91.3%, cmd/validator: 79.3% -> 96.9%)
- Add [validators.csv] section to .cfv.toml for CSV-specific options
  - delimiter: field delimiter character (default comma, supports \t for tab)
  - comment: comment character for skipping lines
  - lazy-quotes: allow quotes in unquoted fields
- CsvValidator struct now accepts Delimiter, Comment, LazyQuotes fields
  (zero values preserve existing behavior)
- ValidatorOptions/CSVOptions structs in configfile package
- applyValidatorOptions creates a copy of file types with configured validators
- Schema validates validator options (unknown keys caught immediately)
- Pattern extends to other validators by adding new option structs
- Updated README and index.md with validator options documentation
- Add forbid-duplicate-keys option for JSON validator (walks token stream)
- Add forbid-duplicate-keys option for INI validator (uses go-ini shadows)
- YAML already rejects duplicate keys via yaml.v3 (documented, no option needed)
- Default: false for both (preserves current behavior)
- Config via .cfv.toml [validators.json] and [validators.ini] sections
- Schema validates all validator options
- Updated README and index.md with full validator options table
- Fix go:generate directive: ../../ not ../../../ (pkg/filetype is 2 levels deep)
- Fix generator output path: write to current directory since go generate runs from package dir
- Use context-aware HTTP request (noctx)
- Use slices.Sort instead of sort.Strings (revive)
- Use fmt.Fprintf instead of WriteString(Sprintf) (staticcheck)
- Use 0600 file permissions (gosec)
- Add //go:build ignore to generator (build tool, not runtime code)
- Point go:generate at main.go file directly (required with build tag)
- Coverage: 89.3% → 93.0%
…go doc comment

- Add Known Files section to README documenting automatic Linguist detection
- Update JSON vs JSONC section: tsconfig.json etc. are now auto-detected
- Document JSON/JSONC family behavior for --file-types and --exclude-file-types
- Note that --exclude-file-types doesn't affect extensionless known files
- Add package doc comment to file_type.go explaining the KnownFiles data flow
- Sync index.md with README.md
Move position formatting (line/column) out of individual validators
and into the CLI's formatErrors function, which is now the single
source of truth for error display format.

Before: each validator embedded position differently in error strings,
causing inconsistent output like:
  - "error at line 3 column 5: invalid character..."
  - "yaml: line 4: did not find expected..."
  - ":1,35-36: Unclosed configuration block; There is no..."

After: all errors follow a consistent pattern:
  - "syntax: line N, column N: message" (when both known)
  - "syntax: line N: message" (when only line known)
  - "syntax: message" (when no position available)
  - "schema: message" (for schema errors)

Validators now store clean descriptions in ValidationError.Err
without position prefixes. The position is carried separately
in ValidationError.Line and ValidationError.Column fields.

Files changed:
- pkg/cli/cli.go: formatErrors now accepts line/col and formats
  position consistently
- pkg/validator/{json,jsonc,toml,hcl,env}.go: removed redundant
  "error at line X column Y" prefixes from error wrapping
- pkg/validator/{yaml,xml,hocon,plist,toon}.go: strip position
  from library error strings to avoid duplication
Schema validation errors now include source positions, pointing to the
exact line and column of the offending key in the original file.

For JSON, a position map is built by tokenizing the source with
encoding/json.Decoder and tracking byte offsets for each key path.
For YAML, the yaml.v3 Node API provides line/column on every node.

The gojsonschema library reports errors with JSON paths like
"(root).server.port". These paths are looked up in the position map
to annotate each error with its source location.

Changes:
- SchemaErrors gains a Positions field (parallel to Items)
- New SourcePosition type and JSONSchemaValidateWithPositions function
- buildJSONPositionMap: tokenizes JSON and maps context paths to positions
- buildYAMLPositionMap/walkYAMLNode: walks yaml.v3 Node tree for positions
- Report gains ErrorLines/ErrorColumns (parallel to ValidationErrors)
- SARIF reporter uses per-error positions instead of file-level position
- formatErrors formats schema errors with consistent line/column prefix

Output before:
  error: schema: version: Invalid type. Expected: string, given: integer

Output after:
  error: schema: line 3, column 3: version: Invalid type. Expected: string, given: integer
Add support for validating Justfiles using the go-just library.
Both syntax errors (unterminated strings, invalid tokens) and
semantic errors (undefined recipes, undefined variables, circular
dependencies) are reported with line/column positions.

New files:
- pkg/validator/justfile.go: JustfileValidator wrapping go-just
- Registered as 'justfile' file type with .just extension
- Known files: justfile, Justfile, .justfile

NOTE: go.mod uses a local replace directive for github.com/Boeing/go-just.
This must be updated to a published version before merging.
# Conflicts:
#	go.mod
#	pkg/cli/cli.go
#	pkg/cli/cli_test.go
#	pkg/filetype/file_type.go
#	pkg/validator/jsonc.go
#	pkg/validator/validator_test.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant