Skip to content

Commit cac1083

Browse files
renovate[bot]github-actions[bot]
authored andcommitted
chore(deps): update typescript-go digest to 865ec14 (#259)
Coming soon: The Renovate bot (GitHub App) will be renamed to Mend. PRs from Renovate will soon appear from 'Mend'. Learn more [here](https://redirect.github.com/renovatebot/renovate/discussions/37842). This PR contains the following updates: | Package | Update | Change | |---|---|---| | typescript-go | digest | `1ca5a2d` -> `865ec14` | --- ### Configuration 📅 **Schedule**: Branch creation - "before 9am" in timezone Asia/Shanghai, Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/oxc-project/tsgolint). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS45Ny4xMCIsInVwZGF0ZWRJblZlciI6IjQxLjk3LjEwIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119--> --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: github-actions <github-actions[bot]@users.noreply.github.com>
1 parent 68e2ffb commit cac1083

File tree

97 files changed

+7383
-2504
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+7383
-2504
lines changed

.github/workflows/autofix.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818

1919
- name: Restore dprint plugin cache
2020
id: cache-restore
21-
uses: actions/cache/restore@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
21+
uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
2222
with:
2323
key: dprint-${{ hashFiles('dprint.json') }}
2424
path: ~/.cache/dprint

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,6 @@ jobs:
8686
runs-on: ubuntu-latest
8787
steps:
8888
- uses: taiki-e/checkout-action@b13d20b7cda4e2f325ef19895128f7ff735c0b3d # v1.3.1
89-
- uses: crate-ci/typos@85f62a8a84f939ae994ab3763f01a0296d61a7ee # v1.36.2
89+
- uses: crate-ci/typos@80c8a4945eec0f6d464eaf9e65ed98ef085283d1 # v1.38.1
9090
with:
9191
files: .

.github/workflows/dprint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ jobs:
1717
steps:
1818
- uses: taiki-e/checkout-action@b13d20b7cda4e2f325ef19895128f7ff735c0b3d # v1.3.1
1919

20-
- uses: taiki-e/install-action@0e09747a63ae497bf945b3dcaf38fef0050d0109 # v2.62.0
20+
- uses: taiki-e/install-action@c5b1b6f479c32f356cc6f4ba672a47f63853b13b # v2.62.38
2121
with:
2222
tool: dprint
2323

2424
- run: dprint check
2525

2626
- name: Save dprint plugin cache
27-
uses: actions/cache/save@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
27+
uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
2828
with:
2929
key: dprint-${{ hashFiles('dprint.json') }}
3030
path: ~/.cache/dprint

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
run: just build
3434

3535
- name: Upload artifacts
36-
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
36+
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
3737
with:
3838
name: tsgolint-${{ matrix.goos }}-${{ matrix.goarch }}
3939
path: tsgolint
@@ -53,7 +53,7 @@ jobs:
5353
- uses: oxc-project/setup-node@fdbf0dfd334c4e6d56ceeb77d91c76339c2a0885 # v1.0.4
5454

5555
- name: Download artifacts
56-
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
56+
uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
5757
with:
5858
pattern: tsgolint-*
5959
path: build
@@ -77,7 +77,7 @@ jobs:
7777
done
7878
7979
- name: Create GitHub Release
80-
uses: softprops/action-gh-release@6cbd405e2c4e67a21c47fa9e383d020e4e28b836 # v2.3.3
80+
uses: softprops/action-gh-release@6da8fa9354ddfdc4aeace5fc48d7f679b5214090 # v2.4.1
8181
with:
8282
draft: false
8383
name: v${{ inputs.version }}

cmd/tsgolint/headless.go

Lines changed: 111 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,25 @@ type headlessSuggestion struct {
5959
Message headlessRuleMessage `json:"message"`
6060
Fixes []headlessFix `json:"fixes"`
6161
}
62+
63+
// Diagnostic kind discriminator
64+
type headlessDiagnosticKind uint8
65+
66+
const (
67+
headlessDiagnosticKindRule headlessDiagnosticKind = iota
68+
headlessDiagnosticKindTsconfig
69+
)
70+
6271
type headlessDiagnostic struct {
63-
Range headlessRange `json:"range"`
64-
Rule string `json:"rule"`
65-
Message headlessRuleMessage `json:"message"`
66-
Fixes []headlessFix `json:"fixes"`
67-
Suggestions []headlessSuggestion `json:"suggestions"`
68-
FilePath string `json:"file_path"`
72+
Kind headlessDiagnosticKind `json:"kind"`
73+
Range headlessRange `json:"range"`
74+
Message headlessRuleMessage `json:"message"`
75+
FilePath *string `json:"file_path"`
76+
77+
// Only for kind="rule"
78+
Rule *string `json:"rule,omitempty"`
79+
Fixes []headlessFix `json:"fixes,omitempty"`
80+
Suggestions []headlessSuggestion `json:"suggestions,omitempty"`
6981
}
7082

7183
type headlessMessageType uint8
@@ -79,6 +91,20 @@ type headlessMessagePayloadError struct {
7991
Error string `json:"error"`
8092
}
8193

94+
// Unified diagnostic type for channel
95+
type anyDiagnostic struct {
96+
ruleDiagnostic *rule.RuleDiagnostic
97+
internalDiagnostic *linter.InternalDiagnostic
98+
}
99+
100+
func ruleToAny(d rule.RuleDiagnostic) anyDiagnostic {
101+
return anyDiagnostic{ruleDiagnostic: &d}
102+
}
103+
104+
func internalToAny(d linter.InternalDiagnostic) anyDiagnostic {
105+
return anyDiagnostic{internalDiagnostic: &d}
106+
}
107+
82108
func writeMessage(w io.Writer, messageType headlessMessageType, payload any) error {
83109
payloadBytes, err := json.Marshal(payload)
84110
if err != nil {
@@ -102,15 +128,19 @@ func runHeadless(args []string) int {
102128
logLevel := utils.GetLogLevel()
103129

104130
var (
105-
traceOut string
106-
cpuprofOut string
107-
heapOut string
108-
allocsOut string
131+
traceOut string
132+
cpuprofOut string
133+
heapOut string
134+
allocsOut string
135+
fix bool
136+
fixSuggestions bool
109137
)
110138
flag.StringVar(&traceOut, "trace", "", "file to put trace to")
111139
flag.StringVar(&cpuprofOut, "cpuprof", "", "file to put cpu profiling to")
112140
flag.StringVar(&heapOut, "heap", "", "file to put heap profiling to")
113141
flag.StringVar(&allocsOut, "allocs", "", "file to put allocs profiling to")
142+
flag.BoolVar(&fix, "fix", false, "generate fixes for code problems")
143+
flag.BoolVar(&fixSuggestions, "fix-suggestions", false, "generate suggestions for code problems")
114144
flag.CommandLine.Parse(args)
115145

116146
log.SetOutput(os.Stderr)
@@ -138,8 +168,6 @@ func runHeadless(args []string) int {
138168
return 1
139169
}
140170

141-
fs := bundled.WrapFS(cachedvfs.From(osvfs.FS()))
142-
143171
configRaw, err := io.ReadAll(os.Stdin)
144172
if err != nil {
145173
writeErrorMessage(fmt.Sprintf("error reading from stdin: %v", err))
@@ -153,6 +181,12 @@ func runHeadless(args []string) int {
153181
return 1
154182
}
155183

184+
baseFS := osvfs.FS()
185+
if len(payload.SourceOverrides) > 0 {
186+
baseFS = newOverlayFS(baseFS, payload.SourceOverrides)
187+
}
188+
fs := bundled.WrapFS(cachedvfs.From(baseFS))
189+
156190
workload := linter.Workload{
157191
Programs: make(map[string][]string),
158192
UnmatchedFiles: []string{},
@@ -226,38 +260,71 @@ func runHeadless(args []string) int {
226260

227261
var wg sync.WaitGroup
228262

229-
diagnosticsChan := make(chan rule.RuleDiagnostic, 4096)
263+
diagnosticsChan := make(chan anyDiagnostic, 4096)
230264

265+
// Handle all diagnostics
231266
wg.Go(func() {
232267
w := bufio.NewWriterSize(os.Stdout, 4096*100)
233268
defer w.Flush()
234269
for d := range diagnosticsChan {
235-
hd := headlessDiagnostic{
236-
Range: headlessRangeFromRange(d.Range),
237-
Rule: d.RuleName,
238-
Message: headlessRuleMessageFromRuleMessage(d.Message),
239-
Fixes: make([]headlessFix, len(d.Fixes())),
240-
Suggestions: make([]headlessSuggestion, len(d.GetSuggestions())),
241-
FilePath: d.SourceFile.FileName(),
242-
}
243-
for i, fix := range d.Fixes() {
244-
hd.Fixes[i] = headlessFix{
245-
Text: fix.Text,
246-
Range: headlessRangeFromRange(fix.Range),
270+
var hd headlessDiagnostic
271+
272+
if d.ruleDiagnostic != nil {
273+
// Rule diagnostic
274+
rd := d.ruleDiagnostic
275+
filePath := rd.SourceFile.FileName()
276+
hd = headlessDiagnostic{
277+
Kind: headlessDiagnosticKindRule,
278+
Range: headlessRangeFromRange(rd.Range),
279+
Rule: &rd.RuleName,
280+
Message: headlessRuleMessageFromRuleMessage(rd.Message),
281+
Fixes: nil,
282+
Suggestions: nil,
283+
FilePath: &filePath,
247284
}
248-
}
249-
for i, suggestion := range d.GetSuggestions() {
250-
hd.Suggestions[i] = headlessSuggestion{
251-
Message: headlessRuleMessageFromRuleMessage(d.Message),
252-
Fixes: make([]headlessFix, len(suggestion.Fixes())),
285+
286+
if fix {
287+
hd.Fixes = make([]headlessFix, len(rd.Fixes()))
288+
for i, fix := range rd.Fixes() {
289+
hd.Fixes[i] = headlessFix{
290+
Text: fix.Text,
291+
Range: headlessRangeFromRange(fix.Range),
292+
}
293+
}
253294
}
254-
for j, fix := range suggestion.Fixes() {
255-
hd.Suggestions[i].Fixes[j] = headlessFix{
256-
Text: fix.Text,
257-
Range: headlessRangeFromRange(fix.Range),
295+
if fixSuggestions {
296+
hd.Suggestions = make([]headlessSuggestion, len(rd.GetSuggestions()))
297+
for i, suggestion := range rd.GetSuggestions() {
298+
hd.Suggestions[i] = headlessSuggestion{
299+
Message: headlessRuleMessageFromRuleMessage(rd.Message),
300+
Fixes: make([]headlessFix, len(suggestion.Fixes())),
301+
}
302+
for j, fix := range suggestion.Fixes() {
303+
hd.Suggestions[i].Fixes[j] = headlessFix{
304+
Text: fix.Text,
305+
Range: headlessRangeFromRange(fix.Range),
306+
}
307+
}
258308
}
259309
}
310+
} else if d.internalDiagnostic != nil {
311+
// Internal diagnostic (tsconfig, type error, etc.)
312+
internalDiagnostic := d.internalDiagnostic
313+
314+
hd = headlessDiagnostic{
315+
Kind: headlessDiagnosticKindTsconfig,
316+
Range: headlessRange{},
317+
Rule: nil, // Internal diagnostics don't have a rule
318+
Message: headlessRuleMessage{
319+
Id: internalDiagnostic.Id,
320+
Description: internalDiagnostic.Description,
321+
},
322+
Fixes: nil,
323+
Suggestions: nil,
324+
FilePath: nil,
325+
}
260326
}
327+
261328
writeMessage(w, headlessMessageTypeDiagnostic, hd)
262329
if w.Available() < 4096 {
263330
w.Flush()
@@ -274,6 +341,7 @@ func runHeadless(args []string) int {
274341
cwd,
275342
workload,
276343
runtime.GOMAXPROCS(0),
344+
fs,
277345
func(sourceFile *ast.SourceFile) []linter.ConfiguredRule {
278346
cfg := fileConfigs[sourceFile.FileName()]
279347
rules := make([]linter.ConfiguredRule, len(cfg))
@@ -286,15 +354,22 @@ func runHeadless(args []string) int {
286354
rules[i] = linter.ConfiguredRule{
287355
Name: r.Name,
288356
Run: func(ctx rule.RuleContext) rule.RuleListeners {
289-
return r.Run(ctx, nil)
357+
return r.Run(ctx, headlessRule.Options)
290358
},
291359
}
292360
}
293361

294362
return rules
295363
},
296364
func(d rule.RuleDiagnostic) {
297-
diagnosticsChan <- d
365+
diagnosticsChan <- ruleToAny(d)
366+
},
367+
func(d linter.InternalDiagnostic) {
368+
diagnosticsChan <- internalToAny(d)
369+
},
370+
linter.Fixes{
371+
Fix: fix,
372+
FixSuggestions: fixSuggestions,
298373
},
299374
)
300375

cmd/tsgolint/main.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import (
5757
"github.com/typescript-eslint/tsgolint/internal/rules/restrict_plus_operands"
5858
"github.com/typescript-eslint/tsgolint/internal/rules/restrict_template_expressions"
5959
"github.com/typescript-eslint/tsgolint/internal/rules/return_await"
60+
"github.com/typescript-eslint/tsgolint/internal/rules/strict_boolean_expressions"
6061
"github.com/typescript-eslint/tsgolint/internal/rules/switch_exhaustiveness_check"
6162
"github.com/typescript-eslint/tsgolint/internal/rules/unbound_method"
6263
"github.com/typescript-eslint/tsgolint/internal/rules/use_unknown_in_catch_callback_variable"
@@ -156,6 +157,7 @@ var allRules = []rule.Rule{
156157
restrict_plus_operands.RestrictPlusOperandsRule,
157158
restrict_template_expressions.RestrictTemplateExpressionsRule,
158159
return_await.ReturnAwaitRule,
160+
strict_boolean_expressions.StrictBooleanExpressionsRule,
159161
switch_exhaustiveness_check.SwitchExhaustivenessCheckRule,
160162
unbound_method.UnboundMethodRule,
161163
use_unknown_in_catch_callback_variable.UseUnknownInCatchCallbackVariableRule,
@@ -175,23 +177,23 @@ func printDiagnostic(d rule.RuleDiagnostic, w *bufio.Writer, comparePathOptions
175177
diagnosticStart := d.Range.Pos()
176178
diagnosticEnd := d.Range.End()
177179

178-
diagnosticStartLine, diagnosticStartColumn := scanner.GetLineAndCharacterOfPosition(d.SourceFile, diagnosticStart)
179-
diagnosticEndline, _ := scanner.GetLineAndCharacterOfPosition(d.SourceFile, diagnosticEnd)
180+
diagnosticStartLine, diagnosticStartColumn := scanner.GetECMALineAndCharacterOfPosition(d.SourceFile, diagnosticStart)
181+
diagnosticEndline, _ := scanner.GetECMALineAndCharacterOfPosition(d.SourceFile, diagnosticEnd)
180182

181-
lineMap := d.SourceFile.LineMap()
183+
lineMap := d.SourceFile.ECMALineMap()
182184
text := d.SourceFile.Text()
183185

184186
codeboxStartLine := max(diagnosticStartLine-1, 0)
185187
codeboxEndLine := min(diagnosticEndline+1, len(lineMap)-1)
186188

187-
codeboxStart := scanner.GetPositionOfLineAndCharacter(d.SourceFile, codeboxStartLine, 0)
189+
codeboxStart := scanner.GetECMAPositionOfLineAndCharacter(d.SourceFile, codeboxStartLine, 0)
188190
var codeboxEndColumn int
189191
if codeboxEndLine == len(lineMap)-1 {
190192
codeboxEndColumn = len(text) - int(lineMap[len(lineMap)-1])
191193
} else {
192194
codeboxEndColumn = int(lineMap[codeboxEndLine+1]-lineMap[codeboxEndLine]) - 1
193195
}
194-
codeboxEnd := scanner.GetPositionOfLineAndCharacter(d.SourceFile, codeboxEndLine, codeboxEndColumn)
196+
codeboxEnd := scanner.GetECMAPositionOfLineAndCharacter(d.SourceFile, codeboxEndLine, codeboxEndColumn)
195197

196198
w.Write([]byte{' ', 0x1b, '[', '7', 'm', 0x1b, '[', '1', 'm', 0x1b, '[', '3', '8', ';', '5', ';', '3', '7', 'm', ' '})
197199
w.WriteString(d.RuleName)
@@ -400,7 +402,7 @@ func runMain() int {
400402
UseCaseSensitiveFileNames: host.FS().UseCaseSensitiveFileNames(),
401403
}
402404

403-
program, err := utils.CreateProgram(singleThreaded, fs, currentDirectory, configFileName, host)
405+
program, _, err := utils.CreateProgram(singleThreaded, fs, currentDirectory, configFileName, host)
404406
if err != nil {
405407
fmt.Fprintf(os.Stderr, "error creating TS program: %v", err)
406408
return 1
@@ -468,6 +470,10 @@ func runMain() int {
468470
func(d rule.RuleDiagnostic) {
469471
diagnosticsChan <- d
470472
},
473+
linter.Fixes{
474+
Fix: true,
475+
FixSuggestions: true,
476+
},
471477
)
472478

473479
close(diagnosticsChan)

0 commit comments

Comments
 (0)