Make lint_only aware of the source kind (#5876)

This commit is contained in:
Dhruv Manilawala 2023-07-19 09:29:35 +05:30 committed by GitHub
parent 1181d25e5a
commit 7e6b472c5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 3 deletions

View file

@ -321,6 +321,7 @@ pub fn lint_only(
package: Option<&Path>,
settings: &Settings,
noqa: flags::Noqa,
source_kind: Option<&SourceKind>,
) -> LinterResult<(Vec<Message>, Option<ImportMap>)> {
// Tokenize once.
let tokens: Vec<LexResult> = ruff_rustpython::tokenize(contents);
@ -353,7 +354,7 @@ pub fn lint_only(
&directives,
settings,
noqa,
None,
source_kind,
);
result.map(|(diagnostics, imports)| {

View file

@ -63,6 +63,7 @@ fn benchmark_linter(mut group: BenchmarkGroup<WallTime>, settings: &Settings) {
None,
settings,
flags::Noqa::Enabled,
None,
);
// Assert that file contains no parse errors

View file

@ -204,12 +204,26 @@ pub(crate) fn lint_path(
(result, fixed)
} else {
// If we fail to autofix, lint the original source code.
let result = lint_only(&contents, path, package, &settings.lib, noqa);
let result = lint_only(
&contents,
path,
package,
&settings.lib,
noqa,
Some(&source_kind),
);
let fixed = FxHashMap::default();
(result, fixed)
}
} else {
let result = lint_only(&contents, path, package, &settings.lib, noqa);
let result = lint_only(
&contents,
path,
package,
&settings.lib,
noqa,
Some(&source_kind),
);
let fixed = FxHashMap::default();
(result, fixed)
};
@ -316,6 +330,7 @@ pub(crate) fn lint_stdin(
package,
settings,
noqa,
Some(&source_kind),
);
let fixed = FxHashMap::default();
@ -333,6 +348,7 @@ pub(crate) fn lint_stdin(
package,
settings,
noqa,
Some(&source_kind),
);
let fixed = FxHashMap::default();
(result, fixed)