mirror of
https://github.com/denoland/deno.git
synced 2024-11-28 16:20:57 -05:00
feat: add support for globs in the config file and CLI arguments for files (#19102)
Follow up to https://github.com/denoland/deno/pull/19084. This commit adds support for globs in the configuration file as well as CLI arguments for files. With this change users can now use glob syntax for "include" and "exclude" fields, like so: ```json { "lint": { "include": [ "directory/test*.ts", "other_dir/" ], "exclude": [ "other_dir/foo*.ts", "nested/nested2/*" ] }, "test": { "include": [ "data/test*.ts", "nested/", "tests/test[1-9].ts" ], "exclude": [ "nested/foo?.ts", "nested/nested2/*" ] } } ``` Or in CLI args like so: ``` // notice quotes here; these values will be passed to Deno verbatim // and deno will perform glob expansion $ deno fmt --ignore="data/*.ts" $ deno lint "data/**/*.ts" ``` Closes https://github.com/denoland/deno/issues/17971 Closes https://github.com/denoland/deno/issues/6365
This commit is contained in:
parent
bb37dfb5b7
commit
5874fc3d0a
52 changed files with 528 additions and 34 deletions
|
@ -35,6 +35,8 @@
|
|||
"cli/tests/testdata/byte_order_mark.ts",
|
||||
"cli/tests/testdata/encoding",
|
||||
"cli/tests/testdata/fmt/*",
|
||||
"cli/tests/testdata/lint/glob/*",
|
||||
"cli/tests/testdata/test/glob/*",
|
||||
"cli/tests/testdata/import_assertions/json_with_shebang.json",
|
||||
"cli/tests/testdata/run/inline_js_source_map*",
|
||||
"cli/tests/testdata/malformed_config/*",
|
||||
|
|
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -750,6 +750,7 @@ dependencies = [
|
|||
"fs3",
|
||||
"fwdansi",
|
||||
"glibc_version",
|
||||
"glob",
|
||||
"http",
|
||||
"hyper 0.14.26",
|
||||
"import_map 0.15.0",
|
||||
|
|
|
@ -75,6 +75,7 @@ fancy-regex = "=0.10.0"
|
|||
fastwebsockets.workspace = true
|
||||
flate2.workspace = true
|
||||
fs3.workspace = true
|
||||
glob = "0.3.1"
|
||||
http.workspace = true
|
||||
hyper.workspace = true
|
||||
import_map = "=0.15.0"
|
||||
|
|
|
@ -299,24 +299,19 @@ impl SerializedFilesConfig {
|
|||
self,
|
||||
config_file_specifier: &ModuleSpecifier,
|
||||
) -> Result<FilesConfig, AnyError> {
|
||||
let config_dir = specifier_parent(config_file_specifier);
|
||||
let config_dir =
|
||||
specifier_to_file_path(&specifier_parent(config_file_specifier))?;
|
||||
Ok(FilesConfig {
|
||||
include: self
|
||||
.include
|
||||
.into_iter()
|
||||
.map(|p| {
|
||||
let url = config_dir.join(&p)?;
|
||||
specifier_to_file_path(&url)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?,
|
||||
.map(|p| config_dir.join(p))
|
||||
.collect::<Vec<_>>(),
|
||||
exclude: self
|
||||
.exclude
|
||||
.into_iter()
|
||||
.map(|p| {
|
||||
let url = config_dir.join(&p)?;
|
||||
specifier_to_file_path(&url)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?,
|
||||
.map(|p| config_dir.join(p))
|
||||
.collect::<Vec<_>>(),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
122
cli/args/mod.rs
122
cli/args/mod.rs
|
@ -138,7 +138,7 @@ impl BenchOptions {
|
|||
files: resolve_files(
|
||||
maybe_bench_config.map(|c| c.files),
|
||||
Some(bench_flags.files),
|
||||
),
|
||||
)?,
|
||||
filter: bench_flags.filter,
|
||||
json: bench_flags.json,
|
||||
no_run: bench_flags.no_run,
|
||||
|
@ -183,7 +183,7 @@ impl FmtOptions {
|
|||
files: resolve_files(
|
||||
maybe_config_files,
|
||||
maybe_fmt_flags.map(|f| f.files),
|
||||
),
|
||||
)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -253,7 +253,7 @@ impl TestOptions {
|
|||
files: resolve_files(
|
||||
maybe_test_config.map(|c| c.files),
|
||||
Some(test_flags.files),
|
||||
),
|
||||
)?,
|
||||
allow_none: test_flags.allow_none,
|
||||
concurrent_jobs: test_flags
|
||||
.concurrent_jobs
|
||||
|
@ -348,7 +348,7 @@ impl LintOptions {
|
|||
Ok(Self {
|
||||
reporter_kind: maybe_reporter_kind.unwrap_or_default(),
|
||||
is_stdin,
|
||||
files: resolve_files(maybe_config_files, Some(maybe_file_flags)),
|
||||
files: resolve_files(maybe_config_files, Some(maybe_file_flags))?,
|
||||
rules: resolve_lint_rules_options(
|
||||
maybe_config_rules,
|
||||
maybe_rules_tags,
|
||||
|
@ -1323,13 +1323,46 @@ impl StorageKeyResolver {
|
|||
}
|
||||
}
|
||||
|
||||
fn expand_globs(paths: &[PathBuf]) -> Result<Vec<PathBuf>, AnyError> {
|
||||
let mut new_paths = vec![];
|
||||
for path in paths {
|
||||
let path_str = path.to_string_lossy();
|
||||
if path_str.chars().any(|c| matches!(c, '*' | '?')) {
|
||||
// Escape brackets - we currently don't support them, because with introduction
|
||||
// of glob expansion paths like "pages/[id].ts" would suddenly start giving
|
||||
// wrong results. We might want to revisit that in the future.
|
||||
let escaped_path_str = path_str.replace('[', "[[]").replace(']', "[]]");
|
||||
let globbed_paths = glob::glob_with(
|
||||
&escaped_path_str,
|
||||
// Matches what `deno_task_shell` does
|
||||
glob::MatchOptions {
|
||||
// false because it should work the same way on case insensitive file systems
|
||||
case_sensitive: false,
|
||||
// true because it copies what sh does
|
||||
require_literal_separator: true,
|
||||
// true because it copies with sh does—these files are considered "hidden"
|
||||
require_literal_leading_dot: true,
|
||||
},
|
||||
)?;
|
||||
|
||||
for globbed_path_result in globbed_paths {
|
||||
new_paths.push(globbed_path_result?);
|
||||
}
|
||||
} else {
|
||||
new_paths.push(path.clone());
|
||||
}
|
||||
}
|
||||
|
||||
Ok(new_paths)
|
||||
}
|
||||
|
||||
/// Collect included and ignored files. CLI flags take precedence
|
||||
/// over config file, i.e. if there's `files.ignore` in config file
|
||||
/// and `--ignore` CLI flag, only the flag value is taken into account.
|
||||
fn resolve_files(
|
||||
maybe_files_config: Option<FilesConfig>,
|
||||
maybe_file_flags: Option<FileFlags>,
|
||||
) -> FilesConfig {
|
||||
) -> Result<FilesConfig, AnyError> {
|
||||
let mut result = maybe_files_config.unwrap_or_default();
|
||||
if let Some(file_flags) = maybe_file_flags {
|
||||
if !file_flags.include.is_empty() {
|
||||
|
@ -1339,7 +1372,16 @@ fn resolve_files(
|
|||
result.exclude = file_flags.ignore;
|
||||
}
|
||||
}
|
||||
result
|
||||
// Now expand globs if there are any
|
||||
if !result.include.is_empty() {
|
||||
result.include = expand_globs(&result.include)?;
|
||||
}
|
||||
|
||||
if !result.exclude.is_empty() {
|
||||
result.exclude = expand_globs(&result.exclude)?;
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
/// Resolves the no_prompt value based on the cli flags and environment.
|
||||
|
@ -1365,6 +1407,7 @@ pub fn npm_pkg_req_ref_to_binary_command(
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[cfg(not(windows))]
|
||||
#[test]
|
||||
|
@ -1520,4 +1563,71 @@ mod test {
|
|||
let resolver = StorageKeyResolver::empty();
|
||||
assert_eq!(resolver.resolve_storage_key(&specifier), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resolve_files_test() {
|
||||
use test_util::TempDir;
|
||||
let temp_dir = TempDir::new();
|
||||
|
||||
temp_dir.create_dir_all("data");
|
||||
temp_dir.create_dir_all("nested");
|
||||
temp_dir.create_dir_all("nested/foo");
|
||||
temp_dir.create_dir_all("nested/fizz");
|
||||
temp_dir.create_dir_all("pages");
|
||||
|
||||
temp_dir.write("data/tes.ts", "");
|
||||
temp_dir.write("data/test1.js", "");
|
||||
temp_dir.write("data/test1.ts", "");
|
||||
temp_dir.write("data/test12.ts", "");
|
||||
|
||||
temp_dir.write("nested/foo/foo.ts", "");
|
||||
temp_dir.write("nested/foo/bar.ts", "");
|
||||
temp_dir.write("nested/foo/fizz.ts", "");
|
||||
temp_dir.write("nested/foo/bazz.ts", "");
|
||||
|
||||
temp_dir.write("nested/fizz/foo.ts", "");
|
||||
temp_dir.write("nested/fizz/bar.ts", "");
|
||||
temp_dir.write("nested/fizz/fizz.ts", "");
|
||||
temp_dir.write("nested/fizz/bazz.ts", "");
|
||||
|
||||
temp_dir.write("pages/[id].ts", "");
|
||||
|
||||
let resolved_files = resolve_files(
|
||||
Some(FilesConfig {
|
||||
include: vec![
|
||||
temp_dir.path().join("data/test1.?s"),
|
||||
temp_dir.path().join("nested/foo/*.ts"),
|
||||
temp_dir.path().join("nested/fizz/*.ts"),
|
||||
temp_dir.path().join("pages/[id].ts"),
|
||||
],
|
||||
exclude: vec![temp_dir.path().join("nested/**/*bazz.ts")],
|
||||
}),
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
resolved_files.include,
|
||||
vec![
|
||||
temp_dir.path().join("data/test1.js"),
|
||||
temp_dir.path().join("data/test1.ts"),
|
||||
temp_dir.path().join("nested/foo/bar.ts"),
|
||||
temp_dir.path().join("nested/foo/bazz.ts"),
|
||||
temp_dir.path().join("nested/foo/fizz.ts"),
|
||||
temp_dir.path().join("nested/foo/foo.ts"),
|
||||
temp_dir.path().join("nested/fizz/bar.ts"),
|
||||
temp_dir.path().join("nested/fizz/bazz.ts"),
|
||||
temp_dir.path().join("nested/fizz/fizz.ts"),
|
||||
temp_dir.path().join("nested/fizz/foo.ts"),
|
||||
temp_dir.path().join("pages/[id].ts"),
|
||||
]
|
||||
);
|
||||
assert_eq!(
|
||||
resolved_files.exclude,
|
||||
vec![
|
||||
temp_dir.path().join("nested/fizz/bazz.ts"),
|
||||
temp_dir.path().join("nested/foo/bazz.ts"),
|
||||
]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -225,7 +225,7 @@
|
|||
},
|
||||
"exclude": {
|
||||
"type": "array",
|
||||
"description": "List of files or directories that will be ignored by all other configurations. Requires Deno 1.34 or later.",
|
||||
"description": "List of files, directories or globs that will be ignored by all other configurations. Requires Deno 1.34 or later.",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
|
@ -236,14 +236,14 @@
|
|||
"properties": {
|
||||
"include": {
|
||||
"type": "array",
|
||||
"description": "List of files or directories that will be linted.",
|
||||
"description": "List of files, directories or globs that will be linted.",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"exclude": {
|
||||
"type": "array",
|
||||
"description": "List of files or directories that will not be linted.",
|
||||
"description": "List of files, directories or globs that will not be linted.",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
|
@ -253,14 +253,14 @@
|
|||
"properties": {
|
||||
"include": {
|
||||
"type": "array",
|
||||
"description": "List of files or directories that will be linted.",
|
||||
"description": "List of files, directories or globs that will be linted.",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"exclude": {
|
||||
"type": "array",
|
||||
"description": "List of files or directories that will not be linted.",
|
||||
"description": "List of files, directories or globs that will not be linted.",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
|
@ -316,14 +316,14 @@
|
|||
"properties": {
|
||||
"include": {
|
||||
"type": "array",
|
||||
"description": "List of files or directories that will be formatted.",
|
||||
"description": "List of files, directories or globs that will be formatted.",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"exclude": {
|
||||
"type": "array",
|
||||
"description": "List of files or directories that will not be formatted.",
|
||||
"description": "List of files, directories or globs that will not be formatted.",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
|
@ -333,14 +333,14 @@
|
|||
"properties": {
|
||||
"include": {
|
||||
"type": "array",
|
||||
"description": "List of files or directories that will be formatted.",
|
||||
"description": "List of files, directories or globs that will be formatted.",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"exclude": {
|
||||
"type": "array",
|
||||
"description": "List of files or directories that will not be formatted.",
|
||||
"description": "List of files, directories or globs that will not be formatted.",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
|
@ -443,14 +443,14 @@
|
|||
"properties": {
|
||||
"include": {
|
||||
"type": "array",
|
||||
"description": "List of files or directories that will be searched for tests.",
|
||||
"description": "List of files, directories or globs that will be searched for tests.",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"exclude": {
|
||||
"type": "array",
|
||||
"description": "List of files or directories that will not be searched for tests.",
|
||||
"description": "List of files, directories or globs that will not be searched for tests.",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
|
@ -460,14 +460,14 @@
|
|||
"properties": {
|
||||
"include": {
|
||||
"type": "array",
|
||||
"description": "List of files or directories that will be searched for tests.",
|
||||
"description": "List of files, directories or globs that will be searched for tests.",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"exclude": {
|
||||
"type": "array",
|
||||
"description": "List of files or directories that will not be searched for tests.",
|
||||
"description": "List of files, directories or globs that will not be searched for tests.",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
|
@ -482,14 +482,14 @@
|
|||
"properties": {
|
||||
"include": {
|
||||
"type": "array",
|
||||
"description": "List of files or directories that will be searched for benchmarks.",
|
||||
"description": "List of files, directories or globs that will be searched for benchmarks.",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"exclude": {
|
||||
"type": "array",
|
||||
"description": "List of files or directories that will not be searched for benchmarks.",
|
||||
"description": "List of files, directories or globs that will not be searched for benchmarks.",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
|
@ -499,14 +499,14 @@
|
|||
"properties": {
|
||||
"include": {
|
||||
"type": "array",
|
||||
"description": "List of files or directories that will be searched for benchmarks.",
|
||||
"description": "List of files, directories or globs that will be searched for benchmarks.",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"exclude": {
|
||||
"type": "array",
|
||||
"description": "List of files or directories that will not be searched for benchmarks.",
|
||||
"description": "List of files, directories or globs that will not be searched for benchmarks.",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
use test_util as util;
|
||||
use test_util::TempDir;
|
||||
use util::assert_contains;
|
||||
use util::TestContext;
|
||||
use util::TestContextBuilder;
|
||||
|
||||
#[test]
|
||||
fn fmt_test() {
|
||||
|
@ -257,3 +259,93 @@ itest!(fmt_with_malformed_config2 {
|
|||
output: "fmt/fmt_with_malformed_config2.out",
|
||||
exit_code: 1,
|
||||
});
|
||||
|
||||
#[test]
|
||||
fn fmt_with_glob_config() {
|
||||
let context = TestContextBuilder::new().cwd("fmt").build();
|
||||
|
||||
let cmd_output = context
|
||||
.new_command()
|
||||
.args("fmt --check --config deno.glob.json")
|
||||
.run();
|
||||
|
||||
cmd_output.assert_exit_code(1);
|
||||
|
||||
let output = cmd_output.combined_output();
|
||||
if cfg!(windows) {
|
||||
assert_contains!(output, r#"glob\nested\fizz\fizz.ts"#);
|
||||
assert_contains!(output, r#"glob\pages\[id].ts"#);
|
||||
assert_contains!(output, r#"glob\nested\fizz\bar.ts"#);
|
||||
assert_contains!(output, r#"glob\nested\foo\foo.ts"#);
|
||||
assert_contains!(output, r#"glob\data\test1.js"#);
|
||||
assert_contains!(output, r#"glob\nested\foo\bar.ts"#);
|
||||
assert_contains!(output, r#"glob\nested\foo\fizz.ts"#);
|
||||
assert_contains!(output, r#"glob\nested\fizz\foo.ts"#);
|
||||
assert_contains!(output, r#"glob\data\test1.ts"#);
|
||||
} else {
|
||||
assert_contains!(output, "glob/nested/fizz/fizz.ts");
|
||||
assert_contains!(output, "glob/pages/[id].ts");
|
||||
assert_contains!(output, "glob/nested/fizz/bar.ts");
|
||||
assert_contains!(output, "glob/nested/foo/foo.ts");
|
||||
assert_contains!(output, "glob/data/test1.js");
|
||||
assert_contains!(output, "glob/nested/foo/bar.ts");
|
||||
assert_contains!(output, "glob/nested/foo/fizz.ts");
|
||||
assert_contains!(output, "glob/nested/fizz/foo.ts");
|
||||
assert_contains!(output, "glob/data/test1.ts");
|
||||
}
|
||||
|
||||
assert_contains!(output, "Found 9 not formatted files in 9 files");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fmt_with_glob_config_and_flags() {
|
||||
let context = TestContextBuilder::new().cwd("fmt").build();
|
||||
|
||||
let cmd_output = context
|
||||
.new_command()
|
||||
.args("fmt --check --config deno.glob.json --ignore=glob/nested/**/bar.ts")
|
||||
.run();
|
||||
|
||||
cmd_output.assert_exit_code(1);
|
||||
|
||||
let output = cmd_output.combined_output();
|
||||
if cfg!(windows) {
|
||||
assert_contains!(output, r#"glob\nested\fizz\fizz.ts"#);
|
||||
assert_contains!(output, r#"glob\pages\[id].ts"#);
|
||||
assert_contains!(output, r#"glob\nested\fizz\bazz.ts"#);
|
||||
assert_contains!(output, r#"glob\nested\foo\foo.ts"#);
|
||||
assert_contains!(output, r#"glob\data\test1.js"#);
|
||||
assert_contains!(output, r#"glob\nested\foo\bazz.ts"#);
|
||||
assert_contains!(output, r#"glob\nested\foo\fizz.ts"#);
|
||||
assert_contains!(output, r#"glob\nested\fizz\foo.ts"#);
|
||||
assert_contains!(output, r#"glob\data\test1.ts"#);
|
||||
} else {
|
||||
assert_contains!(output, "glob/nested/fizz/fizz.ts");
|
||||
assert_contains!(output, "glob/pages/[id].ts");
|
||||
assert_contains!(output, "glob/nested/fizz/bazz.ts");
|
||||
assert_contains!(output, "glob/nested/foo/foo.ts");
|
||||
assert_contains!(output, "glob/data/test1.js");
|
||||
assert_contains!(output, "glob/nested/foo/bazz.ts");
|
||||
assert_contains!(output, "glob/nested/foo/fizz.ts");
|
||||
assert_contains!(output, "glob/nested/fizz/foo.ts");
|
||||
assert_contains!(output, "glob/data/test1.ts");
|
||||
}
|
||||
assert_contains!(output, "Found 9 not formatted files in 9 files");
|
||||
let cmd_output = context
|
||||
.new_command()
|
||||
.args("fmt --check --config deno.glob.json glob/data/test1.?s")
|
||||
.run();
|
||||
|
||||
cmd_output.assert_exit_code(1);
|
||||
|
||||
let output = cmd_output.combined_output();
|
||||
if cfg!(windows) {
|
||||
assert_contains!(output, r#"glob\data\test1.js"#);
|
||||
assert_contains!(output, r#"glob\data\test1.ts"#);
|
||||
} else {
|
||||
assert_contains!(output, "glob/data/test1.js");
|
||||
assert_contains!(output, "glob/data/test1.ts");
|
||||
}
|
||||
|
||||
assert_contains!(output, "Found 2 not formatted files in 2 files");
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use test_util::assert_contains;
|
||||
use test_util::TestContextBuilder;
|
||||
|
||||
itest!(ignore_unexplicit_files {
|
||||
args: "lint --unstable --ignore=./",
|
||||
output_str: Some("error: No target files found.\n"),
|
||||
|
@ -114,3 +117,95 @@ itest!(lint_with_malformed_config2 {
|
|||
output: "lint/with_malformed_config2.out",
|
||||
exit_code: 1,
|
||||
});
|
||||
|
||||
#[test]
|
||||
fn lint_with_glob_config() {
|
||||
let context = TestContextBuilder::new().cwd("lint").build();
|
||||
|
||||
let cmd_output = context
|
||||
.new_command()
|
||||
.args("lint --config deno.glob.json")
|
||||
.run();
|
||||
|
||||
cmd_output.assert_exit_code(1);
|
||||
|
||||
let output = cmd_output.combined_output();
|
||||
if cfg!(windows) {
|
||||
assert_contains!(output, r#"glob\nested\fizz\fizz.ts:1:10"#);
|
||||
assert_contains!(output, r#"glob\pages\[id].ts:1:10"#);
|
||||
assert_contains!(output, r#"glob\nested\fizz\bar.ts:1:10"#);
|
||||
assert_contains!(output, r#"glob\nested\foo\foo.ts:1:10"#);
|
||||
assert_contains!(output, r#"glob\data\test1.js:1:10"#);
|
||||
assert_contains!(output, r#"glob\nested\foo\bar.ts:1:10"#);
|
||||
assert_contains!(output, r#"glob\nested\foo\fizz.ts:1:10"#);
|
||||
assert_contains!(output, r#"glob\nested\fizz\foo.ts:1:10"#);
|
||||
assert_contains!(output, r#"glob\data\test1.ts:1:10"#);
|
||||
} else {
|
||||
assert_contains!(output, "glob/nested/fizz/fizz.ts:1:10");
|
||||
assert_contains!(output, "glob/pages/[id].ts:1:10");
|
||||
assert_contains!(output, "glob/nested/fizz/bar.ts:1:10");
|
||||
assert_contains!(output, "glob/nested/foo/foo.ts:1:10");
|
||||
assert_contains!(output, "glob/data/test1.js:1:10");
|
||||
assert_contains!(output, "glob/nested/foo/bar.ts:1:10");
|
||||
assert_contains!(output, "glob/nested/foo/fizz.ts:1:10");
|
||||
assert_contains!(output, "glob/nested/fizz/foo.ts:1:10");
|
||||
assert_contains!(output, "glob/data/test1.ts:1:10");
|
||||
}
|
||||
assert_contains!(output, "Found 9 problems");
|
||||
assert_contains!(output, "Checked 9 files");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lint_with_glob_config_and_flags() {
|
||||
let context = TestContextBuilder::new().cwd("lint").build();
|
||||
|
||||
let cmd_output = context
|
||||
.new_command()
|
||||
.args("lint --config deno.glob.json --ignore=glob/nested/**/bar.ts")
|
||||
.run();
|
||||
|
||||
cmd_output.assert_exit_code(1);
|
||||
|
||||
let output = cmd_output.combined_output();
|
||||
if cfg!(windows) {
|
||||
assert_contains!(output, r#"glob\nested\fizz\fizz.ts:1:10"#);
|
||||
assert_contains!(output, r#"glob\pages\[id].ts:1:10"#);
|
||||
assert_contains!(output, r#"glob\nested\fizz\bazz.ts:1:10"#);
|
||||
assert_contains!(output, r#"glob\nested\foo\foo.ts:1:10"#);
|
||||
assert_contains!(output, r#"glob\data\test1.js:1:10"#);
|
||||
assert_contains!(output, r#"glob\nested\foo\bazz.ts:1:10"#);
|
||||
assert_contains!(output, r#"glob\nested\foo\fizz.ts:1:10"#);
|
||||
assert_contains!(output, r#"glob\nested\fizz\foo.ts:1:10"#);
|
||||
assert_contains!(output, r#"glob\data\test1.ts:1:10"#);
|
||||
} else {
|
||||
assert_contains!(output, "glob/nested/fizz/fizz.ts:1:10");
|
||||
assert_contains!(output, "glob/pages/[id].ts:1:10");
|
||||
assert_contains!(output, "glob/nested/fizz/bazz.ts:1:10");
|
||||
assert_contains!(output, "glob/nested/foo/foo.ts:1:10");
|
||||
assert_contains!(output, "glob/data/test1.js:1:10");
|
||||
assert_contains!(output, "glob/nested/foo/bazz.ts:1:10");
|
||||
assert_contains!(output, "glob/nested/foo/fizz.ts:1:10");
|
||||
assert_contains!(output, "glob/nested/fizz/foo.ts:1:10");
|
||||
assert_contains!(output, "glob/data/test1.ts:1:10");
|
||||
}
|
||||
assert_contains!(output, "Found 9 problems");
|
||||
assert_contains!(output, "Checked 9 files");
|
||||
|
||||
let cmd_output = context
|
||||
.new_command()
|
||||
.args("lint --config deno.glob.json glob/data/test1.?s")
|
||||
.run();
|
||||
|
||||
cmd_output.assert_exit_code(1);
|
||||
|
||||
let output = cmd_output.combined_output();
|
||||
if cfg!(windows) {
|
||||
assert_contains!(output, r#"glob\data\test1.js:1:10"#);
|
||||
assert_contains!(output, r#"glob\data\test1.ts:1:10"#);
|
||||
} else {
|
||||
assert_contains!(output, "glob/data/test1.js:1:10");
|
||||
assert_contains!(output, "glob/data/test1.ts:1:10");
|
||||
}
|
||||
assert_contains!(output, "Found 2 problems");
|
||||
assert_contains!(output, "Checked 2 files");
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ use util::assert_contains;
|
|||
use util::env_vars_for_npm_tests;
|
||||
use util::wildcard_match;
|
||||
use util::TestContext;
|
||||
use util::TestContextBuilder;
|
||||
|
||||
#[test]
|
||||
fn no_color() {
|
||||
|
@ -508,3 +509,60 @@ itest!(test_no_lock {
|
|||
cwd: Some("lockfile/basic"),
|
||||
output: "lockfile/basic/test.nolock.out",
|
||||
});
|
||||
|
||||
#[test]
|
||||
fn test_with_glob_config() {
|
||||
let context = TestContextBuilder::new().cwd("test").build();
|
||||
|
||||
let cmd_output = context
|
||||
.new_command()
|
||||
.args("test --config deno.glob.json")
|
||||
.run();
|
||||
|
||||
cmd_output.assert_exit_code(0);
|
||||
|
||||
let output = cmd_output.combined_output();
|
||||
assert_contains!(output, "glob/nested/fizz/fizz.ts");
|
||||
assert_contains!(output, "glob/pages/[id].ts");
|
||||
assert_contains!(output, "glob/nested/fizz/bar.ts");
|
||||
assert_contains!(output, "glob/nested/foo/foo.ts");
|
||||
assert_contains!(output, "glob/data/test1.js");
|
||||
assert_contains!(output, "glob/nested/foo/bar.ts");
|
||||
assert_contains!(output, "glob/nested/foo/fizz.ts");
|
||||
assert_contains!(output, "glob/nested/fizz/foo.ts");
|
||||
assert_contains!(output, "glob/data/test1.ts");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_with_glob_config_and_flags() {
|
||||
let context = TestContextBuilder::new().cwd("test").build();
|
||||
|
||||
let cmd_output = context
|
||||
.new_command()
|
||||
.args("test --config deno.glob.json --ignore=glob/nested/**/bar.ts")
|
||||
.run();
|
||||
|
||||
cmd_output.assert_exit_code(0);
|
||||
|
||||
let output = cmd_output.combined_output();
|
||||
assert_contains!(output, "glob/nested/fizz/fizz.ts");
|
||||
assert_contains!(output, "glob/pages/[id].ts");
|
||||
assert_contains!(output, "glob/nested/fizz/bazz.ts");
|
||||
assert_contains!(output, "glob/nested/foo/foo.ts");
|
||||
assert_contains!(output, "glob/data/test1.js");
|
||||
assert_contains!(output, "glob/nested/foo/bazz.ts");
|
||||
assert_contains!(output, "glob/nested/foo/fizz.ts");
|
||||
assert_contains!(output, "glob/nested/fizz/foo.ts");
|
||||
assert_contains!(output, "glob/data/test1.ts");
|
||||
|
||||
let cmd_output = context
|
||||
.new_command()
|
||||
.args("test --config deno.glob.json glob/data/test1.?s")
|
||||
.run();
|
||||
|
||||
cmd_output.assert_exit_code(0);
|
||||
|
||||
let output = cmd_output.combined_output();
|
||||
assert_contains!(output, "glob/data/test1.js");
|
||||
assert_contains!(output, "glob/data/test1.ts");
|
||||
}
|
||||
|
|
11
cli/tests/testdata/fmt/deno.glob.json
vendored
Normal file
11
cli/tests/testdata/fmt/deno.glob.json
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"fmt": {
|
||||
"include": [
|
||||
"glob/data/test1.?s",
|
||||
"glob/nested/foo/*.ts",
|
||||
"glob/nested/fizz/*.ts",
|
||||
"glob/pages/[id].ts"
|
||||
],
|
||||
"exclude": ["glob/nested/**/*bazz.ts"]
|
||||
}
|
||||
}
|
3
cli/tests/testdata/fmt/glob/data/tes.ts
vendored
Normal file
3
cli/tests/testdata/fmt/glob/data/tes.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
function foo() {
|
||||
|
||||
}
|
2
cli/tests/testdata/fmt/glob/data/test1.js
vendored
Normal file
2
cli/tests/testdata/fmt/glob/data/test1.js
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
function foo() {
|
||||
}
|
2
cli/tests/testdata/fmt/glob/data/test1.ts
vendored
Normal file
2
cli/tests/testdata/fmt/glob/data/test1.ts
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
function foo() {
|
||||
}
|
3
cli/tests/testdata/fmt/glob/data/test12.ts
vendored
Normal file
3
cli/tests/testdata/fmt/glob/data/test12.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
function foo() {
|
||||
|
||||
}
|
2
cli/tests/testdata/fmt/glob/nested/fizz/bar.ts
vendored
Normal file
2
cli/tests/testdata/fmt/glob/nested/fizz/bar.ts
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
function foo() {
|
||||
}
|
3
cli/tests/testdata/fmt/glob/nested/fizz/bazz.ts
vendored
Normal file
3
cli/tests/testdata/fmt/glob/nested/fizz/bazz.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
function foo() {
|
||||
|
||||
}
|
2
cli/tests/testdata/fmt/glob/nested/fizz/fizz.ts
vendored
Normal file
2
cli/tests/testdata/fmt/glob/nested/fizz/fizz.ts
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
function foo() {
|
||||
}
|
2
cli/tests/testdata/fmt/glob/nested/fizz/foo.ts
vendored
Normal file
2
cli/tests/testdata/fmt/glob/nested/fizz/foo.ts
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
function foo() {
|
||||
}
|
2
cli/tests/testdata/fmt/glob/nested/foo/bar.ts
vendored
Normal file
2
cli/tests/testdata/fmt/glob/nested/foo/bar.ts
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
function foo() {
|
||||
}
|
3
cli/tests/testdata/fmt/glob/nested/foo/bazz.ts
vendored
Normal file
3
cli/tests/testdata/fmt/glob/nested/foo/bazz.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
function foo() {
|
||||
|
||||
}
|
2
cli/tests/testdata/fmt/glob/nested/foo/fizz.ts
vendored
Normal file
2
cli/tests/testdata/fmt/glob/nested/foo/fizz.ts
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
function foo() {
|
||||
}
|
2
cli/tests/testdata/fmt/glob/nested/foo/foo.ts
vendored
Normal file
2
cli/tests/testdata/fmt/glob/nested/foo/foo.ts
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
function foo() {
|
||||
}
|
2
cli/tests/testdata/fmt/glob/pages/[id].ts
vendored
Normal file
2
cli/tests/testdata/fmt/glob/pages/[id].ts
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
function foo() {
|
||||
}
|
11
cli/tests/testdata/lint/deno.glob.json
vendored
Normal file
11
cli/tests/testdata/lint/deno.glob.json
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"lint": {
|
||||
"include": [
|
||||
"glob/data/test1.?s",
|
||||
"glob/nested/foo/*.ts",
|
||||
"glob/nested/fizz/*.ts",
|
||||
"glob/pages/[id].ts"
|
||||
],
|
||||
"exclude": ["glob/nested/**/*bazz.ts"]
|
||||
}
|
||||
}
|
3
cli/tests/testdata/lint/glob/data/tes.ts
vendored
Normal file
3
cli/tests/testdata/lint/glob/data/tes.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
function foo() {
|
||||
|
||||
}
|
3
cli/tests/testdata/lint/glob/data/test1.js
vendored
Normal file
3
cli/tests/testdata/lint/glob/data/test1.js
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
function foo() {
|
||||
|
||||
}
|
3
cli/tests/testdata/lint/glob/data/test1.ts
vendored
Normal file
3
cli/tests/testdata/lint/glob/data/test1.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
function foo() {
|
||||
|
||||
}
|
3
cli/tests/testdata/lint/glob/data/test12.ts
vendored
Normal file
3
cli/tests/testdata/lint/glob/data/test12.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
function foo() {
|
||||
|
||||
}
|
3
cli/tests/testdata/lint/glob/nested/fizz/bar.ts
vendored
Normal file
3
cli/tests/testdata/lint/glob/nested/fizz/bar.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
function foo() {
|
||||
|
||||
}
|
3
cli/tests/testdata/lint/glob/nested/fizz/bazz.ts
vendored
Normal file
3
cli/tests/testdata/lint/glob/nested/fizz/bazz.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
function foo() {
|
||||
|
||||
}
|
2
cli/tests/testdata/lint/glob/nested/fizz/fizz.ts
vendored
Normal file
2
cli/tests/testdata/lint/glob/nested/fizz/fizz.ts
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
function foo() {
|
||||
}
|
3
cli/tests/testdata/lint/glob/nested/fizz/foo.ts
vendored
Normal file
3
cli/tests/testdata/lint/glob/nested/fizz/foo.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
function foo() {
|
||||
|
||||
}
|
3
cli/tests/testdata/lint/glob/nested/foo/bar.ts
vendored
Normal file
3
cli/tests/testdata/lint/glob/nested/foo/bar.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
function foo() {
|
||||
|
||||
}
|
3
cli/tests/testdata/lint/glob/nested/foo/bazz.ts
vendored
Normal file
3
cli/tests/testdata/lint/glob/nested/foo/bazz.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
function foo() {
|
||||
|
||||
}
|
3
cli/tests/testdata/lint/glob/nested/foo/fizz.ts
vendored
Normal file
3
cli/tests/testdata/lint/glob/nested/foo/fizz.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
function foo() {
|
||||
|
||||
}
|
3
cli/tests/testdata/lint/glob/nested/foo/foo.ts
vendored
Normal file
3
cli/tests/testdata/lint/glob/nested/foo/foo.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
function foo() {
|
||||
|
||||
}
|
3
cli/tests/testdata/lint/glob/pages/[id].ts
vendored
Normal file
3
cli/tests/testdata/lint/glob/pages/[id].ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
function foo() {
|
||||
|
||||
}
|
11
cli/tests/testdata/test/deno.glob.json
vendored
Normal file
11
cli/tests/testdata/test/deno.glob.json
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"test": {
|
||||
"include": [
|
||||
"glob/data/test1.?s",
|
||||
"glob/nested/foo/*.ts",
|
||||
"glob/nested/fizz/*.ts",
|
||||
"glob/pages/[id].ts"
|
||||
],
|
||||
"exclude": ["glob/nested/**/*bazz.ts"]
|
||||
}
|
||||
}
|
3
cli/tests/testdata/test/glob/data/tes.ts
vendored
Normal file
3
cli/tests/testdata/test/glob/data/tes.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
function foo() {
|
||||
|
||||
}
|
3
cli/tests/testdata/test/glob/data/test1.js
vendored
Normal file
3
cli/tests/testdata/test/glob/data/test1.js
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
function foo() {
|
||||
|
||||
}
|
3
cli/tests/testdata/test/glob/data/test1.ts
vendored
Normal file
3
cli/tests/testdata/test/glob/data/test1.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
function foo() {
|
||||
|
||||
}
|
3
cli/tests/testdata/test/glob/data/test12.ts
vendored
Normal file
3
cli/tests/testdata/test/glob/data/test12.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
function foo() {
|
||||
|
||||
}
|
3
cli/tests/testdata/test/glob/nested/fizz/bar.ts
vendored
Normal file
3
cli/tests/testdata/test/glob/nested/fizz/bar.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
function foo() {
|
||||
|
||||
}
|
3
cli/tests/testdata/test/glob/nested/fizz/bazz.ts
vendored
Normal file
3
cli/tests/testdata/test/glob/nested/fizz/bazz.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
function foo() {
|
||||
|
||||
}
|
2
cli/tests/testdata/test/glob/nested/fizz/fizz.ts
vendored
Normal file
2
cli/tests/testdata/test/glob/nested/fizz/fizz.ts
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
function foo() {
|
||||
}
|
3
cli/tests/testdata/test/glob/nested/fizz/foo.ts
vendored
Normal file
3
cli/tests/testdata/test/glob/nested/fizz/foo.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
function foo() {
|
||||
|
||||
}
|
3
cli/tests/testdata/test/glob/nested/foo/bar.ts
vendored
Normal file
3
cli/tests/testdata/test/glob/nested/foo/bar.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
function foo() {
|
||||
|
||||
}
|
3
cli/tests/testdata/test/glob/nested/foo/bazz.ts
vendored
Normal file
3
cli/tests/testdata/test/glob/nested/foo/bazz.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
function foo() {
|
||||
|
||||
}
|
3
cli/tests/testdata/test/glob/nested/foo/fizz.ts
vendored
Normal file
3
cli/tests/testdata/test/glob/nested/foo/fizz.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
function foo() {
|
||||
|
||||
}
|
3
cli/tests/testdata/test/glob/nested/foo/foo.ts
vendored
Normal file
3
cli/tests/testdata/test/glob/nested/foo/foo.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
function foo() {
|
||||
|
||||
}
|
3
cli/tests/testdata/test/glob/pages/[id].ts
vendored
Normal file
3
cli/tests/testdata/test/glob/pages/[id].ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
function foo() {
|
||||
|
||||
}
|
|
@ -55,6 +55,7 @@ async function dlint() {
|
|||
":!:cli/tests/testdata/lint/**",
|
||||
":!:cli/tests/testdata/run/**",
|
||||
":!:cli/tests/testdata/tsc/**",
|
||||
":!:cli/tests/testdata/test/glob/**",
|
||||
":!:cli/tsc/*typescript.js",
|
||||
":!:cli/tsc/compiler.d.ts",
|
||||
":!:test_util/wpt/**",
|
||||
|
|
Loading…
Reference in a new issue