azproviderlint

command module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

README

azproviderlint

GitHub release build test lint govulncheck CodeQL Go Version License

A custom golangci-lint module plugin providing Azure provider-specific linting rules built on Go's analysis framework.

Installation

Standalone
go install github.com/katbyte/azproviderlint@latest

Then run directly (all rules run by default):

azproviderlint ./...

Each rule is also a flag, and setting any rule flag switches to running only the named rules; a category on its own (-AZG) runs every rule in that category:

azproviderlint -AZG001 ./...
azproviderlint -AZR001 -AZR003 ./...
azproviderlint -AZG ./...
azproviderlint -AZG -AZR001 ./...
As a golangci-lint Plugin

Add to your .custom-gcl.yml:

version: v2.12.2
plugins:
  - module: "github.com/katbyte/azproviderlint"
    import: "github.com/katbyte/azproviderlint/plugin"
    version: v0.1.0

Build the custom binary:

golangci-lint custom

Then enable in .golangci.yml:

linters:
  enable:
    - azproviderlint
  settings:
    custom:
      azproviderlint:
        type: module

Individual rules can be enabled/disabled via plugin settings (an empty enable list means all rules):

linters:
  settings:
    custom:
      azproviderlint:
        type: module
        settings:
          disable: [AZR002]

To run just azproviderlint through the custom binary, skipping every other linter:

custom-gcl run --enable-only azproviderlint ./...

There is no CLI flag for a single rule — combine --enable-only with an enable: [AZG001] list in the plugin settings above, or use the standalone binary's per-rule flags.

Why the plugin over the standalone binary?

The plugin requires every consumer to build a custom golangci-lint binary (golangci-lint custom), but that one-time cost buys a lot on a codebase the size of a provider:

  • One package-load instead of two. On azurerm this is the dominant cost — loading and type-checking the provider codebase (with its enormous vendor tree) takes minutes, and every separate analysis binary pays it again from scratch. Folding checks into golangci-lint amortizes it, and golangci-lint's result cache makes warm local re-runs dramatically faster; a standalone multichecker reloads the world every single time.
  • Unified config and reporting. .golangci.yml path exclusions (generated files, /sdk/, third_party — already curated in the provider repo) apply to these checks for free; one output stream, one CI job, SARIF/annotations, and --new-from-rev — the killer feature for a codebase with 22+ pre-existing findings per service, since checks can be enforced on new code only instead of azignoring a decade of history.
  • //nolint works uniformly alongside //azignore (see Ignoring Reports).

The standalone binary remains the right tool for one-off or single-rule runs (azproviderlint -AZG001 ./...), editor integrations that expect a plain analysis-style vet tool, and quick iteration while developing new checks.

Rules

Rules are named AZ<category letter><number>, aligned with tfproviderlint's category letters (R, S, V, AT) where they overlap.

AZG — General Go Style / Readability
Rule Description
AZG001 err := SomeFunc() or _, err := SomeFunc() followed by if err != nil should be combined into a single if init statement
AZG002 Error messages should describe the expected format instead of saying invalid format of ...
AZR — Resource Implementation
Rule Description
AZR001 SetId must not be passed a dereferenced pointer (d.SetId(*read.ID)) — use a generated Resource ID Formatter/Parser and d.SetId(id.ID())
AZR002 Resources must register separate Create and Update methods instead of a combined CreateUpdate method
AZR003 d.Get / metadata.ResourceData.Get must not be used inside a resource's Delete function, where it does not work as expected
AZR004 Resource IDs must not be compared with ==/!= — use resourceids.Match
AZR005 features.TreatUserSpecifiedSegmentsAsCaseInsensitive must not be set — the case-aware comparisons feature is not ready for use
AZR006 ctx must not be assigned directly from meta.(*clients.Client).StopContext — use timeouts.ForCreate/ForRead/ForUpdate/ForDelete so Custom Timeouts work
AZD — Data Sources
Rule Description
AZD001 Data sources must return an error when a resource cannot be found, not call d.SetId("")
AZD002 Data sources must return an error when a resource cannot be found, not call metadata.MarkAsGone
AZS — Schema & Typed SDK Models
Rule Description
AZS001 Typed SDK model fields (tagged tfschema) must use 64-bit numeric types — int64 not int/int16/int32, float64 not float32 — including slices, maps, pointers, named types, and aliases of them
AZC — Clients & SDK Usage
Rule Description
AZC001 Azure SDK (track1 & kermit) clients must be created via NewFoosClientWithBaseURI with the resource manager endpoint explicitly specified, not NewFoosClient(o.SubscriptionId)
AZT — Acceptance Testing
Rule Description
AZT001 Acceptance test files (resource, data source, action, ephemeral — incl. list and generated variants) must use an external _test package to prevent circular dependencies
AZT002 Tests must not obtain credentials via os.Getenv("ARM_CLIENT_ID"/"ARM_CLIENT_SECRET"/"ARM_CLIENT_SECRET_ALT") — create an azurerm_user_assigned_identity with minimal permissions instead
AZN — Naming Conventions

No rules yet — reserved for property naming convention rules (e.g. percentage properties using a _percentage suffix rather than _in_percent).

AZV — Validation

No rules yet — reserved for missing/incorrect validation rules (e.g. string arguments without a ValidateFunc).

Ignoring Reports

When run via golangci-lint, all azproviderlint reports on a line can be ignored with a //nolint:azproviderlint comment at the end of the offending line or on the line immediately preceding it.

To ignore a specific check — leaving the others active, and working under any driver including the standalone binary — use a //azignore:<Rule> comment in the same positions. Multiple rules can be listed separated by commas:

d.SetId(*read.ID) //azignore:AZR001

//azignore:AZG001,AZR003
err := client.Delete(ctx, id)

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package checks exposes all azproviderlint analyzers, grouped by category.
Package checks exposes all azproviderlint analyzers, grouped by category.
AZC
Package AZC collects the client & SDK usage checks.
Package AZC collects the client & SDK usage checks.
AZC/AZC001_client_missing_base_uri
Package AZC001 defines an analyzer that reports Azure SDK clients being created without the resource manager endpoint explicitly specified.
Package AZC001 defines an analyzer that reports Azure SDK clients being created without the resource manager endpoint explicitly specified.
AZD
Package AZD collects the data source checks.
Package AZD collects the data source checks.
AZD/AZD001_data_source_empty_set_id
Package AZD001 defines an analyzer that reports data sources calling SetId with an empty string instead of returning an error when the resource cannot be found.
Package AZD001 defines an analyzer that reports data sources calling SetId with an empty string instead of returning an error when the resource cannot be found.
AZD/AZD002_data_source_mark_as_gone
Package AZD002 defines an analyzer that reports data sources using MarkAsGone instead of returning an error when the resource cannot be found.
Package AZD002 defines an analyzer that reports data sources using MarkAsGone instead of returning an error when the resource cannot be found.
AZG
Package AZG collects the general Go style & readability checks.
Package AZG collects the general Go style & readability checks.
AZG/AZG001_combine_err_assignment_and_check
Package AZG001 defines an analyzer that reports 'err := SomeFunc()' and '_, err := SomeFunc()' assignments that should be combined with the following 'if err != nil' into a single 'if' init statement.
Package AZG001 defines an analyzer that reports 'err := SomeFunc()' and '_, err := SomeFunc()' assignments that should be combined with the following 'if err != nil' into a single 'if' init statement.
AZG/AZG002_error_should_describe_expected_format
Package AZG002 defines an analyzer that reports unclear 'invalid format of' error messages that should describe the expected format instead.
Package AZG002 defines an analyzer that reports unclear 'invalid format of' error messages that should describe the expected format instead.
AZR
Package AZR collects the resource implementation checks.
Package AZR collects the resource implementation checks.
AZR/AZR001_set_id_dereferenced_pointer
Package AZR001 defines an analyzer that reports SetId being called with a dereferenced pointer (typically the raw Azure API resource ID) instead of a generated Resource ID Formatter/Parser's id.ID().
Package AZR001 defines an analyzer that reports SetId being called with a dereferenced pointer (typically the raw Azure API resource ID) instead of a generated Resource ID Formatter/Parser's id.ID().
AZR/AZR002_combined_create_update_method
Package AZR002 defines an analyzer that reports resources registering a combined CreateUpdate method instead of separate Create and Update methods.
Package AZR002 defines an analyzer that reports resources registering a combined CreateUpdate method instead of separate Create and Update methods.
AZR/AZR003_resource_data_get_in_delete
Package AZR003 defines an analyzer that reports ResourceData.Get being used inside a resource's Delete function, where it does not work as expected.
Package AZR003 defines an analyzer that reports ResourceData.Get being used inside a resource's Delete function, where it does not work as expected.
AZR/AZR004_resource_id_equality_comparison
Package AZR004 defines an analyzer that reports Resource IDs being compared with the == or != operators instead of resourceids.Match.
Package AZR004 defines an analyzer that reports Resource IDs being compared with the == or != operators instead of resourceids.Match.
AZR/AZR005_case_insensitive_segments_feature_flag
Package AZR005 defines an analyzer that reports assignments to the TreatUserSpecifiedSegmentsAsCaseInsensitive feature flag, which must not be configured.
Package AZR005 defines an analyzer that reports assignments to the TreatUserSpecifiedSegmentsAsCaseInsensitive feature flag, which must not be configured.
AZR/AZR006_stop_context_without_timeouts
Package AZR006 defines an analyzer that reports resources assigning ctx directly from the provider meta object instead of using a timeouts-wrapped StopContext.
Package AZR006 defines an analyzer that reports resources assigning ctx directly from the provider meta object instead of using a timeouts-wrapped StopContext.
AZS
Package AZS collects the schema & typed SDK model checks.
Package AZS collects the schema & typed SDK model checks.
AZS/AZS001_typed_sdk_model_64bit_types
Package AZS001 defines an analyzer that reports tfschema-tagged typed SDK model fields using non-64-bit numeric types where the SDK's Encode/Decode requires int64/float64.
Package AZS001 defines an analyzer that reports tfschema-tagged typed SDK model fields using non-64-bit numeric types where the SDK's Encode/Decode requires int64/float64.
AZT
Package AZT collects the acceptance testing checks.
Package AZT collects the acceptance testing checks.
AZT/AZT001_acceptance_test_external_package
Package AZT001 defines an analyzer that reports acceptance test files (for resources, data sources, actions and ephemeral resources) that do not use an external _test package.
Package AZT001 defines an analyzer that reports acceptance test files (for resources, data sources, actions and ephemeral resources) that do not use an external _test package.
AZT/AZT002_credentials_from_environment
Package AZT002 defines an analyzer that reports acceptance tests reading provider credentials from the environment instead of provisioning their own identity.
Package AZT002 defines an analyzer that reports acceptance tests reading provider credentials from the environment instead of provisioning their own identity.
azignore
Package azignore implements '//azignore:AZX001' comment directives, letting individual checks be suppressed per line without disabling every azproviderlint check on that line the way '//nolint:azproviderlint' does.
Package azignore implements '//azignore:AZX001' comment directives, letting individual checks be suppressed per line without disabling every azproviderlint check on that line the way '//nolint:azproviderlint' does.
Package plugin registers azproviderlint's analyzers as a golangci-lint module plugin.
Package plugin registers azproviderlint's analyzers as a golangci-lint module plugin.
Package version records the version and git commit the azproviderlint binary was built from.
Package version records the version and git commit the azproviderlint binary was built from.

Jump to

Keyboard shortcuts

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