---
# golangci-lint configuration file made by @ccoVeille
# Source: https://github.com/ccoVeille/golangci-lint-config-examples/
# Author: @ccoVeille
# License: MIT
# Variant: 03-safe
# Version: v2.0.0
#
version: "2"

formatters:
  enable:
    # format the code
    - gofmt
    # format the block of imports
    - gci

  settings:
    # format the code with Go standard library
    gofmt:
      # simplify the code
      # https://pkg.go.dev/cmd/gofmt#hdr-The_simplify_command
      simplify: true
      rewrite-rules:
        # replace `interface{}` with `any` in the code on format
        - pattern: 'interface{}'
          replacement: 'any'

    # make sure imports are always in a deterministic order
    # https://github.com/daixiang0/gci/
    gci:  # define the section orders for imports
      sections:
        # Standard section: captures all standard packages.
        - standard
        # Default section: catchall that is not standard or custom
        - default
        # linters that related to local tool, so they should be separated
        - localmodule

linters:
  enable:
    # Errcheck is a program for checking for unchecked errors in Go code.
    - errcheck

    # Vet examines Go source code and reports suspicious constructs.
    - govet

    # Detects when assignments to existing variables are not used.
    - ineffassign

    # It's a set of rules from staticcheck. See https://staticcheck.io/
    - staticcheck

    # Checks Go code for unused constants, variables, functions and types.
    - unused

    # Fast, configurable, extensible, flexible, and beautiful linter for Go.
    # Drop-in replacement of golint.
    - revive

    # make sure to use t.Helper() when needed
    - thelper

    # checks if package imports are in a list of acceptable packages.
    - depguard

    # mirror suggests rewrites to avoid unnecessary []byte/string conversion
    - mirror

    # detect the possibility to use variables/constants from the Go standard library.
    - usestdlibvars

    # Finds commonly misspelled English words.
    - misspell

    # Checks for duplicate words in the source code.
    - dupword

    # gosec is a security linter for Go code.
    - gosec

    # Reports uses of functions with replacement inside the testing package.
    - usetesting


  settings:

    depguard:
      rules:
        # enforce the library has no dependencies except the standard library
        code:
          files:
            - '!$test'
          allow:
            - $gostd
        # enforce the test files have no dependencies except the standard library and the library itself
        test:
          files:
            - $test
          allow:
            - $gostd
            - github.com/ccoveille/go-safecast

    revive:
      rules:
        # Blank import should be only in a main or test package, or have a comment justifying it.
        - name: blank-imports

        # context.Context() should be the first parameter of a function when provided as argument.
        - name: context-as-argument
          arguments:
            - allowTypesBefore: "*testing.T"

        # Basic types should not be used as a key in `context.WithValue`
        - name: context-keys-type

        # Importing with `.` makes the programs much harder to understand
        - name: dot-imports

        # Empty blocks make code less readable and could be a symptom of a bug or unfinished refactoring.
        - name: empty-block

        # for better readability, variables of type `error` must be named with the prefix `err`.
        - name: error-naming

        # for better readability, the errors should be last in the list of returned values by a function.
        - name: error-return

        # for better readability, error messages should not be capitalized or end with punctuation or a newline.
        - name: error-strings

        # report when replacing `errors.New(fmt.Sprintf())` with `fmt.Errorf()` is possible
        - name: errorf

        # exported functions, structs, and methods should have comments.
        - name: exported
          arguments:
            # make error messages clearer
            - "sayRepetitiveInsteadOfStutters"

        # enforces conventions on source file names.
        - name: filename-format

        # incrementing an integer variable by 1 is recommended to be done using the `++` operator
        - name: increment-decrement

        # highlights redundant else-blocks that can be eliminated from the code
        - name: indent-error-flow

        # This rule suggests a shorter way of writing ranges that do not use the second value.
        - name: range

        # receiver names in a method should reflect the struct name (p for Person, for example)
        - name: receiver-naming

        # redefining built in names (true, false, append, make) can lead to bugs very difficult to detect.
        - name: redefines-builtin-id

        # redundant else-blocks that can be eliminated from the code.
        - name: superfluous-else

        # prevent confusing name for variables when using `time` package
        - name: time-naming

        # warns when an exported function or method returns a value of an un-exported type.
        - name: unexported-return

        # spots and proposes to remove unreachable code. also helps to spot errors
        - name: unreachable-code

        # Functions or methods with unused parameters can be a symptom of an unfinished refactoring or a bug.
        - name: unused-parameter

        # report when a variable declaration can be simplified
        - name: var-declaration

        # warns when initialism, variable or package naming conventions are not followed.
        - name: var-naming

    misspell:
      # Correct spellings using locale preferences for US or UK.
      # Setting locale to US will correct the British spelling of 'colour' to 'color'.
      # Default ("") is to use a neutral variety of English.
      locale: US

output:
  sort-order:
    - linter
    - severity
    - file # filepath, line, and column.
