on master help sign in
Applied linter fixes
commit82f14121bd70432080820c245e67c0eb3113f2c5 authorDaniele Esposti <daniele.esposti@gmail.com> dateFri 8 Mar 2019, 10:46 (8 years ago) parenta21ae61
12 files changed+37−44
.DS_Store src/app.rs+12−14 src/assets.rs+3−3 src/clap_app.rs+1−1 src/config.rs+4−4 src/controller.rs+1−1 src/line_range.rs+4−10 src/main.rs+1−1 src/output.rs+1−1 src/printer.rs+5−5 src/style.rs+2−2 src/syntax_mapping.rs+3−2
.DS_Storenew file

Binary file not shown.

src/app.rs+12−14
@@ -120,7 +120,7 @@ impl App {
120120
121121 // Read arguments from bats config file
122122 let mut args = get_args_from_env_var()
123− .unwrap_or_else(|| get_args_from_config_file())
123+ .unwrap_or_else(get_args_from_config_file)
124124 .chain_err(|| "Could not parse configuration file")?;
125125
126126 // Put the zero-th CLI argument (program name) first
@@ -152,12 +152,10 @@ impl App {
152152 } else {
153153 PagingMode::Never
154154 }
155+ } else if self.interactive_output {
156+ PagingMode::QuitIfOneScreen
155157 } else {
156− if self.interactive_output {
157− PagingMode::QuitIfOneScreen
158− } else {
159− PagingMode::Never
160− }
158+ PagingMode::Never
161159 }
162160 }
163161 };
@@ -166,7 +164,7 @@ impl App {
166164
167165 if let Some(values) = self.matches.values_of("map-syntax") {
168166 for from_to in values {
169− let parts: Vec<_> = from_to.split(":").collect();
167+ let parts: Vec<_> = from_to.split(':').collect();
170168
171169 if parts.len() != 2 {
172170 return Err("Invalid syntax mapping. The format of the -m/--map-syntax option is 'from:to'.".into());
@@ -213,11 +211,11 @@ impl App {
213211 .matches
214212 .value_of("terminal-width")
215213 .and_then(|w| {
216− if w.starts_with("+") || w.starts_with("-") {
214+ if w.starts_with('+') || w.starts_with('-') {
217215 // Treat argument as a delta to the current terminal width
218216 w.parse().ok().map(|delta: i16| {
219217 let old_width: u16 = Term::stdout().size().1;
220− let new_width: i32 = old_width as i32 + delta as i32;
218+ let new_width: i32 = i32::from(old_width) + i32::from(delta);
221219
222220 if new_width <= 0 {
223221 old_width as usize
@@ -252,14 +250,14 @@ impl App {
252250 .value_of("theme")
253251 .map(String::from)
254252 .or_else(|| env::var("BAT_THEME").ok())
255− .unwrap_or(String::from(BAT_THEME_DEFAULT)),
253+ .unwrap_or_else(|| String::from(BAT_THEME_DEFAULT)),
256254 line_ranges: LineRanges::from(
257255 transpose(
258256 self.matches
259257 .values_of("line-range")
260258 .map(|vs| vs.map(LineRange::from).collect()),
261259 )?
262− .unwrap_or(vec![]),
260+ .unwrap_or_else(|| vec![]),
263261 ),
264262 output_components,
265263 syntax_mapping,
@@ -306,7 +304,7 @@ impl App {
306304 let env_style_components: Option<Vec<OutputComponent>> =
307305 transpose(env::var("BAT_STYLE").ok().map(|style_str| {
308306 style_str
309− .split(",")
307+ .split(',')
310308 .map(|x| OutputComponent::from_str(&x))
311309 .collect::<Result<Vec<OutputComponent>>>()
312310 }))?;
@@ -315,13 +313,13 @@ impl App {
315313 .value_of("style")
316314 .map(|styles| {
317315 styles
318− .split(",")
316+ .split(',')
319317 .map(|style| style.parse::<OutputComponent>())
320318 .filter_map(|style| style.ok())
321319 .collect::<Vec<_>>()
322320 })
323321 .or(env_style_components)
324− .unwrap_or(vec![OutputComponent::Full])
322+ .unwrap_or_else(|| vec![OutputComponent::Full])
325323 .into_iter()
326324 .map(|style| style.components(self.interactive_output))
327325 .fold(HashSet::new(), |mut acc, components| {
src/assets.rs+3−3
@@ -40,7 +40,7 @@ impl HighlightingAssets {
4040 let theme_dir = source_dir.join("themes");
4141
4242 let res = theme_set.add_from_folder(&theme_dir);
43− if !res.is_ok() {
43+ if res.is_err() {
4444 println!(
4545 "No themes were found in '{}', using the default set",
4646 theme_dir.to_string_lossy()
@@ -191,8 +191,8 @@ impl HighlightingAssets {
191191 } else {
192192 None
193193 };
194− let syntax = ext_syntax.or(line_syntax);
195− syntax
194+
195+ ext_syntax.or(line_syntax)
196196 }
197197 (None, InputFile::StdIn) => String::from_utf8(reader.first_line.clone())
198198 .ok()
src/clap_app.rs+1−1
@@ -109,7 +109,7 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
109109 .overrides_with("number")
110110 // Cannot use clap's built in validation because we have to turn off clap's delimiters
111111 .validator(|val| {
112− let mut invalid_vals = val.split(",").filter(|style| {
112+ let mut invalid_vals = val.split(',').filter(|style| {
113113 !&[
114114 "auto", "full", "plain", "changes", "header", "grid", "numbers",
115115 ]
src/config.rs+4−4
@@ -13,7 +13,7 @@ pub fn config_file() -> PathBuf {
1313 .ok()
1414 .map(PathBuf::from)
1515 .filter(|config_path| config_path.is_file())
16− .unwrap_or(PROJECT_DIRS.config_dir().join("config"))
16+ .unwrap_or_else(|| PROJECT_DIRS.config_dir().join("config"))
1717}
1818
1919pub fn get_args_from_config_file() -> Result<Vec<OsString>, shell_words::ParseError> {
@@ -22,19 +22,19 @@ pub fn get_args_from_config_file() -> Result<Vec<OsString>, shell_words::ParseEr
2222 .ok()
2323 .map(|content| get_args_from_str(&content)),
2424 )?
25− .unwrap_or(vec![]))
25+ .unwrap_or_else(|| vec![]))
2626}
2727
2828pub fn get_args_from_env_var() -> Option<Result<Vec<OsString>, shell_words::ParseError>> {
2929 env::var("BAT_OPTS").ok().map(|s| get_args_from_str(&s))
3030}
3131
32−fn get_args_from_str<'a>(content: &'a str) -> Result<Vec<OsString>, shell_words::ParseError> {
32+fn get_args_from_str(content: &str) -> Result<Vec<OsString>, shell_words::ParseError> {
3333 let args_per_line = content
3434 .split('\n')
3535 .map(|line| line.trim())
3636 .filter(|line| !line.is_empty())
37− .filter(|line| !line.starts_with("#"))
37+ .filter(|line| !line.starts_with('#'))
3838 .map(|line| shell_words::split(line))
3939 .collect::<Result<Vec<_>, _>>()?;
4040
src/controller.rs+1−1
@@ -88,7 +88,7 @@ impl<'b> Controller<'b> {
8888 Ok(())
8989 }
9090
91− fn print_file_ranges<'a, P: Printer>(
91+ fn print_file_ranges<P: Printer>(
9292 &self,
9393 printer: &mut P,
9494 writer: &mut Write,
src/line_range.rs+4−10
@@ -109,18 +109,12 @@ impl LineRanges {
109109 }
110110
111111 pub fn check(&self, line: usize) -> RangeCheckResult {
112− if self.ranges.is_empty() {
112+ if self.ranges.is_empty() | self.ranges.iter().any(|r| r.is_inside(line)) {
113113 RangeCheckResult::InRange
114+ } else if line < self.largest_upper_bound {
115+ RangeCheckResult::OutsideRange
114116 } else {
115− if self.ranges.iter().any(|r| r.is_inside(line)) {
116− RangeCheckResult::InRange
117− } else {
118− if line < self.largest_upper_bound {
119− RangeCheckResult::OutsideRange
120− } else {
121− RangeCheckResult::AfterLastRange
122− }
123− }
117+ RangeCheckResult::AfterLastRange
124118 }
125119 }
126120}
src/main.rs+1−1
@@ -67,7 +67,7 @@ mod errors {
6767
6868 pub fn handle_error(error: &Error) {
6969 match error {
70− &Error(ErrorKind::Io(ref io_error), _)
70+ Error(ErrorKind::Io(ref io_error), _)
7171 if io_error.kind() == super::io::ErrorKind::BrokenPipe =>
7272 {
7373 super::process::exit(0);
src/output.rs+1−1
@@ -51,7 +51,7 @@ impl OutputType {
5151
5252 let pager = pager_from_config
5353 .or(pager_from_env)
54− .unwrap_or(String::from("less"));
54+ .unwrap_or_else(|| String::from("less"));
5555
5656 let pagerflags =
5757 shell_words::split(&pager).chain_err(|| "Could not parse pager command.")?;
src/printer.rs+5−5
@@ -64,7 +64,7 @@ impl Printer for SimplePrinter {
6464 line_buffer: &[u8],
6565 ) -> Result<()> {
6666 if !out_of_range {
67− handle.write(line_buffer)?;
67+ handle.write_all(line_buffer)?;
6868 }
6969 Ok(())
7070 }
@@ -270,7 +270,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
270270 };
271271
272272 if self.config.show_nonprintable {
273− line = replace_nonprintable(&mut line, self.config.tab_width);
273+ line = replace_nonprintable(&line, self.config.tab_width);
274274 }
275275
276276 let regions = {
@@ -355,11 +355,11 @@ impl<'a> Printer for InteractivePrinter<'a> {
355355 }
356356
357357 if line.bytes().next_back() != Some(b'\n') {
358− write!(handle, "\n")?;
358+ writeln!(handle)?;
359359 }
360360 } else {
361361 for &(style, region) in regions.iter() {
362− let mut ansi_iterator = AnsiCodeIterator::new(region);
362+ let ansi_iterator = AnsiCodeIterator::new(region);
363363 let mut ansi_prefix: String = String::new();
364364 for chunk in ansi_iterator {
365365 match chunk {
@@ -472,7 +472,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
472472 ansi_style.paint(" ".repeat(cursor_max - cursor))
473473 )?;
474474 }
475− write!(handle, "\n")?;
475+ writeln!(handle)?;
476476 }
477477
478478 Ok(())
src/style.rs+2−2
@@ -21,8 +21,8 @@ pub enum OutputWrap {
2121}
2222
2323impl OutputComponent {
24− pub fn components(&self, interactive_terminal: bool) -> &'static [OutputComponent] {
25− match *self {
24+ pub fn components(self, interactive_terminal: bool) -> &'static [OutputComponent] {
25+ match self {
2626 OutputComponent::Auto => {
2727 if interactive_terminal {
2828 OutputComponent::Full.components(interactive_terminal)
src/syntax_mapping.rs+3−2
@@ -1,14 +1,15 @@
11use std::borrow::Cow;
22use std::collections::HashMap;
33
4−#[derive(Debug, Clone)]
4+#[derive(Debug, Clone, Default)]
55pub struct SyntaxMapping(HashMap<String, String>);
66
77impl SyntaxMapping {
88 pub fn new() -> SyntaxMapping {
9− SyntaxMapping(HashMap::new())
9+ Default::default()
1010 }
1111
12+
1213 pub fn insert(&mut self, from: impl Into<String>, to: impl Into<String>) -> Option<String> {
1314 self.0.insert(from.into(), to.into())
1415 }