Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
1783bec
Enable staticcheck
jakebailey Mar 26, 2025
07cfcfb
Fix staticcheck issues
jakebailey Mar 26, 2025
b29938d
Just drop the param
jakebailey Mar 26, 2025
e499d77
fmt
jakebailey Mar 26, 2025
4fc24e9
Merge branch 'main' into jabaile/staticcheck
jakebailey Apr 9, 2025
c7f34e9
Fix
jakebailey Apr 9, 2025
08b608b
Merge branch 'main' into jabaile/staticcheck
jakebailey Apr 18, 2025
7ca8f4c
Restore comment
jakebailey Apr 18, 2025
4468f4c
Merge branch 'main' into jabaile/staticcheck
jakebailey Apr 21, 2025
6c612a5
Merge branch 'main' into jabaile/staticcheck
jakebailey May 23, 2025
9e36d0e
Merge branch 'main' into jabaile/staticcheck
jakebailey May 29, 2025
8cd9960
Fix new stuff
jakebailey May 29, 2025
a351984
Merge branch 'main' into jabaile/staticcheck
jakebailey Jun 19, 2025
4187f47
fmt
jakebailey Jun 19, 2025
bbeded5
Merge branch 'main' into jabaile/staticcheck
jakebailey Jun 24, 2025
34ec1c2
Merge branch 'main' into jabaile/staticcheck
jakebailey Jul 2, 2025
f1ec936
oops
jakebailey Jul 2, 2025
fe4db02
oops
jakebailey Jul 2, 2025
287e1ec
Merge branch 'main' into jabaile/staticcheck
jakebailey Jul 8, 2025
983ed07
Merge branch 'main' into jabaile/staticcheck
jakebailey Jul 24, 2025
2ed61c6
Fixesg
jakebailey Jul 25, 2025
d24e3e2
Merge branch 'main' into jabaile/staticcheck
jakebailey Aug 8, 2025
a9945c0
Fix
jakebailey Aug 8, 2025
410900e
Merge branch 'main' into jabaile/staticcheck
jakebailey Oct 2, 2025
ea5773a
fix
jakebailey Oct 2, 2025
37d43ba
more
jakebailey Oct 2, 2025
2f60a43
more
jakebailey Oct 2, 2025
07d57d8
more
jakebailey Oct 2, 2025
59c2035
more
jakebailey Oct 2, 2025
446148e
remove unused assignment
jakebailey Oct 2, 2025
9eb4b3d
fmt
jakebailey Oct 2, 2025
b4cd226
Merge branch 'main' into jabaile/staticcheck
jakebailey Oct 31, 2025
0fbcbd2
Auto fix
jakebailey Oct 31, 2025
af4b744
Silence
jakebailey Oct 31, 2025
d864ad3
Merge branch 'main' into jabaile/staticcheck
jakebailey Nov 12, 2025
73bdae2
Merge branch 'main' into jabaile/staticcheck
jakebailey Nov 12, 2025
6dd858a
Fix
jakebailey Nov 12, 2025
7e8a25d
Fix
jakebailey Nov 12, 2025
0a3b5ae
oops
jakebailey Nov 12, 2025
d7e7d7a
Merge branch 'main' into jabaile/staticcheck
jakebailey Dec 3, 2025
0ead3e2
fix
jakebailey Dec 3, 2025
52e5cd2
Remove bad nil check
jakebailey Dec 3, 2025
c096d54
Merge branch 'main' into jabaile/staticcheck
jakebailey Dec 9, 2025
5861922
Move funcg
jakebailey Dec 9, 2025
e764d44
Merge branch 'main' into jabaile/staticcheck
jakebailey Dec 17, 2025
8911737
Fix lint
jakebailey Dec 17, 2025
3ff027b
Merge branch 'main' into jabaile/staticcheck
jakebailey Dec 29, 2025
331f8a6
Document disabled rules
jakebailey Dec 29, 2025
57e11bb
all fixed
jakebailey Dec 29, 2025
ce0e7d0
Merge branch 'main' into jabaile/staticcheck
jakebailey Jan 12, 2026
238bb09
some fixes
jakebailey Jan 12, 2026
bba802b
some fixes
jakebailey Jan 12, 2026
a2f42d6
Merge branch 'main' into jabaile/staticcheck
jakebailey Jan 31, 2026
3a2ff27
fix
jakebailey Jan 31, 2026
f9754db
Merge branch 'main' into jabaile/staticcheck
jakebailey Feb 5, 2026
c109a51
Merge branch 'main' into jabaile/staticcheck
jakebailey Feb 19, 2026
7f49afb
Fix
jakebailey Feb 19, 2026
76ad05e
oops
jakebailey Feb 19, 2026
eeafc73
Merge branch 'main' into jabaile/staticcheck
jakebailey Feb 19, 2026
a2c4e35
fix
jakebailey Feb 19, 2026
b435107
Merge branch 'main' into jabaile/staticcheck
jakebailey Feb 27, 2026
32bcdba
Merge branch 'main' into jabaile/staticcheck
jakebailey Mar 5, 2026
2f94c7c
Merge branch 'main' into jabaile/staticcheck
jakebailey Mar 10, 2026
4ab816c
Merge branch 'main' into jabaile/staticcheck
jakebailey Mar 25, 2026
0250d37
fix
jakebailey Mar 25, 2026
260bee9
Merge branch 'main' into jabaile/staticcheck
jakebailey Mar 31, 2026
0ddf4f4
Fix
jakebailey Mar 31, 2026
96c87d3
Merge branch 'main' into jabaile/staticcheck
jakebailey Apr 9, 2026
f1a3c10
Merge branch 'main' into jabaile/staticcheck
jakebailey Apr 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ linters:
- perfsprint
- predeclared
- reassign
- staticcheck
- testableexamples
- tparallel
- unconvert
Expand All @@ -55,7 +56,6 @@ linters:
# - gocritic
# - gosec
# - revive
# - staticcheck
# - testifylint
# - unparam
# - unused
Expand Down Expand Up @@ -87,6 +87,21 @@ linters:
msg: a host implementation should likely be used instead
pkg: ^runtime$

staticcheck:
checks:
- all
- -QF1001 # Apply De Morgan’s law
- -QF1003 # Convert if/else-if chain to tagged switch
- -SA1019 # Using a deprecated function, variable, constant or field
- -SA9003 # Empty body in an if or else branch
- -ST1000 # Incorrect or missing package comment
- -ST1003 # Poorly chosen identifier
- -ST1006 # Poorly chosen receiver name
- -ST1016 # Use consistent method receiver names
- -ST1020 # The documentation of an exported function should start with the function’s name
- -ST1021 # The documentation of an exported type should start with type’s name
- -ST1022 # The documentation of an exported variable or constant should start with variable’s name

exclusions:
rules:
- path: internal/fourslash/tests/gen/
Expand Down
2 changes: 1 addition & 1 deletion internal/api/encoder/encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func formatEncodedSourceFile(encoded []byte) string {
strStart := readUint32(encoded, int(offsetStringOffsets+stringIndex*4))
strEnd := readUint32(encoded, int(offsetStringOffsets+stringIndex*4)+4)
str := string(encoded[offsetStrings+strStart : offsetStrings+strEnd])
result.WriteString(fmt.Sprintf(" \"%s\"", str))
fmt.Fprintf(&result, " \"%s\"", str)
}
fmt.Fprintf(&result, " [%d, %d), i=%d, next=%d", pos, end, j, encoded[i+encoder.NodeOffsetNext])
result.WriteString("\n")
Expand Down
10 changes: 5 additions & 5 deletions internal/astnav/tokens_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,23 +408,23 @@ func writeRangeDiff(output *strings.Builder, file *ast.SourceFile, diff tokenDif
output.WriteString("\n\n")
}

output.WriteString(fmt.Sprintf("〚Positions: [%d, %d]〛\n", rng.Pos(), rng.End()))
fmt.Fprintf(output, "〚Positions: [%d, %d]〛\n", rng.Pos(), rng.End())
if diff.tsToken != nil {
output.WriteString(fmt.Sprintf("【TS: %s [%d, %d)】\n", diff.tsToken.Kind, tsTokenPos, tsTokenEnd))
fmt.Fprintf(output, "【TS: %s [%d, %d)】\n", diff.tsToken.Kind, tsTokenPos, tsTokenEnd)
} else {
output.WriteString("【TS: nil】\n")
}
if diff.goToken != nil {
output.WriteString(fmt.Sprintf("《Go: %s [%d, %d)》\n", diff.goToken.Kind, goTokenPos, goTokenEnd))
fmt.Fprintf(output, "《Go: %s [%d, %d)》\n", diff.goToken.Kind, goTokenPos, goTokenEnd)
} else {
output.WriteString("《Go: nil》\n")
}
for line := contextStart; line <= contextEnd; line++ {
if truncate, skipTo := shouldTruncate(line); truncate {
output.WriteString(fmt.Sprintf("%s │........ %d lines omitted ........\n", strings.Repeat(" ", digits), skipTo-line+1))
fmt.Fprintf(output, "%s │........ %d lines omitted ........\n", strings.Repeat(" ", digits), skipTo-line+1)
line = skipTo
}
output.WriteString(fmt.Sprintf("%*d │", digits, line+1))
fmt.Fprintf(output, "%*d │", digits, line+1)
end := len(file.Text()) + 1
if line < len(lines)-1 {
end = int(lines[line+1])
Expand Down
6 changes: 3 additions & 3 deletions internal/binder/binder.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func (b *Binder) declareSymbolEx(symbolTable ast.SymbolTable, parent *ast.Symbol
}
}
}
var declarationName *ast.Node = ast.GetNameOfDeclaration(node)
declarationName := ast.GetNameOfDeclaration(node)
if declarationName == nil {
declarationName = node
}
Expand All @@ -264,7 +264,7 @@ func (b *Binder) declareSymbolEx(symbolTable ast.SymbolTable, parent *ast.Symbol
diag.AddRelatedInfo(b.createDiagnosticForNode(node, diagnostics.Did_you_mean_0, "export type { "+node.AsTypeAliasDeclaration().Name().Text()+" }"))
}
for index, declaration := range symbol.Declarations {
var decl *ast.Node = ast.GetNameOfDeclaration(declaration)
decl := ast.GetNameOfDeclaration(declaration)
if decl == nil {
decl = declaration
}
Expand Down Expand Up @@ -2061,7 +2061,7 @@ func (b *Binder) bindCaseBlock(node *ast.Node) {
switchStatement := node.Parent
clauses := node.AsCaseBlock().Clauses.Nodes
isNarrowingSwitch := switchStatement.Expression().Kind == ast.KindTrueKeyword || isNarrowingExpression(switchStatement.Expression())
var fallthroughFlow *ast.FlowNode = b.unreachableFlow
fallthroughFlow := b.unreachableFlow
for i := 0; i < len(clauses); i++ {
clauseStart := i
for len(clauses[i].Statements()) == 0 && i+1 < len(clauses) {
Expand Down
46 changes: 22 additions & 24 deletions internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -10510,10 +10510,10 @@ func (c *Checker) checkPrefixUnaryExpression(node *ast.Node) *Type {
case ast.KindExclamationToken:
c.checkTruthinessOfType(operandType, expr.Operand)
facts := c.getTypeFacts(operandType, TypeFactsTruthy|TypeFactsFalsy)
switch {
case facts == TypeFactsTruthy:
switch facts {
case TypeFactsTruthy:
return c.falseType
case facts == TypeFactsFalsy:
case TypeFactsFalsy:
return c.trueType
default:
return c.booleanType
Expand Down Expand Up @@ -13382,7 +13382,7 @@ func (c *Checker) isReadonlyAssignmentDeclaration(node *ast.Node) bool {
} else {
writableType = c.getTypeOfSymbol(writableProp)
}
return writableType.flags&TypeFlagsBooleanLiteral != 0 && getBooleanLiteralValue(writableType) == false
return writableType.flags&TypeFlagsBooleanLiteral != 0 && !getBooleanLiteralValue(writableType)
}
return true
}
Expand Down Expand Up @@ -14959,10 +14959,10 @@ func (c *Checker) getSuggestedImportSource(moduleReference string, tsExtension s
if c.moduleKind.IsNonNodeESM() || mode == core.ModuleKindESNext {
preferTs := tspath.IsDeclarationFileName(moduleReference) && c.compilerOptions.GetAllowImportingTsExtensions()
var ext string
switch {
case tsExtension == tspath.ExtensionMts || tsExtension == tspath.ExtensionDmts:
switch tsExtension {
case tspath.ExtensionMts, tspath.ExtensionDmts:
ext = core.IfElse(preferTs, ".mts", ".mjs")
case tsExtension == tspath.ExtensionCts || tsExtension == tspath.ExtensionDcts:
case tspath.ExtensionCts, tspath.ExtensionDcts:
ext = core.IfElse(preferTs, ".cts", ".cjs")
default:
ext = core.IfElse(preferTs, ".ts", ".js")
Expand Down Expand Up @@ -15694,10 +15694,8 @@ func (c *Checker) getExportsOfModuleWorker(moduleSymbol *ast.Symbol) (exports as
return symbols
}
var originalModule *ast.Symbol
if moduleSymbol != nil {
if c.resolveSymbolEx(moduleSymbol.Exports[ast.InternalSymbolNameExportEquals], false /*dontResolveAlias*/) != nil {
originalModule = moduleSymbol
}
if c.resolveSymbolEx(moduleSymbol.Exports[ast.InternalSymbolNameExportEquals], false /*dontResolveAlias*/) != nil {
originalModule = moduleSymbol
}
// A module defined by an 'export=' consists of one export that needs to be resolved
moduleSymbol = c.resolveExternalModuleSymbol(moduleSymbol, false /*dontResolveAlias*/)
Expand Down Expand Up @@ -16471,7 +16469,7 @@ func (c *Checker) getBaseConstructorTypeOfClass(t *Type) *Type {
err := c.error(baseTypeNode.Expression(), diagnostics.Type_0_is_not_a_constructor_function_type, c.TypeToString(baseConstructorType))
if baseConstructorType.flags&TypeFlagsTypeParameter != 0 {
constraint := c.getConstraintFromTypeParameter(baseConstructorType)
var ctorReturn *Type = c.unknownType
ctorReturn := c.unknownType
if constraint != nil {
ctorSigs := c.getSignaturesOfType(constraint, SignatureKindConstruct)
if len(ctorSigs) != 0 {
Expand Down Expand Up @@ -18097,12 +18095,12 @@ func (c *Checker) getOptionalType(t *Type, isProperty bool) *Type {
// Add undefined or null or both to a type if they are missing.
func (c *Checker) getNullableType(t *Type, flags TypeFlags) *Type {
missing := (flags & ^t.flags) & (TypeFlagsUndefined | TypeFlagsNull)
switch {
case missing == 0:
switch missing {
case 0:
return t
case missing == TypeFlagsUndefined:
case TypeFlagsUndefined:
return c.getUnionType([]*Type{t, c.undefinedType})
case missing == TypeFlagsNull:
case TypeFlagsNull:
return c.getUnionType([]*Type{t, c.nullType})
}
return c.getUnionType([]*Type{t, c.undefinedType, c.nullType})
Expand Down Expand Up @@ -19581,7 +19579,7 @@ func (c *Checker) getReturnTypeFromBody(fn *ast.Node, checkMode CheckMode) *Type
var returnType *Type
var yieldType *Type
var nextType *Type
var fallbackReturnType *Type = c.voidType
fallbackReturnType := c.voidType
switch {
case !ast.IsBlock(body):
returnType = c.checkExpressionCachedEx(body, checkMode & ^CheckModeSkipGenericFunctions)
Expand Down Expand Up @@ -20606,7 +20604,7 @@ func (c *Checker) getUnionSignatures(signatureLists [][]*Signature) []*Signature
// nature and having overloads in multiple constituents would necessitate making a power set of signatures from the type, whose
// ordering would be non-obvious)
masterList := signatureLists[indexWithLengthOverOne]
var results []*Signature = slices.Clone(masterList)
results := slices.Clone(masterList)
for _, signatures := range signatureLists {
if !core.Same(signatures, masterList) {
signature := signatures[0]
Expand Down Expand Up @@ -28809,10 +28807,10 @@ func (c *Checker) getContextualTypeForArgument(callTarget *ast.Node, arg *ast.No

func (c *Checker) getContextualTypeForArgumentAtIndex(callTarget *ast.Node, argIndex int) *Type {
if ast.IsImportCall(callTarget) {
switch {
case argIndex == 0:
switch argIndex {
case 0:
return c.stringType
case argIndex == 1:
case 1:
return c.getGlobalImportCallOptionsType()
default:
return c.anyType
Expand Down Expand Up @@ -30249,10 +30247,10 @@ func (c *Checker) getGlobalNonNullableTypeInstantiation(t *Type) *Type {
}

func (c *Checker) convertAutoToAny(t *Type) *Type {
switch {
case t == c.autoType:
switch t {
case c.autoType:
return c.anyType
case t == c.autoArrayType:
case c.autoArrayType:
return c.anyArrayType
}
return t
Expand Down
2 changes: 1 addition & 1 deletion internal/checker/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -1987,7 +1987,7 @@ func (c *Checker) getSwitchClauseTypeOfWitnesses(node *ast.Node) []string {

// Return the combined not-equal type facts for all cases except those between the start and end indices.
func (c *Checker) getNotEqualFactsFromTypeofSwitch(start int, end int, witnesses []string) TypeFacts {
var facts TypeFacts = TypeFactsNone
facts := TypeFactsNone
for i, witness := range witnesses {
if (i < start || i >= end) && witness != "" {
f, ok := typeofNEFacts[witness]
Expand Down
12 changes: 6 additions & 6 deletions internal/checker/grammarchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -1485,7 +1485,7 @@ func (c *Checker) checkGrammarMethod(node *ast.Node /*Union[MethodDeclaration, M

func (c *Checker) checkGrammarBreakOrContinueStatement(node *ast.Node) bool {
targetLabel := node.Label()
var current *ast.Node = node
current := node
for current != nil {
if ast.IsFunctionLikeOrClassStaticBlockDeclaration(current) {
return c.grammarErrorOnNode(node, diagnostics.Jump_target_cannot_cross_function_boundary)
Expand Down Expand Up @@ -1798,14 +1798,14 @@ func (c *Checker) checkGrammarForDisallowedBlockScopedVariableStatement(node *as
blockScopeKind := c.getCombinedNodeFlagsCached(node.DeclarationList) & ast.NodeFlagsBlockScoped
if blockScopeKind != 0 {
var keyword string
switch {
case blockScopeKind == ast.NodeFlagsLet:
switch blockScopeKind {
case ast.NodeFlagsLet:
keyword = "let"
case blockScopeKind == ast.NodeFlagsConst:
case ast.NodeFlagsConst:
keyword = "const"
case blockScopeKind == ast.NodeFlagsUsing:
case ast.NodeFlagsUsing:
keyword = "using"
case blockScopeKind == ast.NodeFlagsAwaitUsing:
case ast.NodeFlagsAwaitUsing:
keyword = "await using"
default:
panic("Unknown BlockScope flag")
Expand Down
6 changes: 3 additions & 3 deletions internal/checker/inference.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,10 +575,10 @@ func (c *Checker) inferToTemplateLiteralType(n *InferenceState, source *Type, ta
case left.flags&TypeFlagsBoolean != 0:
return left
case right.flags&TypeFlagsBoolean != 0:
switch {
case str == "true":
switch str {
case "true":
return c.trueType
case str == "false":
case "false":
return c.falseType
default:
return c.booleanType
Expand Down
2 changes: 1 addition & 1 deletion internal/checker/jsx.go
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ func (c *Checker) createJsxAttributesTypeFromAttributesProperty(openingLikeEleme
return len(ast.GetSemanticJsxChildren(children)) != 0
}
if parentHasSemanticJsxChildren(openingLikeElement) {
var childTypes []*Type = c.checkJsxChildren(openingLikeElement.Parent, checkMode)
childTypes := c.checkJsxChildren(openingLikeElement.Parent, checkMode)
if !hasSpreadAnyType && jsxChildrenPropertyName != ast.InternalSymbolNameMissing && jsxChildrenPropertyName != "" {
// Error if there is a attribute named "children" explicitly specified and children element.
// This is because children element will overwrite the value from attributes.
Expand Down
Loading
Loading