modulepackage
0.0.6
Repository: https://github.com/ethanthatonekid/difflint.git
Documentation: pkg.go.dev
# README
difflint
š Git-based linter tool that scans code changes for compliance with defined rules in source code.
Installation
go get -u github.com/EthanThatOneKid/difflint
Usage
difflint --help
Single file
# File: ./main.py
#LINT.IF
print("Edit me first!")
#LINT.END bar
#LINT.IF :bar
print("Edit me second!")
#LINT.END
Multiple files
# File ./foo.py
#LINT.IF
print("Edit me first!")
#LINT.END bar
# File: ./main.py
#LINT.IF ./foo.py:bar
print("Edit me second!")
#LINT.END
Exhaustive switch statement
In programming languages lacking a comprehensive match statement for enumerations, our only option is to verify whether the switch statement aligns with the enumerated type.
//LINT.IF
enum Thing {
ONE = 1,
TWO = 2,
}
//LINT.END :thing_enum
//LINT.IF :thing_enum
switch (thing) {
case Thing.ONE: {
return doThingOne();
}
case Thing.TWO: {
return doThingTwo();
}
}
//LINT.END
Custom file extensions
git diff | difflint --ext_map="difflint.json"
difflint.json
{
"yaml": ["#LINT.?"]
}
Development
Run the tool from source with the Go toolchain:
go run cli/main.go --help
Created with š by @EthanThatOneKid
# Packages
No description provided by the author
# Functions
Check returns the list of unsatisfied rules for the given map of rules.
Do is the difflint command's entrypoint.
Include determines if a given diff should be included in the linting process.
Intersects returns true if the given ranges intersect.
Lint lints the given hunks against the given rules and returns the result.
NewExtMap returns a new ExtMap instance.
ParseHunks parses the input diff and returns the extracted file paths along with associated line number ranges.
RulesMapFromHunks parses rules from the given hunks by file name and returns the map of rules and the set of all the target keys that are present.
TargetKey returns the key for the given target.
Walk walks the file tree rooted at root, calling callback for each file or directory in the tree, including root.
# Variables
DefaultFileExtMap is the default map of file extensions to directive templates.
DefaultTemplates is the default list of directive templates.
# Structs
ExtMap represents the extensions and templates for a linting operation.
Hunk represents a diff hunk that must be present in the diff.
LintOptions represents the options for a linting operation.
Result of a linting operation.
Range represents a range of line numbers.
A rule says that file or range of code must be present in the diff if another range is present.
Target represents a file or range of code that must be present in the diff if a diff hunk is present.
UnsatisfiedRule represents a rule that is not satisfied.
# Type aliases
ExtFileJSON is a JSON representation of a file extension to directive template map.
UnsatisfiedRules is a list of unsatisfied rules.