chore: Fix several style lints (#17488)

It's not comprehensive enough to start linting on `style` group, but
hey, it's a start.

Release Notes:

- N/A
This commit is contained in:
Piotr Osiewicz 2024-09-06 11:58:39 +02:00 committed by GitHub
parent 93249fc82b
commit e6c1c51b37
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
361 changed files with 3530 additions and 3587 deletions

View file

@ -139,7 +139,7 @@ impl Vim {
}
Mode::VisualBlock => {
ranges.push(selection.start..selection.end);
if cursor_positions.len() == 0 {
if cursor_positions.is_empty() {
cursor_positions.push(selection.start..selection.start);
}
}
@ -165,7 +165,7 @@ impl Vim {
let text = snapshot
.text_for_range(range.start..range.end)
.flat_map(|s| s.chars())
.flat_map(|c| transform(c))
.flat_map(transform)
.collect::<String>();
buffer.edit([(range, text)], None, cx)

View file

@ -61,7 +61,7 @@ impl Vim {
selection.start.to_offset(map, Bias::Left);
let classifier = map
.buffer_snapshot
.char_classifier_at(selection.start.to_point(&map));
.char_classifier_at(selection.start.to_point(map));
for (ch, offset) in map.buffer_chars_at(start_offset) {
if ch == '\n' || !classifier.is_whitespace(ch) {
break;
@ -136,7 +136,7 @@ fn expand_changed_word_selection(
.next()
.map(|(c, _)| !classifier.is_whitespace(c))
.unwrap_or_default();
return in_word;
in_word
};
if (times.is_none() || times.unwrap() == 1) && is_in_word() {
let next_char = map
@ -164,7 +164,7 @@ fn expand_changed_word_selection(
} else {
Motion::NextWordStart { ignore_punctuation }
};
motion.expand_selection(map, selection, times, false, &text_layout_details)
motion.expand_selection(map, selection, times, false, text_layout_details)
}
}

View file

@ -36,13 +36,13 @@ impl Vim {
if selection.is_empty()
&& map
.buffer_snapshot
.line_len(MultiBufferRow(selection.start.to_point(&map).row))
.line_len(MultiBufferRow(selection.start.to_point(map).row))
== 0
{
selection.end = map
.buffer_snapshot
.clip_point(
Point::new(selection.start.to_point(&map).row + 1, 0),
Point::new(selection.start.to_point(map).row + 1, 0),
Bias::Left,
)
.to_display_point(map)

View file

@ -34,7 +34,7 @@ pub fn register(editor: &mut Editor, cx: &mut ViewContext<Vim>) {
vim.record_current_action(cx);
let count = vim.take_count(cx).unwrap_or(1);
let step = if action.step { -1 } else { 0 };
vim.increment(count as i32 * -1, step, cx)
vim.increment(-(count as i32), step, cx)
});
}
@ -47,10 +47,10 @@ impl Vim {
let snapshot = editor.buffer().read(cx).snapshot(cx);
for selection in editor.selections.all_adjusted(cx) {
if !selection.is_empty() {
if vim.mode != Mode::VisualBlock || new_anchors.is_empty() {
new_anchors.push((true, snapshot.anchor_before(selection.start)))
}
if !selection.is_empty()
&& (vim.mode != Mode::VisualBlock || new_anchors.is_empty())
{
new_anchors.push((true, snapshot.anchor_before(selection.start)))
}
for row in selection.start.row..=selection.end.row {
let start = if row == selection.start.row {
@ -80,10 +80,8 @@ impl Vim {
if selection.is_empty() {
new_anchors.push((false, snapshot.anchor_after(range.end)))
}
} else {
if selection.is_empty() {
new_anchors.push((true, snapshot.anchor_after(start)))
}
} else if selection.is_empty() {
new_anchors.push((true, snapshot.anchor_after(start)))
}
}
}
@ -140,7 +138,11 @@ fn find_number(
begin = None;
num = String::new();
}
if num == "0" && ch == 'x' && chars.peek().is_some() && chars.peek().unwrap().is_digit(16) {
if num == "0"
&& ch == 'x'
&& chars.peek().is_some()
&& chars.peek().unwrap().is_ascii_hexdigit()
{
radix = 16;
begin = None;
num = String::new();
@ -156,13 +158,11 @@ fn find_number(
begin = Some(offset);
}
num.push(ch);
} else {
if begin.is_some() {
end = Some(offset);
break;
} else if ch == '\n' {
break;
}
} else if begin.is_some() {
end = Some(offset);
break;
} else if ch == '\n' {
break;
}
offset += ch.len_utf8();
}

View file

@ -102,7 +102,6 @@ impl Vim {
cx,
)
}
return;
} else {
self.update_editor(cx, |_, editor, cx| {
let map = editor.snapshot(cx);

View file

@ -117,7 +117,7 @@ impl Vim {
to_insert = "\n".to_owned() + &to_insert;
}
} else if !line_mode && vim.mode == Mode::VisualLine {
to_insert = to_insert + "\n";
to_insert += "\n";
}
let display_range = if !selection.is_empty() {
@ -432,7 +432,7 @@ mod test {
the laˇzy dog"});
// paste in visual mode
cx.simulate_shared_keystrokes("v i w p").await;
cx.shared_state().await.assert_eq(&indoc! {"
cx.shared_state().await.assert_eq(indoc! {"
The quick brown
the
ˇfox jumps over

View file

@ -178,10 +178,7 @@ impl Vim {
}
globals.last_replayed_register = Some(register);
let mut replayer = globals
.replayer
.get_or_insert_with(|| Replayer::new())
.clone();
let mut replayer = globals.replayer.get_or_insert_with(Replayer::new).clone();
replayer.replay(repeated_actions, cx);
}
@ -313,10 +310,7 @@ impl Vim {
let globals = Vim::globals(cx);
globals.dot_replaying = true;
let mut replayer = globals
.replayer
.get_or_insert_with(|| Replayer::new())
.clone();
let mut replayer = globals.replayer.get_or_insert_with(Replayer::new).clone();
replayer.replay(actions, cx);
}
}

View file

@ -298,7 +298,7 @@ impl Vim {
return None;
}
let mut query = action.query.clone();
if query == "" {
if query.is_empty() {
query = search_bar.query(cx);
};
@ -365,7 +365,7 @@ impl Vim {
if replacement.is_case_sensitive {
options.set(SearchOptions::CASE_SENSITIVE, true)
}
let search = if replacement.search == "" {
let search = if replacement.search.is_empty() {
search_bar.query(cx)
} else {
replacement.search
@ -442,7 +442,7 @@ impl Replacement {
for c in chars {
if escaped {
escaped = false;
if phase == 1 && c.is_digit(10) {
if phase == 1 && c.is_ascii_digit() {
buffer.push('$')
// unescape escaped parens
} else if phase == 0 && c == '(' || c == ')' {

View file

@ -121,7 +121,7 @@ impl Vim {
if is_first {
is_first = false;
} else {
text.push_str("\n");
text.push('\n');
}
let initial_len = text.len();
@ -147,7 +147,7 @@ impl Vim {
text.push_str(chunk);
}
if is_last_line {
text.push_str("\n");
text.push('\n');
}
clipboard_selections.push(ClipboardSelection {
len: text.len() - initial_len,