lintFile creates a new `File` from the path `src` and selects a linter based on its format.
(src string)
| 166 | // lintFile creates a new `File` from the path `src` and selects a linter based |
| 167 | // on its format. |
| 168 | func (l *Linter) lintFile(src string) lintResult { |
| 169 | var err error |
| 170 | |
| 171 | file, err := core.NewFile(src, l.Manager.Config) |
| 172 | if err != nil { |
| 173 | return lintResult{err: err} |
| 174 | } else if len(file.Checks) == 0 && len(file.BaseStyles) == 0 { |
| 175 | if len(l.Manager.Config.GBaseStyles) == 0 && len(l.Manager.Config.GChecks) == 0 { |
| 176 | // There's nothing to do; bail early. |
| 177 | return lintResult{file: file} |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | // Determine what NLP tasks this particular file needs; the goal is to do |
| 182 | // the least amount of work possible. |
| 183 | file.NLP = l.Manager.AssignNLP(file) |
| 184 | simple := l.Manager.Config.Flags.Simple |
| 185 | |
| 186 | // NOTE: This is a sanity check to ensure that we don't run any checks that |
| 187 | // we actually have a View to apply. |
| 188 | hasViews := len(l.Manager.Config.Views) > 0 |
| 189 | |
| 190 | if file.Format == "markup" && !simple { //nolint:gocritic |
| 191 | switch file.NormedExt { |
| 192 | case ".adoc": |
| 193 | err = l.lintADoc(file) |
| 194 | case ".md": |
| 195 | err = l.lintMarkdown(file) |
| 196 | case ".mdx": |
| 197 | err = l.lintMDX(file) |
| 198 | case ".rst": |
| 199 | err = l.lintRST(file) |
| 200 | case ".xml", ".xsd": |
| 201 | err = l.lintXML(file) |
| 202 | case ".dita": |
| 203 | err = l.lintDITA(file) |
| 204 | case ".html": |
| 205 | err = l.lintHTML(file) |
| 206 | case ".org": |
| 207 | err = l.lintOrg(file) |
| 208 | } |
| 209 | } else if file.Format == "data" && !simple && hasViews { |
| 210 | err = l.lintData(file) |
| 211 | } else if file.Format == "code" && !simple { |
| 212 | err = l.lintCode(file) |
| 213 | } else if file.Format == "fragment" && !simple { |
| 214 | err = l.lintFragments(file) |
| 215 | } else if file.NormedExt == ".txt" && !simple { |
| 216 | err = l.lintTxt(file) |
| 217 | } else { |
| 218 | err = l.lintLines(file) |
| 219 | } |
| 220 | |
| 221 | if err == nil { |
| 222 | // Run all rules with `scope: raw` |
| 223 | // |
| 224 | // NOTE: We need to use `f.Lines` (instead of `f.Content`) to ensure |
| 225 | // that we don't include any markup preprocessing. |