Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fmt and lint respect .gitignore file #26897

Merged
merged 5 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {}