Repository: Nukesor/comfy-table
Pull request #11 (2020-10-04 13:07:39)

Clippy and ci


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3740d23..938ef34 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,13 +3,7 @@ All notable changes to this project will be documented in this file.
 
 The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 
-## [1.1.1] - 2020-08-23
-
-### Changed
-
-- A simple update of all dependencies.
-
-## [1.1.0] - 2020-08-23
+## [1.1.0] - 
 
 ### Changed
 
diff --git a/codecov.yml b/codecov.yml
index e8fce93..6dcba33 100644
--- a/codecov.yml
+++ b/codecov.yml
@@ -2,3 +2,7 @@ ignore:
   - "examples"
   - "proptest_regressions"
   - "tests"
+  - "README.md"
+  - "LICENSE"
+  - "Cargo.lock"
+  - "Cargo.toml"
diff --git a/examples/readme_table.rs b/examples/readme_table.rs
index a2934cc..fb98d4a 100644
--- a/examples/readme_table.rs
+++ b/examples/readme_table.rs
@@ -1,5 +1,5 @@
-use comfy_table::*;
 use comfy_table::presets::UTF8_FULL;
+use comfy_table::*;
 
 fn main() {
     let mut table = Table::new();
@@ -30,4 +30,3 @@ fn main() {
 
     println!("{}", table);
 }
-
diff --git a/src/cell.rs b/src/cell.rs
index f1f4211..f0fa2ab 100644
--- a/src/cell.rs
+++ b/src/cell.rs
@@ -33,7 +33,7 @@ impl Cell {
 
     /// Return a copy of the content contained in this cell.
     pub fn get_content(&self) -> String {
-        return self.content.join("\n").clone();
+        self.content.join("\n")
     }
 
     /// Set the alignment of content for this cell.
diff --git a/src/column.rs b/src/column.rs
index a25fe38..8464eb5 100644
--- a/src/column.rs
+++ b/src/column.rs
@@ -41,7 +41,7 @@ pub struct Column {
 impl Column {
     pub fn new(index: usize) -> Self {
         Column {
-            index: index,
+            index,
             padding: (1, 1),
             constraint: None,
             max_content_width: 0,
diff --git a/src/row.rs b/src/row.rs
index a7d80d2..0a2059a 100644
--- a/src/row.rs
+++ b/src/row.rs
@@ -9,6 +9,12 @@ pub struct Row {
     pub(crate) cells: Vec<Cell>,
 }
 
+impl Default for Row {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl Row {
     pub fn new() -> Row {
         Row {
diff --git a/src/table.rs b/src/table.rs
index 9a091d3..e1e1dea 100644
--- a/src/table.rs
+++ b/src/table.rs
@@ -38,6 +38,12 @@ impl fmt::Display for Table {
     }
 }
 
+impl Default for Table {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl Table {
     /// Create a new table with default ASCII styling, no rows and a header
     pub fn new() -> Self {
@@ -161,7 +167,7 @@ impl Table {
             return false;
         }
 
-        return ::std::io::stdout().is_tty();
+        ::std::io::stdout().is_tty()
     }
 
     /// Enforce terminal styling. Only useful if you forcefully disabled tty,
@@ -207,8 +213,7 @@ impl Table {
         constraints: T,
     ) -> &mut Self {
         let mut constraints = constraints.into_iter();
-        let mut column_iter = self.column_iter_mut();
-        while let Some(column) = column_iter.next() {
+        for column in self.column_iter_mut() {
             if let Some(constraint) = constraints.next() {
                 column.set_constraint(constraint);
             } else {
diff --git a/src/utils/borders.rs b/src/utils/borders.rs
index f211daf..b0d6085 100644
--- a/src/utils/borders.rs
+++ b/src/utils/borders.rs
@@ -5,7 +5,7 @@ use crate::utils::arrangement::ColumnDisplayInfo;
 pub fn draw_borders(
     table: &Table,
     rows: Vec<Vec<Vec<String>>>,
-    display_info: &Vec<ColumnDisplayInfo>,
+    display_info: &[ColumnDisplayInfo],
 ) -> Vec<String> {
     let mut lines = Vec::new();
     if should_draw_top_border(table) {
@@ -21,7 +21,7 @@ pub fn draw_borders(
     lines
 }
 
-fn draw_top_border(table: &Table, display_info: &Vec<ColumnDisplayInfo>) -> String {
+fn draw_top_border(table: &Table, display_info: &[ColumnDisplayInfo]) -> String {
     let left_corner = table.style_or_default(TableComponent::TopLeftCorner);
     let top_border = table.style_or_default(TableComponent::TopBorder);
     let border_intersection = table.style_or_default(TableComponent::TopBorderIntersections);
@@ -54,7 +54,7 @@ fn draw_top_border(table: &Table, display_info: &Vec<ColumnDisplayInfo>) -> Stri
 fn draw_rows(
     rows: Vec<Vec<Vec<String>>>,
     table: &Table,
-    display_info: &Vec<ColumnDisplayInfo>,
+    display_info: &[ColumnDisplayInfo],
 ) -> Vec<String> {
     let mut lines = Vec::new();
     // Iterate over all rows
@@ -83,7 +83,7 @@ fn draw_rows(
 }
 
 // Takes the parts of a single line, surrounds them with borders and adds vertical lines.
-fn embed_line(line_parts: &Vec<String>, table: &Table) -> String {
+fn embed_line(line_parts: &[String], table: &Table) -> String {
     let vertical_lines = table.style_or_default(TableComponent::VerticalLines);
     let left_border = table.style_or_default(TableComponent::LeftBorder);
     let right_border = table.style_or_default(TableComponent::RightBorder);
@@ -98,7 +98,7 @@ fn embed_line(line_parts: &Vec<String>, table: &Table) -> String {
         line += part;
         if should_draw_vertical_lines(table) && part_iter.peek().is_some() {
             line += &vertical_lines;
-        } else if should_draw_right_border(table) && !part_iter.peek().is_some() {
+        } else if should_draw_right_border(table) && part_iter.peek().is_none() {
             line += &right_border;
         }
     }
@@ -109,7 +109,7 @@ fn embed_line(line_parts: &Vec<String>, table: &Table) -> String {
 // The horizontal line that separates between rows.
 fn draw_horizontal_lines(
     table: &Table,
-    display_info: &Vec<ColumnDisplayInfo>,
+    display_info: &[ColumnDisplayInfo],
     header: bool,
 ) -> String {
     let (left_intersection, horizontal_lines, middle_intersection, right_intersection) = if header {
@@ -152,7 +152,7 @@ fn draw_horizontal_lines(
     line
 }
 
-fn draw_bottom_border(table: &Table, display_info: &Vec<ColumnDisplayInfo>) -> String {
+fn draw_bottom_border(table: &Table, display_info: &[ColumnDisplayInfo]) -> String {
     let left_corner = table.style_or_default(TableComponent::BottomLeftCorner);
     let bottom_border = table.style_or_default(TableComponent::BottomBorder);
     let middle_intersection = table.style_or_default(TableComponent::BottomBorderIntersections);
diff --git a/src/utils/format.rs b/src/utils/format.rs
index 5d80317..6a10ea4 100644
--- a/src/utils/format.rs
+++ b/src/utils/format.rs
@@ -24,19 +24,13 @@ use crate::utils::arrangement::ColumnDisplayInfo;
 ///
 /// The strings for each row will be padded and aligned accordingly
 /// to their respective column.
-pub fn format_content(
-    table: &Table,
-    display_info: &Vec<ColumnDisplayInfo>,
-) -> Vec<Vec<Vec<String>>> {
+pub fn format_content(table: &Table, display_info: &[ColumnDisplayInfo]) -> Vec<Vec<Vec<String>>> {
     // The content of the whole table
     let mut table_content = Vec::new();
 
     // Format table header if it exists
-    match table.get_header() {
-        Some(header) => {
-            table_content.push(format_row(header, display_info, table));
-        }
-        None => (),
+    if let Some(header) = table.get_header() {
+        table_content.push(format_row(header, display_info, table));
     }
 
     for row in table.rows.iter() {
@@ -47,7 +41,7 @@ pub fn format_content(
 
 pub fn format_row(
     row: &Row,
-    display_info: &Vec<ColumnDisplayInfo>,
+    display_info: &[ColumnDisplayInfo],
     table: &Table,
 ) -> Vec<Vec<String>> {
     // The content of this specific row
@@ -160,7 +154,7 @@ pub fn split_line(
         let added_length = next_length + current_length + 1;
 
         // The line is empty try to add the next part
-        if current_line.len() == 0 {
+        if current_line.is_empty() {
             // Next part fits in line. Add and continue
             if next_length as u16 <= content_width {
                 current_line += &next;
@@ -218,7 +212,7 @@ pub fn split_line(
         }
     }
 
-    if current_line.len() != 0 {
+    if !current_line.is_empty() {
         lines.push(current_line);
     }
 


Test patch:
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index e0544ca..2957107 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -15,10 +15,35 @@ jobs:
         os: [ubuntu-latest, macos-latest]
 
     steps:
-    - uses: hecrj/setup-rust-action@v1
-      with:
-        rust-version: stable
-    - uses: actions/checkout@v1
+      - name: Checkout code
+        uses: actions/checkout@v2
 
-    - run: cargo test --verbose
-    - run: cargo build
+      - name: Setup Rust toolchain
+        uses: actions-rs/toolchain@v1
+        with:
+          profile: minimal
+          toolchain: stable
+          override: true
+          components: rustfmt, clippy
+
+      - name: cargo build
+        uses: actions-rs/cargo@v1
+        with:
+          command: build
+
+      - name: cargo test
+        uses: actions-rs/cargo@v1
+        with:
+          command: test
+
+      - name: cargo fmt
+        uses: actions-rs/cargo@v1
+        with:
+          command: fmt
+          args: --all -- --check
+
+      - name: cargo clippy
+        uses: actions-rs/cargo@v1
+        with:
+          command: clippy
+          args: -- -D warnings