44 "context"
55 "fmt"
66 "log"
7+ "strconv"
78 "strings"
89
910 "github.com/typescript-eslint/tsgolint/internal/diagnostic"
@@ -34,6 +35,11 @@ type Fixes struct {
3435 FixSuggestions bool
3536}
3637
38+ type TypeErrors struct {
39+ ReportSyntactic bool
40+ ReportSemantic bool
41+ }
42+
3743func RunLinter (
3844 logLevel utils.LogLevel ,
3945 currentDirectory string ,
@@ -44,6 +50,7 @@ func RunLinter(
4450 onRuleDiagnostic func (diagnostic rule.RuleDiagnostic ),
4551 onInternalDiagnostic func (d diagnostic.Internal ),
4652 fixState Fixes ,
53+ typeErrors TypeErrors ,
4754) error {
4855
4956 idx := 0
@@ -99,7 +106,7 @@ func RunLinter(
99106 panic (fmt .Sprintf ("Expected file '%s' to be in program '%s'" , unmatchedFilesString , configFileName ))
100107 }
101108
102- err = RunLinterOnProgram (logLevel , program , sourceFiles , workers , getRulesForFile , onRuleDiagnostic , fixState )
109+ err = RunLinterOnProgram (logLevel , program , sourceFiles , workers , getRulesForFile , onRuleDiagnostic , onInternalDiagnostic , fixState , typeErrors )
103110 if err != nil {
104111 return err
105112 }
@@ -130,7 +137,7 @@ func RunLinter(
130137 files = append (files , sf )
131138 }
132139
133- err = RunLinterOnProgram (logLevel , program , files , workers , getRulesForFile , onRuleDiagnostic , fixState )
140+ err = RunLinterOnProgram (logLevel , program , files , workers , getRulesForFile , onRuleDiagnostic , onInternalDiagnostic , fixState , typeErrors )
134141 if err != nil {
135142 return err
136143 }
@@ -140,7 +147,7 @@ func RunLinter(
140147
141148}
142149
143- func RunLinterOnProgram (logLevel utils.LogLevel , program * compiler.Program , files []* ast.SourceFile , workers int , getRulesForFile func (sourceFile * ast.SourceFile ) []ConfiguredRule , onDiagnostic func (diagnostic rule.RuleDiagnostic ), fixState Fixes ) error {
150+ func RunLinterOnProgram (logLevel utils.LogLevel , program * compiler.Program , files []* ast.SourceFile , workers int , getRulesForFile func (sourceFile * ast.SourceFile ) []ConfiguredRule , onDiagnostic func (diagnostic rule.RuleDiagnostic ), onInternalDiagnostic func ( d diagnostic. Internal ), fixState Fixes , typeErrors TypeErrors ) error {
144151 type checkerWorkload struct {
145152 checker * checker.Checker
146153 program * compiler.Program
@@ -157,6 +164,41 @@ func RunLinterOnProgram(logLevel utils.LogLevel, program *compiler.Program, file
157164 program .BindSourceFiles ()
158165
159166 ctx := core .WithRequestID (context .Background (), "__single_run__" )
167+
168+ if typeErrors .ReportSyntactic || typeErrors .ReportSemantic {
169+ for _ , file := range files {
170+ fileName := file .FileName ()
171+
172+ if typeErrors .ReportSyntactic {
173+ syntacticDiagnostics := program .GetSyntacticDiagnostics (ctx , file )
174+ for _ , d := range syntacticDiagnostics {
175+ if d .File () != nil && d .File ().FileName () == fileName {
176+ onInternalDiagnostic (diagnostic.Internal {
177+ Range : d .Loc (),
178+ Id : "TS" + strconv .Itoa (int (d .Code ())),
179+ Description : d .Message (),
180+ FilePath : & fileName ,
181+ })
182+ }
183+ }
184+ }
185+
186+ if typeErrors .ReportSemantic {
187+ semanticDiagnostics := program .GetSemanticDiagnostics (ctx , file )
188+ for _ , d := range semanticDiagnostics {
189+ if d .File () != nil && d .File ().FileName () == fileName {
190+ onInternalDiagnostic (diagnostic.Internal {
191+ Range : d .Loc (),
192+ Id : "TS" + strconv .Itoa (int (d .Code ())),
193+ Description : d .Message (),
194+ FilePath : & fileName ,
195+ })
196+ }
197+ }
198+ }
199+ }
200+ }
201+
160202 program .ForEachCheckerParallel (ctx , func (idx int , ch * checker.Checker ) {
161203 flatQueue = append (flatQueue , checkerWorkload {ch , program , queue })
162204 })
0 commit comments