Skip to content

Make lint_only aware of the source kind #5876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/ruff/src/linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -353,7 +354,7 @@ pub fn lint_only(
&directives,
settings,
noqa,
None,
source_kind,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this not be optional? Seems like maybe it should be required everywhere 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should be. It probably needs to be defined at a top level and I've a local branch where I worked on that a bit. I'll be looking into it soon.

);

result.map(|(diagnostics, imports)| {
Expand Down
1 change: 1 addition & 0 deletions crates/ruff_benchmark/benches/linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 18 additions & 2 deletions crates/ruff_cli/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};
Expand Down Expand Up @@ -316,6 +330,7 @@ pub(crate) fn lint_stdin(
package,
settings,
noqa,
Some(&source_kind),
);
let fixed = FxHashMap::default();

Expand All @@ -333,6 +348,7 @@ pub(crate) fn lint_stdin(
package,
settings,
noqa,
Some(&source_kind),
);
let fixed = FxHashMap::default();
(result, fixed)
Expand Down