Skip to content

Configuration of nilaway using golangci-lint.yml requires nilaway_analyzer to also be built. #5

Description

@taimoorgit

Steps to reproduce

  1. build the plugin
  2. copy to your project folder
  3. setup a config, like this:
linters-settings:
  custom:
    nilaway:
      path: ./bin/nilaway.so
      description: self-built nilaway plugin
      original-url: github.com/nilaway-plugin
      settings:
        pretty-print: false
  1. run golangci-lint run --disable-all -E nilaway
  2. no errors will be thrown but pretty-print is not actually disabled. --include-pkgs won't work etiher.

Reason

This is happening because the config isn't read by the plugin.New()

func New(conf any) ([]*analysis.Analyzer, error) {
	return []*analysis.Analyzer{nilaway.Analyzer}, nil
}

Part of the solution is to take this conf any and turn it into a map[string]any, then read key value pairs from there and feed them into the analyzer flag sets. However, it's more complicated than that.

nilaway has a multi-tiered architecture, where the config needs to actually be read by a separate analyzer that all analyzers are dependent on, called 'nilaway_config'

To address this problem, we have defined a separate "nilaway_config" analyzer which is only responsible for defining the Flags field and expose the configs through its return value. All other sub-analyzers will depend on the config.Analyzer and use the values there to execute different logic.

Reference

Solution

We need to also build nilaway_analyzer.so somehow.

The YAML config will need to look more like:

run:
  timeout: 2m
linters-settings:
  custom:
    nilaway_config:
      path: ./bin/nilaway_config.so
      description: self-built nilaway plugin
      original-url: github.com/nilaway_config-plugin
      settings:
        pretty-print: false

    nilaway:
      path: ./bin/nilaway.so
      description: self-built nilaway plugin
      original-url: github.com/nilaway-plugin

# like the nilaway/golangci-custom linter docs mention, you apply the golangci-related stuff (like excludes) on nilaway, but the actual flag setting gets done on nilaway_analyzer
issues:
  exclude-rules:
    - linters:
        - nilaway
      path: "cmd/terraform.go"

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions