golangci/golangci-lint · error

unknown type

Error message

unknown type %s

What it means

goconst's toType maps user-facing string values (from config) to goconst API option types; an unrecognized string falls to the default branch and yields 'unknown type %s'. The config value for which option it applies to (e.g. match-constant vs number-minimum occurrences category or occurrence type) is not one of the accepted literals.

Solutions

  1. Check the goconst settings documentation and use exact accepted values (e.g. 'compositelit', not 'compositeliteral')
  2. Fix casing/typos — values are compared as raw strings
  3. Remove the invalid option to fall back to defaults
  4. Upgrade/downgrade golangci-lint if the valid value set changed between versions

Example fix

# before
linters-settings:
  goconst:
    ignore-type: compositeliteral
# after
linters-settings:
  goconst:
    ignore-type: compositelit
Defensive patterns

Strategy: validation

Validate before calling

validGoconstValues := map[string]bool{"string": true, "number": true, "compositelit": true}
for _, v := range goconstTypeValues {
    if !validGoconstValues[strings.ToLower(v)] {
        return fmt.Errorf("invalid goconst type value %q; allowed: string|number|compositelit", v)
    }
}

Try / catch

if err := golangci.Run(); err != nil {
    if strings.Contains(err.Error(), "unknown type") {
        fmt.Fprintln(os.Stderr, "fix goconst setting value: must be one of the documented literals (e.g. compositelit)")
        os.Exit(1)
    }
    return err
}

Prevention

When it happens

Trigger: runGoconst read a goconst setting (e.g. the type/occurrence-related option such as 'find-duplicates' or the string-vs-compositelit selector) whose value isn't 'string' equivalent, 'number', or 'compositelit', so the switch in toType hits default.

Common situations: Typo in .golangci.yml (e.g. 'compositeliteral', 'CompositLit', 'str'), copying an option name from a newer/older goconst version with renamed values, or YAML quoting introducing unexpected characters.

Related errors


AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02). Data as JSON: /api/errors/5671f0f0afc845a1. Report an issue: GitHub.

Appendix: source

Thrown at pkg/golinters/goconst/goconst.go:150

		return goconstAPI.Assignment, nil

	case "binary":
		return goconstAPI.Binary, nil

	case "case":
		return goconstAPI.Case, nil

	case "return":
		return goconstAPI.Return, nil

	case "call":
		return goconstAPI.Call, nil

	case "compositelit":
		return goconstAPI.CompositeLit, nil

	default:
		return 0, fmt.Errorf("unknown type %s", v)
	}
}

View on GitHub (pinned to ed7a235d2d)