-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Make SourceKind
a required parameter
#7013
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,15 +10,6 @@ pub enum SourceKind { | |
} | ||
|
||
impl SourceKind { | ||
/// Return the [`Notebook`] if the source kind is [`SourceKind::IpyNotebook`]. | ||
pub fn notebook(&self) -> Option<&Notebook> { | ||
if let Self::IpyNotebook(notebook) = self { | ||
Some(notebook) | ||
} else { | ||
None | ||
} | ||
} | ||
|
||
Comment on lines
-13
to
-21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not required because of |
||
#[must_use] | ||
pub(crate) fn updated(&self, new_source: String, source_map: &SourceMap) -> Self { | ||
match self { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ use ruff_python_ast::{PySourceType, SourceType}; | |
use ruff_workspace::resolver::{python_files_in_path, PyprojectConfig}; | ||
|
||
use crate::args::Overrides; | ||
use crate::diagnostics::LintSource; | ||
|
||
/// Add `noqa` directives to a collection of files. | ||
pub(crate) fn add_noqa( | ||
|
@@ -56,7 +57,15 @@ pub(crate) fn add_noqa( | |
.and_then(|parent| package_roots.get(parent)) | ||
.and_then(|package| *package); | ||
let settings = resolver.resolve(path, pyproject_config); | ||
match add_noqa_to_path(path, package, source_type, settings) { | ||
let LintSource(source_kind) = match LintSource::try_from_path(path, source_type) { | ||
Ok(Some(source)) => source, | ||
Ok(None) => return None, | ||
Err(e) => { | ||
error!("Failed to extract source from {}: {e}", path.display()); | ||
return None; | ||
} | ||
}; | ||
match add_noqa_to_path(path, package, &source_kind, source_type, settings) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe unify the error handling either by using |
||
Ok(count) => Some(count), | ||
Err(e) => { | ||
error!("Failed to add noqa to {}: {e}", path.display()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the main change in this section of the diff otherwise it's just a formatter change.