goimmutablelint

module
v0.0.0-...-9025ec3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2024 License: MIT

README

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:

  1. Fork the repository
  2. Create a new branch for your feature or bug fix
  3. Write tests for your changes
  4. Implement your changes
  5. Run tests and ensure they pass
  6. Submit a pull request

Please make sure to update tests as appropriate and adhere to the existing coding style.

License

MIT License

Contact

If you have any questions or feedback, please open an issue on the GitHub repository.

Directories

Path Synopsis
cmd
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL