Skip to content

Commit

Permalink
feat: fmt and lint respect .gitignore file (#26897)
Browse files Browse the repository at this point in the history
Closes #26573
  • Loading branch information
bartlomieju authored Nov 18, 2024
1 parent c36f877 commit 106d47a
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions cli/tools/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ fn collect_fmt_files(
})
.ignore_git_folder()
.ignore_node_modules()
.use_gitignore()
.set_vendor_folder(cli_options.vendor_dir_path().map(ToOwned::to_owned))
.collect_file_patterns(&deno_config::fs::RealDenoConfigFs, files)
}
Expand Down
1 change: 1 addition & 0 deletions cli/tools/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ fn collect_lint_files(
})
.ignore_git_folder()
.ignore_node_modules()
.use_gitignore()
.set_vendor_folder(cli_options.vendor_dir_path().map(ToOwned::to_owned))
.collect_file_patterns(&deno_config::fs::RealDenoConfigFs, files)
}
Expand Down
1 change: 1 addition & 0 deletions tests/specs/fmt/gitignore/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/dist/
6 changes: 6 additions & 0 deletions tests/specs/fmt/gitignore/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"tempDir": true,
"args": "fmt --check",
"output": "expected.out",
"exitCode": 1
}
6 changes: 6 additions & 0 deletions tests/specs/fmt/gitignore/dist/file1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// This file is in `.gitignore` simulating that it's generated by a build tool
// and should not be linted
function foo( ) {
console.log( "hello")
}

10 changes: 10 additions & 0 deletions tests/specs/fmt/gitignore/expected.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

from [WILDCARD]file2.ts:
1 | -function foo( ): any {
1 | +function foo(): any {
2 | - console.log( "hello")
2 | + console.log("hello");
3 | - }
3 | +}

error: Found 1 not formatted file in 1 file
3 changes: 3 additions & 0 deletions tests/specs/fmt/gitignore/file2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function foo( ): any {
console.log( "hello")
}
1 change: 1 addition & 0 deletions tests/specs/lint/gitignore/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/dist/
5 changes: 5 additions & 0 deletions tests/specs/lint/gitignore/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"args": "lint",
"output": "expected.out",
"exitCode": 1
}
3 changes: 3 additions & 0 deletions tests/specs/lint/gitignore/dist/file1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file is in `.gitignore` simulating that it's generated by a build tool
// and should not be linted
while (false) {}
12 changes: 12 additions & 0 deletions tests/specs/lint/gitignore/expected.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[no-empty]: Empty block statement
--> [WILDCARD]file2.ts:3:14
|
3 | } catch (_e) {}
| ^^
= hint: Add code or comment to the empty block

docs: https://lint.deno.land/rules/no-empty


Found 1 problem
Checked 1 file
6 changes: 6 additions & 0 deletions tests/specs/lint/gitignore/file2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
try {
await Deno.open("./some/file.txt");
} catch (_e) {}

// deno-lint-ignore no-explicit-any
function _foo(): any {}

0 comments on commit 106d47a

Please sign in to comment.