Skip to content

Commit 7aadbe6

Browse files
hardfistAmour1688
authored andcommitted
fix: only lint opened file (#151)
1 parent f9ae2cd commit 7aadbe6

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

cmd/rslint/lsp.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,11 +426,13 @@ func runLintWithPrograms(uri lsproto.DocumentUri, programs []*compiler.Program,
426426
defer diagnosticsLock.Unlock()
427427
diagnostics = append(diagnostics, d)
428428
}
429+
filename := uriToPath(string(uri))
430+
429431
// Run linter with all programs using rule registry
430432
_, err := linter.RunLinter(
431433
programs,
432434
false, // Don't use single-threaded mode for LSP
433-
nil,
435+
[]string{filename},
434436
func(sourceFile *ast.SourceFile) []linter.ConfiguredRule {
435437
activeRules := config.GlobalRuleRegistry.GetEnabledRules(rslintConfig, sourceFile.FileName())
436438
return activeRules

internal/linter/linter.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type ConfiguredRule struct {
2121

2222
// when allowedFiles is passed as nil which means all files are allowed
2323
// when allowedFiles is passed as slice, only files in the slice are allowed
24-
func RunLinter(programs []*compiler.Program, singleThreaded bool, allowFiles []*ast.SourceFile, getRulesForFile func(sourceFile *ast.SourceFile) []ConfiguredRule, onDiagnostic func(diagnostic rule.RuleDiagnostic)) (int32, error) {
24+
func RunLinter(programs []*compiler.Program, singleThreaded bool, allowFiles []string, getRulesForFile func(sourceFile *ast.SourceFile) []ConfiguredRule, onDiagnostic func(diagnostic rule.RuleDiagnostic)) (int32, error) {
2525

2626
wg := core.NewWorkGroup(singleThreaded)
2727

@@ -33,7 +33,6 @@ func RunLinter(programs []*compiler.Program, singleThreaded bool, allowFiles []*
3333

3434
wg.Queue(func() {
3535
for _, file := range program.GetSourceFiles() {
36-
3736
p := string(file.Path())
3837
// skip lint node_modules and bundled files
3938
// FIXME: we may have better api to tell whether a file is a bundled file or not
@@ -43,8 +42,9 @@ func RunLinter(programs []*compiler.Program, singleThreaded bool, allowFiles []*
4342
// only lint allowedFiles if allowedFiles is not empty
4443
if allowFiles != nil {
4544
found := false
46-
for _, f := range allowFiles {
47-
if f.Path() == file.Path() {
45+
for _, filePath := range allowFiles {
46+
47+
if filePath == file.FileName() {
4848
found = true
4949
break
5050
}

internal/rule_tester/rule_tester.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,13 @@ func RunRuleTester(rootDir string, tsconfigPath string, t *testing.T, r *rule.Ru
7676
program, err := utils.CreateProgram(true, fs, rootDir, tsconfigPath, host)
7777
assert.NilError(t, err, "couldn't create program. code: "+code)
7878

79-
files := []*ast.SourceFile{program.GetSourceFile(fileName)}
79+
sourceFile := program.GetSourceFile(fileName)
80+
allowedFiles := []string{string(sourceFile.Path())}
8081

8182
_, err = linter.RunLinter(
8283
[]*compiler.Program{program},
8384
true,
84-
files,
85+
allowedFiles,
8586
func(sourceFile *ast.SourceFile) []linter.ConfiguredRule {
8687
return []linter.ConfiguredRule{
8788
{

0 commit comments

Comments
 (0)