@owenlamont/ryl 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -0
- package/bin/ryl.js +195 -1
- package/package.json +35 -13
- package/.github/CODEOWNERS +0 -1
- package/.github/dependabot.yml +0 -13
- package/.github/workflows/ci.yml +0 -107
- package/.github/workflows/release.yml +0 -613
- package/.github/workflows/update_dependencies.yml +0 -61
- package/.github/workflows/update_linters.yml +0 -56
- package/.pre-commit-config.yaml +0 -87
- package/.yamllint +0 -4
- package/AGENTS.md +0 -200
- package/Cargo.lock +0 -908
- package/Cargo.toml +0 -32
- package/clippy.toml +0 -1
- package/docs/config-presets.md +0 -100
- package/img/benchmark-5x5-5runs.svg +0 -2176
- package/pyproject.toml +0 -42
- package/ruff.toml +0 -107
- package/rumdl.toml +0 -20
- package/rust-toolchain.toml +0 -3
- package/rustfmt.toml +0 -3
- package/scripts/benchmark_perf_vs_yamllint.py +0 -400
- package/scripts/coverage-missing.ps1 +0 -80
- package/scripts/coverage-missing.sh +0 -60
- package/src/bin/discover_config_bin.rs +0 -24
- package/src/cli_support.rs +0 -33
- package/src/conf/mod.rs +0 -85
- package/src/config.rs +0 -2099
- package/src/decoder.rs +0 -326
- package/src/discover.rs +0 -31
- package/src/lib.rs +0 -19
- package/src/lint.rs +0 -558
- package/src/main.rs +0 -535
- package/src/migrate.rs +0 -233
- package/src/rules/anchors.rs +0 -517
- package/src/rules/braces.rs +0 -77
- package/src/rules/brackets.rs +0 -77
- package/src/rules/colons.rs +0 -475
- package/src/rules/commas.rs +0 -372
- package/src/rules/comments.rs +0 -299
- package/src/rules/comments_indentation.rs +0 -243
- package/src/rules/document_end.rs +0 -175
- package/src/rules/document_start.rs +0 -84
- package/src/rules/empty_lines.rs +0 -152
- package/src/rules/empty_values.rs +0 -255
- package/src/rules/float_values.rs +0 -259
- package/src/rules/flow_collection.rs +0 -562
- package/src/rules/hyphens.rs +0 -104
- package/src/rules/indentation.rs +0 -803
- package/src/rules/key_duplicates.rs +0 -218
- package/src/rules/key_ordering.rs +0 -303
- package/src/rules/line_length.rs +0 -326
- package/src/rules/mod.rs +0 -25
- package/src/rules/new_line_at_end_of_file.rs +0 -23
- package/src/rules/new_lines.rs +0 -95
- package/src/rules/octal_values.rs +0 -121
- package/src/rules/quoted_strings.rs +0 -577
- package/src/rules/span_utils.rs +0 -37
- package/src/rules/trailing_spaces.rs +0 -65
- package/src/rules/truthy.rs +0 -420
- package/tests/brackets_carriage_return.rs +0 -114
- package/tests/build_global_cfg_error.rs +0 -23
- package/tests/cli_anchors_rule.rs +0 -143
- package/tests/cli_braces_rule.rs +0 -104
- package/tests/cli_brackets_rule.rs +0 -104
- package/tests/cli_colons_rule.rs +0 -65
- package/tests/cli_commas_rule.rs +0 -104
- package/tests/cli_comments_indentation_rule.rs +0 -61
- package/tests/cli_comments_rule.rs +0 -67
- package/tests/cli_config_data_error.rs +0 -30
- package/tests/cli_config_flags.rs +0 -66
- package/tests/cli_config_migrate.rs +0 -229
- package/tests/cli_document_end_rule.rs +0 -92
- package/tests/cli_document_start_rule.rs +0 -92
- package/tests/cli_empty_lines_rule.rs +0 -87
- package/tests/cli_empty_values_rule.rs +0 -68
- package/tests/cli_env_config.rs +0 -34
- package/tests/cli_exit_and_errors.rs +0 -41
- package/tests/cli_file_encoding.rs +0 -203
- package/tests/cli_float_values_rule.rs +0 -64
- package/tests/cli_format_options.rs +0 -316
- package/tests/cli_global_cfg_relaxed.rs +0 -20
- package/tests/cli_hyphens_rule.rs +0 -104
- package/tests/cli_indentation_rule.rs +0 -65
- package/tests/cli_invalid_project_config.rs +0 -39
- package/tests/cli_key_duplicates_rule.rs +0 -104
- package/tests/cli_key_ordering_rule.rs +0 -59
- package/tests/cli_line_length_rule.rs +0 -85
- package/tests/cli_list_files.rs +0 -29
- package/tests/cli_new_line_rule.rs +0 -141
- package/tests/cli_new_lines_rule.rs +0 -119
- package/tests/cli_octal_values_rule.rs +0 -60
- package/tests/cli_quoted_strings_rule.rs +0 -47
- package/tests/cli_toml_config.rs +0 -119
- package/tests/cli_trailing_spaces_rule.rs +0 -77
- package/tests/cli_truthy_rule.rs +0 -83
- package/tests/cli_yaml_files_negation.rs +0 -45
- package/tests/colons_rule.rs +0 -303
- package/tests/common/compat.rs +0 -114
- package/tests/common/fake_env.rs +0 -93
- package/tests/common/mod.rs +0 -1
- package/tests/conf_builtin.rs +0 -9
- package/tests/config_anchors.rs +0 -84
- package/tests/config_braces.rs +0 -121
- package/tests/config_brackets.rs +0 -127
- package/tests/config_commas.rs +0 -79
- package/tests/config_comments.rs +0 -65
- package/tests/config_comments_indentation.rs +0 -20
- package/tests/config_deep_merge_nonstring_key.rs +0 -24
- package/tests/config_document_end.rs +0 -54
- package/tests/config_document_start.rs +0 -55
- package/tests/config_empty_lines.rs +0 -48
- package/tests/config_empty_values.rs +0 -35
- package/tests/config_env_errors.rs +0 -23
- package/tests/config_env_invalid_inline.rs +0 -15
- package/tests/config_env_missing.rs +0 -63
- package/tests/config_env_shim.rs +0 -301
- package/tests/config_explicit_file_parse_error.rs +0 -55
- package/tests/config_extended_features.rs +0 -225
- package/tests/config_extends_inline.rs +0 -185
- package/tests/config_extends_sequence.rs +0 -18
- package/tests/config_find_project_home_boundary.rs +0 -54
- package/tests/config_find_project_two_files_in_cwd.rs +0 -47
- package/tests/config_float_values.rs +0 -34
- package/tests/config_from_yaml_paths.rs +0 -32
- package/tests/config_hyphens.rs +0 -51
- package/tests/config_ignore_errors.rs +0 -243
- package/tests/config_ignore_overrides.rs +0 -83
- package/tests/config_indentation.rs +0 -65
- package/tests/config_invalid_globs.rs +0 -16
- package/tests/config_invalid_types.rs +0 -19
- package/tests/config_key_duplicates.rs +0 -34
- package/tests/config_key_ordering.rs +0 -70
- package/tests/config_line_length.rs +0 -65
- package/tests/config_locale.rs +0 -111
- package/tests/config_merge.rs +0 -26
- package/tests/config_new_lines.rs +0 -89
- package/tests/config_octal_values.rs +0 -33
- package/tests/config_quoted_strings.rs +0 -195
- package/tests/config_rule_level.rs +0 -147
- package/tests/config_rules_non_string_keys.rs +0 -23
- package/tests/config_scalar_overrides.rs +0 -27
- package/tests/config_to_toml.rs +0 -110
- package/tests/config_toml_coverage.rs +0 -80
- package/tests/config_toml_discovery.rs +0 -304
- package/tests/config_trailing_spaces.rs +0 -152
- package/tests/config_truthy.rs +0 -77
- package/tests/config_yaml_files.rs +0 -62
- package/tests/config_yaml_files_all_non_string.rs +0 -15
- package/tests/config_yaml_files_empty.rs +0 -30
- package/tests/coverage_commas.rs +0 -46
- package/tests/decoder_decode.rs +0 -338
- package/tests/discover_config_bin_all.rs +0 -66
- package/tests/discover_config_bin_env_invalid_yaml.rs +0 -26
- package/tests/discover_config_bin_project_config_parse_error.rs +0 -24
- package/tests/discover_config_bin_user_global_error.rs +0 -26
- package/tests/discover_module.rs +0 -30
- package/tests/discover_per_file_dir.rs +0 -10
- package/tests/discover_per_file_project_config_error.rs +0 -21
- package/tests/float_values.rs +0 -43
- package/tests/lint_multi_errors.rs +0 -32
- package/tests/main_yaml_ok_filtering.rs +0 -30
- package/tests/migrate_module.rs +0 -259
- package/tests/resolve_ctx_empty_parent.rs +0 -16
- package/tests/rule_anchors.rs +0 -442
- package/tests/rule_braces.rs +0 -258
- package/tests/rule_brackets.rs +0 -217
- package/tests/rule_commas.rs +0 -205
- package/tests/rule_comments.rs +0 -197
- package/tests/rule_comments_indentation.rs +0 -127
- package/tests/rule_document_end.rs +0 -118
- package/tests/rule_document_start.rs +0 -60
- package/tests/rule_empty_lines.rs +0 -96
- package/tests/rule_empty_values.rs +0 -102
- package/tests/rule_float_values.rs +0 -109
- package/tests/rule_hyphens.rs +0 -65
- package/tests/rule_indentation.rs +0 -455
- package/tests/rule_key_duplicates.rs +0 -76
- package/tests/rule_key_ordering.rs +0 -207
- package/tests/rule_line_length.rs +0 -200
- package/tests/rule_new_lines.rs +0 -51
- package/tests/rule_octal_values.rs +0 -53
- package/tests/rule_quoted_strings.rs +0 -290
- package/tests/rule_trailing_spaces.rs +0 -41
- package/tests/rule_truthy.rs +0 -236
- package/tests/user_global_invalid_yaml.rs +0 -32
- package/tests/yamllint_compat_anchors.rs +0 -280
- package/tests/yamllint_compat_braces.rs +0 -411
- package/tests/yamllint_compat_brackets.rs +0 -364
- package/tests/yamllint_compat_colons.rs +0 -298
- package/tests/yamllint_compat_colors.rs +0 -80
- package/tests/yamllint_compat_commas.rs +0 -375
- package/tests/yamllint_compat_comments.rs +0 -167
- package/tests/yamllint_compat_comments_indentation.rs +0 -281
- package/tests/yamllint_compat_config.rs +0 -170
- package/tests/yamllint_compat_document_end.rs +0 -243
- package/tests/yamllint_compat_document_start.rs +0 -136
- package/tests/yamllint_compat_empty_lines.rs +0 -117
- package/tests/yamllint_compat_empty_values.rs +0 -179
- package/tests/yamllint_compat_float_values.rs +0 -216
- package/tests/yamllint_compat_hyphens.rs +0 -223
- package/tests/yamllint_compat_indentation.rs +0 -398
- package/tests/yamllint_compat_key_duplicates.rs +0 -139
- package/tests/yamllint_compat_key_ordering.rs +0 -170
- package/tests/yamllint_compat_line_length.rs +0 -375
- package/tests/yamllint_compat_list.rs +0 -127
- package/tests/yamllint_compat_new_line.rs +0 -133
- package/tests/yamllint_compat_newline_types.rs +0 -185
- package/tests/yamllint_compat_octal_values.rs +0 -172
- package/tests/yamllint_compat_quoted_strings.rs +0 -154
- package/tests/yamllint_compat_syntax.rs +0 -200
- package/tests/yamllint_compat_trailing_spaces.rs +0 -162
- package/tests/yamllint_compat_truthy.rs +0 -130
- package/tests/yamllint_compat_yaml_files.rs +0 -81
- package/typos.toml +0 -2
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
use std::fs;
|
|
2
|
-
|
|
3
|
-
use ryl::config::{Env, Overrides, SystemEnv, discover_config_with_env};
|
|
4
|
-
use tempfile::tempdir;
|
|
5
|
-
|
|
6
|
-
#[test]
|
|
7
|
-
fn env_points_to_missing_file_is_ignored() {
|
|
8
|
-
let workspace = tempdir().unwrap();
|
|
9
|
-
let inputs = vec![workspace.path().join("input.yaml")];
|
|
10
|
-
let ctx = discover_config_with_env(&inputs, &Overrides::default(), &|k| {
|
|
11
|
-
if k == "YAMLLINT_CONFIG_FILE" {
|
|
12
|
-
Some("/tmp/this/does/not/exist.yml".into())
|
|
13
|
-
} else {
|
|
14
|
-
None
|
|
15
|
-
}
|
|
16
|
-
})
|
|
17
|
-
.expect("discover should succeed");
|
|
18
|
-
// Missing env config falls back to default preset
|
|
19
|
-
assert!(ctx.source.is_none());
|
|
20
|
-
assert!(ctx.config.rule_names().iter().any(|r| r == "anchors"));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
#[test]
|
|
24
|
-
fn env_tilde_path_uses_closure_home_dir() {
|
|
25
|
-
let dir = tempdir().unwrap();
|
|
26
|
-
let config_path = dir
|
|
27
|
-
.path()
|
|
28
|
-
.join(".config")
|
|
29
|
-
.join("yamllint")
|
|
30
|
-
.join("custom.yml");
|
|
31
|
-
fs::create_dir_all(config_path.parent().unwrap()).unwrap();
|
|
32
|
-
fs::write(&config_path, "rules: {}\n").unwrap();
|
|
33
|
-
|
|
34
|
-
let project_root = dir.path().join("workspace");
|
|
35
|
-
fs::create_dir_all(&project_root).unwrap();
|
|
36
|
-
let inputs = vec![project_root.join("input.yaml")];
|
|
37
|
-
let ctx = discover_config_with_env(&inputs, &Overrides::default(), &|k| match k {
|
|
38
|
-
"YAMLLINT_CONFIG_FILE" => Some("~/.config/yamllint/custom.yml".into()),
|
|
39
|
-
"HOME" => Some(dir.path().to_str().unwrap().into()),
|
|
40
|
-
_ => None,
|
|
41
|
-
})
|
|
42
|
-
.expect("discover should succeed");
|
|
43
|
-
|
|
44
|
-
assert_eq!(ctx.source.as_deref(), Some(config_path.as_path()));
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
#[test]
|
|
48
|
-
fn env_tilde_path_without_home_falls_back_to_system_home() {
|
|
49
|
-
let workspace = tempdir().unwrap();
|
|
50
|
-
let inputs = vec![workspace.path().join("input.yaml")];
|
|
51
|
-
let _ = SystemEnv.home_dir();
|
|
52
|
-
let ctx = discover_config_with_env(&inputs, &Overrides::default(), &|k| {
|
|
53
|
-
if k == "YAMLLINT_CONFIG_FILE" {
|
|
54
|
-
Some("~/.config/yamllint/missing.yml".into())
|
|
55
|
-
} else {
|
|
56
|
-
None
|
|
57
|
-
}
|
|
58
|
-
})
|
|
59
|
-
.expect("discover should succeed");
|
|
60
|
-
|
|
61
|
-
// No config file found; default preset applies.
|
|
62
|
-
assert!(ctx.source.is_none());
|
|
63
|
-
}
|
package/tests/config_env_shim.rs
DELETED
|
@@ -1,301 +0,0 @@
|
|
|
1
|
-
use std::collections::{HashMap, HashSet};
|
|
2
|
-
use std::path::{Path, PathBuf};
|
|
3
|
-
|
|
4
|
-
use ryl::config::{
|
|
5
|
-
Env, Overrides, SystemEnv, discover_config_with, discover_per_file_with,
|
|
6
|
-
};
|
|
7
|
-
use tempfile::tempdir;
|
|
8
|
-
|
|
9
|
-
#[derive(Default)]
|
|
10
|
-
struct FakeEnv {
|
|
11
|
-
cwd: PathBuf,
|
|
12
|
-
cfg_dir: Option<PathBuf>,
|
|
13
|
-
files: HashMap<PathBuf, String>,
|
|
14
|
-
exists: HashSet<PathBuf>,
|
|
15
|
-
vars: HashMap<String, String>,
|
|
16
|
-
home: Option<PathBuf>,
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
impl FakeEnv {
|
|
20
|
-
fn with_cwd(mut self, p: impl Into<PathBuf>) -> Self {
|
|
21
|
-
self.cwd = p.into();
|
|
22
|
-
self
|
|
23
|
-
}
|
|
24
|
-
fn with_config_dir(mut self, p: impl Into<PathBuf>) -> Self {
|
|
25
|
-
self.cfg_dir = Some(p.into());
|
|
26
|
-
self
|
|
27
|
-
}
|
|
28
|
-
fn add_file(mut self, p: impl Into<PathBuf>, content: impl Into<String>) -> Self {
|
|
29
|
-
self.files.insert(p.into(), content.into());
|
|
30
|
-
self
|
|
31
|
-
}
|
|
32
|
-
fn add_exist(mut self, p: impl Into<PathBuf>) -> Self {
|
|
33
|
-
self.exists.insert(p.into());
|
|
34
|
-
self
|
|
35
|
-
}
|
|
36
|
-
fn set_var(mut self, k: impl Into<String>, v: impl Into<String>) -> Self {
|
|
37
|
-
self.vars.insert(k.into(), v.into());
|
|
38
|
-
self
|
|
39
|
-
}
|
|
40
|
-
fn with_home(mut self, p: impl Into<PathBuf>) -> Self {
|
|
41
|
-
self.home = Some(p.into());
|
|
42
|
-
self
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
impl Env for FakeEnv {
|
|
47
|
-
fn current_dir(&self) -> PathBuf {
|
|
48
|
-
self.cwd.clone()
|
|
49
|
-
}
|
|
50
|
-
fn config_dir(&self) -> Option<PathBuf> {
|
|
51
|
-
self.cfg_dir.clone()
|
|
52
|
-
}
|
|
53
|
-
fn read_to_string(&self, p: &Path) -> Result<String, String> {
|
|
54
|
-
self.files.get(p).cloned().ok_or_else(|| {
|
|
55
|
-
format!("failed to read config file {}: not found", p.display())
|
|
56
|
-
})
|
|
57
|
-
}
|
|
58
|
-
fn path_exists(&self, p: &Path) -> bool {
|
|
59
|
-
self.files.contains_key(p) || self.exists.contains(p)
|
|
60
|
-
}
|
|
61
|
-
fn env_var(&self, key: &str) -> Option<String> {
|
|
62
|
-
self.vars.get(key).cloned()
|
|
63
|
-
}
|
|
64
|
-
fn home_dir(&self) -> Option<PathBuf> {
|
|
65
|
-
self.home
|
|
66
|
-
.clone()
|
|
67
|
-
.or_else(|| self.vars.get("HOME").map(PathBuf::from))
|
|
68
|
-
.or_else(|| self.vars.get("USERPROFILE").map(PathBuf::from))
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
fn cfg_rules_empty() -> String {
|
|
73
|
-
"rules: {}\n".to_string()
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
#[test]
|
|
77
|
-
fn shim_inline_config_path() {
|
|
78
|
-
let env = FakeEnv::default().with_cwd("/home/user");
|
|
79
|
-
let ctx = discover_config_with(
|
|
80
|
-
&[],
|
|
81
|
-
&Overrides {
|
|
82
|
-
config_file: None,
|
|
83
|
-
config_data: Some(cfg_rules_empty()),
|
|
84
|
-
},
|
|
85
|
-
&env,
|
|
86
|
-
)
|
|
87
|
-
.unwrap();
|
|
88
|
-
assert!(ctx.config.rule_names().is_empty());
|
|
89
|
-
assert_eq!(ctx.base_dir, PathBuf::from("/home/user"));
|
|
90
|
-
assert!(ctx.source.is_none());
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
#[test]
|
|
94
|
-
fn shim_file_config_path_with_parent_none_uses_cwd() {
|
|
95
|
-
let env = FakeEnv::default()
|
|
96
|
-
.with_cwd("/work")
|
|
97
|
-
.add_file("", cfg_rules_empty());
|
|
98
|
-
let ctx = discover_config_with(
|
|
99
|
-
&[],
|
|
100
|
-
&Overrides {
|
|
101
|
-
config_file: Some(PathBuf::from("")),
|
|
102
|
-
config_data: None,
|
|
103
|
-
},
|
|
104
|
-
&env,
|
|
105
|
-
)
|
|
106
|
-
.unwrap();
|
|
107
|
-
assert_eq!(ctx.base_dir, PathBuf::from("/work"));
|
|
108
|
-
assert_eq!(ctx.source.unwrap(), PathBuf::from(""));
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
#[test]
|
|
112
|
-
fn shim_env_var_points_to_file_base_dir_from_cwd() {
|
|
113
|
-
let env = FakeEnv::default()
|
|
114
|
-
.with_cwd("/tmp/cwd")
|
|
115
|
-
.add_file("", cfg_rules_empty())
|
|
116
|
-
.set_var("YAMLLINT_CONFIG_FILE", "");
|
|
117
|
-
let ctx = discover_config_with(&[], &Overrides::default(), &env).unwrap();
|
|
118
|
-
assert_eq!(ctx.base_dir, PathBuf::from("/tmp/cwd"));
|
|
119
|
-
assert_eq!(ctx.source.unwrap(), PathBuf::from(""));
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
#[test]
|
|
123
|
-
fn shim_env_var_with_tilde_expands_home() {
|
|
124
|
-
let env = FakeEnv::default()
|
|
125
|
-
.with_cwd("/tmp/cwd")
|
|
126
|
-
.with_home("/home/tester")
|
|
127
|
-
.set_var("YAMLLINT_CONFIG_FILE", "~/.config/yamllint/custom.yml")
|
|
128
|
-
.add_file(
|
|
129
|
-
"/home/tester/.config/yamllint/custom.yml",
|
|
130
|
-
cfg_rules_empty(),
|
|
131
|
-
);
|
|
132
|
-
let ctx = discover_config_with(&[], &Overrides::default(), &env).unwrap();
|
|
133
|
-
assert_eq!(
|
|
134
|
-
ctx.source.unwrap(),
|
|
135
|
-
PathBuf::from("/home/tester/.config/yamllint/custom.yml")
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
#[test]
|
|
140
|
-
fn shim_env_var_tilde_alone_uses_home_directory() {
|
|
141
|
-
let env = FakeEnv::default()
|
|
142
|
-
.with_cwd("/tmp/cwd")
|
|
143
|
-
.with_home("/home/tester")
|
|
144
|
-
.set_var("YAMLLINT_CONFIG_FILE", "~")
|
|
145
|
-
.add_file("/home/tester", cfg_rules_empty());
|
|
146
|
-
let ctx = discover_config_with(&[], &Overrides::default(), &env).unwrap();
|
|
147
|
-
assert_eq!(ctx.source.unwrap(), PathBuf::from("/home/tester"));
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
#[test]
|
|
151
|
-
fn shim_env_var_tilde_without_home_keeps_literal_path() {
|
|
152
|
-
let env = FakeEnv::default()
|
|
153
|
-
.with_cwd("/tmp/cwd")
|
|
154
|
-
.set_var("YAMLLINT_CONFIG_FILE", "~/.config/yamllint/custom.yml")
|
|
155
|
-
.add_file("~/.config/yamllint/custom.yml", cfg_rules_empty());
|
|
156
|
-
let ctx = discover_config_with(&[], &Overrides::default(), &env).unwrap();
|
|
157
|
-
assert_eq!(
|
|
158
|
-
ctx.source.unwrap(),
|
|
159
|
-
PathBuf::from("~/.config/yamllint/custom.yml")
|
|
160
|
-
);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
#[test]
|
|
164
|
-
fn system_env_home_dir_accessible() {
|
|
165
|
-
let env = SystemEnv;
|
|
166
|
-
let _ = env.home_dir();
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
#[test]
|
|
170
|
-
fn shim_env_var_userprofile_handles_windows_tilde_backslash() {
|
|
171
|
-
let env = FakeEnv::default()
|
|
172
|
-
.with_cwd("/tmp/cwd")
|
|
173
|
-
.set_var("USERPROFILE", "/profiles/user")
|
|
174
|
-
.set_var("YAMLLINT_CONFIG_FILE", "~\\config.yml")
|
|
175
|
-
.add_file("/profiles/user/config.yml", cfg_rules_empty());
|
|
176
|
-
let ctx = discover_config_with(&[], &Overrides::default(), &env).unwrap();
|
|
177
|
-
assert_eq!(
|
|
178
|
-
ctx.source.unwrap(),
|
|
179
|
-
PathBuf::from("/profiles/user/config.yml")
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
#[test]
|
|
184
|
-
fn shim_project_config_discovered_from_inputs() {
|
|
185
|
-
let env = FakeEnv::default()
|
|
186
|
-
.with_cwd("/wd")
|
|
187
|
-
.add_file("/proj/.yamllint", cfg_rules_empty())
|
|
188
|
-
.add_exist("/proj/.yamllint")
|
|
189
|
-
.add_exist("/proj/file.yaml");
|
|
190
|
-
let ctx = discover_config_with(
|
|
191
|
-
&[PathBuf::from("/proj/file.yaml")],
|
|
192
|
-
&Overrides::default(),
|
|
193
|
-
&env,
|
|
194
|
-
)
|
|
195
|
-
.unwrap();
|
|
196
|
-
assert_eq!(ctx.base_dir, PathBuf::from("/proj"));
|
|
197
|
-
assert!(ctx.source.unwrap().ends_with(".yamllint"));
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
#[test]
|
|
201
|
-
fn shim_user_global_config_applies_when_no_project_or_env() {
|
|
202
|
-
let env = FakeEnv::default()
|
|
203
|
-
.with_cwd("/wd")
|
|
204
|
-
.with_config_dir("/xdg")
|
|
205
|
-
.add_file("/xdg/yamllint/config", cfg_rules_empty())
|
|
206
|
-
.add_exist("/xdg/yamllint/config");
|
|
207
|
-
let ctx = discover_config_with(&[], &Overrides::default(), &env).unwrap();
|
|
208
|
-
assert!(ctx.source.unwrap().ends_with("yamllint/config"));
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
#[test]
|
|
212
|
-
fn shim_user_global_missing_falls_back_to_default() {
|
|
213
|
-
let env = FakeEnv::default()
|
|
214
|
-
.with_cwd("/wd")
|
|
215
|
-
.with_config_dir("/xdg-none");
|
|
216
|
-
let ctx = discover_config_with(&[], &Overrides::default(), &env).unwrap();
|
|
217
|
-
assert!(ctx.source.is_none());
|
|
218
|
-
// default preset filters by extension
|
|
219
|
-
assert!(
|
|
220
|
-
ctx.config
|
|
221
|
-
.is_yaml_candidate(&PathBuf::from("x.yaml"), &ctx.base_dir)
|
|
222
|
-
);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
#[test]
|
|
226
|
-
fn shim_systemenv_read_error_is_mapped() {
|
|
227
|
-
let env = SystemEnv;
|
|
228
|
-
let err = discover_config_with(
|
|
229
|
-
&[],
|
|
230
|
-
&Overrides {
|
|
231
|
-
config_file: Some(PathBuf::from("no_such_file.yml")),
|
|
232
|
-
config_data: None,
|
|
233
|
-
},
|
|
234
|
-
&env,
|
|
235
|
-
)
|
|
236
|
-
.unwrap_err();
|
|
237
|
-
assert!(err.contains("failed to read config file"));
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
#[test]
|
|
241
|
-
fn shim_systemenv_read_success_is_used() {
|
|
242
|
-
let td = tempfile::tempdir().unwrap();
|
|
243
|
-
let cfgp = td.path().join("ok.yml");
|
|
244
|
-
std::fs::write(&cfgp, "rules: {}\n").unwrap();
|
|
245
|
-
let env = SystemEnv;
|
|
246
|
-
let ctx = discover_config_with(
|
|
247
|
-
&[],
|
|
248
|
-
&Overrides {
|
|
249
|
-
config_file: Some(cfgp.clone()),
|
|
250
|
-
config_data: None,
|
|
251
|
-
},
|
|
252
|
-
&env,
|
|
253
|
-
)
|
|
254
|
-
.unwrap();
|
|
255
|
-
assert!(ctx.source.unwrap().ends_with("ok.yml"));
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
#[test]
|
|
259
|
-
fn system_env_read_invalid_encoding_reports_error() {
|
|
260
|
-
let td = tempdir().unwrap();
|
|
261
|
-
let path = td.path().join("bad.yml");
|
|
262
|
-
std::fs::write(&path, [0xFFu8, 0xFE, 0x00]).unwrap();
|
|
263
|
-
let env = SystemEnv;
|
|
264
|
-
let err = env.read_to_string(&path).unwrap_err();
|
|
265
|
-
assert!(err.contains("invalid"));
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
#[test]
|
|
269
|
-
fn shim_env_var_tilde_slash_only_returns_home() {
|
|
270
|
-
let env = FakeEnv::default()
|
|
271
|
-
.with_cwd("/tmp/cwd")
|
|
272
|
-
.set_var("HOME", "/home/tester")
|
|
273
|
-
.set_var("YAMLLINT_CONFIG_FILE", "~/")
|
|
274
|
-
.add_file("/home/tester", cfg_rules_empty());
|
|
275
|
-
let ctx = discover_config_with(&[], &Overrides::default(), &env).unwrap();
|
|
276
|
-
assert_eq!(ctx.source.unwrap(), PathBuf::from("/home/tester"));
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
#[test]
|
|
280
|
-
fn shim_env_var_tilde_backslash_only_returns_home() {
|
|
281
|
-
let env = FakeEnv::default()
|
|
282
|
-
.with_cwd("/tmp/cwd")
|
|
283
|
-
.set_var("USERPROFILE", "/profiles/user")
|
|
284
|
-
.set_var("YAMLLINT_CONFIG_FILE", "~\\")
|
|
285
|
-
.add_file("/profiles/user", cfg_rules_empty());
|
|
286
|
-
let ctx = discover_config_with(&[], &Overrides::default(), &env).unwrap();
|
|
287
|
-
assert_eq!(ctx.source.unwrap(), PathBuf::from("/profiles/user"));
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
#[test]
|
|
291
|
-
fn shim_discover_per_file_uses_project_else_user_global_else_default() {
|
|
292
|
-
let env = FakeEnv::default()
|
|
293
|
-
.with_cwd("/wd")
|
|
294
|
-
.with_config_dir("/xdg")
|
|
295
|
-
.add_file("/xdg/yamllint/config", cfg_rules_empty())
|
|
296
|
-
.add_exist("/xdg/yamllint/config");
|
|
297
|
-
// No project config, so user-global applies
|
|
298
|
-
let file = PathBuf::from("/proj/no_config/file.yaml");
|
|
299
|
-
let ctx = discover_per_file_with(&file, &env).unwrap();
|
|
300
|
-
assert!(ctx.source.unwrap().ends_with("yamllint/config"));
|
|
301
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
use std::collections::{HashMap, HashSet};
|
|
2
|
-
use std::path::{Path, PathBuf};
|
|
3
|
-
|
|
4
|
-
struct FakeEnv {
|
|
5
|
-
exists: HashSet<PathBuf>,
|
|
6
|
-
files: HashMap<PathBuf, String>,
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
impl FakeEnv {
|
|
10
|
-
fn new() -> Self {
|
|
11
|
-
Self {
|
|
12
|
-
exists: HashSet::new(),
|
|
13
|
-
files: HashMap::new(),
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
impl ryl::config::Env for FakeEnv {
|
|
19
|
-
fn current_dir(&self) -> PathBuf {
|
|
20
|
-
PathBuf::from(".")
|
|
21
|
-
}
|
|
22
|
-
fn config_dir(&self) -> Option<PathBuf> {
|
|
23
|
-
None
|
|
24
|
-
}
|
|
25
|
-
fn read_to_string(&self, p: &Path) -> Result<String, String> {
|
|
26
|
-
self.files
|
|
27
|
-
.get(p)
|
|
28
|
-
.cloned()
|
|
29
|
-
.ok_or_else(|| format!("missing {}", p.display()))
|
|
30
|
-
}
|
|
31
|
-
fn path_exists(&self, p: &Path) -> bool {
|
|
32
|
-
self.exists.contains(p)
|
|
33
|
-
}
|
|
34
|
-
fn home_dir(&self) -> Option<PathBuf> {
|
|
35
|
-
None
|
|
36
|
-
}
|
|
37
|
-
fn env_var(&self, _key: &str) -> Option<String> {
|
|
38
|
-
None
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
#[test]
|
|
43
|
-
fn explicit_config_file_with_invalid_yaml_errors() {
|
|
44
|
-
let mut envx = FakeEnv::new();
|
|
45
|
-
let file = PathBuf::from("cfg.yml");
|
|
46
|
-
envx.exists.insert(file.clone());
|
|
47
|
-
envx.files.insert(file.clone(), "rules: {".into());
|
|
48
|
-
|
|
49
|
-
let overrides = ryl::config::Overrides {
|
|
50
|
-
config_file: Some(file),
|
|
51
|
-
config_data: None,
|
|
52
|
-
};
|
|
53
|
-
let res = ryl::config::discover_config_with(&[], &overrides, &envx);
|
|
54
|
-
assert!(res.is_err());
|
|
55
|
-
}
|
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
use ryl::config::{Overrides, discover_config};
|
|
2
|
-
use std::fs;
|
|
3
|
-
use tempfile::tempdir;
|
|
4
|
-
|
|
5
|
-
#[test]
|
|
6
|
-
fn ignore_block_supports_negation() {
|
|
7
|
-
let td = tempdir().unwrap();
|
|
8
|
-
let cfg = td.path().join("conf.yaml");
|
|
9
|
-
fs::write(
|
|
10
|
-
&cfg,
|
|
11
|
-
"ignore: |\n **/*.skip.yaml\n !**/keep.skip.yaml\n nested/\nyaml-files: []\nrules: {}\n",
|
|
12
|
-
)
|
|
13
|
-
.unwrap();
|
|
14
|
-
|
|
15
|
-
let ctx = discover_config(
|
|
16
|
-
&[],
|
|
17
|
-
&Overrides {
|
|
18
|
-
config_file: Some(cfg.clone()),
|
|
19
|
-
config_data: None,
|
|
20
|
-
},
|
|
21
|
-
)
|
|
22
|
-
.expect("config parse");
|
|
23
|
-
let base = ctx.base_dir.clone();
|
|
24
|
-
|
|
25
|
-
assert!(
|
|
26
|
-
ctx.config
|
|
27
|
-
.is_file_ignored(&td.path().join("a.skip.yaml"), &base)
|
|
28
|
-
);
|
|
29
|
-
assert!(
|
|
30
|
-
!ctx.config
|
|
31
|
-
.is_file_ignored(&td.path().join("keep.skip.yaml"), &base)
|
|
32
|
-
);
|
|
33
|
-
assert!(
|
|
34
|
-
ctx.config
|
|
35
|
-
.is_file_ignored(&td.path().join("nested/file.yaml"), &base)
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
#[test]
|
|
40
|
-
fn ignore_from_file_patterns_are_loaded() {
|
|
41
|
-
let td = tempdir().unwrap();
|
|
42
|
-
let cfg = td.path().join("conf.yaml");
|
|
43
|
-
let ignore = td.path().join(".yamllint-ignore");
|
|
44
|
-
fs::write(
|
|
45
|
-
&cfg,
|
|
46
|
-
"ignore-from-file: .yamllint-ignore\nyaml-files: []\nrules: {}\n",
|
|
47
|
-
)
|
|
48
|
-
.unwrap();
|
|
49
|
-
fs::write(&ignore, "*.gen.yaml\n!.keep.yaml\n").unwrap();
|
|
50
|
-
|
|
51
|
-
let ctx = discover_config(
|
|
52
|
-
&[],
|
|
53
|
-
&Overrides {
|
|
54
|
-
config_file: Some(cfg.clone()),
|
|
55
|
-
config_data: None,
|
|
56
|
-
},
|
|
57
|
-
)
|
|
58
|
-
.expect("config parse");
|
|
59
|
-
let base = ctx.base_dir.clone();
|
|
60
|
-
|
|
61
|
-
assert!(
|
|
62
|
-
ctx.config
|
|
63
|
-
.is_file_ignored(&td.path().join("output.gen.yaml"), &base)
|
|
64
|
-
);
|
|
65
|
-
assert!(
|
|
66
|
-
!ctx.config
|
|
67
|
-
.is_file_ignored(&td.path().join(".keep.yaml"), &base)
|
|
68
|
-
);
|
|
69
|
-
assert!(
|
|
70
|
-
ctx.config
|
|
71
|
-
.ignore_patterns()
|
|
72
|
-
.iter()
|
|
73
|
-
.any(|p| p == "*.gen.yaml")
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
#[test]
|
|
78
|
-
fn ignore_directory_pattern_allows_reinclude_of_specific_file() {
|
|
79
|
-
let td = tempdir().unwrap();
|
|
80
|
-
let cfg = td.path().join("conf.yaml");
|
|
81
|
-
fs::write(
|
|
82
|
-
&cfg,
|
|
83
|
-
"ignore: |\n build/\n !build/keep.yaml\nyaml-files: []\nrules: {}\n",
|
|
84
|
-
)
|
|
85
|
-
.unwrap();
|
|
86
|
-
|
|
87
|
-
let ctx = discover_config(
|
|
88
|
-
&[],
|
|
89
|
-
&Overrides {
|
|
90
|
-
config_file: Some(cfg.clone()),
|
|
91
|
-
config_data: None,
|
|
92
|
-
},
|
|
93
|
-
)
|
|
94
|
-
.expect("config parse");
|
|
95
|
-
let base = ctx.base_dir.clone();
|
|
96
|
-
|
|
97
|
-
assert!(
|
|
98
|
-
ctx.config
|
|
99
|
-
.is_file_ignored(&td.path().join("build/drop.yaml"), &base)
|
|
100
|
-
);
|
|
101
|
-
assert!(
|
|
102
|
-
!ctx.config
|
|
103
|
-
.is_file_ignored(&td.path().join("build/keep.yaml"), &base)
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
#[test]
|
|
108
|
-
fn ignore_from_file_directory_pattern_allows_reinclude_of_specific_file() {
|
|
109
|
-
let td = tempdir().unwrap();
|
|
110
|
-
let cfg = td.path().join("conf.yaml");
|
|
111
|
-
let ignore = td.path().join(".yamllint-ignore");
|
|
112
|
-
fs::write(
|
|
113
|
-
&cfg,
|
|
114
|
-
"ignore-from-file: .yamllint-ignore\nyaml-files: []\nrules: {}\n",
|
|
115
|
-
)
|
|
116
|
-
.unwrap();
|
|
117
|
-
fs::write(&ignore, "build/\n!build/keep.yaml\n").unwrap();
|
|
118
|
-
|
|
119
|
-
let ctx = discover_config(
|
|
120
|
-
&[],
|
|
121
|
-
&Overrides {
|
|
122
|
-
config_file: Some(cfg.clone()),
|
|
123
|
-
config_data: None,
|
|
124
|
-
},
|
|
125
|
-
)
|
|
126
|
-
.expect("config parse");
|
|
127
|
-
let base = ctx.base_dir.clone();
|
|
128
|
-
|
|
129
|
-
assert!(
|
|
130
|
-
ctx.config
|
|
131
|
-
.is_file_ignored(&td.path().join("build/drop.yaml"), &base)
|
|
132
|
-
);
|
|
133
|
-
assert!(
|
|
134
|
-
!ctx.config
|
|
135
|
-
.is_file_ignored(&td.path().join("build/keep.yaml"), &base)
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
#[test]
|
|
140
|
-
fn rule_ignore_handles_direct_ignore_whitelist_and_parent_fallback() {
|
|
141
|
-
let td = tempdir().unwrap();
|
|
142
|
-
let cfg = td.path().join("conf.yaml");
|
|
143
|
-
fs::write(
|
|
144
|
-
&cfg,
|
|
145
|
-
"yaml-files: []\nrules:\n trailing-spaces:\n ignore: |\n build/\n !build/keep.yaml\n drop.yaml\n",
|
|
146
|
-
)
|
|
147
|
-
.unwrap();
|
|
148
|
-
|
|
149
|
-
let ctx = discover_config(
|
|
150
|
-
&[],
|
|
151
|
-
&Overrides {
|
|
152
|
-
config_file: Some(cfg.clone()),
|
|
153
|
-
config_data: None,
|
|
154
|
-
},
|
|
155
|
-
)
|
|
156
|
-
.expect("config parse");
|
|
157
|
-
let base = ctx.base_dir.clone();
|
|
158
|
-
|
|
159
|
-
assert!(!ctx.config.is_rule_ignored(
|
|
160
|
-
"trailing-spaces",
|
|
161
|
-
&td.path().join("build/keep.yaml"),
|
|
162
|
-
&base
|
|
163
|
-
));
|
|
164
|
-
assert!(ctx.config.is_rule_ignored(
|
|
165
|
-
"trailing-spaces",
|
|
166
|
-
&td.path().join("drop.yaml"),
|
|
167
|
-
&base
|
|
168
|
-
));
|
|
169
|
-
assert!(ctx.config.is_rule_ignored(
|
|
170
|
-
"trailing-spaces",
|
|
171
|
-
&td.path().join("build/sub/nested.yaml"),
|
|
172
|
-
&base,
|
|
173
|
-
));
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
#[test]
|
|
177
|
-
fn extends_resolves_relative_file_paths() {
|
|
178
|
-
let td = tempdir().unwrap();
|
|
179
|
-
let base_cfg = td.path().join("base.yaml");
|
|
180
|
-
fs::write(
|
|
181
|
-
&base_cfg,
|
|
182
|
-
"ignore: ['base/**']\nyaml-files: []\nrules: {}\n",
|
|
183
|
-
)
|
|
184
|
-
.unwrap();
|
|
185
|
-
let child_cfg = td.path().join("child.yaml");
|
|
186
|
-
fs::write(
|
|
187
|
-
&child_cfg,
|
|
188
|
-
"extends: base.yaml\nignore: ['child/**']\nyaml-files: []\nrules: {}\n",
|
|
189
|
-
)
|
|
190
|
-
.unwrap();
|
|
191
|
-
|
|
192
|
-
let ctx = discover_config(
|
|
193
|
-
&[],
|
|
194
|
-
&Overrides {
|
|
195
|
-
config_file: Some(child_cfg.clone()),
|
|
196
|
-
config_data: None,
|
|
197
|
-
},
|
|
198
|
-
)
|
|
199
|
-
.expect("config parse");
|
|
200
|
-
let base = ctx.base_dir.clone();
|
|
201
|
-
|
|
202
|
-
assert!(
|
|
203
|
-
!ctx.config
|
|
204
|
-
.is_file_ignored(&td.path().join("base/one.yaml"), &base),
|
|
205
|
-
"parent ignore entries should be replaced by child overrides"
|
|
206
|
-
);
|
|
207
|
-
assert!(
|
|
208
|
-
ctx.config
|
|
209
|
-
.is_file_ignored(&td.path().join("child/two.yaml"), &base)
|
|
210
|
-
);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
#[test]
|
|
214
|
-
fn config_data_builtin_name_expands() {
|
|
215
|
-
let ctx = discover_config(
|
|
216
|
-
&[],
|
|
217
|
-
&Overrides {
|
|
218
|
-
config_file: None,
|
|
219
|
-
config_data: Some("extends: relaxed".to_string()),
|
|
220
|
-
},
|
|
221
|
-
)
|
|
222
|
-
.expect("config parse");
|
|
223
|
-
|
|
224
|
-
assert!(ctx.config.rule_names().iter().any(|r| r == "braces"));
|
|
225
|
-
}
|