Repository: dotenv-linter/dotenv-linter
Pull request #392 (2021-03-18 21:12:03)

Print message if there are no input files (#384)
This implements #384 

I had to change the exclude tests as well, as they just excluded all loaded files... :)

#### ✔ Checklist:
<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->

- [x] Commit messages have been written in [Conventional Commits](https://www.conventionalcommits.org) format;
- [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);
- [ ] Docs have been added / updated on the [dotenv-linter.github.io](https://github.com/dotenv-linter/dotenv-linter.github.io) (for bug fixes / features).

<!-- _NOTE: these things are not required to open a PR and can be done afterwards / while the PR is open._ -->


codecov-io: # [Codecov](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/392?src=pr&el=h1) Report
> Merging [#392](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/392?src=pr&el=desc) (d44e3de) into [master](https://codecov.io/gh/dotenv-linter/dotenv-linter/commit/9ffbbe703fe011907b5c608491db9ae10b9be589?el=desc) (9ffbbe7) will **increase** coverage by `0.00%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/392/graphs/tree.svg?width=650&height=150&src=pr&token=wQybePfHI1)](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/392?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master     #392   +/-   ##
=======================================
  Coverage   95.57%   95.58%           
=======================================
  Files          37       37           
  Lines        2375     2380    +5     
=======================================
+ Hits         2270     2275    +5     
  Misses        105      105           
```


| [Impacted Files](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/392?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/common/output/check.rs](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/392/diff?src=pr&el=tree#diff-c3JjL2NvbW1vbi9vdXRwdXQvY2hlY2sucnM=) | `100.00% <100.00%> (ø)` | |
| [src/lib.rs](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/392/diff?src=pr&el=tree#diff-c3JjL2xpYi5ycw==) | `90.00% <100.00%> (+0.07%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/392?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/392?src=pr&el=footer). Last update [9ffbbe7...d44e3de](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/392?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ba53dca..8f33535 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,7 @@ # Changelog
 
 ## [Unreleased]
 ### 🚀 Added
+- Print a message when there are no input files [#392](https://github.com/dotenv-linter/dotenv-linter/pull/392) ([@jodli](https://github.com/jodli))
 - Add a GitHub Action to compare benchmarks [#378](https://github.com/dotenv-linter/dotenv-linter/pull/378) ([@mgrachev](https://github.com/mgrachev))
 - Add benchmark for the check function [#376](https://github.com/dotenv-linter/dotenv-linter/pull/376) ([@mgrachev](https://github.com/mgrachev))
 
diff --git a/src/common/output/check.rs b/src/common/output/check.rs
index ca22070..eee3e83 100644
--- a/src/common/output/check.rs
+++ b/src/common/output/check.rs
@@ -16,6 +16,13 @@ pub fn new(is_quiet_mode: bool, files_count: usize) -> Self {
         }
     }
 
+    /// Prints a message that there is nothing to check
+    pub fn print_nothing_to_check(&self) {
+        if !self.is_quiet_mode {
+            println!("Nothing to check");
+        }
+    }
+
     /// Prints information about a file in process
     pub fn print_processing_info(&self, file: &FileEntry) {
         if !self.is_quiet_mode {
diff --git a/src/lib.rs b/src/lib.rs
index cff80a2..c68af25 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -16,9 +16,10 @@
 
 pub fn check(args: &clap::ArgMatches, current_dir: &PathBuf) -> Result<usize, Box<dyn Error>> {
     let lines_map = get_lines(args, current_dir);
+    let output = CheckOutput::new(args.is_present("quiet"), lines_map.len());
 
-    // Nothing to check
     if lines_map.is_empty() {
+        output.print_nothing_to_check();
         return Ok(0);
     }
 
@@ -27,7 +28,6 @@ pub fn check(args: &clap::ArgMatches, current_dir: &PathBuf) -> Result<usize, Bo
         skip_checks = skip.collect();
     }
 
-    let output = CheckOutput::new(args.is_present("quiet"), lines_map.len());
     let warnings_count =
         lines_map
             .into_iter()


Test patch:
diff --git a/tests/options/exclude.rs b/tests/options/exclude.rs
index dc783f6..0307bd7 100644
--- a/tests/options/exclude.rs
+++ b/tests/options/exclude.rs
@@ -5,7 +5,10 @@ fn exclude_one_file() {
     let test_dir = TestDir::new();
     let testfile = test_dir.create_testfile(".env", " FOO=\n");
 
-    let expected_output = check_output(&[]);
+    let expected_output = String::from(
+        r#"Nothing to check
+"#,
+    );
 
     test_dir.test_command_success_with_args(&["--exclude", testfile.as_str()], expected_output);
 }
@@ -16,7 +19,10 @@ fn exclude_two_files() {
     let testfile_1 = test_dir.create_testfile(".env", " FOO=\n");
     let testfile_2 = test_dir.create_testfile(".local.env", " BAR=\n");
 
-    let expected_output = check_output(&[]);
+    let expected_output = String::from(
+        r#"Nothing to check
+"#,
+    );
 
     test_dir.test_command_success_with_args(
         &["-e", testfile_1.as_str(), "-e", testfile_2.as_str()],
diff --git a/tests/output/check.rs b/tests/output/check.rs
index 5285936..74045d1 100644
--- a/tests/output/check.rs
+++ b/tests/output/check.rs
@@ -107,6 +107,18 @@ fn no_problems_multiple_files() {
     test_dir.test_command_success(expected_output);
 }
 
+#[test]
+fn no_files() {
+    let test_dir = TestDir::new();
+
+    let expected_output = String::from(
+        r#"Nothing to check
+"#,
+    );
+
+    test_dir.test_command_success(expected_output);
+}
+
 #[test]
 fn quiet() {
     let test_dir = TestDir::new();
@@ -130,3 +142,13 @@ fn quiet_no_problems() {
 
     test_dir.test_command_success_with_args(args, expected_output);
 }
+
+#[test]
+fn quiet_no_files() {
+    let test_dir = TestDir::new();
+
+    let args = &["--quiet"];
+    let expected_output = String::from("");
+
+    test_dir.test_command_success_with_args(args, expected_output);
+}