feat: fmt and lint respect .gitignore file (#26897)

Closes https://github.com/denoland/deno/issues/26573
This commit is contained in:
Bartek Iwańczuk 2024-11-18 22:54:28 +00:00 committed by GitHub
parent c36f877f8d
commit 106d47a013
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 55 additions and 0 deletions

View File

@ -228,6 +228,7 @@ fn collect_fmt_files(
}) })
.ignore_git_folder() .ignore_git_folder()
.ignore_node_modules() .ignore_node_modules()
.use_gitignore()
.set_vendor_folder(cli_options.vendor_dir_path().map(ToOwned::to_owned)) .set_vendor_folder(cli_options.vendor_dir_path().map(ToOwned::to_owned))
.collect_file_patterns(&deno_config::fs::RealDenoConfigFs, files) .collect_file_patterns(&deno_config::fs::RealDenoConfigFs, files)
} }

View File

@ -436,6 +436,7 @@ fn collect_lint_files(
}) })
.ignore_git_folder() .ignore_git_folder()
.ignore_node_modules() .ignore_node_modules()
.use_gitignore()
.set_vendor_folder(cli_options.vendor_dir_path().map(ToOwned::to_owned)) .set_vendor_folder(cli_options.vendor_dir_path().map(ToOwned::to_owned))
.collect_file_patterns(&deno_config::fs::RealDenoConfigFs, files) .collect_file_patterns(&deno_config::fs::RealDenoConfigFs, files)
} }

1
tests/specs/fmt/gitignore/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/dist/

View File

@ -0,0 +1,6 @@
{
"tempDir": true,
"args": "fmt --check",
"output": "expected.out",
"exitCode": 1
}

View File

@ -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")
}

View File

@ -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

View File

@ -0,0 +1,3 @@
function foo( ): any {
console.log( "hello")
}

1
tests/specs/lint/gitignore/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/dist/

View File

@ -0,0 +1,5 @@
{
"args": "lint",
"output": "expected.out",
"exitCode": 1
}

View File

@ -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) {}

View File

@ -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

View File

@ -0,0 +1,6 @@
try {
await Deno.open("./some/file.txt");
} catch (_e) {}
// deno-lint-ignore no-explicit-any
function _foo(): any {}