Skip to content

Commit

Permalink
Display -> DisplayOnly
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb committed Nov 7, 2023
1 parent 7ff08a9 commit 1854ae4
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 26 deletions.
14 changes: 7 additions & 7 deletions crates/ruff_diagnostics/src/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::edit::Edit;
pub enum Applicability {
/// The fix is unsafe and should only be displayed for manual application by the user.
/// The fix is likely to be incorrect or the resulting code may have invalid syntax.
Display,
DisplayOnly,

/// The fix is unsafe and should only be applied with user opt-in.
/// The fix may be what the user intended, but it is uncertain; the resulting code will have valid syntax.
Expand Down Expand Up @@ -87,22 +87,22 @@ impl Fix {
}
}

/// Create a new [`Fix`] that should only [display](Applicability::Display) and not apply from an [`Edit`] element .
pub fn display_edit(edit: Edit) -> Self {
/// Create a new [`Fix`] that should only [display](Applicability::DisplayOnly) and not apply from an [`Edit`] element .
pub fn display_only_edit(edit: Edit) -> Self {
Self {
edits: vec![edit],
applicability: Applicability::Display,
applicability: Applicability::DisplayOnly,
isolation_level: IsolationLevel::default(),
}
}

/// Create a new [`Fix`] that should only [display](Applicability::Display) and not apply from multiple [`Edit`] elements.
pub fn display_edits(edit: Edit, rest: impl IntoIterator<Item = Edit>) -> Self {
/// Create a new [`Fix`] that should only [display](Applicability::DisplayOnly) and not apply from multiple [`Edit`] elements.
pub fn display_only_edits(edit: Edit, rest: impl IntoIterator<Item = Edit>) -> Self {
let mut edits: Vec<Edit> = std::iter::once(edit).chain(rest).collect();
edits.sort_by_key(|edit| (edit.start(), edit.end()));
Self {
edits,
applicability: Applicability::Display,
applicability: Applicability::DisplayOnly,
isolation_level: IsolationLevel::default(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_linter/src/message/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl Display for Diff<'_> {
// TODO(zanieb): Adjust this messaging once it's user-facing
Applicability::Safe => "Safe fix",
Applicability::Unsafe => "Unsafe fix",
Applicability::Display => "Display only fix",
Applicability::DisplayOnly => "Display-only fix",
};
writeln!(f, "ℹ {}", message.blue())?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub(crate) fn commented_out_code(
if is_standalone_comment(line) && comment_contains_code(line, &settings.task_tags[..]) {
let mut diagnostic = Diagnostic::new(CommentedOutCode, *range);

diagnostic.set_fix(Fix::display_edit(Edit::range_deletion(
diagnostic.set_fix(Fix::display_only_edit(Edit::range_deletion(
locator.full_lines_range(*range),
)));
diagnostics.push(diagnostic);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ERA001.py:1:1: ERA001 Found commented-out code
|
= help: Remove commented-out code

Display only fix
Display-only fix
1 |-#import os
2 1 | # from foo import junk
3 2 | #a = 3
Expand All @@ -26,7 +26,7 @@ ERA001.py:2:1: ERA001 Found commented-out code
|
= help: Remove commented-out code

Display only fix
Display-only fix
1 1 | #import os
2 |-# from foo import junk
3 2 | #a = 3
Expand All @@ -44,7 +44,7 @@ ERA001.py:3:1: ERA001 Found commented-out code
|
= help: Remove commented-out code

Display only fix
Display-only fix
1 1 | #import os
2 2 | # from foo import junk
3 |-#a = 3
Expand All @@ -63,7 +63,7 @@ ERA001.py:5:1: ERA001 Found commented-out code
|
= help: Remove commented-out code

Display only fix
Display-only fix
2 2 | # from foo import junk
3 3 | #a = 3
4 4 | a = 4
Expand All @@ -82,7 +82,7 @@ ERA001.py:13:5: ERA001 Found commented-out code
|
= help: Remove commented-out code

Display only fix
Display-only fix
10 10 |
11 11 | # This is a real comment.
12 12 | # # This is a (nested) comment.
Expand All @@ -100,7 +100,7 @@ ERA001.py:21:5: ERA001 Found commented-out code
|
= help: Remove commented-out code

Display only fix
Display-only fix
18 18 |
19 19 | class A():
20 20 | pass
Expand All @@ -120,7 +120,7 @@ ERA001.py:26:5: ERA001 Found commented-out code
|
= help: Remove commented-out code

Display only fix
Display-only fix
23 23 |
24 24 | dictionary = {
25 25 | # "key1": 123, # noqa: ERA001
Expand All @@ -139,7 +139,7 @@ ERA001.py:27:5: ERA001 Found commented-out code
|
= help: Remove commented-out code

Display only fix
Display-only fix
24 24 | dictionary = {
25 25 | # "key1": 123, # noqa: ERA001
26 26 | # "key2": 456,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ pub(crate) fn lambda_assignment(
.get_all(id)
.any(|binding_id| checker.semantic().binding(binding_id).kind.is_annotation())
{
diagnostic.set_fix(Fix::display_edit(Edit::range_replacement(
diagnostic.set_fix(Fix::display_only_edit(Edit::range_replacement(
indented,
stmt.range(),
)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ E731.py:57:5: E731 Do not assign a `lambda` expression, use a `def`
|
= help: Rewrite `f` as a `def`

Display only fix
Display-only fix
54 54 |
55 55 | class Scope:
56 56 | # E731
Expand All @@ -128,7 +128,7 @@ E731.py:64:5: E731 Do not assign a `lambda` expression, use a `def`
|
= help: Rewrite `f` as a `def`

Display only fix
Display-only fix
61 61 | from typing import Callable
62 62 |
63 63 | # E731
Expand All @@ -150,7 +150,7 @@ E731.py:73:9: E731 Do not assign a `lambda` expression, use a `def`
|
= help: Rewrite `x` as a `def`

Display only fix
Display-only fix
70 70 |
71 71 | x: Callable[[int], int]
72 72 | if True:
Expand All @@ -171,7 +171,7 @@ E731.py:75:9: E731 Do not assign a `lambda` expression, use a `def`
|
= help: Rewrite `x` as a `def`

Display only fix
Display-only fix
72 72 | if True:
73 73 | x = lambda: 1
74 74 | else:
Expand Down Expand Up @@ -331,7 +331,7 @@ E731.py:139:5: E731 Do not assign a `lambda` expression, use a `def`
|
= help: Rewrite `CELSIUS` as a `def`

Display only fix
Display-only fix
136 136 |
137 137 |
138 138 | class TemperatureScales(Enum):
Expand All @@ -351,7 +351,7 @@ E731.py:140:5: E731 Do not assign a `lambda` expression, use a `def`
|
= help: Rewrite `FAHRENHEIT` as a `def`

Display only fix
Display-only fix
137 137 |
138 138 | class TemperatureScales(Enum):
139 139 | CELSIUS = (lambda deg_c: deg_c)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RUF100_5.py:7:5: ERA001 Found commented-out code
|
= help: Remove commented-out code

Display only fix
Display-only fix
4 4 | dictionary = {
5 5 | # "key1": 123, # noqa: ERA001
6 6 | # "key2": 456, # noqa
Expand All @@ -27,7 +27,7 @@ RUF100_5.py:11:1: ERA001 Found commented-out code
|
= help: Remove commented-out code

Display only fix
Display-only fix
8 8 | }
9 9 |
10 10 |
Expand Down

0 comments on commit 1854ae4

Please sign in to comment.