Skip to content

Commit a0cd8e9

Browse files
committed
chore: address lints in emmylua_parser_desc
1 parent 4637b56 commit a0cd8e9

File tree

8 files changed

+43
-45
lines changed

8 files changed

+43
-45
lines changed

crates/emmylua_parser_desc/src/lang/json/json_lexer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use emmylua_parser::{LexerState, Reader, SourceRange};
22

3+
#[allow(clippy::enum_variant_names)]
34
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
45
pub enum JsonTokenKind {
56
TkEof,

crates/emmylua_parser_desc/src/lang/protobuf/protobuf_lexer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use emmylua_parser::{LexerState, Reader, SourceRange};
22

3+
#[allow(clippy::enum_variant_names)]
34
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
45
pub enum ProtobufTokenKind {
56
TkEof,

crates/emmylua_parser_desc/src/lang/shell/shell_lexer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use emmylua_parser::{LexerState, Reader, SourceRange};
22

3+
#[allow(clippy::enum_variant_names)]
34
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
45
pub enum ShellTokenKind {
56
TkEof,

crates/emmylua_parser_desc/src/lang/sql/sql_lexer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use emmylua_parser::{LexerState, Reader, SourceRange};
22

3+
#[allow(clippy::enum_variant_names)]
34
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
45
pub enum SqlTokenKind {
56
TkEof,

crates/emmylua_parser_desc/src/lang/vimscript/vim_lexer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use emmylua_parser::{LexerState, Reader, SourceRange};
22

3+
#[allow(clippy::enum_variant_names)]
34
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
45
pub enum VimTokenKind {
56
TkEof,

crates/emmylua_parser_desc/src/markdown_rst/mod.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,7 @@ impl MarkdownRstParser {
438438
line.eat_till_end();
439439
self.emit(line, DescItemKind::CodeBlock);
440440

441-
for i in start + 1..lines.len() {
442-
let line = &mut lines[i];
443-
441+
for (i, line) in lines.iter_mut().enumerate().skip(start) {
444442
if is_blank(line.tail_text()) {
445443
line.eat_till_end();
446444
line.reset_buff();
@@ -769,8 +767,8 @@ impl MarkdownRstParser {
769767
}
770768

771769
let mut line_ending = LineEnding::Normal;
772-
for i in start..end {
773-
line_ending = self.process_inline_content(&mut lines[i]);
770+
for line in lines.iter_mut().take(end).skip(start) {
771+
line_ending = self.process_inline_content(line);
774772
}
775773

776774
(end, line_ending)
@@ -784,8 +782,7 @@ impl MarkdownRstParser {
784782
) -> usize {
785783
let mut end = start;
786784
let mut common_indent = None;
787-
for i in start..lines.len() {
788-
let line = &lines[i];
785+
for (i, line) in lines.iter().enumerate().skip(start) {
789786
let indent = line.tail_text().chars().take_while(|c| is_ws(*c)).count();
790787
if indent >= 1 {
791788
end = i + 1;
@@ -815,8 +812,7 @@ impl MarkdownRstParser {
815812
allow_blank_lines: bool,
816813
) -> usize {
817814
let mut end = start;
818-
for i in start..lines.len() {
819-
let line = &mut lines[i];
815+
for (i, line) in lines.iter_mut().enumerate().skip(start) {
820816
let indent = line.tail_text().chars().take_while(|c| is_ws(*c)).count();
821817
if indent >= min_indent {
822818
end = i + 1;
@@ -831,8 +827,7 @@ impl MarkdownRstParser {
831827

832828
fn gather_prefixed_lines(&mut self, lines: &mut [Reader], start: usize, prefix: char) -> usize {
833829
let mut end = start;
834-
for i in start..lines.len() {
835-
let line = &mut lines[i];
830+
for (i, line) in lines.iter_mut().enumerate().skip(start) {
836831
if line.current_char() == prefix {
837832
end = i + 1;
838833
line.bump();

crates/emmylua_parser_desc/src/markdown_rst/test.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -456,9 +456,9 @@ mod tests {
456456
"#;
457457

458458
test(
459-
&code,
459+
code,
460460
Box::new(MarkdownRstParser::new(None, None, None)),
461-
&expected,
461+
expected,
462462
)
463463
.or_fail()?;
464464
Ok(())
@@ -493,13 +493,13 @@ local t = 123
493493
"#;
494494

495495
test(
496-
&code,
496+
code,
497497
Box::new(MarkdownRstParser::new(
498498
None,
499499
Some("lua:obj".to_string()),
500500
None,
501501
)),
502-
&expected,
502+
expected,
503503
)
504504
.or_fail()?;
505505
Ok(())
@@ -512,13 +512,13 @@ local t = 123
512512
let expected = r#"--- See <Markup>`</Markup><Ref>ref</Ref><Markup>`</Markup>"#;
513513

514514
test(
515-
&code,
515+
code,
516516
Box::new(MarkdownRstParser::new(
517517
None,
518518
Some("lua:obj".to_string()),
519519
None,
520520
)),
521-
&expected,
521+
expected,
522522
)
523523
.or_fail()?;
524524
Ok(())
@@ -533,9 +533,9 @@ local t = 123
533533
"#;
534534

535535
test(
536-
&code,
536+
code,
537537
Box::new(MarkdownRstParser::new(Some("lua".to_string()), None, None)),
538-
&expected,
538+
expected,
539539
)
540540
.or_fail()?;
541541
Ok(())
@@ -546,39 +546,39 @@ local t = 123
546546
let code = r#"--- See :lua:obj:`x` :lua:obj:`ref`"#;
547547
let expected = r#"--- See :lua:obj:`x` :lua:obj:`<Ref>ref</Ref>`"#;
548548
test(
549-
&code,
549+
code,
550550
Box::new(MarkdownRstParser::new(None, None, Some(31))),
551-
&expected,
551+
expected,
552552
)
553553
.or_fail()?;
554554
test(
555-
&code,
555+
code,
556556
Box::new(MarkdownRstParser::new(None, None, Some(32))),
557-
&expected,
557+
expected,
558558
)
559559
.or_fail()?;
560560
test(
561-
&code,
561+
code,
562562
Box::new(MarkdownRstParser::new(None, None, Some(34))),
563-
&expected,
563+
expected,
564564
)
565565
.or_fail()?;
566566

567567
let code = r#"--- See :lua:obj:`x` :lua:obj:`"#;
568568
let expected = r#"--- See :lua:obj:`x` :lua:obj:`<Ref></Ref>"#;
569569
test(
570-
&code,
570+
code,
571571
Box::new(MarkdownRstParser::new(None, None, Some(31))),
572-
&expected,
572+
expected,
573573
)
574574
.or_fail()?;
575575

576576
let code = r#"--- See :lua:obj:`x` :lua:obj:``..."#;
577577
let expected = r#"--- See :lua:obj:`x` :lua:obj:`<Ref>`</Ref>..."#;
578578
test(
579-
&code,
579+
code,
580580
Box::new(MarkdownRstParser::new(None, None, Some(31))),
581-
&expected,
581+
expected,
582582
)
583583
.or_fail()?;
584584
Ok(())
@@ -589,72 +589,72 @@ local t = 123
589589
let code = r#"--- See `ab`"#;
590590
let expected = r#"--- See `<Ref>ab</Ref>`"#;
591591
test(
592-
&code,
592+
code,
593593
Box::new(MarkdownRstParser::new(
594594
None,
595595
Some("lua:obj".to_string()),
596596
Some(9),
597597
)),
598-
&expected,
598+
expected,
599599
)
600600
.or_fail()?;
601601
test(
602-
&code,
602+
code,
603603
Box::new(MarkdownRstParser::new(
604604
None,
605605
Some("lua:obj".to_string()),
606606
Some(10),
607607
)),
608-
&expected,
608+
expected,
609609
)
610610
.or_fail()?;
611611
test(
612-
&code,
612+
code,
613613
Box::new(MarkdownRstParser::new(
614614
None,
615615
Some("lua:obj".to_string()),
616616
Some(11),
617617
)),
618-
&expected,
618+
expected,
619619
)
620620
.or_fail()?;
621621

622622
let code = r#"--- See `"#;
623623
let expected = r#"--- See `<Ref></Ref>"#;
624624
test(
625-
&code,
625+
code,
626626
Box::new(MarkdownRstParser::new(
627627
None,
628628
Some("lua:obj".to_string()),
629629
Some(9),
630630
)),
631-
&expected,
631+
expected,
632632
)
633633
.or_fail()?;
634634

635635
let code = r#"--- See `..."#;
636636
let expected = r#"--- See `<Ref>...</Ref>"#;
637637
test(
638-
&code,
638+
code,
639639
Box::new(MarkdownRstParser::new(
640640
None,
641641
Some("lua:obj".to_string()),
642642
Some(9),
643643
)),
644-
&expected,
644+
expected,
645645
)
646646
.or_fail()?;
647647

648648
let code = r#"--- See ``"#;
649649
let expected = r#"--- See `<Ref>`</Ref>"#;
650650
test(
651-
&code,
651+
code,
652652
Box::new(MarkdownRstParser::new(
653653
None,
654654
Some("lua:obj".to_string()),
655655
Some(9),
656656
)),
657-
&expected,
657+
expected,
658658
)
659659
.or_fail()?;
660660
Ok(())

crates/emmylua_parser_desc/src/testlib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ pub fn test(code: &str, mut parser: Box<dyn LuaDescParser>, expected: &str) -> R
1010
let Some(desc) = tree
1111
.get_red_root()
1212
.descendants()
13-
.filter(|node| matches!(node.kind(), LuaKind::Syntax(LuaSyntaxKind::DocDescription)))
14-
.next()
13+
.find(|node| matches!(node.kind(), LuaKind::Syntax(LuaSyntaxKind::DocDescription)))
1514
else {
1615
return fail!("No desc found in {:?}", tree.get_red_root());
1716
};
@@ -32,8 +31,7 @@ pub fn print_result(code: &str, mut parser: Box<dyn LuaDescParser>) {
3231
let Some(desc) = tree
3332
.get_red_root()
3433
.descendants()
35-
.filter(|node| matches!(node.kind(), LuaKind::Syntax(LuaSyntaxKind::DocDescription)))
36-
.next()
34+
.find(|node| matches!(node.kind(), LuaKind::Syntax(LuaSyntaxKind::DocDescription)))
3735
else {
3836
panic!("No desc found in {:?}", tree.get_red_root());
3937
};

0 commit comments

Comments
 (0)