44 "fmt"
55 "go/ast"
66 "go/token"
7+ "os"
78 "strings"
89 "unicode"
910
@@ -12,50 +13,38 @@ import (
1213
1314 "github.com/golangci/golangci-lint/pkg/config"
1415 "github.com/golangci/golangci-lint/pkg/goanalysis"
15- "github.com/golangci/golangci-lint/pkg/lint/linter "
16+ "github.com/golangci/golangci-lint/pkg/golinters/internal "
1617)
1718
1819const linterName = "misspell"
1920
2021func New (settings * config.MisspellSettings ) * goanalysis.Linter {
21- analyzer := & analysis.Analyzer {
22- Name : linterName ,
23- Doc : goanalysis .TheOnlyanalyzerDoc ,
24- Run : goanalysis .DummyRun ,
22+ replacer , err := createMisspellReplacer (settings )
23+ if err != nil {
24+ internal .LinterLogger .Fatalf ("%s: %v" , linterName , err )
2525 }
2626
27- return goanalysis .NewLinter (
28- linterName ,
29- "Finds commonly misspelled English words" ,
30- []* analysis.Analyzer {analyzer },
31- nil ,
32- ).WithContextSetter (func (lintCtx * linter.Context ) {
33- replacer , ruleErr := createMisspellReplacer (settings )
34-
35- analyzer .Run = func (pass * analysis.Pass ) (any , error ) {
36- if ruleErr != nil {
37- return nil , ruleErr
38- }
39-
40- err := runMisspell (lintCtx , pass , replacer , settings .Mode )
41- if err != nil {
42- return nil , err
27+ a := & analysis.Analyzer {
28+ Name : linterName ,
29+ Doc : "Finds commonly misspelled English words" ,
30+ Run : func (pass * analysis.Pass ) (any , error ) {
31+ for _ , file := range pass .Files {
32+ err := runMisspellOnFile (pass , file , replacer , settings .Mode )
33+ if err != nil {
34+ return nil , err
35+ }
4336 }
4437
4538 return nil , nil
46- }
47- }).WithLoadMode (goanalysis .LoadModeSyntax )
48- }
49-
50- func runMisspell (lintCtx * linter.Context , pass * analysis.Pass , replacer * misspell.Replacer , mode string ) error {
51- for _ , file := range pass .Files {
52- err := runMisspellOnFile (lintCtx , pass , file , replacer , mode )
53- if err != nil {
54- return err
55- }
39+ },
5640 }
5741
58- return nil
42+ return goanalysis .NewLinter (
43+ a .URL ,
44+ a .Doc ,
45+ []* analysis.Analyzer {a },
46+ nil ,
47+ ).WithLoadMode (goanalysis .LoadModeSyntax )
5948}
6049
6150func createMisspellReplacer (settings * config.MisspellSettings ) (* misspell.Replacer , error ) {
@@ -90,13 +79,13 @@ func createMisspellReplacer(settings *config.MisspellSettings) (*misspell.Replac
9079 return replacer , nil
9180}
9281
93- func runMisspellOnFile (lintCtx * linter. Context , pass * analysis.Pass , file * ast.File , replacer * misspell.Replacer , mode string ) error {
82+ func runMisspellOnFile (pass * analysis.Pass , file * ast.File , replacer * misspell.Replacer , mode string ) error {
9483 position , isGoFile := goanalysis .GetGoFilePosition (pass , file )
9584 if ! isGoFile {
9685 return nil
9786 }
9887
99- fileContent , err := lintCtx . FileCache . GetFileBytes (position .Filename )
88+ fileContent , err := os . ReadFile (position .Filename )
10089 if err != nil {
10190 return fmt .Errorf ("can't get file %s contents: %w" , position .Filename , err )
10291 }
0 commit comments