Skip to content

Commit

Permalink
fix: improve lint issues and add -D warnings to github ci
Browse files Browse the repository at this point in the history
  • Loading branch information
sunng87 committed May 18, 2022
1 parent 9c6ba19 commit 18afe68
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
components: clippy
override: true
- name: Lint
run: cargo clippy --all-features
run: cargo clippy --all-features -- -D warnings
- name: Build and run tests
run: cargo test --all-features

Expand Down
4 changes: 2 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// use std::backtrace::Backtrace;
use std::error::Error as StdError;
use std::fmt;
use std::fmt::{self, Write};
use std::io::Error as IOError;
use std::num::ParseIntError;
use std::string::FromUtf8Error;
Expand Down Expand Up @@ -205,7 +205,7 @@ fn template_segment(template_str: &str, line: usize, col: usize) -> String {
let mut buf = String::new();
for (line_count, line_content) in template_str.lines().enumerate() {
if line_count >= line_start && line_count <= line_end {
buf.push_str(&format!("{:4} | {}\n", line_count, line_content));
let _ = writeln!(&mut buf, "{:4} | {}", line_count, line_content);
if line_count == line - 1 {
buf.push_str(" |");
for c in 0..line_content.len() {
Expand Down
11 changes: 4 additions & 7 deletions src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,9 @@ impl<'reg> Registry<'reg> {
{
let dir_path = dir_path.as_ref();

// Allowing dots at the beginning as to not break old applications.
let tpl_extension = if tpl_extension.starts_with(".") {
&tpl_extension[1..]
} else {
tpl_extension
};
// Allowing dots at the beginning as to not break old
// applications.
let tpl_extension = tpl_extension.strip_prefix('.').unwrap_or(tpl_extension);

let walker = WalkDir::new(dir_path);
let dir_iter = walker
Expand All @@ -322,7 +319,7 @@ impl<'reg> Registry<'reg> {
tpl_path
.file_stem()
.map(|stem| stem.to_string_lossy())
.map(|stem| !(stem.starts_with(".") || stem.starts_with("#")))
.map(|stem| !(stem.starts_with('.') || stem.starts_with('#')))
.unwrap_or(false)
})
.filter_map(|tpl_path| {
Expand Down
2 changes: 1 addition & 1 deletion src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ fn indent_aware_write(
out: &mut dyn Output,
) -> Result<(), RenderError> {
if let Some(indent) = rc.get_indent_string() {
out.write(support::str::with_indent(v.as_ref(), indent).as_ref())?;
out.write(support::str::with_indent(v, indent).as_ref())?;
} else {
out.write(v.as_ref())?;
}
Expand Down
2 changes: 1 addition & 1 deletion src/support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub mod str {
}

/// add indent for lines but last
pub fn with_indent<'a>(s: &'a str, indent: &String) -> String {
pub fn with_indent(s: &str, indent: &str) -> String {
let mut output = String::new();

let mut it = s.chars().peekable();
Expand Down

0 comments on commit 18afe68

Please sign in to comment.