Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 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
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
18 changes: 17 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ linters:
- perfsprint
- predeclared
- reassign
- staticcheck
- testableexamples
- tparallel
- unconvert
Expand All @@ -53,7 +54,6 @@ linters:
# - gocritic
# - gosec
# - revive
# - staticcheck
# - testifylint
# - unparam
# - unused
Expand All @@ -70,6 +70,22 @@ linters:
- pkg: 'encoding/json$'
desc: 'Use "github.com/go-json-experiment/json" instead.'

staticcheck:
checks:
- all
- -QF1001
- -QF1003
- -SA1019
- -SA6005
- -SA9003
- -ST1000
- -ST1003
- -ST1006 # TODO: enable
- -ST1016
- -ST1020
- -ST1021
- -ST1022

exclusions:
rules:
- path: internal/fourslash/tests/gen/
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 @@ -285,23 +285,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 @@ -245,7 +245,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 @@ -260,7 +260,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().AsIdentifier().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 @@ -2101,7 +2101,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].AsCaseOrDefaultClause().Statements.Nodes) == 0 && i+1 < len(clauses) {
Expand Down
45 changes: 19 additions & 26 deletions internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1651,13 +1651,6 @@ func (c *Checker) getSuggestedLibForNonExistentName(name string) string {
return ""
}

func (c *Checker) getPrimitiveAliasSymbols() {
var symbols []*ast.Symbol
for _, name := range []string{"string", "number", "boolean", "object", "bigint", "symbol"} {
symbols = append(symbols, c.newSymbol(ast.SymbolFlagsTypeAlias, name))
}
}

func (c *Checker) getSuggestedSymbolForNonexistentSymbol(location *ast.Node, outerName string, meaning ast.SymbolFlags) *ast.Symbol {
return c.resolveNameForSymbolSuggestion(location, outerName, meaning, nil /*nameNotFoundMessage*/, false /*isUse*/, false /*excludeGlobals*/)
}
Expand Down Expand Up @@ -10412,10 +10405,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 @@ -14754,10 +14747,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 @@ -16231,7 +16224,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 @@ -17802,12 +17795,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 @@ -19280,7 +19273,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 @@ -20292,7 +20285,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 @@ -28405,10 +28398,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 @@ -29831,10 +29824,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 @@ -1979,7 +1979,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 @@ -1525,7 +1525,7 @@ func (c *Checker) checkGrammarBreakOrContinueStatement(node *ast.Node) bool {
panic(fmt.Sprintf("Unexpected node kind %q", node.Kind))
}

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 @@ -1829,14 +1829,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 @@ -580,10 +580,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 @@ -806,7 +806,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
42 changes: 21 additions & 21 deletions internal/checker/nodebuilderimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (b *nodeBuilderImpl) appendReferenceToType(root *ast.TypeNode, ref *ast.Typ
// !!! Without the above, nested type args are silently elided
// then move qualifiers
ids := getAccessStack(ref)
var typeName *ast.Node = root.AsTypeReferenceNode().TypeName
typeName := root.AsTypeReferenceNode().TypeName
for _, id := range ids {
typeName = b.f.NewQualifiedName(typeName, id)
}
Expand All @@ -190,7 +190,7 @@ func (b *nodeBuilderImpl) appendReferenceToType(root *ast.TypeNode, ref *ast.Typ
}

func getAccessStack(ref *ast.Node) []*ast.Node {
var state *ast.Node = ref.AsTypeReferenceNode().TypeName
state := ref.AsTypeReferenceNode().TypeName
ids := []*ast.Node{}
for !ast.IsIdentifier(state) {
entity := state.AsQualifiedName()
Expand Down Expand Up @@ -1320,7 +1320,7 @@ func (b *nodeBuilderImpl) typeParameterToName(typeParameter *Type) *ast.Identifi
}
text := rawText

for true {
for {
_, present := b.ctx.typeParameterNamesByText[text]
if !present && !b.typeParameterShadowsOtherTypeParameterInScope(text, typeParameter) {
break
Expand Down Expand Up @@ -1752,47 +1752,47 @@ func (b *nodeBuilderImpl) signatureToSignatureDeclarationHelper(signature *Signa
}

var node *ast.Node
switch {
case kind == ast.KindCallSignature:
switch kind {
case ast.KindCallSignature:
node = b.f.NewCallSignatureDeclaration(typeParamList, paramList, returnTypeNode)
case kind == ast.KindConstructSignature:
case ast.KindConstructSignature:
node = b.f.NewConstructSignatureDeclaration(typeParamList, paramList, returnTypeNode)
case kind == ast.KindMethodSignature:
case ast.KindMethodSignature:
var questionToken *ast.Node
if options != nil {
questionToken = options.questionToken
}
node = b.f.NewMethodSignatureDeclaration(modifierList, name, questionToken, typeParamList, paramList, returnTypeNode)
case kind == ast.KindMethodDeclaration:
case ast.KindMethodDeclaration:
node = b.f.NewMethodDeclaration(modifierList, nil /*asteriskToken*/, name, nil /*questionToken*/, typeParamList, paramList, returnTypeNode, nil /*fullSignature*/, nil /*body*/)
case kind == ast.KindConstructor:
case ast.KindConstructor:
node = b.f.NewConstructorDeclaration(modifierList, nil /*typeParamList*/, paramList, nil /*returnTypeNode*/, nil /*fullSignature*/, nil /*body*/)
case kind == ast.KindGetAccessor:
case ast.KindGetAccessor:
node = b.f.NewGetAccessorDeclaration(modifierList, name, nil /*typeParamList*/, paramList, returnTypeNode, nil /*fullSignature*/, nil /*body*/)
case kind == ast.KindSetAccessor:
case ast.KindSetAccessor:
node = b.f.NewSetAccessorDeclaration(modifierList, name, nil /*typeParamList*/, paramList, nil /*returnTypeNode*/, nil /*fullSignature*/, nil /*body*/)
case kind == ast.KindIndexSignature:
case ast.KindIndexSignature:
node = b.f.NewIndexSignatureDeclaration(modifierList, paramList, returnTypeNode)
// !!! JSDoc Support
// case kind == ast.KindJSDocFunctionType:
// case ast.KindJSDocFunctionType:
// node = b.f.NewJSDocFunctionType(parameters, returnTypeNode)
case kind == ast.KindFunctionType:
case ast.KindFunctionType:
if returnTypeNode == nil {
returnTypeNode = b.f.NewTypeReferenceNode(b.f.NewIdentifier(""), nil)
}
node = b.f.NewFunctionTypeNode(typeParamList, paramList, returnTypeNode)
case kind == ast.KindConstructorType:
case ast.KindConstructorType:
if returnTypeNode == nil {
returnTypeNode = b.f.NewTypeReferenceNode(b.f.NewIdentifier(""), nil)
}
node = b.f.NewConstructorTypeNode(modifierList, typeParamList, paramList, returnTypeNode)
case kind == ast.KindFunctionDeclaration:
case ast.KindFunctionDeclaration:
// TODO: assert name is Identifier
node = b.f.NewFunctionDeclaration(modifierList, nil /*asteriskToken*/, name, typeParamList, paramList, returnTypeNode, nil /*fullSignature*/, nil /*body*/)
case kind == ast.KindFunctionExpression:
case ast.KindFunctionExpression:
// TODO: assert name is Identifier
node = b.f.NewFunctionExpression(modifierList, nil /*asteriskToken*/, name, typeParamList, paramList, returnTypeNode, nil /*fullSignature*/, b.f.NewBlock(b.f.NewNodeList([]*ast.Node{}), false))
case kind == ast.KindArrowFunction:
case ast.KindArrowFunction:
node = b.f.NewArrowFunction(modifierList, typeParamList, paramList, returnTypeNode, nil /*fullSignature*/, nil /*equalsGreaterThanToken*/, b.f.NewBlock(b.f.NewNodeList([]*ast.Node{}), false))
default:
panic("Unhandled kind in signatureToSignatureDeclarationHelper")
Expand Down Expand Up @@ -1834,7 +1834,7 @@ func (c *Checker) getExpandedParameters(sig *Signature, skipUnionExpanding bool)
counter = 1
}
var name string
for true {
for {
name = fmt.Sprintf("%s_%d", names[i], counter)
_, ok := uniqueNames[name]
if ok {
Expand Down Expand Up @@ -2551,7 +2551,7 @@ func (b *nodeBuilderImpl) conditionalTypeToTypeNode(_t *Type) *ast.TypeNode {

func (b *nodeBuilderImpl) getParentSymbolOfTypeParameter(typeParameter *TypeParameter) *ast.Symbol {
tp := ast.GetDeclarationOfKind(typeParameter.symbol, ast.KindTypeParameter)
var host *ast.Node
var host *ast.Node //nolint:staticcheck
// !!! JSDoc support
// if ast.IsJSDocTemplateTag(tp.Parent) {
// host = getEffectiveContainerForJSDocTemplateTag(tp.Parent)
Expand All @@ -2565,7 +2565,7 @@ func (b *nodeBuilderImpl) getParentSymbolOfTypeParameter(typeParameter *TypePara
}

func (b *nodeBuilderImpl) typeReferenceToTypeNode(t *Type) *ast.TypeNode {
var typeArguments []*Type = b.ch.getTypeArguments(t)
typeArguments := b.ch.getTypeArguments(t)
if t.Target() == b.ch.globalArrayType || t.Target() == b.ch.globalReadonlyArrayType {
if b.ctx.flags&nodebuilder.FlagsWriteArrayAsGenericType != 0 {
typeArgumentNode := b.typeToTypeNode(typeArguments[0])
Expand Down
Loading
Loading