POC: automated linting of nixpkgs with rules files #427098
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
In this POC I'm exploring how we could convert linting rules from documentation to code.
There is prior art such as nixpkgs-vet, nixpkgs-hammer, etc... The difference here is that the rules would live in rule files, sitting in nixpkgs. By having them here, it makes it easy to understand, discuss and evolve them alongside the code.
ast-grep is a tool that allows doing just that for any language that can be parsed with tree-sitter. That means we can also use it to set rules for accompanying Bash and Python scripts. Another nice thing is the support for auto-fixing rules, if the rule author can express the fix automatically.
In this POC I just put down the base structure to demonstrate the capabilities. Something production-ready would also integrate with the CI, linting only the changed files, and post comments for errors it encounters.
Before moving further, I'd like to get some feedback. I am not aware of all the ongoing plans and how this would fit in the big picture. /cc @NixOS/nixpkgs-ci team and also @SuperSandro2000 that cares about linting a lot.
Things done
passthru.tests
.nixpkgs-review
on this PR. See nixpkgs-review usage../result/bin/
.Add a 👍 reaction to pull requests you find important.