lintFiles walks the `root` directory, creating a new goroutine to lint any file that matches the given glob pattern.
(done <-chan core.File, root string)
| 116 | // lintFiles walks the `root` directory, creating a new goroutine to lint any |
| 117 | // file that matches the given glob pattern. |
| 118 | func (l *Linter) lintFiles(done <-chan core.File, root string) (<-chan lintResult, <-chan error) { |
| 119 | filesChan := make(chan lintResult) |
| 120 | errChan := make(chan error, 1) |
| 121 | |
| 122 | go func() { |
| 123 | wg := sizedwaitgroup.New(5) |
| 124 | |
| 125 | err := system.Walk(root, func(fp string, info fs.FileInfo, err error) error { |
| 126 | if err != nil { |
| 127 | return err |
| 128 | } |
| 129 | |
| 130 | if info.IsDir() && core.ShouldIgnoreDirectory(fp) { |
| 131 | return filepath.SkipDir |
| 132 | } else if info.IsDir() || l.skip(fp) { |
| 133 | return nil |
| 134 | } |
| 135 | |
| 136 | wg.Add() |
| 137 | go func(fp string) { |
| 138 | select { |
| 139 | case filesChan <- l.lintFile(fp): |
| 140 | case <-done: |
| 141 | } |
| 142 | wg.Done() |
| 143 | }(fp) |
| 144 | |
| 145 | // Abort the walk if done is closed. |
| 146 | select { |
| 147 | case <-done: |
| 148 | return errors.New("walk canceled") |
| 149 | default: |
| 150 | return nil |
| 151 | } |
| 152 | }) |
| 153 | |
| 154 | // Walk has returned, so all calls to wg.Add are done. Start a |
| 155 | // goroutine to close c once all the sends are done. |
| 156 | go func() { |
| 157 | wg.Wait() |
| 158 | close(filesChan) |
| 159 | }() |
| 160 | errChan <- err |
| 161 | }() |
| 162 | |
| 163 | return filesChan, errChan |
| 164 | } |
| 165 | |
| 166 | // lintFile creates a new `File` from the path `src` and selects a linter based |
| 167 | // on its format. |
no test coverage detected