### Install NilAway Standalone Checker Source: https://context7.com/uber-go/nilaway/llms.txt Installs the standalone NilAway checker using Go's module system. Verify the installation by running `nilaway -help`. ```bash # Install the standalone NilAway checker go install go.uber.org/nilaway/cmd/nilaway@latest # Verify installation nilaway -help ``` -------------------------------- ### Install NilAway Binary Source: https://github.com/uber-go/nilaway/blob/main/README.md Install the NilAway standalone checker directly from the source repository. ```shell go install go.uber.org/nilaway/cmd/nilaway@latest ``` -------------------------------- ### Define Function Contracts Source: https://context7.com/uber-go/nilaway/llms.txt Specify input-output relationships using special comments to guide NilAway's nil tracking logic. ```go package example // contract(nonnil -> nonnil) // When the input parameter is nonnil, the return value is guaranteed nonnil func safeLookup(key *string) *Value { if key != nil { return &Value{Data: *key} } return nil } func useContract() { // With nonnil input, NilAway knows the result is nonnil key := "mykey" val := safeLookup(&key) print(val.Data) // Safe - contract guarantees nonnil return // With potentially nil input, result may be nil var maybeKey *string val2 := safeLookup(maybeKey) print(val2.Data) // ERROR: may be nil } // Contract value keywords: // - nonnil: Value must be non-nil // - true/false: Boolean values // - _: Any value (wildcard) // contract(nonnil, _ -> nonnil) // First param nonnil guarantees nonnil return, second param doesn't matter func lookupWithDefault(key *string, defaultVal *Value) *Value { if key != nil { if result := lookup(*key); result != nil { return result } } return defaultVal } // contract(true -> nonnil) // Boolean condition true guarantees nonnil return func conditionalCreate(shouldCreate bool) *Resource { if shouldCreate { return &Resource{} } return nil } ``` -------------------------------- ### Build and Run Custom GolangCI-Lint Source: https://context7.com/uber-go/nilaway/llms.txt Commands to build the custom binary and execute analysis. ```bash # Build custom golangci-lint binary with NilAway golangci-lint custom # Run the custom binary ./custom-gcl run ./... # Or with specific flags ./custom-gcl run --enable nilaway ./... ``` -------------------------------- ### Build and run custom golangci-lint binary Source: https://github.com/uber-go/nilaway/blob/main/README.md Commands to build the custom linter binary and execute it against the project. ```shell # Note that your `golangci-lint` to bootstrap the custom binary must also be version >= v1.57.0. $ golangci-lint custom ``` ```shell # Arguments are the same as `golangci-lint`. $ ./custom-gcl run ./... ``` -------------------------------- ### Run Unit and Coverage Tests Source: https://github.com/uber-go/nilaway/blob/main/AGENTS.md Execute unit tests for all modules using 'make test'. For tests with coverage reports, use 'make cover'. Integration tests require real drivers and can be run with 'make integration-test'. ```bash make test ``` ```bash make cover ``` ```bash make integration-test ``` -------------------------------- ### Basic NilAway Usage Source: https://context7.com/uber-go/nilaway/llms.txt Run NilAway on your Go project to detect potential nil panics. Use `include-pkgs` to focus analysis on your first-party code. ```bash # Basic usage - analyze current package nilaway ./... # Recommended: Analyze only first-party code by specifying package prefixes nilaway -include-pkgs="github.com/myorg/myproject" ./... # Analyze multiple package prefixes nilaway -include-pkgs="github.com/myorg/myproject,github.com/myorg/shared" ./... # Exclude specific packages from analysis nilaway -include-pkgs="github.com/myorg" -exclude-pkgs="github.com/myorg/vendor" ./... # Output errors in JSON format (disable pretty-print for parsing) nilaway -json -pretty-print=false -include-pkgs="github.com/myorg" ./... # Filter error reporting to specific files nilaway -include-pkgs="github.com/myorg" \ -include-errors-in-files="/path/to/mycode" \ -exclude-errors-in-files="/path/to/generated" ./... ``` -------------------------------- ### Run Unit and Coverage Tests Source: https://github.com/uber-go/nilaway/blob/main/CLAUDE.md Execute unit tests for all modules using 'make test'. For tests with coverage reports, use 'make cover'. ```bash make test ``` ```bash make cover ``` -------------------------------- ### Build NilAway Binary Source: https://github.com/uber-go/nilaway/blob/main/AGENTS.md Run this command to build the nilaway binary. The executable will be placed in the project's root directory under the 'bin/' folder. ```bash make build ``` -------------------------------- ### Run NilAway with Custom GolangCI-Lint Build Source: https://github.com/uber-go/nilaway/blob/main/AGENTS.md Build a custom golangci-lint binary that includes the NilAway plugin using 'golangci-lint custom'. Then, run this custom binary to analyze code with NilAway integrated. ```bash golangci-lint custom ``` ```bash ./custom-gcl run ./... ``` -------------------------------- ### Build NilAway Source: https://github.com/uber-go/nilaway/blob/main/docs/developing.md Compiles the NilAway binary into the project root's bin directory. ```bash make build # Build the nilaway binary to /bin/ ``` -------------------------------- ### Run NilAway Source: https://github.com/uber-go/nilaway/blob/main/docs/developing.md Instructions for running the NilAway binary in standalone mode or via golangci-lint. ```bash # Build nilaway in current codebase. make build # Standalone usage bin/nilaway -include-pkgs="" ./... # With JSON output (disable pretty-print) bin/nilaway -json -pretty-print=false -include-pkgs="" ./... # Using custom golangci-lint build golangci-lint custom # Build custom binary with NilAway plugin ./custom-gcl run ./... # Run custom golangci-lint with NilAway ``` -------------------------------- ### Run Bazel build with nogo Source: https://github.com/uber-go/nilaway/blob/main/README.md Execute the Bazel build process with nogo analysis enabled. ```bash $ bazel build --keep_going //... ``` -------------------------------- ### Run Bazel Analysis Source: https://context7.com/uber-go/nilaway/llms.txt Command to execute the build with analysis enabled. ```bash bazel build --keep_going //... ``` -------------------------------- ### Configure GolangCI-Lint Settings Source: https://context7.com/uber-go/nilaway/llms.txt Enable NilAway and define package inclusion/exclusion rules in the golangci-lint configuration. ```yaml version: "2" linters: enable: - nilaway settings: custom: nilaway: type: module description: Static analysis tool to detect potential nil panics in Go code. settings: include-pkgs: "github.com/myorg/myproject" exclude-pkgs: "github.com/myorg/myproject/vendor" exclude-file-docstrings: "@generated,Code generated by" ``` ```yaml linters-settings: custom: nilaway: type: "module" description: Static analysis tool to detect potential nil panics in Go code. settings: include-pkgs: "github.com/myorg/myproject" exclude-file-docstrings: "@generated,Code generated by" linters: enable: - nilaway ``` -------------------------------- ### Passing Configurations Source: https://github.com/uber-go/nilaway/wiki/Configuration How to pass NilAway configuration flags. ```APIDOC ## Passing Configurations ### Standalone Checker Flags can be specified directly on the command line: ```bash nilaway -flag1 -flag2 ./... ``` ### golangci-lint Flags can be specified in the `.golangci.yaml` configuration file: ```yaml linters-settings: custom: nilaway: type: "module" description: Static analysis tool to detect potential nil panics in Go code. settings: # Settings must be a "map from string to string" to mimic command line flags: the keys are # flag names and the values are the values to the particular flags. include-pkgs: "" ``` ``` -------------------------------- ### Configure Bazel BUILD.bazel Source: https://context7.com/uber-go/nilaway/llms.txt Load and configure the nogo analyzer in the Bazel build file. ```python load("@io_bazel_rules_go//go:def.bzl", "nogo") nogo( name = "my_nogo", visibility = ["//visibility:public"], deps = [ "@org_uber_go_nilaway//:go_default_library", "@org_uber_go_nilaway//config:go_default_library", # Required for rules_go < 0.55.0 ], config = "nogo_config.json", ) ``` -------------------------------- ### Run Individual Linting Components Source: https://github.com/uber-go/nilaway/blob/main/docs/developing.md Executes specific linting tasks individually. ```bash make format-lint # Check if Go files are correctly formatted make tidy-lint # Check go.mod tidiness make golangci-lint # Run golangci-lint only make nilaway-lint # Run nilaway on itself ``` -------------------------------- ### Configure NilAway via Command Line Source: https://github.com/uber-go/nilaway/blob/main/docs/configurations.md Pass configuration flags directly to the NilAway standalone checker when running analysis. ```bash nilaway -flag1 -flag2 ./... ``` -------------------------------- ### Run Individual Linting Components Source: https://github.com/uber-go/nilaway/blob/main/AGENTS.md Execute specific linting components like format checks ('make format-lint'), go.mod tidiness ('make tidy-lint'), golangci-lint ('make golangci-lint'), or NilAway self-checks ('make nilaway-lint'). Set FIX=true to apply auto-fixes where available. ```bash make format-lint ``` ```bash make tidy-lint ``` ```bash make golangci-lint ``` ```bash make nilaway-lint ``` -------------------------------- ### Upgrade Dependencies Source: https://github.com/uber-go/nilaway/blob/main/AGENTS.md Run 'make upgrade-deps' to update all dependencies and tools to their latest versions. Optionally specify a Go version using the GO_VERSION environment variable, e.g., 'GO_VERSION=1.21'. ```bash make upgrade-deps ``` -------------------------------- ### NilAway Key Analyzers and Entry Points Source: https://context7.com/uber-go/nilaway/llms.txt Imports for key NilAway analyzers and their main entry points. These are exposed for advanced integration scenarios. ```go // Key analyzers exposed for advanced integration import ( "go.uber.org/nilaway" // Top-level analyzer "go.uber.org/nilaway/config" // Configuration "go.uber.org/nilaway/accumulation" // Core workflow coordinator "go.uber.org/nilaway/annotation" // Annotation tracking "go.uber.org/nilaway/assertion" // Assertion tree building "go.uber.org/nilaway/diagnostic" // Error reporting engine "go.uber.org/nilaway/inference" // Nilability inference engine ) // Main entry points var nilaway.Analyzer *analysis.Analyzer // Top-level analyzer var config.Analyzer *analysis.Analyzer // Configuration pseudo-analyzer var accumulation.Analyzer *analysis.Analyzer // Workflow coordinator ``` -------------------------------- ### Register NilAway in tools.go Source: https://context7.com/uber-go/nilaway/llms.txt Add NilAway as a dependency in a tools.go file for Bazel integration. ```go //go:build tools // +build tools package tools import ( _ "go.uber.org/nilaway" ) ``` -------------------------------- ### Configure NilAway in golangci-lint Source: https://github.com/uber-go/nilaway/blob/main/docs/configurations.md Specify NilAway settings within the `.golangci.yaml` configuration file. Use `include-pkgs` to define the package prefixes NilAway should analyze. ```yaml linters-settings: custom: nilaway: type: "module" description: Static analysis tool to detect potential nil panics in Go code. settings: # Settings must be a "map from string to string" to mimic command line flags: the keys are # flag names and the values are the values to the particular flags. include-pkgs: "" # NilAway can be referred to as `nilaway` just like any other golangci-lint analyzers in other # parts of the configuration file. ``` -------------------------------- ### Run NilAway Standalone Checker Source: https://github.com/uber-go/nilaway/blob/main/testdata/integration/README.md Commands to build the NilAway binary and execute it against the integration test project. ```shell # Build NilAway make build # Run NilAway on the integration test project cd testdata/integration ../../bin/nilaway ./... ``` -------------------------------- ### Configure golangci-lint Custom Plugin Source: https://github.com/uber-go/nilaway/blob/main/README.md Define the custom linter configuration in a .custom-gcl.yml file to integrate NilAway as a module plugin. ```yaml linters: custom: nilaway: path: go.uber.org/nilaway description: "NilAway is a static analysis tool that seeks to help developers avoid nil panics in production." original-url: github.com/uber-go/nilaway ``` -------------------------------- ### Configure nogo_config.json Source: https://context7.com/uber-go/nilaway/llms.txt Define analyzer flags and file exclusion rules for nogo. ```json { "nilaway_config": { "analyzer_flags": { "include-pkgs": "github.com/myorg/myproject", "exclude-pkgs": "vendor/", "exclude-file-docstrings": "@generated,Code generated by,Autogenerated by" } }, "nilaway": { "exclude_files": { "bazel-out": "prevents diagnostics on intermediate test files" }, "only_files": { "github.com/myorg/myproject": "enable NilAway on project code" } } } ``` -------------------------------- ### Configure NilAway in nogo Source: https://github.com/uber-go/nilaway/blob/main/README.md Add the NilAway library to the nogo configuration in the BUILD.bazel file. ```diff nogo( name = "my_nogo", visibility = ["//visibility:public"], # must have public visibility deps = [ + "@org_uber_go_nilaway//:go_default_library", + "@org_uber_go_nilaway//config:go_default_library", # Add this line if your have rules_go < 0.55.0 ], config = "config.json", ) ``` -------------------------------- ### Detect Nil Flow in Go Source: https://context7.com/uber-go/nilaway/llms.txt Demonstrates how NilAway identifies potential nil panics in conditional assignments and cross-function returns, along with the corresponding nil-check fixes. ```go package example // Example 1: Conditional nil assignment // NilAway detects that p may be nil when someCondition is false func conditionalNil(someCondition bool) { var p *Person if someCondition { p = &Person{Name: "Alice"} } // ERROR: Potential nil panic detected. Observed nil flow from source to dereference point: // - unassigned variable `p` accessed field `Name` fmt.Println(p.Name) } // Fix: Add nil check before accessing func conditionalNilFixed(someCondition bool) { var p *Person if someCondition { p = &Person{Name: "Alice"} } if p != nil { fmt.Println(p.Name) // Safe - guarded by nil check } } // Example 2: Cross-function nil flow // NilAway tracks nil returns across function boundaries func getUser(id int) *User { if id <= 0 { return nil // Potential nil source } return &User{ID: id} } func processUser(id int) { user := getUser(id) // ERROR: Potential nil panic detected. Observed nil flow from source to dereference point: // - literal `nil` returned from `getUser()` in position 0 // - result 0 of `getUser()` dereferenced fmt.Println(user.Name) } // Fix: Check for nil before use func processUserFixed(id int) { user := getUser(id) if user != nil { fmt.Println(user.Name) // Safe } } ``` -------------------------------- ### Run NilAway Standalone Checker Source: https://github.com/uber-go/nilaway/blob/main/README.md Execute the linter on specific packages using the include-pkgs flag to focus analysis on first-party code. ```shell nilaway -include-pkgs="," ./... ``` -------------------------------- ### Run NilAway Standalone Source: https://github.com/uber-go/nilaway/blob/main/AGENTS.md Execute NilAway as a standalone tool. The '-include-pkgs' flag is recommended to specify package prefixes for analysis. './...' indicates analysis of the current directory and its subdirectories. ```bash bin/nilaway -include-pkgs="" ./... ``` -------------------------------- ### Add NilAway as a Bazel/nogo dependency Source: https://github.com/uber-go/nilaway/blob/main/README.md Commands to fetch NilAway and sync dependencies for Bazel projects. ```bash # Get NilAway as a dependency, as well as getting its transitive dependencies in go.mod file. $ go get go.uber.org/nilaway@latest # This should not remove NilAway as a dependency in your go.mod file. $ go mod tidy # Run gazelle to sync dependencies from go.mod to WORKSPACE file. $ bazel run //:gazelle -- update-repos -from_file=go.mod ``` -------------------------------- ### Configure GolangCI-Lint Plugin Source: https://context7.com/uber-go/nilaway/llms.txt Define the NilAway plugin for golangci-lint v1.57.0+ using a custom configuration file. ```yaml version: v1.57.0 plugins: - module: "go.uber.org/nilaway" import: "go.uber.org/nilaway/cmd/gclplugin" version: latest # Or pin to specific version for reproducibility ``` -------------------------------- ### Update Bazel Dependencies Source: https://context7.com/uber-go/nilaway/llms.txt Commands to update Go modules and Gazelle repositories. ```bash go get go.uber.org/nilaway@latest go mod tidy bazel run //:gazelle -- update-repos -from_file=go.mod ``` -------------------------------- ### Run Linting Checks Source: https://github.com/uber-go/nilaway/blob/main/AGENTS.md Perform comprehensive linting, including format checks, mod tidiness, golangci-lint, and NilAway self-checks with 'make lint'. Use 'make lint-fix' to apply auto-fixes and auto-formats. ```bash make lint ``` ```bash make lint-fix ``` -------------------------------- ### Configure NilAway as a golangci-lint module plugin Source: https://github.com/uber-go/nilaway/blob/main/README.md Define the NilAway plugin in the .custom-gcl.yml file for the golangci-lint module plugin system. ```yaml version: v1.57.0 plugins: - module: "go.uber.org/nilaway" import: "go.uber.org/nilaway/cmd/gclplugin" version: latest # Or a fixed version for reproducible builds. ``` -------------------------------- ### Configure NilAway in golangci-lint Source: https://github.com/uber-go/nilaway/wiki/Configuration Define NilAway settings within the .golangci.yaml configuration file using a map of flag names to values. ```yaml linters-settings: custom: nilaway: type: "module" description: Static analysis tool to detect potential nil panics in Go code. settings: # Settings must be a "map from string to string" to mimic command line flags: the keys are # flag names and the values are the values to the particular flags. include-pkgs: "" ``` -------------------------------- ### Run Integration Tests Source: https://github.com/uber-go/nilaway/blob/main/CLAUDE.md Execute integration tests which utilize real drivers. This command ensures that NilAway functions correctly with external dependencies. ```bash make integration-test ``` -------------------------------- ### Test NilAway Source: https://github.com/uber-go/nilaway/blob/main/docs/developing.md Commands for executing unit, coverage, and integration tests. ```bash make test # Run unit tests for all modules make cover # Run tests with coverage reports make integration-test # Run integration tests (using real drivers) ``` -------------------------------- ### Configure NilAway with Bazel/nogo Source: https://github.com/uber-go/nilaway/blob/main/docs/configurations.md Configure NilAway for Bazel/nogo by specifying settings for both `nilaway_config` and `nilaway` analyzers in your `config.json`. Use `analyzer_flags` for NilAway specific flags and `exclude_files`/`only_files` for error suppression and path targeting. ```json { "nilaway_config": { "analyzer_flags": { "include-pkgs": "go.uber.org", "exclude-pkgs": "vendor/", "exclude-file-docstrings": "@generated,Code generated by,Autogenerated by" } }, "nilaway": { "exclude_files": { "bazel-out": "this prevents nilaway from outputting diagnostics on intermediate test files" }, "only_files": { "my/code/path": "This is the comment for why we want to enable NilAway on this code path" } } } ``` -------------------------------- ### Lint NilAway Source: https://github.com/uber-go/nilaway/blob/main/docs/developing.md Commands for running project linting and formatting checks. ```bash make lint # Run all linting (format check, mod tidy, golangci-lint, nilaway self-check) make lint-fix # Run all linting with autofix (and auto-formats) applied ``` -------------------------------- ### Configure NilAway in golangci-lint v2 Source: https://github.com/uber-go/nilaway/blob/main/README.md Add NilAway to the linters configuration for golangci-lint v2. ```yaml version: "2" linters: enable: - nilaway settings: custom: nilaway: type: module description: Static analysis tool to detect potential nil panics in Go code. settings: # Settings must be a "map from string to string" to mimic command line flags: the keys are # flag names and the values are the values to the particular flags. include-pkgs: "" ``` -------------------------------- ### Use NilAway Programmatically Source: https://context7.com/uber-go/nilaway/llms.txt Integrate NilAway into custom analysis tools using the Go analysis API. ```go package main import ( "go.uber.org/nilaway" "go.uber.org/nilaway/config" "golang.org/x/tools/go/analysis" "golang.org/x/tools/go/analysis/singlechecker" ) func main() { // NilAway exposes its main analyzer for integration // The analyzer requires config.Analyzer to be run first analyzers := []*analysis.Analyzer{ config.Analyzer, // Configuration pseudo-analyzer nilaway.Analyzer, // Main NilAway analyzer } // Set configuration flags programmatically config.Analyzer.Flags.Set("include-pkgs", "github.com/myorg") config.Analyzer.Flags.Set("pretty-print", "true") config.Analyzer.Flags.Set("group-error-messages", "true") // Run with singlechecker or your custom driver singlechecker.Main(nilaway.Analyzer) } ``` ```go // Config struct fields available for inspection type Config struct { PrettyPrint bool // Pretty print error messages GroupErrorMessages bool // Group similar errors ExperimentalStructInitEnable bool // Experimental struct init support ExperimentalAnonymousFuncEnable bool // Experimental anonymous func support PrintFullFilePath bool // Print full file paths ExcludeTestFiles bool // Exclude test file diagnostics } // IsPkgInScope checks if a package should be analyzed func (c *Config) IsPkgInScope(pkg *types.Package) bool // IsFileInScope checks if a file should be analyzed func (c *Config) IsFileInScope(file *ast.File) bool ``` -------------------------------- ### Run NilAway with JSON Output Source: https://github.com/uber-go/nilaway/blob/main/AGENTS.md Configure NilAway to output results in JSON format and disable pretty-printing by setting '-json' and '-pretty-print=false'. This is useful for programmatic processing of analysis results. ```bash bin/nilaway -json -pretty-print=false -include-pkgs="" ./... ``` -------------------------------- ### Run NilAway with JSON Output Source: https://github.com/uber-go/nilaway/blob/main/CLAUDE.md Run NilAway with JSON output enabled and pretty-printing disabled. This is useful for programmatic processing of analysis results. ```bash # With JSON output (disable pretty-print) bin/nilaway -json -pretty-print=false -include-pkgs="" ./... ``` -------------------------------- ### Configure NilAway Analyzers in nogo Source: https://github.com/uber-go/nilaway/wiki/Configuration This JSON configuration is used for nogo's `config.json` file. It specifies flags for the `nilaway_config` analyzer and exclusion/inclusion rules for the `nilaway` analyzer. Ensure correct paths and values for your project. ```json { "nilaway_config": { "analyzer_flags": { "include-pkgs": "go.uber.org", "exclude-pkgs": "vendor/", "exclude-file-docstrings": "@generated,Code generated by,Autogenerated by" } }, "nilaway": { "exclude_files": { "bazel-out": "this prevents nilaway from outputting diagnostics on intermediate test files" }, "only_files": { "my/code/path": "This is the comment for why we want to enable NilAway on this code path" } }, } ``` -------------------------------- ### Driver-Specific Flags (Standalone Checker) Source: https://github.com/uber-go/nilaway/wiki/Configuration Flags specific to the standalone NilAway checker. ```APIDOC ## Driver-Specific Flags - Standalone Checker ### `include-errors-in-files` #### Description A comma-separated list of file prefixes to report errors. Since the standalone checker does not support error suppression, this flag helps to filter errors. #### Default The current working directory (only errors within the current working directory are reported). #### Added in v0.1.0 ### `exclude-errors-in-files` #### Description A comma-separated list of file prefixes to exclude from error reporting. This flag takes precedence over `include-errors-in-files`. #### Default `""` (no errors are suppressed) #### Added in v0.1.0 ### `json` #### Description A boolean flag indicating if NilAway errors should be printed in JSON format for further post-processing. #### Default `false` #### Added in v0.1.0 ``` -------------------------------- ### Run Golden Tests Source: https://github.com/uber-go/nilaway/blob/main/AGENTS.md Golden tests compare NilAway violations between base and test branches on stdlib. Arguments are passed via the ARGS environment variable. Use 'make golden-test ARGS="-h"' to see available arguments. ```bash # The arguments are passed as an environment variable `ARGS`. # Use `make golden-test ARGS="-h" to see the available arguments. make golden-test ARGS="-base-branch main -test-branch HEAD -result-file /tmp/result.txt" ``` -------------------------------- ### Production-Focused NilAway Analysis Source: https://context7.com/uber-go/nilaway/llms.txt Configures NilAway for production use by excluding test files and specific file docstrings, while grouping similar error messages. Analysis is focused on the specified package prefixes. ```bash # Example: Production-focused analysis with grouped errors nilaway -include-pkgs="github.com/myorg" \ -exclude-file-docstrings="@generated,Code generated by" \ -exclude-test-files=true \ -group-error-messages=true \ ./... ``` -------------------------------- ### General Flags Source: https://github.com/uber-go/nilaway/wiki/Configuration These flags apply to all NilAway analysis drivers. ```APIDOC ## General Flags ### `include-pkgs` #### Description A comma-separated list of package prefixes to include for analysis. By default, all packages are included. This flag helps to focus analysis on first-party code. #### Default `""` (all packages are included) #### Added in v0.1.0 ### `exclude-pkgs` #### Description A comma-separated list of package prefixes to exclude from analysis. This flag takes precedence over `include-pkgs`. #### Default `""` (no packages are excluded) #### Added in v0.1.0 ### `exclude-file-docstrings` #### Description A comma-separated list of strings to search for in a file's docstrings to exclude a file from analysis. #### Default `""` (no files are excluded) #### Added in v0.1.0 ### `pretty-print` #### Description A boolean flag indicating if NilAway should pretty print the errors with ANSI color codes. #### Default `false` #### Added in v0.1.0 ### `group-error-messages` #### Description A boolean flag indicating if NilAway should group similar error messages together. #### Default `true` #### Added in v0.1.0 ### `experimental-struct-init` #### Description A boolean flag enabling experimental support for more sophisticated tracking and analysis around struct fields and initializations. Note that this feature may incur performance penalties and false positives. #### Default `false` #### Added in v0.1.0 ### `experimental-anonymous-function` #### Description A boolean flag enabling experimental support for anonymous functions. Note that this feature may introduce a fair number of false positives. #### Default `false` #### Added in v0.1.0 ``` -------------------------------- ### Disable Package Inference Source: https://context7.com/uber-go/nilaway/llms.txt Use the docstring to disable automatic nil tracking for a package, forcing reliance on explicit annotations. ```go // // Package legacycode contains code patterns that NilAway's inference // cannot accurately track. Use syntactic annotations only. package legacycode // With inference disabled, NilAway will only use explicit annotations // and will not automatically infer nilability across functions. func legacyFunction() *int { return nil // No automatic tracking of this nil flow } ``` -------------------------------- ### Detecting nil pointer dereference in local variables Source: https://github.com/uber-go/nilaway/blob/main/README.md Identifies potential panics when a variable is conditionally initialized. ```go // Example 1: var p *P if someCondition { p = &P{} } print(p.f) // nilness reports NO error here, but NilAway does. ``` -------------------------------- ### Debug Mode NilAway Analysis Source: https://context7.com/uber-go/nilaway/llms.txt Enables debug mode for NilAway analysis, including full file paths and experimental features like struct initialization tracking and anonymous function support. Analysis is focused on the specified package prefixes. ```bash # Example: Debug mode with full paths and all experimental features nilaway -include-pkgs="github.com/myorg" \ -print-full-file-path=true \ -experimental-struct-init=true \ -experimental-anonymous-function=true \ ./... ``` -------------------------------- ### Detecting nil pointer dereference across function boundaries Source: https://github.com/uber-go/nilaway/blob/main/README.md Identifies potential panics when a function returns a nil pointer that is subsequently dereferenced. ```go // Example 2: func foo() *int { return nil } func bar() { print(*foo()) // nilness reports NO error here, but NilAway does. } ``` -------------------------------- ### NilAway Analyzer Hierarchy Source: https://context7.com/uber-go/nilaway/llms.txt Visual representation of NilAway's analyzer coordination. Each analyzer has a specific role in tracking nil flows and reporting errors. ```text nilaway.Analyzer (top-level - reports errors) └── accumulation.Analyzer (coordinates workflow) ├── config.Analyzer (configuration flags) ├── annotation.Analyzer (reads nilability annotations) ├── assertion.Analyzer (builds assertion trees) │ ├── function.Analyzer (per-function analysis) │ │ ├── anonymousfunc.Analyzer (anonymous functions) │ │ └── structfield.Analyzer (struct fields) │ ├── affiliation.Analyzer (interface-struct affiliations) │ └── global.Analyzer (global variables) └── diagnostic.NoLintAnalyzer (nolint comment handling) ``` -------------------------------- ### Suppress NilAway Errors Source: https://context7.com/uber-go/nilaway/llms.txt Use //nolint:nilaway comments to suppress false positives or intentional nil handling patterns at the line, function, or block level. ```go package example // Suppress a single line func suppressLine(p *int) { print(*p) //nolint:nilaway } // Suppress all linters on a line func suppressAll(p *int) { print(*p) //nolint:all } // Suppress an entire function //nolint:nilaway func suppressedFunction(v *int) { // All nil dereferences in this function are suppressed print(*v) anotherPtr := getPtr() print(*anotherPtr) } // Suppress a code block using inline comment on statement func suppressBlock() { var p *int if condition { p = new(int) } // The nolint applies to this entire if statement if p != nil { //nolint:nilaway print(*p) } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.