Skip to content

feat: add nixf-tidy and statix linters for comprehensive Nix code quality#66

Open
lessuselesss wants to merge 3 commits into
nizos:mainfrom
lessuselesss:feat/statix-linter-integration
Open

feat: add nixf-tidy and statix linters for comprehensive Nix code quality#66
lessuselesss wants to merge 3 commits into
nizos:mainfrom
lessuselesss:feat/statix-linter-integration

Conversation

@lessuselesss

Copy link
Copy Markdown

Summary

  • Add Statix linter for Nix anti-pattern detection with JSON output support
  • Add NixfTidy linter for semantic analysis (duplicate keys, unused variables)
  • Extend linter schemas with StatixReport and NixfDiagnostic types
  • Update LinterProvider to support 'statix' and 'nixf-tidy' linter types
  • Add comprehensive test coverage for both new linters
  • Update documentation with Statix configuration examples and usage

Features Added

Statix Linter

  • Anti-pattern detection for Nix files
  • JSON output parsing with proper error handling
  • Configurable via LINTER_TYPE=statix
  • Supports custom config files via statix.toml

NixfTidy Linter

  • Semantic analysis using nixf-tidy from nix-community/nixd
  • Detects duplicate attribute names, unused variables, and other semantic issues
  • Precise line/column positioning (converts from nixf's 0-based to 1-based)
  • Configurable via LINTER_TYPE=nixf-tidy
  • Supports variable lookup analysis with --variable-lookup flag

Complementary Analysis

These linters provide complementary Nix code quality checking:

  • statix: Style linting and anti-patterns
  • nixf-tidy: Semantic analysis with precise positioning
  • Together: Comprehensive Nix code quality enforcement

Test Coverage

  • Full test suites for both linters covering success/error scenarios
  • Mock-based testing for process spawning and file I/O
  • Severity conversion and message formatting validation
  • Multi-file processing and error handling tests

Documentation

  • Updated linting.md with Nix linter configuration examples
  • Added troubleshooting sections for both linters
  • Updated README.md to reflect new linter support

Test plan

  • Unit tests pass for new linters
  • Integration tests pass
  • Documentation is accurate
  • No TODO comments remain in code
  • Both linters work with real Nix files

🤖 Generated with Claude Code

wcygan and others added 3 commits September 13, 2025 06:26
- Fix local variable usage outside functions
- Remove unused variables to pass shellcheck
- Improve ANSI color removal with proper sed usage
- Rebuild Nix package with clean shellcheck validation

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…lity

- Add Statix linter for Nix anti-pattern detection with JSON output support
- Add NixfTidy linter for semantic analysis (duplicate keys, unused variables)
- Extend linter schemas with StatixReport and NixfDiagnostic types
- Update LinterProvider to support 'statix' and 'nixf-tidy' linter types
- Add comprehensive test coverage for both new linters
- Update documentation with Statix configuration examples and usage

This provides complementary Nix linting capabilities:
- statix: Style linting and anti-patterns
- nixf-tidy: Semantic analysis with precise line/column positioning

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Replace TODO with explanatory comment about statix character positions
- Document that statix only provides character offsets, not line numbers
- Clarify fallback behavior for line positioning

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@nizos

nizos commented Sep 16, 2025

Copy link
Copy Markdown
Owner

Hi @lessuselesss!

Thanks for the PRs! I will take a look at them tomorrow, got a lot at work at the moment. :)

@nizos

nizos commented Nov 16, 2025

Copy link
Copy Markdown
Owner

I realize that I have dropped the ball on this. I apologize for this, got swarmed with work for a while. I'll take a look at it :)

@nizos

nizos commented Apr 22, 2026

Copy link
Copy Markdown
Owner

Hi @lessuselesss,

Another apology for the delay here. Same situation as #65, I should have gotten to this much sooner.

This one builds on #65's branch, so most of the structural feedback from there applies here too. Once #65 is sorted, the rebase on this one will be a lot simpler.

For the linter-specific changes, a few things worth addressing before a proper review:

  • NixfTidy.ts has a hardcoded /nix/store/... path that is specific to your machine, the linter can't actually run for anyone else. It has to be resolved from PATH or similar.
  • Statix.ts reports line: 1 for every issue and passes a character offset as column, which produces misleading output like Line 1:1247. Worth computing the real line/column from the offset, or parsing statix's non-JSON output instead.
  • The existing linters extract process invocation into a file and inject via constructor, this lets tests work without mocking. It'd be nice to align with that pattern here.
  • LINTER_TYPE values: Having to pick between nixf-tidy and statix makes it impossible to run both. This is worth revisiting and discussing a strategy for.
  • NixfTidy seems to swallow errors if nix fails.

Happy to discuss any of these, especially the one-or-two linter types question. :)

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.

3 participants