Skip to content

Commit e84065c

Browse files
authored
Update golangci-lint, fix issues, modernize (#1981)
1 parent fd94be3 commit e84065c

File tree

30 files changed

+78
-100
lines changed

30 files changed

+78
-100
lines changed

.custom-gcl.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# yaml-language-server: $schema=https://golangci-lint.run/jsonschema/custom-gcl.jsonschema.json
22

3-
version: v2.5.0
3+
version: v2.6.0
44

55
destination: ./_tools
66

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ linters:
3333
- makezero
3434
- mirror
3535
- misspell
36+
- modernize
3637
- musttag
3738
- nakedret
3839
- nolintlint

internal/ast/ast.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func visit(v Visitor, node *Node) bool {
2424
}
2525

2626
func visitNodes(v Visitor, nodes []*Node) bool {
27-
for _, node := range nodes {
27+
for _, node := range nodes { //nolint:modernize
2828
if v(node) {
2929
return true
3030
}

internal/binder/binder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2640,7 +2640,7 @@ func isNarrowableReference(node *ast.Node) bool {
26402640

26412641
func hasNarrowableArgument(expr *ast.Node) bool {
26422642
call := expr.AsCallExpression()
2643-
for _, argument := range call.Arguments.Nodes {
2643+
for _, argument := range call.Arguments.Nodes { //nolint:modernize
26442644
if containsNarrowableReference(argument) {
26452645
return true
26462646
}

internal/checker/grammarchecks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ func (c *Checker) checkGrammarHeritageClause(node *ast.HeritageClause) bool {
900900
return c.grammarErrorAtPos(node.AsNode(), types.Pos(), 0, diagnostics.X_0_list_cannot_be_empty, listType)
901901
}
902902

903-
for _, node := range types.Nodes {
903+
for _, node := range types.Nodes { //nolint:modernize
904904
if c.checkGrammarExpressionWithTypeArguments(node) {
905905
return true
906906
}

internal/checker/mapper.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package checker
22

3-
import "github.com/microsoft/typescript-go/internal/core"
3+
import (
4+
"slices"
5+
6+
"github.com/microsoft/typescript-go/internal/core"
7+
)
48

59
// TypeMapperKind
610

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

160164
func (m *ArrayToSingleTypeMapper) Map(t *Type) *Type {
161-
for _, s := range m.sources {
162-
if t == s {
163-
return m.target
164-
}
165+
if slices.Contains(m.sources, t) {
166+
return m.target
165167
}
166168
return t
167169
}

internal/checker/nodebuilderimpl.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2034,10 +2034,8 @@ func (b *NodeBuilderImpl) shouldUsePlaceholderForProperty(propertySymbol *ast.Sy
20342034
return false
20352035
}
20362036
// (1)
2037-
for _, elem := range b.ctx.reverseMappedStack {
2038-
if elem == propertySymbol {
2039-
return true
2040-
}
2037+
if slices.Contains(b.ctx.reverseMappedStack, propertySymbol) {
2038+
return true
20412039
}
20422040
// (2)
20432041
if len(b.ctx.reverseMappedStack) > 0 {

internal/compiler/fileloader.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -631,16 +631,22 @@ func getLibraryNameFromLibFileName(libFileName string) string {
631631
// lib.dom.iterable.d.ts -> @typescript/lib-dom/iterable
632632
// lib.es2015.symbol.wellknown.d.ts -> @typescript/lib-es2015/symbol-wellknown
633633
components := strings.Split(libFileName, ".")
634-
var path string
634+
var path strings.Builder
635+
path.WriteString("@typescript/lib-")
635636
if len(components) > 1 {
636-
path = components[1]
637+
path.WriteString(components[1])
637638
}
638639
i := 2
639640
for i < len(components) && components[i] != "" && components[i] != "d" {
640-
path += core.IfElse(i == 2, "/", "-") + components[i]
641+
if i == 2 {
642+
path.WriteByte('/')
643+
} else {
644+
path.WriteByte('-')
645+
}
646+
path.WriteString(components[i])
641647
i++
642648
}
643-
return "@typescript/lib-" + path
649+
return path.String()
644650
}
645651

646652
func getInferredLibraryNameResolveFrom(options *core.CompilerOptions, currentDirectory string, libFileName string) string {

internal/compiler/projectreferenceparser.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package compiler
22

33
import (
4+
"maps"
5+
46
"github.com/microsoft/typescript-go/internal/collections"
57
"github.com/microsoft/typescript-go/internal/core"
68
"github.com/microsoft/typescript-go/internal/tsoptions"
@@ -91,12 +93,8 @@ func (p *projectReferenceParser) initMapperWorker(tasks []*projectReferenceParse
9193
if task.resolved == nil || p.loader.projectReferenceFileMapper.opts.Config.ConfigFile == task.resolved.ConfigFile {
9294
continue
9395
}
94-
for key, value := range task.resolved.SourceToProjectReference() {
95-
p.loader.projectReferenceFileMapper.sourceToProjectReference[key] = value
96-
}
97-
for key, value := range task.resolved.OutputDtsToProjectReference() {
98-
p.loader.projectReferenceFileMapper.outputDtsToProjectReference[key] = value
99-
}
96+
maps.Copy(p.loader.projectReferenceFileMapper.sourceToProjectReference, task.resolved.SourceToProjectReference())
97+
maps.Copy(p.loader.projectReferenceFileMapper.outputDtsToProjectReference, task.resolved.OutputDtsToProjectReference())
10098
if p.loader.projectReferenceFileMapper.opts.canUseProjectReferenceSource() {
10199
declDir := task.resolved.CompilerOptions().DeclarationDir
102100
if declDir == "" {

internal/core/core.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func Same[T any](s1 []T, s2 []T) bool {
160160
}
161161

162162
func Some[T any](slice []T, f func(T) bool) bool {
163-
for _, value := range slice {
163+
for _, value := range slice { //nolint:modernize
164164
if f(value) {
165165
return true
166166
}
@@ -407,12 +407,9 @@ func ComputeECMALineStartsSeq(text string) iter.Seq[TextPos] {
407407
}
408408

409409
func PositionToLineAndCharacter(position int, lineStarts []TextPos) (line int, character int) {
410-
line = sort.Search(len(lineStarts), func(i int) bool {
410+
line = max(sort.Search(len(lineStarts), func(i int) bool {
411411
return int(lineStarts[i]) > position
412-
}) - 1
413-
if line < 0 {
414-
line = 0
415-
}
412+
})-1, 0)
416413
return line, position - int(lineStarts[line])
417414
}
418415

0 commit comments

Comments
 (0)