Skip to content

merschformann/keystyle

Repository files navigation

keyStyle

Important

This project is a first attempt at writing a custom linter and used for personal purposes mainly. I am happy if someone finds it useful, but please be aware that it is not necessarily production-ready or well-tested.

Map-key styling linter plugin for golangci-lint.

Example

// ...
someData = LogData{
  "camelCase":     "value1",
  "IncorrectKey2": "value2",
}
// ...

Linter output:

example.go:10:3: Key 'IncorrectKey2' style should be camelCase (keystyle)
  "IncorrectKey2": someValue,
  ^

Usage

Instructions for setting up a custom linter can be found in the golangci-lint documentation. Replace foo with keyStyle in the example (and the paths accordingly).

The following instructions are based on above documentation.

Linter plugin setup (.custom-gcl.yml):

version: v2.1.6
plugins:
  # Import keystyle linter for linting of map key style.
  - module: 'github.com/merschformann/keystyle'
    import: 'github.com/merschformann/keystyle'
    version: v0.0.1

Linter configuration (.golangci.yml):

version: "2"
linters:
  default: none
  enable:
    - keystyle
  settings:
    custom:
      keystyle:
        type: "module"
        description: Keystyle preference.
        settings:
          checks:
            - style: "camelCase"
              type-name: "LogData"
            - style: "custom"
              type-name: "OtherData"
              regex: "^[a-z][a-zA-Z0-9]*$"

About

Plugin linter keystyle for golangci lint.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages