2019-11-07 20:05:39 +01:00
|
|
|
package staticcheck
|
|
|
|
|
|
|
|
import (
|
|
|
|
"honnef.co/go/tools/facts"
|
2020-02-26 19:45:19 +01:00
|
|
|
"honnef.co/go/tools/internal/passes/buildir"
|
2019-11-07 20:05:39 +01:00
|
|
|
"honnef.co/go/tools/lint/lintutil"
|
|
|
|
|
|
|
|
"golang.org/x/tools/go/analysis"
|
|
|
|
"golang.org/x/tools/go/analysis/passes/inspect"
|
|
|
|
)
|
|
|
|
|
2020-02-26 19:45:19 +01:00
|
|
|
func makeCallCheckerAnalyzer(rules map[string]CallCheck, extraReqs ...*analysis.Analyzer) *analysis.Analyzer {
|
|
|
|
reqs := []*analysis.Analyzer{buildir.Analyzer, facts.TokenFile}
|
|
|
|
reqs = append(reqs, extraReqs...)
|
|
|
|
return &analysis.Analyzer{
|
|
|
|
Run: callChecker(rules),
|
|
|
|
Requires: reqs,
|
|
|
|
}
|
2019-11-07 20:05:39 +01:00
|
|
|
}
|
|
|
|
|
2020-02-26 19:45:19 +01:00
|
|
|
var Analyzers = lintutil.InitializeAnalyzers(Docs, map[string]*analysis.Analyzer{
|
|
|
|
"SA1000": makeCallCheckerAnalyzer(checkRegexpRules),
|
2019-11-07 20:05:39 +01:00
|
|
|
"SA1001": {
|
|
|
|
Run: CheckTemplate,
|
|
|
|
Requires: []*analysis.Analyzer{inspect.Analyzer},
|
|
|
|
},
|
2020-02-26 19:45:19 +01:00
|
|
|
"SA1002": makeCallCheckerAnalyzer(checkTimeParseRules),
|
|
|
|
"SA1003": makeCallCheckerAnalyzer(checkEncodingBinaryRules),
|
2019-11-07 20:05:39 +01:00
|
|
|
"SA1004": {
|
|
|
|
Run: CheckTimeSleepConstant,
|
|
|
|
Requires: []*analysis.Analyzer{inspect.Analyzer},
|
|
|
|
},
|
|
|
|
"SA1005": {
|
|
|
|
Run: CheckExec,
|
|
|
|
Requires: []*analysis.Analyzer{inspect.Analyzer},
|
|
|
|
},
|
|
|
|
"SA1006": {
|
|
|
|
Run: CheckUnsafePrintf,
|
|
|
|
Requires: []*analysis.Analyzer{inspect.Analyzer},
|
|
|
|
},
|
2020-02-26 19:45:19 +01:00
|
|
|
"SA1007": makeCallCheckerAnalyzer(checkURLsRules),
|
2019-11-07 20:05:39 +01:00
|
|
|
"SA1008": {
|
|
|
|
Run: CheckCanonicalHeaderKey,
|
|
|
|
Requires: []*analysis.Analyzer{inspect.Analyzer},
|
|
|
|
},
|
2020-02-26 19:45:19 +01:00
|
|
|
"SA1010": makeCallCheckerAnalyzer(checkRegexpFindAllRules),
|
|
|
|
"SA1011": makeCallCheckerAnalyzer(checkUTF8CutsetRules),
|
2019-11-07 20:05:39 +01:00
|
|
|
"SA1012": {
|
|
|
|
Run: CheckNilContext,
|
|
|
|
Requires: []*analysis.Analyzer{inspect.Analyzer},
|
|
|
|
},
|
|
|
|
"SA1013": {
|
|
|
|
Run: CheckSeeker,
|
|
|
|
Requires: []*analysis.Analyzer{inspect.Analyzer},
|
|
|
|
},
|
2020-02-26 19:45:19 +01:00
|
|
|
"SA1014": makeCallCheckerAnalyzer(checkUnmarshalPointerRules),
|
2019-11-07 20:05:39 +01:00
|
|
|
"SA1015": {
|
|
|
|
Run: CheckLeakyTimeTick,
|
2020-02-26 19:45:19 +01:00
|
|
|
Requires: []*analysis.Analyzer{buildir.Analyzer},
|
2019-11-07 20:05:39 +01:00
|
|
|
},
|
|
|
|
"SA1016": {
|
|
|
|
Run: CheckUntrappableSignal,
|
|
|
|
Requires: []*analysis.Analyzer{inspect.Analyzer},
|
|
|
|
},
|
2020-02-26 19:45:19 +01:00
|
|
|
"SA1017": makeCallCheckerAnalyzer(checkUnbufferedSignalChanRules),
|
|
|
|
"SA1018": makeCallCheckerAnalyzer(checkStringsReplaceZeroRules),
|
2019-11-07 20:05:39 +01:00
|
|
|
"SA1019": {
|
|
|
|
Run: CheckDeprecated,
|
2020-05-15 14:02:03 +02:00
|
|
|
Requires: []*analysis.Analyzer{inspect.Analyzer, facts.Deprecated, facts.Generated},
|
2019-11-07 20:05:39 +01:00
|
|
|
},
|
2020-02-26 19:45:19 +01:00
|
|
|
"SA1020": makeCallCheckerAnalyzer(checkListenAddressRules),
|
|
|
|
"SA1021": makeCallCheckerAnalyzer(checkBytesEqualIPRules),
|
2019-11-07 20:05:39 +01:00
|
|
|
"SA1023": {
|
|
|
|
Run: CheckWriterBufferModified,
|
2020-02-26 19:45:19 +01:00
|
|
|
Requires: []*analysis.Analyzer{buildir.Analyzer},
|
2019-11-07 20:05:39 +01:00
|
|
|
},
|
2020-02-26 19:45:19 +01:00
|
|
|
"SA1024": makeCallCheckerAnalyzer(checkUniqueCutsetRules),
|
2019-11-07 20:05:39 +01:00
|
|
|
"SA1025": {
|
|
|
|
Run: CheckTimerResetReturnValue,
|
2020-02-26 19:45:19 +01:00
|
|
|
Requires: []*analysis.Analyzer{buildir.Analyzer},
|
2019-11-07 20:05:39 +01:00
|
|
|
},
|
2020-02-26 19:45:19 +01:00
|
|
|
"SA1026": makeCallCheckerAnalyzer(checkUnsupportedMarshal),
|
|
|
|
"SA1027": makeCallCheckerAnalyzer(checkAtomicAlignment),
|
|
|
|
"SA1028": makeCallCheckerAnalyzer(checkSortSliceRules),
|
|
|
|
"SA1029": makeCallCheckerAnalyzer(checkWithValueKeyRules),
|
2019-11-07 20:05:39 +01:00
|
|
|
|
|
|
|
"SA2000": {
|
|
|
|
Run: CheckWaitgroupAdd,
|
|
|
|
Requires: []*analysis.Analyzer{inspect.Analyzer},
|
|
|
|
},
|
|
|
|
"SA2001": {
|
|
|
|
Run: CheckEmptyCriticalSection,
|
|
|
|
Requires: []*analysis.Analyzer{inspect.Analyzer},
|
|
|
|
},
|
|
|
|
"SA2002": {
|
|
|
|
Run: CheckConcurrentTesting,
|
2020-02-26 19:45:19 +01:00
|
|
|
Requires: []*analysis.Analyzer{buildir.Analyzer},
|
2019-11-07 20:05:39 +01:00
|
|
|
},
|
|
|
|
"SA2003": {
|
|
|
|
Run: CheckDeferLock,
|
2020-02-26 19:45:19 +01:00
|
|
|
Requires: []*analysis.Analyzer{buildir.Analyzer},
|
2019-11-07 20:05:39 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
"SA3000": {
|
|
|
|
Run: CheckTestMainExit,
|
|
|
|
Requires: []*analysis.Analyzer{inspect.Analyzer},
|
|
|
|
},
|
|
|
|
"SA3001": {
|
|
|
|
Run: CheckBenchmarkN,
|
|
|
|
Requires: []*analysis.Analyzer{inspect.Analyzer},
|
|
|
|
},
|
|
|
|
|
|
|
|
"SA4000": {
|
|
|
|
Run: CheckLhsRhsIdentical,
|
|
|
|
Requires: []*analysis.Analyzer{inspect.Analyzer, facts.TokenFile, facts.Generated},
|
|
|
|
},
|
|
|
|
"SA4001": {
|
|
|
|
Run: CheckIneffectiveCopy,
|
|
|
|
Requires: []*analysis.Analyzer{inspect.Analyzer},
|
|
|
|
},
|
|
|
|
"SA4003": {
|
|
|
|
Run: CheckExtremeComparison,
|
|
|
|
Requires: []*analysis.Analyzer{inspect.Analyzer},
|
|
|
|
},
|
|
|
|
"SA4004": {
|
|
|
|
Run: CheckIneffectiveLoop,
|
|
|
|
Requires: []*analysis.Analyzer{inspect.Analyzer},
|
|
|
|
},
|
|
|
|
"SA4006": {
|
|
|
|
Run: CheckUnreadVariableValues,
|
2020-02-26 19:45:19 +01:00
|
|
|
Requires: []*analysis.Analyzer{buildir.Analyzer, facts.Generated},
|
2019-11-07 20:05:39 +01:00
|
|
|
},
|
|
|
|
"SA4008": {
|
|
|
|
Run: CheckLoopCondition,
|
2020-02-26 19:45:19 +01:00
|
|
|
Requires: []*analysis.Analyzer{buildir.Analyzer},
|
2019-11-07 20:05:39 +01:00
|
|
|
},
|
|
|
|
"SA4009": {
|
|
|
|
Run: CheckArgOverwritten,
|
2020-02-26 19:45:19 +01:00
|
|
|
Requires: []*analysis.Analyzer{buildir.Analyzer},
|
2019-11-07 20:05:39 +01:00
|
|
|
},
|
|
|
|
"SA4010": {
|
|
|
|
Run: CheckIneffectiveAppend,
|
2020-02-26 19:45:19 +01:00
|
|
|
Requires: []*analysis.Analyzer{buildir.Analyzer},
|
2019-11-07 20:05:39 +01:00
|
|
|
},
|
|
|
|
"SA4011": {
|
|
|
|
Run: CheckScopedBreak,
|
|
|
|
Requires: []*analysis.Analyzer{inspect.Analyzer},
|
|
|
|
},
|
|
|
|
"SA4012": {
|
|
|
|
Run: CheckNaNComparison,
|
2020-02-26 19:45:19 +01:00
|
|
|
Requires: []*analysis.Analyzer{buildir.Analyzer},
|
2019-11-07 20:05:39 +01:00
|
|
|
},
|
|
|
|
"SA4013": {
|
|
|
|
Run: CheckDoubleNegation,
|
|
|
|
Requires: []*analysis.Analyzer{inspect.Analyzer},
|
|
|
|
},
|
|
|
|
"SA4014": {
|
|
|
|
Run: CheckRepeatedIfElse,
|
|
|
|
Requires: []*analysis.Analyzer{inspect.Analyzer},
|
|
|
|
},
|
2020-02-26 19:45:19 +01:00
|
|
|
"SA4015": makeCallCheckerAnalyzer(checkMathIntRules),
|
2019-11-07 20:05:39 +01:00
|
|
|
"SA4016": {
|
|
|
|
Run: CheckSillyBitwiseOps,
|
2020-02-26 19:45:19 +01:00
|
|
|
Requires: []*analysis.Analyzer{inspect.Analyzer, facts.TokenFile},
|
2019-11-07 20:05:39 +01:00
|
|
|
},
|
|
|
|
"SA4017": {
|
|
|
|
Run: CheckPureFunctions,
|
2020-02-26 19:45:19 +01:00
|
|
|
Requires: []*analysis.Analyzer{buildir.Analyzer, facts.Purity},
|
2019-11-07 20:05:39 +01:00
|
|
|
},
|
|
|
|
"SA4018": {
|
|
|
|
Run: CheckSelfAssignment,
|
2020-02-26 19:45:19 +01:00
|
|
|
Requires: []*analysis.Analyzer{inspect.Analyzer, facts.Generated, facts.TokenFile, facts.Purity},
|
2019-11-07 20:05:39 +01:00
|
|
|
},
|
|
|
|
"SA4019": {
|
|
|
|
Run: CheckDuplicateBuildConstraints,
|
|
|
|
Requires: []*analysis.Analyzer{facts.Generated},
|
|
|
|
},
|
|
|
|
"SA4020": {
|
|
|
|
Run: CheckUnreachableTypeCases,
|
|
|
|
Requires: []*analysis.Analyzer{inspect.Analyzer},
|
|
|
|
},
|
|
|
|
"SA4021": {
|
|
|
|
Run: CheckSingleArgAppend,
|
|
|
|
Requires: []*analysis.Analyzer{inspect.Analyzer, facts.Generated, facts.TokenFile},
|
|
|
|
},
|
|
|
|
|
|
|
|
"SA5000": {
|
|
|
|
Run: CheckNilMaps,
|
2020-02-26 19:45:19 +01:00
|
|
|
Requires: []*analysis.Analyzer{buildir.Analyzer},
|
2019-11-07 20:05:39 +01:00
|
|
|
},
|
|
|
|
"SA5001": {
|
|
|
|
Run: CheckEarlyDefer,
|
|
|
|
Requires: []*analysis.Analyzer{inspect.Analyzer},
|
|
|
|
},
|
|
|
|
"SA5002": {
|
|
|
|
Run: CheckInfiniteEmptyLoop,
|
|
|
|
Requires: []*analysis.Analyzer{inspect.Analyzer},
|
|
|
|
},
|
|
|
|
"SA5003": {
|
|
|
|
Run: CheckDeferInInfiniteLoop,
|
|
|
|
Requires: []*analysis.Analyzer{inspect.Analyzer},
|
|
|
|
},
|
|
|
|
"SA5004": {
|
|
|
|
Run: CheckLoopEmptyDefault,
|
|
|
|
Requires: []*analysis.Analyzer{inspect.Analyzer},
|
|
|
|
},
|
|
|
|
"SA5005": {
|
|
|
|
Run: CheckCyclicFinalizer,
|
2020-02-26 19:45:19 +01:00
|
|
|
Requires: []*analysis.Analyzer{buildir.Analyzer},
|
2019-11-07 20:05:39 +01:00
|
|
|
},
|
|
|
|
"SA5007": {
|
|
|
|
Run: CheckInfiniteRecursion,
|
2020-02-26 19:45:19 +01:00
|
|
|
Requires: []*analysis.Analyzer{buildir.Analyzer},
|
2019-11-07 20:05:39 +01:00
|
|
|
},
|
|
|
|
"SA5008": {
|
|
|
|
Run: CheckStructTags,
|
|
|
|
Requires: []*analysis.Analyzer{inspect.Analyzer},
|
|
|
|
},
|
2020-02-26 19:45:19 +01:00
|
|
|
"SA5009": makeCallCheckerAnalyzer(checkPrintfRules),
|
|
|
|
"SA5010": {
|
|
|
|
Run: CheckImpossibleTypeAssertion,
|
|
|
|
Requires: []*analysis.Analyzer{buildir.Analyzer, facts.TokenFile},
|
2019-11-07 20:05:39 +01:00
|
|
|
},
|
2020-02-26 19:45:19 +01:00
|
|
|
"SA5011": {
|
|
|
|
Run: CheckMaybeNil,
|
|
|
|
Requires: []*analysis.Analyzer{buildir.Analyzer},
|
2019-11-07 20:05:39 +01:00
|
|
|
},
|
2020-02-26 19:45:19 +01:00
|
|
|
|
|
|
|
"SA6000": makeCallCheckerAnalyzer(checkRegexpMatchLoopRules),
|
2019-11-07 20:05:39 +01:00
|
|
|
"SA6001": {
|
|
|
|
Run: CheckMapBytesKey,
|
2020-02-26 19:45:19 +01:00
|
|
|
Requires: []*analysis.Analyzer{buildir.Analyzer},
|
2019-11-07 20:05:39 +01:00
|
|
|
},
|
2020-02-26 19:45:19 +01:00
|
|
|
"SA6002": makeCallCheckerAnalyzer(checkSyncPoolValueRules),
|
2019-11-07 20:05:39 +01:00
|
|
|
"SA6003": {
|
|
|
|
Run: CheckRangeStringRunes,
|
2020-02-26 19:45:19 +01:00
|
|
|
Requires: []*analysis.Analyzer{buildir.Analyzer},
|
2019-11-07 20:05:39 +01:00
|
|
|
},
|
|
|
|
"SA6005": {
|
|
|
|
Run: CheckToLowerToUpperComparison,
|
|
|
|
Requires: []*analysis.Analyzer{inspect.Analyzer},
|
|
|
|
},
|
|
|
|
|
|
|
|
"SA9001": {
|
|
|
|
Run: CheckDubiousDeferInChannelRangeLoop,
|
|
|
|
Requires: []*analysis.Analyzer{inspect.Analyzer},
|
|
|
|
},
|
|
|
|
"SA9002": {
|
|
|
|
Run: CheckNonOctalFileMode,
|
|
|
|
Requires: []*analysis.Analyzer{inspect.Analyzer},
|
|
|
|
},
|
|
|
|
"SA9003": {
|
|
|
|
Run: CheckEmptyBranch,
|
2020-02-26 19:45:19 +01:00
|
|
|
Requires: []*analysis.Analyzer{buildir.Analyzer, facts.TokenFile, facts.Generated},
|
2019-11-07 20:05:39 +01:00
|
|
|
},
|
|
|
|
"SA9004": {
|
|
|
|
Run: CheckMissingEnumTypesInDeclaration,
|
|
|
|
Requires: []*analysis.Analyzer{inspect.Analyzer},
|
|
|
|
},
|
|
|
|
// Filtering generated code because it may include empty structs generated from data models.
|
2020-02-26 19:45:19 +01:00
|
|
|
"SA9005": makeCallCheckerAnalyzer(checkNoopMarshal, facts.Generated),
|
|
|
|
|
|
|
|
"SA4022": {
|
|
|
|
Run: CheckAddressIsNil,
|
|
|
|
Requires: []*analysis.Analyzer{inspect.Analyzer},
|
2019-11-07 20:05:39 +01:00
|
|
|
},
|
2020-02-26 19:45:19 +01:00
|
|
|
})
|