Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
2 changes: 1 addition & 1 deletion .custom-gcl.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# yaml-language-server: $schema=https://golangci-lint.run/jsonschema/custom-gcl.jsonschema.json

version: v2.5.0
version: v2.6.0

destination: ./_tools

Expand Down
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ linters:
- makezero
- mirror
- misspell
- modernize
- musttag
- nakedret
- nolintlint
Expand Down
2 changes: 1 addition & 1 deletion internal/ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func visit(v Visitor, node *Node) bool {
}

func visitNodes(v Visitor, nodes []*Node) bool {
for _, node := range nodes {
for _, node := range nodes { //nolint:modernize
if v(node) {
return true
}
Expand Down
2 changes: 1 addition & 1 deletion internal/binder/binder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2640,7 +2640,7 @@ func isNarrowableReference(node *ast.Node) bool {

func hasNarrowableArgument(expr *ast.Node) bool {
call := expr.AsCallExpression()
for _, argument := range call.Arguments.Nodes {
for _, argument := range call.Arguments.Nodes { //nolint:modernize
if containsNarrowableReference(argument) {
return true
}
Expand Down
2 changes: 1 addition & 1 deletion internal/checker/grammarchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ func (c *Checker) checkGrammarHeritageClause(node *ast.HeritageClause) bool {
return c.grammarErrorAtPos(node.AsNode(), types.Pos(), 0, diagnostics.X_0_list_cannot_be_empty, listType)
}

for _, node := range types.Nodes {
for _, node := range types.Nodes { //nolint:modernize
if c.checkGrammarExpressionWithTypeArguments(node) {
return true
}
Expand Down
12 changes: 7 additions & 5 deletions internal/checker/mapper.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package checker

import "github.com/microsoft/typescript-go/internal/core"
import (
"slices"

"github.com/microsoft/typescript-go/internal/core"
)

// TypeMapperKind

Expand Down Expand Up @@ -158,10 +162,8 @@ func newArrayToSingleTypeMapper(sources []*Type, target *Type) *TypeMapper {
}

func (m *ArrayToSingleTypeMapper) Map(t *Type) *Type {
for _, s := range m.sources {
if t == s {
return m.target
}
if slices.Contains(m.sources, t) {
return m.target
}
return t
}
Expand Down
6 changes: 2 additions & 4 deletions internal/checker/nodebuilderimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2034,10 +2034,8 @@ func (b *nodeBuilderImpl) shouldUsePlaceholderForProperty(propertySymbol *ast.Sy
return false
}
// (1)
for _, elem := range b.ctx.reverseMappedStack {
if elem == propertySymbol {
return true
}
if slices.Contains(b.ctx.reverseMappedStack, propertySymbol) {
return true
}
// (2)
if len(b.ctx.reverseMappedStack) > 0 {
Expand Down
14 changes: 10 additions & 4 deletions internal/compiler/fileloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,16 +638,22 @@ func getLibraryNameFromLibFileName(libFileName string) string {
// lib.dom.iterable.d.ts -> @typescript/lib-dom/iterable
// lib.es2015.symbol.wellknown.d.ts -> @typescript/lib-es2015/symbol-wellknown
components := strings.Split(libFileName, ".")
var path string
var path strings.Builder
path.WriteString("@typescript/lib-")
if len(components) > 1 {
path = components[1]
path.WriteString(components[1])
}
i := 2
for i < len(components) && components[i] != "" && components[i] != "d" {
path += core.IfElse(i == 2, "/", "-") + components[i]
if i == 2 {
path.WriteByte('/')
} else {
path.WriteByte('-')
}
path.WriteString(components[i])
i++
}
return "@typescript/lib-" + path
return path.String()
}

func getInferredLibraryNameResolveFrom(options *core.CompilerOptions, currentDirectory string, libFileName string) string {
Expand Down
10 changes: 4 additions & 6 deletions internal/compiler/projectreferenceparser.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package compiler

import (
"maps"

"github.com/microsoft/typescript-go/internal/collections"
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/tsoptions"
Expand Down Expand Up @@ -91,12 +93,8 @@ func (p *projectReferenceParser) initMapperWorker(tasks []*projectReferenceParse
if task.resolved == nil || p.loader.projectReferenceFileMapper.opts.Config.ConfigFile == task.resolved.ConfigFile {
continue
}
for key, value := range task.resolved.SourceToProjectReference() {
p.loader.projectReferenceFileMapper.sourceToProjectReference[key] = value
}
for key, value := range task.resolved.OutputDtsToProjectReference() {
p.loader.projectReferenceFileMapper.outputDtsToProjectReference[key] = value
}
maps.Copy(p.loader.projectReferenceFileMapper.sourceToProjectReference, task.resolved.SourceToProjectReference())
maps.Copy(p.loader.projectReferenceFileMapper.outputDtsToProjectReference, task.resolved.OutputDtsToProjectReference())
if p.loader.projectReferenceFileMapper.opts.canUseProjectReferenceSource() {
declDir := task.resolved.CompilerOptions().DeclarationDir
if declDir == "" {
Expand Down
9 changes: 3 additions & 6 deletions internal/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func Same[T any](s1 []T, s2 []T) bool {
}

func Some[T any](slice []T, f func(T) bool) bool {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This func arguably shouldn't exist but that's larger diff.

for _, value := range slice {
for _, value := range slice { //nolint:modernize
if f(value) {
return true
}
Expand Down Expand Up @@ -407,12 +407,9 @@ func ComputeECMALineStartsSeq(text string) iter.Seq[TextPos] {
}

func PositionToLineAndCharacter(position int, lineStarts []TextPos) (line int, character int) {
line = sort.Search(len(lineStarts), func(i int) bool {
line = max(sort.Search(len(lineStarts), func(i int) bool {
return int(lineStarts[i]) > position
}) - 1
if line < 0 {
line = 0
}
})-1, 0)
return line, position - int(lineStarts[line])
}

Expand Down
6 changes: 2 additions & 4 deletions internal/core/workgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ func (w *parallelWorkGroup) Queue(fn func()) {
panic("Queue called after RunAndWait returned")
}

w.wg.Add(1)
go func() {
defer w.wg.Done()
w.wg.Go(func() {
fn()
}()
})
}

func (w *parallelWorkGroup) RunAndWait() {
Expand Down
2 changes: 1 addition & 1 deletion internal/execute/tsctests/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (test *tscInput) run(t *testing.T, scenario string) {
baselineBuilder.WriteString(fmt.Sprintf("\n\nDiff:: %s\n", core.IfElse(do.expectedDiff == "", "!!! Unexpected diff, please review and either fix or write explanation as expectedDiff !!!", do.expectedDiff)))
baselineBuilder.WriteString(diff)
if do.expectedDiff == "" {
unexpectedDiff += fmt.Sprintf("Edit [%d]:: %s\n!!! Unexpected diff, please review and either fix or write explanation as expectedDiff !!!\n%s\n", index, do.caption, diff)
unexpectedDiff += fmt.Sprintf("Edit [%d]:: %s\n!!! Unexpected diff, please review and either fix or write explanation as expectedDiff !!!\n%s\n", index, do.caption, diff) //nolint:perfsprint
}
} else if do.expectedDiff != "" {
baselineBuilder.WriteString(fmt.Sprintf("\n\nDiff:: %s !!! Diff not found but explanation present, please review and remove the explanation !!!\n", do.expectedDiff))
Expand Down
2 changes: 1 addition & 1 deletion internal/fourslash/baselineutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ func (t *textWithContext) sliceOfContent(start *int, end *int) string {
return t.content[*start:*end]
}

func (t *textWithContext) getIndex(i interface{}) *int {
func (t *textWithContext) getIndex(i any) *int {
switch i := i.(type) {
case *int:
return i
Expand Down
7 changes: 1 addition & 6 deletions internal/fourslash/fourslash.go
Original file line number Diff line number Diff line change
Expand Up @@ -824,12 +824,7 @@ func (f *FourslashTest) verifyCompletionsAreExactly(t *testing.T, prefix string,
func ignorePaths(paths ...string) cmp.Option {
return cmp.FilterPath(
func(p cmp.Path) bool {
for _, path := range paths {
if p.Last().String() == path {
return true
}
}
return false
return slices.Contains(paths, p.Last().String())
},
cmp.Ignore(),
)
Expand Down
4 changes: 2 additions & 2 deletions internal/fourslash/test_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,13 +407,13 @@ func parseFileContent(fileName string, content string, fileOptions map[string]st

func getObjectMarker(fileName string, location *locationInformation, text string) (*Marker, error) {
// Attempt to parse the marker value as JSON
var v interface{}
var v any
e := json.Unmarshal([]byte("{ "+text+" }"), &v)

if e != nil {
return nil, reportError(fileName, location.sourceLine, location.sourceColumn, "Unable to parse marker text "+text)
}
markerValue, ok := v.(map[string]interface{})
markerValue, ok := v.(map[string]any)
if !ok || len(markerValue) == 0 {
return nil, reportError(fileName, location.sourceLine, location.sourceColumn, "Object markers can not be empty")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/glob/glob.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (g *Glob) Match(input string) bool {
}

func match(elems []element, input string) (ok bool) {
var elem interface{}
var elem any
for len(elems) > 0 {
elem, elems = elems[0], elems[1:]
switch elem := elem.(type) {
Expand Down
21 changes: 11 additions & 10 deletions internal/ls/completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2409,17 +2409,17 @@ func getFilterText(
dotAccessor string,
) string {
// Private field completion, e.g. label `#bar`.
if strings.HasPrefix(label, "#") {
if after, ok := strings.CutPrefix(label, "#"); ok {
if insertText != "" {
if strings.HasPrefix(insertText, "this.#") {
if after, ok := strings.CutPrefix(insertText, "this.#"); ok {
if wordStart == '#' {
// `method() { this.#| }`
// `method() { #| }`
return ""
} else {
// `method() { this.| }`
// `method() { | }`
return strings.TrimPrefix(insertText, "this.#")
return after
}
}
} else {
Expand All @@ -2429,7 +2429,7 @@ func getFilterText(
} else {
// `method() { this.| }`
// `method() { | }`
return strings.TrimPrefix(label, "#")
return after
}
}
}
Expand Down Expand Up @@ -3187,7 +3187,7 @@ func isNamedImportsOrExports(node *ast.Node) bool {

func generateIdentifierForArbitraryString(text string) string {
needsUnderscore := false
identifier := ""
var identifier strings.Builder
var ch rune
var size int

Expand All @@ -3202,25 +3202,26 @@ func generateIdentifierForArbitraryString(text string) string {
}
if size > 0 && validChar {
if needsUnderscore {
identifier += "_"
identifier.WriteRune('_')
}
identifier += string(ch)
identifier.WriteRune(ch)
needsUnderscore = false
} else {
needsUnderscore = true
}
}

if needsUnderscore {
identifier += "_"
identifier.WriteRune('_')
}

// Default to "_" if the provided text was empty
if identifier == "" {
id := identifier.String()
if id == "" {
return "_"
}

return identifier
return id
}

// Copied from vscode TS extension.
Expand Down
2 changes: 1 addition & 1 deletion internal/ls/lsutil/userpreferences.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ func (p *UserPreferences) Parse(item any) *UserPreferences {
return nil
}

func (p *UserPreferences) parseWorker(config map[string]interface{}) {
func (p *UserPreferences) parseWorker(config map[string]any) {
// Process unstable preferences first so that they do not overwrite stable properties
if unstable, ok := config["unstable"]; ok {
// unstable properties must be named the same as userPreferences
Expand Down
12 changes: 2 additions & 10 deletions internal/ls/signaturehelp.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ls
import (
"context"
"fmt"
"slices"
"strings"

"github.com/microsoft/typescript-go/internal/ast"
Expand Down Expand Up @@ -586,7 +587,7 @@ func isSyntacticOwner(startingToken *ast.Node, node *ast.CallLikeExpression, sou
invocationChildren := getChildrenFromNonJSDocNode(node, sourceFile)
switch startingToken.Kind {
case ast.KindOpenParenToken, ast.KindCommaToken:
return containsNode(invocationChildren, startingToken)
return slices.Contains(invocationChildren, startingToken)
case ast.KindLessThanToken:
return containsPrecedingToken(startingToken, sourceFile, node.AsCallExpression().Expression)
default:
Expand Down Expand Up @@ -1102,15 +1103,6 @@ func getTokenFromNodeList(nodeList *ast.NodeList, nodeListParent *ast.Node, sour
return tokens
}

func containsNode(nodes []*ast.Node, node *ast.Node) bool {
for i := range nodes {
if nodes[i] == node {
return true
}
}
return false
}

func getArgumentListInfoForTemplate(tagExpression *ast.TaggedTemplateExpression, argumentIndex int, sourceFile *ast.SourceFile) *argumentListInfo {
// argumentCount is either 1 or (numSpans + 1) to account for the template strings array argument.
argumentCount := 1
Expand Down
6 changes: 2 additions & 4 deletions internal/module/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,9 @@ func runTraceBaseline(t *testing.T, test traceTestCase) {

var wg sync.WaitGroup
for _, call := range test.calls {
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
doCall(t, concurrentResolver, call, true /*skipLocations*/)
}()
})
}

wg.Wait()
Expand Down
2 changes: 1 addition & 1 deletion internal/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ func (p *Parser) isInSomeParsingContext() bool {
// We should be in at least one parsing context, be it SourceElements while parsing
// a SourceFile, or JSDocComment when lazily parsing JSDoc.
debug.Assert(p.parsingContexts != 0, "Missing parsing context")
for kind := ParsingContext(0); kind < PCCount; kind++ {
for kind := range PCCount {
if p.parsingContexts&(1<<kind) != 0 {
if p.isListElement(kind, true /*inErrorRecovery*/) || p.isListTerminator(kind) {
return true
Expand Down
2 changes: 1 addition & 1 deletion internal/project/ata/validatepackagename_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestValidatePackageName(t *testing.T) {
t.Parallel()
packageName := "a"
for range 8 {
packageName += packageName
packageName += packageName //nolint:perfsprint
}
status, _, _ := ata.ValidatePackageName(packageName)
assert.Equal(t, status, ata.NameTooLong)
Expand Down
6 changes: 2 additions & 4 deletions internal/project/background/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ func (q *Queue) Enqueue(ctx context.Context, fn func(context.Context)) {
}
q.mu.RUnlock()

q.wg.Add(1)
go func() {
defer q.wg.Done()
q.wg.Go(func() {
fn(ctx)
}()
})
}

// Wait waits for all active tasks to complete.
Expand Down
Loading
Loading