Repository: dotenv-linter/dotenv-linter (rust)

Issue:
v3 recursively lints backup files by default
I could be mistaken, but I don't think v2.x re-linted the backup files. I think that it ignored them.

Feel free to close this out if this is the desired behavior, but it seems like either these should be ignored by the date pattern, or should get a `.bak` extension and be excluded that way.

```bash
dotenv-linter fix
```

```
Fixing .env
Fixing .env_1610361920
Fixing .env_1610361920_1610361924
Fixing .env_1610361920_1610361924_1610361927
Original file was backed up to: ".env_1610361920_1610361924_1610361927_1610361929"

.env_1610361920_1610361924_1610361927:3 UnorderedKey: The AWS_REGION key should go before the AWS_SECRET_ACCESS_KEY key
```

Pull request description:
feat: dont lint backup files
also:
    * add `.bak` extension to backup files

What are your thoughts on this solution @dotenv-linter/core - is this the right way to do it?

closes #359 

<!--
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] 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._ -->


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 69e5c49..0d16515 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@ ## [Unreleased]
 ### 🚀 Added
 
 ### 🔧 Changed
+- Add `.bak` extension to backup files and don't lint backup files [#367](https://github.com/dotenv-linter/dotenv-linter/pull/367) ([@mstruebing](https://github.com/mstruebing))
 - Add `.env` explanation [#363](https://github.com/dotenv-linter/dotenv-linter/pull/363) ([@henryboisdequin](https://github.com/henryboisdequin))
 
 ## [v3.0.0] - 2021-01-11
diff --git a/src/common/file_entry.rs b/src/common/file_entry.rs
index fd4def5..db97a1e 100644
--- a/src/common/file_entry.rs
+++ b/src/common/file_entry.rs
@@ -49,6 +49,7 @@ pub fn is_env_file(path: &PathBuf) -> bool {
         Self::get_file_name(path)
             .filter(|file_name| !EXCLUDED_FILES.contains(file_name))
             .filter(|file_name| file_name.starts_with(pattern) || file_name.ends_with(pattern))
+            .filter(|file_name| !file_name.ends_with(".bak"))
             .is_some()
     }
 
@@ -106,6 +107,7 @@ fn is_env_file_test() {
             ("foo-env", false),
             (".my-env-file", false),
             ("dev.env.js", false),
+            (".env.bak", false),
         ];
 
         assertions.extend(EXCLUDED_FILES.iter().map(|file| (*file, false)));
diff --git a/src/fs_utils.rs b/src/fs_utils.rs
index ac8bfca..9a27941 100644
--- a/src/fs_utils.rs
+++ b/src/fs_utils.rs
@@ -52,7 +52,7 @@ pub fn backup_file(fe: &FileEntry) -> Result<PathBuf, Box<dyn Error>> {
         .as_secs();
 
     let mut new_path = fe.path.to_owned();
-    new_path.set_file_name(format!("{}_{}", &fe.file_name, timestamp));
+    new_path.set_file_name(format!("{}_{}.bak", &fe.file_name, timestamp));
 
     copy(&fe.path, &new_path)
         .map(|_| new_path)


Test patch:
diff --git a/tests/flags/backup.rs b/tests/flags/backup.rs
index 8af6ac2..98f493c 100644
--- a/tests/flags/backup.rs
+++ b/tests/flags/backup.rs
@@ -22,6 +22,7 @@ fn output_backup_file() {
 
     assert_eq!(backup_contents, content);
     assert_eq!(testfile.contents(), "FOO=bar\n");
+    assert_eq!(backup_file.path().extension().unwrap(), "bak");
 
     testdir.close()
 }