Skip to content
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

Use function range for no-self-use #8637

Merged
merged 1 commit into from
Nov 12, 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
15 changes: 8 additions & 7 deletions crates/ruff_linter/src/rules/pylint/rules/no_self_use.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::call_path::{from_qualified_name, CallPath};
use ruff_python_ast::identifier::Identifier;
use ruff_python_ast::{self as ast, ParameterWithDefault};
use ruff_python_semantic::{
analyze::{function_type, visibility},
Scope, ScopeId, ScopeKind,
};
use ruff_text_size::Ranged;

use crate::{checkers::ast::Checker, rules::flake8_unused_arguments::helpers};

Expand Down Expand Up @@ -53,16 +53,17 @@ pub(crate) fn no_self_use(
return;
};

let ScopeKind::Function(ast::StmtFunctionDef {
let ScopeKind::Function(func) = scope.kind else {
return;
};

let ast::StmtFunctionDef {
name,
parameters,
body,
decorator_list,
..
}) = scope.kind
else {
return;
};
} = func;

if !matches!(
function_type::classify(
Expand Down Expand Up @@ -135,7 +136,7 @@ pub(crate) fn no_self_use(
NoSelfUse {
method_name: name.to_string(),
},
parameter.range(),
func.identifier(),
));
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
---
source: crates/ruff_linter/src/rules/pylint/mod.rs
---
no_self_use.py:7:28: PLR6301 Method `developer_greeting` could be a function, class method, or static method
no_self_use.py:7:9: PLR6301 Method `developer_greeting` could be a function, class method, or static method
|
6 | class Person:
7 | def developer_greeting(self, name): # [no-self-use]
| ^^^^ PLR6301
| ^^^^^^^^^^^^^^^^^^ PLR6301
8 | print(f"Greetings {name}!")
|

no_self_use.py:10:20: PLR6301 Method `greeting_1` could be a function, class method, or static method
no_self_use.py:10:9: PLR6301 Method `greeting_1` could be a function, class method, or static method
|
8 | print(f"Greetings {name}!")
9 |
10 | def greeting_1(self): # [no-self-use]
| ^^^^ PLR6301
| ^^^^^^^^^^ PLR6301
11 | print("Hello!")
|

no_self_use.py:13:20: PLR6301 Method `greeting_2` could be a function, class method, or static method
no_self_use.py:13:9: PLR6301 Method `greeting_2` could be a function, class method, or static method
|
11 | print("Hello!")
12 |
13 | def greeting_2(self): # [no-self-use]
| ^^^^ PLR6301
| ^^^^^^^^^^ PLR6301
14 | print("Hi!")
|

Expand Down
Loading