Repository: dotenv-linter/dotenv-linter
Pull request #289 (2020-09-28 15:34:02)

Remove code related to Fixed/Unfixed
<!--
Thank you for your pull request. Please provide a description above and review
the requirements below.

Bug fixes and new features should include tests.
-->

<!-- _Please make sure to review and check all of these items:_ -->

#### ✔ Checklist:
<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->

- [x] This PR has been added to [CHANGELOG.md](https://github.com/dotenv-linter/dotenv-linter/blob/master/CHANGELOG.md) (at the top of the list);
- [x] Tests for the changes have been added (for bug fixes / features);
- [x] Docs have been added / updated (for bug fixes / features).

<!-- _NOTE: these things are not required to open a PR and can be done afterwards / while the PR is open._ -->

@evgeniy-r Please take a look 👀


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 51c49ae..6ca3941 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -24,6 +24,7 @@ ### 🚀 Added
 - Add installation CI test for Windows (via `install.sh`) [#235](https://github.com/dotenv-linter/dotenv-linter/pull/235) ([@DDtKey](https://github.com/DDtKey))
 
 ### 🔧 Changed
+- Remove code related to "Fixed/Unfixed warnings" [#289](https://github.com/dotenv-linter/dotenv-linter/pull/289) ([@mgrachev](https://github.com/mgrachev))
 - Refactoring integration tests [#288](https://github.com/dotenv-linter/dotenv-linter/pull/288) ([@mgrachev](https://github.com/mgrachev))
 - Fix a bug with fixers spawning new warnings [#287](https://github.com/dotenv-linter/dotenv-linter/pull/287) ([@evgeniy-r](https://github.com/evgeniy-r))
 - Fix a bug with `UnorderedKeyChecker` and control comments [#283](https://github.com/dotenv-linter/dotenv-linter/pull/283) ([@mgrachev](https://github.com/mgrachev))
diff --git a/README.md b/README.md
index 7e9620f..9d0671e 100644
--- a/README.md
+++ b/README.md
@@ -245,11 +245,12 @@ # dotenv-linter:on UnorderedKey (And enable it again)
 
 ```shell script
 $ dotenv-linter -f
-Fixed warnings:
-.env:3 LowercaseKey: The foo key should be in uppercase
+Original file was backed up to: ".env_1601378896"
 
-Unfixed warnings:
 .env:2 DuplicatedKey: The BAR key is duplicated
+.env:3 LowercaseKey: The foo key should be in uppercase
+
+All warnings are fixed. Total: 2
 ```
 
 ## ✅ Checks
diff --git a/docs/quick_start.md b/docs/quick_start.md
index 1b17054..155acc8 100644
--- a/docs/quick_start.md
+++ b/docs/quick_start.md
@@ -94,9 +94,10 @@ # dotenv-linter:on UnorderedKey (And enable it again)
 
 ```shell script
 $ dotenv-linter -f
-Fixed warnings:
-.env:3 LowercaseKey: The foo key should be in uppercase
+Original file was backed up to: ".env_1601378896"
 
-Unfixed warnings:
 .env:2 DuplicatedKey: The BAR key is duplicated
+.env:3 LowercaseKey: The foo key should be in uppercase
+
+All warnings are fixed. Total: 2
 ```
diff --git a/src/common/warning.rs b/src/common/warning.rs
index b197836..257acea 100644
--- a/src/common/warning.rs
+++ b/src/common/warning.rs
@@ -7,7 +7,6 @@ pub struct Warning {
     pub check_name: String,
     line: LineEntry,
     message: String,
-    pub is_fixed: bool,
 }
 
 impl Warning {
@@ -17,21 +16,12 @@ pub fn new(line: LineEntry, check_name: &str, message: String) -> Self {
             line,
             check_name,
             message,
-            is_fixed: false,
         }
     }
 
     pub fn line_number(&self) -> usize {
         self.line.number
     }
-
-    pub fn mark_as_fixed(&mut self) {
-        self.is_fixed = true;
-    }
-
-    pub fn mark_as_unfixed(&mut self) {
-        self.is_fixed = false;
-    }
 }
 
 impl fmt::Display for Warning {
diff --git a/src/fixes.rs b/src/fixes.rs
index 43c65d1..743c40c 100644
--- a/src/fixes.rs
+++ b/src/fixes.rs
@@ -24,7 +24,6 @@ fn fix_warnings(
         for warning in warnings {
             let line = lines.get_mut(warning.line_number() - 1)?;
             if self.fix_line(line).is_some() {
-                warning.mark_as_fixed();
                 count += 1;
             }
         }
@@ -79,9 +78,6 @@ pub fn run(warnings: &mut [Warning], lines: &mut Vec<LineEntry>, skip_checks: &[
             match fixer.fix_warnings(fixer_warnings, lines) {
                 Some(fixer_count) => count += fixer_count,
                 None => {
-                    for warning in warnings {
-                        warning.mark_as_unfixed();
-                    }
                     return 0;
                 }
             }
@@ -122,7 +118,6 @@ fn run_with_fixable_warning_test() {
 
         assert_eq!(1, run(&mut warnings, &mut lines, &[]));
         assert_eq!("C=d", lines[1].raw_string);
-        assert!(warnings[0].is_fixed);
     }
 
     #[test]
@@ -139,7 +134,6 @@ fn run_with_unfixable_warning_test() {
         )];
 
         assert_eq!(0, run(&mut warnings, &mut lines, &[]));
-        assert!(!warnings[0].is_fixed);
     }
 
     #[test]
@@ -163,7 +157,6 @@ fn run_when_lines_do_not_fit_numbers_test() {
         ];
 
         assert_eq!(0, run(&mut warnings, &mut lines, &[]));
-        assert!(!warnings[0].is_fixed);
     }
 
     #[test]
@@ -273,30 +266,4 @@ fn fix_line(&mut self, line: &mut LineEntry) -> Option<()> {
             }
         }
     }
-
-    #[test]
-    fn warnings_are_marked_as_fixed_if_fix_returns_some() {
-        let mut lines = vec![line_entry(1, 2, "foo=bar"), blank_line_entry(2, 2)];
-
-        let mut warning = Warning::new(lines[0].clone(), "", String::from(""));
-
-        let mut fixer = TestFixer { name: "fixer" };
-
-        fixer.fix_warnings(vec![&mut warning], &mut lines);
-
-        assert!(warning.is_fixed)
-    }
-
-    #[test]
-    fn warnings_are_not_marked_as_fixed_if_fix_returns_none() {
-        let mut lines = vec![line_entry(1, 2, "a=b"), blank_line_entry(2, 2)];
-
-        let mut warning = Warning::new(lines[0].clone(), "", String::from(""));
-
-        let mut fixer = TestFixer { name: "fixer" };
-
-        fixer.fix_warnings(vec![&mut warning], &mut lines);
-
-        assert!(!warning.is_fixed)
-    }
 }
diff --git a/src/fixes/duplicated_key.rs b/src/fixes/duplicated_key.rs
index f2a1ec4..c6bdb7d 100644
--- a/src/fixes/duplicated_key.rs
+++ b/src/fixes/duplicated_key.rs
@@ -46,12 +46,7 @@ fn fix_warnings(
             }
         }
 
-        let count = warnings.len();
-        for warning in warnings {
-            warning.mark_as_fixed();
-        }
-
-        Some(count)
+        Some(warnings.len())
     }
 
     fn fix_line(&mut self, line: &mut LineEntry) -> Option<()> {
@@ -100,8 +95,6 @@ fn fix_warnings() {
             &lines[..2],
             &[line_entry(1, 4, "FOO=BAR"), line_entry(2, 4, "Z=Y")]
         );
-
-        assert!(warnings.iter().all(|w| w.is_fixed));
     }
 
     #[test]
diff --git a/src/fixes/ending_blank_line.rs b/src/fixes/ending_blank_line.rs
index c41c1c7..19c8e68 100644
--- a/src/fixes/ending_blank_line.rs
+++ b/src/fixes/ending_blank_line.rs
@@ -20,28 +20,24 @@ fn name(&self) -> &str {
 
     fn fix_warnings(
         &mut self,
-        warnings: Vec<&mut Warning>,
+        _warnings: Vec<&mut Warning>,
         lines: &mut Vec<LineEntry>,
     ) -> Option<usize> {
         let file = lines.first()?.file.clone();
         let last_line = lines.last()?;
 
-        if !last_line.raw_string.ends_with(LF) {
-            lines.push(LineEntry {
-                number: lines.len() + 1,
-                file,
-                raw_string: LF.to_string(),
-                is_deleted: false,
-            });
-
-            for warning in warnings {
-                warning.mark_as_fixed()
-            }
-
-            return Some(1);
+        if last_line.raw_string.ends_with(LF) {
+            return Some(0);
         }
 
-        Some(0)
+        lines.push(LineEntry {
+            number: lines.len() + 1,
+            file,
+            raw_string: LF.to_string(),
+            is_deleted: false,
+        });
+
+        Some(1)
     }
 }
 
@@ -62,7 +58,6 @@ fn fix_warnings_test() {
 
         assert_eq!(Some(1), fixer.fix_warnings(vec![&mut warning], &mut lines));
         assert_eq!("\n", lines[2].raw_string);
-        assert!(warning.is_fixed);
     }
 
     #[test]
diff --git a/src/fixes/extra_blank_line.rs b/src/fixes/extra_blank_line.rs
index 027c818..2133c8e 100644
--- a/src/fixes/extra_blank_line.rs
+++ b/src/fixes/extra_blank_line.rs
@@ -61,7 +61,6 @@ fn fix_one_extra_blank_line_test() {
         let warnings = vec![&mut warning];
         let mut lines = vec![line1.clone(), line2.clone(), line3.clone(), line4.clone()];
         assert_eq!(Some(1), fixer.fix_warnings(warnings, &mut lines));
-        assert!(warning.is_fixed);
     }
 
     #[test]
@@ -92,7 +91,5 @@ fn fix_multiple_blank_lines_test() {
             line5.clone(),
         ];
         assert_eq!(Some(2), fixer.fix_warnings(warnings, &mut lines));
-        assert!(warning1.is_fixed);
-        assert!(warning2.is_fixed);
     }
 }
diff --git a/src/fixes/incorrect_delimiter.rs b/src/fixes/incorrect_delimiter.rs
index df139c0..0358486 100644
--- a/src/fixes/incorrect_delimiter.rs
+++ b/src/fixes/incorrect_delimiter.rs
@@ -86,6 +86,5 @@ fn fix_warnings_test() {
 
         assert_eq!(Some(1), fixer.fix_warnings(vec![&mut warning], &mut lines));
         assert_eq!("RAILS_ENV=development", lines[0].raw_string);
-        assert!(warning.is_fixed);
     }
 }
diff --git a/src/fixes/key_without_value.rs b/src/fixes/key_without_value.rs
index 6793e62..db4e13f 100644
--- a/src/fixes/key_without_value.rs
+++ b/src/fixes/key_without_value.rs
@@ -55,6 +55,5 @@ fn fix_warnings_test() {
 
         assert_eq!(Some(1), fixer.fix_warnings(vec![&mut warning], &mut lines));
         assert_eq!("FOO=", lines[0].raw_string);
-        assert!(warning.is_fixed);
     }
 }
diff --git a/src/fixes/lowercase_key.rs b/src/fixes/lowercase_key.rs
index 45cab18..8f4dd08 100644
--- a/src/fixes/lowercase_key.rs
+++ b/src/fixes/lowercase_key.rs
@@ -57,6 +57,5 @@ fn fix_warnings_test() {
 
         assert_eq!(Some(1), fixer.fix_warnings(vec![&mut warning], &mut lines));
         assert_eq!("FOO=BAR", lines[0].raw_string);
-        assert!(warning.is_fixed);
     }
 }
diff --git a/src/fixes/quote_character.rs b/src/fixes/quote_character.rs
index e8492dc..9bd0e12 100644
--- a/src/fixes/quote_character.rs
+++ b/src/fixes/quote_character.rs
@@ -58,6 +58,5 @@ fn fix_warnings_test() {
 
         assert_eq!(Some(1), fixer.fix_warnings(vec![&mut warning], &mut lines));
         assert_eq!("FOO=bar", lines[0].raw_string);
-        assert!(warning.is_fixed);
     }
 }
diff --git a/src/fixes/trailing_whitespace.rs b/src/fixes/trailing_whitespace.rs
index 6f49a89..f7bceef 100644
--- a/src/fixes/trailing_whitespace.rs
+++ b/src/fixes/trailing_whitespace.rs
@@ -55,6 +55,5 @@ fn fix_warnings_test() {
 
         assert_eq!(Some(1), fixer.fix_warnings(vec![&mut warning], &mut lines));
         assert_eq!("FOO=BAR", lines[0].raw_string);
-        assert!(warning.is_fixed);
     }
 }
diff --git a/src/fixes/unordered_key.rs b/src/fixes/unordered_key.rs
index c00ea68..0613df6 100644
--- a/src/fixes/unordered_key.rs
+++ b/src/fixes/unordered_key.rs
@@ -39,7 +39,6 @@ fn fix_warnings(
         lines: &mut Vec<LineEntry>,
     ) -> Option<usize> {
         // We find all sorting groups and sort them
-
         let mut start_index = 0;
         let mut end = None;
         let mut is_disabled = false;
@@ -77,12 +76,7 @@ fn fix_warnings(
             }
         }
 
-        let count = warnings.len();
-        for warning in warnings {
-            warning.mark_as_fixed();
-        }
-
-        Some(count)
+        Some(warnings.len())
     }
 }
 
@@ -156,8 +150,6 @@ fn fix_warnings_test() {
         assert_eq!(Some(1), run_fixer(&mut warnings, &mut lines));
 
         assert_lines(&lines, vec!["A=B", "B=C", "D=E", "\n"]);
-
-        assert!(warnings[0].is_fixed);
     }
 
     #[test]
@@ -188,10 +180,6 @@ fn many_moves_test() {
             &lines,
             vec!["A=A", "D=D", "KLM=123", "X=X", "Y=Y", "Z=Z", "\n"],
         );
-
-        for warning in warnings {
-            assert!(warning.is_fixed);
-        }
     }
 
     #[test]
@@ -223,8 +211,6 @@ fn previous_comments_test() {
                 "\n",
             ],
         );
-
-        assert!(warnings[0].is_fixed);
     }
 
     #[test]
@@ -282,10 +268,6 @@ fn several_groups_test() {
                 "\n",
             ],
         );
-
-        for warning in warnings {
-            assert!(warning.is_fixed);
-        }
     }
 
     #[test]
@@ -296,8 +278,6 @@ fn no_ending_blank_line_test() {
         assert_eq!(Some(1), run_fixer(&mut warnings, &mut lines));
 
         assert_lines(&lines, vec!["A=B", "B=C", "D=E"]);
-
-        assert!(warnings[0].is_fixed);
     }
 
     #[test]
@@ -366,10 +346,6 @@ fn some_lines_control_comments_test() {
                 "\n",
             ],
         );
-
-        for warning in warnings {
-            assert!(warning.is_fixed);
-        }
     }
 
     #[test]
@@ -410,10 +386,6 @@ fn other_checker_control_comments_test() {
                 "\n",
             ],
         );
-
-        for warning in warnings {
-            assert!(warning.is_fixed);
-        }
     }
 
     #[test]
@@ -459,10 +431,6 @@ fn different_control_comments_test() {
                 "\n",
             ],
         );
-
-        for warning in warnings {
-            assert!(warning.is_fixed);
-        }
     }
 
     #[test]
@@ -498,8 +466,6 @@ fn comment_between_control_comments_test() {
                 "\n",
             ],
         );
-
-        assert!(warnings[0].is_fixed);
     }
 
     #[test]
@@ -545,10 +511,6 @@ fn crossed_control_comments_test() {
                 "\n",
             ],
         );
-
-        for warning in warnings {
-            assert!(warning.is_fixed);
-        }
     }
 
     #[test]
@@ -599,10 +561,6 @@ fn nested_control_comments_test() {
                 "\n",
             ],
         );
-
-        for warning in warnings {
-            assert!(warning.is_fixed);
-        }
     }
 
     #[test]
@@ -642,10 +600,6 @@ fn empty_control_comments_test() {
                 "\n",
             ],
         );
-
-        for warning in warnings {
-            assert!(warning.is_fixed);
-        }
     }
 
     #[test]
@@ -727,9 +681,5 @@ fn control_comments_and_blank_lines_test() {
                 "\n",
             ],
         );
-
-        for warning in warnings {
-            assert!(warning.is_fixed);
-        }
     }
 }
diff --git a/src/main.rs b/src/main.rs
index 28bab04..e466c93 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -20,31 +20,22 @@ fn main() -> Result<(), Box<dyn Error>> {
         process::exit(0);
     }
 
-    let is_fix = args.is_present("fix");
+    let total = warnings.len();
+    let is_not_quiet = !args.is_present("quiet");
 
-    if is_fix {
-        let (fixed, unfixed): (Vec<_>, Vec<_>) = warnings.iter().partition(|w| w.is_fixed);
-
-        if !fixed.is_empty() {
-            println!("Fixed warnings:");
-            for w in fixed {
-                println!("{}", w);
-            }
+    if args.is_present("fix") {
+        if is_not_quiet {
+            warnings.iter().for_each(|w| println!("{}", w));
+            println!();
         }
 
-        if !unfixed.is_empty() {
-            println!("\nUnfixed warnings:");
-            for w in unfixed {
-                println!("{}", w);
-            }
-        } else {
-            process::exit(0);
-        }
+        println!("All warnings are fixed. Total: {}", total);
+        process::exit(0);
     } else {
         warnings.iter().for_each(|w| println!("{}", w));
 
-        if !args.is_present("quiet") {
-            print_total(warnings.len());
+        if is_not_quiet {
+            print_total(total);
         }
     }
 


Test patch:
diff --git a/tests/common/output.rs b/tests/common/output.rs
index 96877f7..ab2729a 100644
--- a/tests/common/output.rs
+++ b/tests/common/output.rs
@@ -1,6 +1,7 @@
-const FIX_SENTENCE: &str = "Fixed warnings:";
+const FIX_SENTENCE: &str = "All warnings are fixed. Total:";
 
 pub fn fix_output(warnings: &[&str]) -> String {
+    let total = warnings.len();
     let output: &str = &warnings.join("\n");
-    String::from(format!("{}\n{}\n", FIX_SENTENCE, output))
+    String::from(format!("{}\n\n{} {}\n", output, FIX_SENTENCE, total))
 }
diff --git a/tests/flags/quiet.rs b/tests/flags/quiet.rs
index a4c234e..5bb03b0 100644
--- a/tests/flags/quiet.rs
+++ b/tests/flags/quiet.rs
@@ -1,7 +1,7 @@
 use crate::common::TestDir;
 
 #[test]
-fn output_without_total() {
+fn check_output_in_quiet_mode() {
     let test_dir = TestDir::new();
     let testfile_to_check = test_dir.create_testfile(".env", " BAR='Baz'\n");
 
@@ -13,3 +13,15 @@ fn output_without_total() {
 
     test_dir.test_command_fail_with_args(args, expected_output);
 }
+
+#[test]
+fn fix_output_in_quiet_mode() {
+    let test_dir = TestDir::new();
+    let _ = test_dir.create_testfile(".env", "abc=DEF\n\nF=BAR\nB=bbb\n");
+
+    let args = &["--quiet"];
+    let expected_output = format!("All warnings are fixed. Total: {}\n", 2);
+
+    test_dir.test_command_fix_success_with_args(expected_output, args);
+    test_dir.close();
+}