goimmutablelint
goimmutablelint
is a static analysis tool for Go that helps enforce immutability in function parameters. It detects and reports instances where function parameters are modified, which can lead to unexpected behavior and make code harder to reason about.
Features
- Detects modifications of function parameters
- Supports whitelist mode to only check specified functions
- Concurrent analysis for improved performance
- Outputs results in JSON format for easy integration with other tools
Installation
To install goimmutablelint
, use the following command:
go get -u github.com/upamune/goimmutablelint
Usage
Run goimmutablelint
on your Go packages:
goimmutablelint [flags] <package patterns...>
Flags
-v
: Enable verbose output
-j <n>
: Set the number of concurrent workers (default is the number of CPUs)
-w
: Enable whitelist mode (only check functions with goimmutablelint:check
comment)
-h
: Show help message
Examples
Check all packages in the current directory and subdirectories:
goimmutablelint ./...
Check specific packages with verbose output:
goimmutablelint -v github.com/upamune/project/pkg1 github.com/upamune/project/pkg2
Use whitelist mode with 4 workers:
goimmutablelint -w -j 4 ./...
Whitelist Mode
In whitelist mode, only functions with the goimmutablelint:check
comment will be checked. To mark a function for checking in whitelist mode, add the following comment above the function:
// goimmutablelint:check
func myFunction(param *int) {
// This function will be checked in whitelist mode
}
Output
goimmutablelint
outputs results in JSON format. Each issue includes the following information:
- File name
- Line and column numbers
- Function name
- Description of the issue
Contributing
Contributions to goimmutablelint
are welcome! Please follow these steps:
- Fork the repository
- Create a new branch for your feature or bug fix
- Write tests for your changes
- Implement your changes
- Run tests and ensure they pass
- Submit a pull request
Please make sure to update tests as appropriate and adhere to the existing coding style.
License
MIT License
If you have any questions or feedback, please open an issue on the GitHub repository.