@owenlamont/ryl 0.4.1
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/.github/CODEOWNERS +1 -0
- package/.github/dependabot.yml +13 -0
- package/.github/workflows/ci.yml +107 -0
- package/.github/workflows/release.yml +613 -0
- package/.github/workflows/update_dependencies.yml +61 -0
- package/.github/workflows/update_linters.yml +56 -0
- package/.pre-commit-config.yaml +87 -0
- package/.yamllint +4 -0
- package/AGENTS.md +200 -0
- package/Cargo.lock +908 -0
- package/Cargo.toml +32 -0
- package/LICENSE +21 -0
- package/README.md +230 -0
- package/bin/ryl.js +1 -0
- package/clippy.toml +1 -0
- package/docs/config-presets.md +100 -0
- package/img/benchmark-5x5-5runs.svg +2176 -0
- package/package.json +28 -0
- package/pyproject.toml +42 -0
- package/ruff.toml +107 -0
- package/rumdl.toml +20 -0
- package/rust-toolchain.toml +3 -0
- package/rustfmt.toml +3 -0
- package/scripts/benchmark_perf_vs_yamllint.py +400 -0
- package/scripts/coverage-missing.ps1 +80 -0
- package/scripts/coverage-missing.sh +60 -0
- package/src/bin/discover_config_bin.rs +24 -0
- package/src/cli_support.rs +33 -0
- package/src/conf/mod.rs +85 -0
- package/src/config.rs +2099 -0
- package/src/decoder.rs +326 -0
- package/src/discover.rs +31 -0
- package/src/lib.rs +19 -0
- package/src/lint.rs +558 -0
- package/src/main.rs +535 -0
- package/src/migrate.rs +233 -0
- package/src/rules/anchors.rs +517 -0
- package/src/rules/braces.rs +77 -0
- package/src/rules/brackets.rs +77 -0
- package/src/rules/colons.rs +475 -0
- package/src/rules/commas.rs +372 -0
- package/src/rules/comments.rs +299 -0
- package/src/rules/comments_indentation.rs +243 -0
- package/src/rules/document_end.rs +175 -0
- package/src/rules/document_start.rs +84 -0
- package/src/rules/empty_lines.rs +152 -0
- package/src/rules/empty_values.rs +255 -0
- package/src/rules/float_values.rs +259 -0
- package/src/rules/flow_collection.rs +562 -0
- package/src/rules/hyphens.rs +104 -0
- package/src/rules/indentation.rs +803 -0
- package/src/rules/key_duplicates.rs +218 -0
- package/src/rules/key_ordering.rs +303 -0
- package/src/rules/line_length.rs +326 -0
- package/src/rules/mod.rs +25 -0
- package/src/rules/new_line_at_end_of_file.rs +23 -0
- package/src/rules/new_lines.rs +95 -0
- package/src/rules/octal_values.rs +121 -0
- package/src/rules/quoted_strings.rs +577 -0
- package/src/rules/span_utils.rs +37 -0
- package/src/rules/trailing_spaces.rs +65 -0
- package/src/rules/truthy.rs +420 -0
- package/tests/brackets_carriage_return.rs +114 -0
- package/tests/build_global_cfg_error.rs +23 -0
- package/tests/cli_anchors_rule.rs +143 -0
- package/tests/cli_braces_rule.rs +104 -0
- package/tests/cli_brackets_rule.rs +104 -0
- package/tests/cli_colons_rule.rs +65 -0
- package/tests/cli_commas_rule.rs +104 -0
- package/tests/cli_comments_indentation_rule.rs +61 -0
- package/tests/cli_comments_rule.rs +67 -0
- package/tests/cli_config_data_error.rs +30 -0
- package/tests/cli_config_flags.rs +66 -0
- package/tests/cli_config_migrate.rs +229 -0
- package/tests/cli_document_end_rule.rs +92 -0
- package/tests/cli_document_start_rule.rs +92 -0
- package/tests/cli_empty_lines_rule.rs +87 -0
- package/tests/cli_empty_values_rule.rs +68 -0
- package/tests/cli_env_config.rs +34 -0
- package/tests/cli_exit_and_errors.rs +41 -0
- package/tests/cli_file_encoding.rs +203 -0
- package/tests/cli_float_values_rule.rs +64 -0
- package/tests/cli_format_options.rs +316 -0
- package/tests/cli_global_cfg_relaxed.rs +20 -0
- package/tests/cli_hyphens_rule.rs +104 -0
- package/tests/cli_indentation_rule.rs +65 -0
- package/tests/cli_invalid_project_config.rs +39 -0
- package/tests/cli_key_duplicates_rule.rs +104 -0
- package/tests/cli_key_ordering_rule.rs +59 -0
- package/tests/cli_line_length_rule.rs +85 -0
- package/tests/cli_list_files.rs +29 -0
- package/tests/cli_new_line_rule.rs +141 -0
- package/tests/cli_new_lines_rule.rs +119 -0
- package/tests/cli_octal_values_rule.rs +60 -0
- package/tests/cli_quoted_strings_rule.rs +47 -0
- package/tests/cli_toml_config.rs +119 -0
- package/tests/cli_trailing_spaces_rule.rs +77 -0
- package/tests/cli_truthy_rule.rs +83 -0
- package/tests/cli_yaml_files_negation.rs +45 -0
- package/tests/colons_rule.rs +303 -0
- package/tests/common/compat.rs +114 -0
- package/tests/common/fake_env.rs +93 -0
- package/tests/common/mod.rs +1 -0
- package/tests/conf_builtin.rs +9 -0
- package/tests/config_anchors.rs +84 -0
- package/tests/config_braces.rs +121 -0
- package/tests/config_brackets.rs +127 -0
- package/tests/config_commas.rs +79 -0
- package/tests/config_comments.rs +65 -0
- package/tests/config_comments_indentation.rs +20 -0
- package/tests/config_deep_merge_nonstring_key.rs +24 -0
- package/tests/config_document_end.rs +54 -0
- package/tests/config_document_start.rs +55 -0
- package/tests/config_empty_lines.rs +48 -0
- package/tests/config_empty_values.rs +35 -0
- package/tests/config_env_errors.rs +23 -0
- package/tests/config_env_invalid_inline.rs +15 -0
- package/tests/config_env_missing.rs +63 -0
- package/tests/config_env_shim.rs +301 -0
- package/tests/config_explicit_file_parse_error.rs +55 -0
- package/tests/config_extended_features.rs +225 -0
- package/tests/config_extends_inline.rs +185 -0
- package/tests/config_extends_sequence.rs +18 -0
- package/tests/config_find_project_home_boundary.rs +54 -0
- package/tests/config_find_project_two_files_in_cwd.rs +47 -0
- package/tests/config_float_values.rs +34 -0
- package/tests/config_from_yaml_paths.rs +32 -0
- package/tests/config_hyphens.rs +51 -0
- package/tests/config_ignore_errors.rs +243 -0
- package/tests/config_ignore_overrides.rs +83 -0
- package/tests/config_indentation.rs +65 -0
- package/tests/config_invalid_globs.rs +16 -0
- package/tests/config_invalid_types.rs +19 -0
- package/tests/config_key_duplicates.rs +34 -0
- package/tests/config_key_ordering.rs +70 -0
- package/tests/config_line_length.rs +65 -0
- package/tests/config_locale.rs +111 -0
- package/tests/config_merge.rs +26 -0
- package/tests/config_new_lines.rs +89 -0
- package/tests/config_octal_values.rs +33 -0
- package/tests/config_quoted_strings.rs +195 -0
- package/tests/config_rule_level.rs +147 -0
- package/tests/config_rules_non_string_keys.rs +23 -0
- package/tests/config_scalar_overrides.rs +27 -0
- package/tests/config_to_toml.rs +110 -0
- package/tests/config_toml_coverage.rs +80 -0
- package/tests/config_toml_discovery.rs +304 -0
- package/tests/config_trailing_spaces.rs +152 -0
- package/tests/config_truthy.rs +77 -0
- package/tests/config_yaml_files.rs +62 -0
- package/tests/config_yaml_files_all_non_string.rs +15 -0
- package/tests/config_yaml_files_empty.rs +30 -0
- package/tests/coverage_commas.rs +46 -0
- package/tests/decoder_decode.rs +338 -0
- package/tests/discover_config_bin_all.rs +66 -0
- package/tests/discover_config_bin_env_invalid_yaml.rs +26 -0
- package/tests/discover_config_bin_project_config_parse_error.rs +24 -0
- package/tests/discover_config_bin_user_global_error.rs +26 -0
- package/tests/discover_module.rs +30 -0
- package/tests/discover_per_file_dir.rs +10 -0
- package/tests/discover_per_file_project_config_error.rs +21 -0
- package/tests/float_values.rs +43 -0
- package/tests/lint_multi_errors.rs +32 -0
- package/tests/main_yaml_ok_filtering.rs +30 -0
- package/tests/migrate_module.rs +259 -0
- package/tests/resolve_ctx_empty_parent.rs +16 -0
- package/tests/rule_anchors.rs +442 -0
- package/tests/rule_braces.rs +258 -0
- package/tests/rule_brackets.rs +217 -0
- package/tests/rule_commas.rs +205 -0
- package/tests/rule_comments.rs +197 -0
- package/tests/rule_comments_indentation.rs +127 -0
- package/tests/rule_document_end.rs +118 -0
- package/tests/rule_document_start.rs +60 -0
- package/tests/rule_empty_lines.rs +96 -0
- package/tests/rule_empty_values.rs +102 -0
- package/tests/rule_float_values.rs +109 -0
- package/tests/rule_hyphens.rs +65 -0
- package/tests/rule_indentation.rs +455 -0
- package/tests/rule_key_duplicates.rs +76 -0
- package/tests/rule_key_ordering.rs +207 -0
- package/tests/rule_line_length.rs +200 -0
- package/tests/rule_new_lines.rs +51 -0
- package/tests/rule_octal_values.rs +53 -0
- package/tests/rule_quoted_strings.rs +290 -0
- package/tests/rule_trailing_spaces.rs +41 -0
- package/tests/rule_truthy.rs +236 -0
- package/tests/user_global_invalid_yaml.rs +32 -0
- package/tests/yamllint_compat_anchors.rs +280 -0
- package/tests/yamllint_compat_braces.rs +411 -0
- package/tests/yamllint_compat_brackets.rs +364 -0
- package/tests/yamllint_compat_colons.rs +298 -0
- package/tests/yamllint_compat_colors.rs +80 -0
- package/tests/yamllint_compat_commas.rs +375 -0
- package/tests/yamllint_compat_comments.rs +167 -0
- package/tests/yamllint_compat_comments_indentation.rs +281 -0
- package/tests/yamllint_compat_config.rs +170 -0
- package/tests/yamllint_compat_document_end.rs +243 -0
- package/tests/yamllint_compat_document_start.rs +136 -0
- package/tests/yamllint_compat_empty_lines.rs +117 -0
- package/tests/yamllint_compat_empty_values.rs +179 -0
- package/tests/yamllint_compat_float_values.rs +216 -0
- package/tests/yamllint_compat_hyphens.rs +223 -0
- package/tests/yamllint_compat_indentation.rs +398 -0
- package/tests/yamllint_compat_key_duplicates.rs +139 -0
- package/tests/yamllint_compat_key_ordering.rs +170 -0
- package/tests/yamllint_compat_line_length.rs +375 -0
- package/tests/yamllint_compat_list.rs +127 -0
- package/tests/yamllint_compat_new_line.rs +133 -0
- package/tests/yamllint_compat_newline_types.rs +185 -0
- package/tests/yamllint_compat_octal_values.rs +172 -0
- package/tests/yamllint_compat_quoted_strings.rs +154 -0
- package/tests/yamllint_compat_syntax.rs +200 -0
- package/tests/yamllint_compat_trailing_spaces.rs +162 -0
- package/tests/yamllint_compat_truthy.rs +130 -0
- package/tests/yamllint_compat_yaml_files.rs +81 -0
- package/typos.toml +2 -0
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
use std::fs;
|
|
2
|
+
use std::path::PathBuf;
|
|
3
|
+
|
|
4
|
+
use ryl::migrate::{
|
|
5
|
+
MigrateOptions, MigrationEntry, OutputMode, SourceCleanup, WriteMode,
|
|
6
|
+
apply_migration_entries, migrate_configs,
|
|
7
|
+
};
|
|
8
|
+
use tempfile::tempdir;
|
|
9
|
+
|
|
10
|
+
#[test]
|
|
11
|
+
fn migrate_errors_when_root_is_missing() {
|
|
12
|
+
let opts = MigrateOptions {
|
|
13
|
+
root: PathBuf::from("/no/such/path/for/ryl-migrate"),
|
|
14
|
+
write_mode: WriteMode::Preview,
|
|
15
|
+
output_mode: OutputMode::SummaryOnly,
|
|
16
|
+
cleanup: SourceCleanup::Keep,
|
|
17
|
+
};
|
|
18
|
+
let err = migrate_configs(&opts).unwrap_err();
|
|
19
|
+
assert!(err.contains("migrate root does not exist"));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
#[test]
|
|
23
|
+
fn migrate_single_non_config_file_returns_no_entries() {
|
|
24
|
+
let td = tempdir().unwrap();
|
|
25
|
+
let file = td.path().join("notes.txt");
|
|
26
|
+
fs::write(&file, "hello").unwrap();
|
|
27
|
+
let opts = MigrateOptions {
|
|
28
|
+
root: file,
|
|
29
|
+
write_mode: WriteMode::Preview,
|
|
30
|
+
output_mode: OutputMode::SummaryOnly,
|
|
31
|
+
cleanup: SourceCleanup::Keep,
|
|
32
|
+
};
|
|
33
|
+
let res = migrate_configs(&opts).unwrap();
|
|
34
|
+
assert!(res.entries.is_empty());
|
|
35
|
+
assert!(res.cleanup_only_sources.is_empty());
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
#[test]
|
|
39
|
+
fn migrate_single_yaml_config_file_path_returns_entry() {
|
|
40
|
+
let td = tempdir().unwrap();
|
|
41
|
+
let file = td.path().join(".yamllint");
|
|
42
|
+
fs::write(&file, "rules: { document-start: disable }\n").unwrap();
|
|
43
|
+
let opts = MigrateOptions {
|
|
44
|
+
root: file.clone(),
|
|
45
|
+
write_mode: WriteMode::Preview,
|
|
46
|
+
output_mode: OutputMode::SummaryOnly,
|
|
47
|
+
cleanup: SourceCleanup::Keep,
|
|
48
|
+
};
|
|
49
|
+
let res = migrate_configs(&opts).unwrap();
|
|
50
|
+
assert_eq!(res.entries.len(), 1);
|
|
51
|
+
assert_eq!(res.entries[0].source, file);
|
|
52
|
+
assert!(res.cleanup_only_sources.is_empty());
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
#[test]
|
|
56
|
+
fn migrate_write_mode_with_delete_removes_source_file() {
|
|
57
|
+
let td = tempdir().unwrap();
|
|
58
|
+
let source = td.path().join(".yamllint");
|
|
59
|
+
fs::write(&source, "rules: { document-start: disable }\n").unwrap();
|
|
60
|
+
let opts = MigrateOptions {
|
|
61
|
+
root: td.path().to_path_buf(),
|
|
62
|
+
write_mode: WriteMode::Write,
|
|
63
|
+
output_mode: OutputMode::SummaryOnly,
|
|
64
|
+
cleanup: SourceCleanup::Delete,
|
|
65
|
+
};
|
|
66
|
+
let res = migrate_configs(&opts).unwrap();
|
|
67
|
+
assert_eq!(res.entries.len(), 1);
|
|
68
|
+
assert!(!source.exists());
|
|
69
|
+
assert!(td.path().join(".ryl.toml").exists());
|
|
70
|
+
assert!(res.cleanup_only_sources.is_empty());
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
#[test]
|
|
74
|
+
fn migrate_write_mode_with_keep_preserves_source_file() {
|
|
75
|
+
let td = tempdir().unwrap();
|
|
76
|
+
let source = td.path().join(".yamllint");
|
|
77
|
+
fs::write(&source, "rules: { document-start: disable }\n").unwrap();
|
|
78
|
+
let opts = MigrateOptions {
|
|
79
|
+
root: td.path().to_path_buf(),
|
|
80
|
+
write_mode: WriteMode::Write,
|
|
81
|
+
output_mode: OutputMode::SummaryOnly,
|
|
82
|
+
cleanup: SourceCleanup::Keep,
|
|
83
|
+
};
|
|
84
|
+
let res = migrate_configs(&opts).unwrap();
|
|
85
|
+
assert_eq!(res.entries.len(), 1);
|
|
86
|
+
assert!(source.exists());
|
|
87
|
+
assert!(td.path().join(".ryl.toml").exists());
|
|
88
|
+
assert!(res.cleanup_only_sources.is_empty());
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
#[test]
|
|
92
|
+
fn migrate_write_mode_with_rename_suffix_renames_source_file() {
|
|
93
|
+
let td = tempdir().unwrap();
|
|
94
|
+
let source = td.path().join(".yamllint");
|
|
95
|
+
fs::write(&source, "rules: { document-start: disable }\n").unwrap();
|
|
96
|
+
let opts = MigrateOptions {
|
|
97
|
+
root: td.path().to_path_buf(),
|
|
98
|
+
write_mode: WriteMode::Write,
|
|
99
|
+
output_mode: OutputMode::SummaryOnly,
|
|
100
|
+
cleanup: SourceCleanup::RenameSuffix(".bak".to_string()),
|
|
101
|
+
};
|
|
102
|
+
let res = migrate_configs(&opts).unwrap();
|
|
103
|
+
assert_eq!(res.entries.len(), 1);
|
|
104
|
+
assert!(!source.exists());
|
|
105
|
+
assert!(td.path().join(".yamllint.bak").exists());
|
|
106
|
+
assert!(td.path().join(".ryl.toml").exists());
|
|
107
|
+
assert!(res.cleanup_only_sources.is_empty());
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
#[test]
|
|
111
|
+
fn migrate_warns_on_multiple_same_directory_configs() {
|
|
112
|
+
let td = tempdir().unwrap();
|
|
113
|
+
fs::write(td.path().join(".yamllint.yaml"), "rules: {}\n").unwrap();
|
|
114
|
+
fs::write(td.path().join(".yamllint.yml"), "rules: {}\n").unwrap();
|
|
115
|
+
let opts = MigrateOptions {
|
|
116
|
+
root: td.path().to_path_buf(),
|
|
117
|
+
write_mode: WriteMode::Preview,
|
|
118
|
+
output_mode: OutputMode::SummaryOnly,
|
|
119
|
+
cleanup: SourceCleanup::Keep,
|
|
120
|
+
};
|
|
121
|
+
let res = migrate_configs(&opts).unwrap();
|
|
122
|
+
assert_eq!(res.entries.len(), 1);
|
|
123
|
+
assert_eq!(res.cleanup_only_sources.len(), 1);
|
|
124
|
+
assert_eq!(res.warnings.len(), 1);
|
|
125
|
+
assert!(res.warnings[0].contains("lower-precedence"));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
#[test]
|
|
129
|
+
fn migrate_errors_on_invalid_yaml_config_data() {
|
|
130
|
+
let td = tempdir().unwrap();
|
|
131
|
+
fs::write(td.path().join(".yamllint"), "rules: {\n").unwrap();
|
|
132
|
+
let opts = MigrateOptions {
|
|
133
|
+
root: td.path().to_path_buf(),
|
|
134
|
+
write_mode: WriteMode::Preview,
|
|
135
|
+
output_mode: OutputMode::SummaryOnly,
|
|
136
|
+
cleanup: SourceCleanup::Keep,
|
|
137
|
+
};
|
|
138
|
+
let err = migrate_configs(&opts).unwrap_err();
|
|
139
|
+
assert!(err.contains("failed to parse config data"));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
#[test]
|
|
143
|
+
fn migrate_errors_when_generated_toml_conversion_fails() {
|
|
144
|
+
let td = tempdir().unwrap();
|
|
145
|
+
fs::write(
|
|
146
|
+
td.path().join(".yamllint"),
|
|
147
|
+
"rules: { custom-rule: { opt: ~ } }\n",
|
|
148
|
+
)
|
|
149
|
+
.unwrap();
|
|
150
|
+
let opts = MigrateOptions {
|
|
151
|
+
root: td.path().to_path_buf(),
|
|
152
|
+
write_mode: WriteMode::Preview,
|
|
153
|
+
output_mode: OutputMode::SummaryOnly,
|
|
154
|
+
cleanup: SourceCleanup::Keep,
|
|
155
|
+
};
|
|
156
|
+
let err = migrate_configs(&opts).unwrap_err();
|
|
157
|
+
assert!(err.contains("cannot convert null values to TOML"));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
#[test]
|
|
161
|
+
fn migrate_write_errors_when_target_path_is_directory() {
|
|
162
|
+
let td = tempdir().unwrap();
|
|
163
|
+
fs::write(td.path().join(".yamllint"), "rules: {}\n").unwrap();
|
|
164
|
+
fs::create_dir(td.path().join(".ryl.toml")).unwrap();
|
|
165
|
+
let opts = MigrateOptions {
|
|
166
|
+
root: td.path().to_path_buf(),
|
|
167
|
+
write_mode: WriteMode::Write,
|
|
168
|
+
output_mode: OutputMode::SummaryOnly,
|
|
169
|
+
cleanup: SourceCleanup::Keep,
|
|
170
|
+
};
|
|
171
|
+
let err = migrate_configs(&opts).unwrap_err();
|
|
172
|
+
assert!(err.contains("failed to write migrated config"));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
#[test]
|
|
176
|
+
fn migrate_write_errors_when_rename_destination_is_invalid() {
|
|
177
|
+
let td = tempdir().unwrap();
|
|
178
|
+
fs::write(td.path().join(".yamllint"), "rules: {}\n").unwrap();
|
|
179
|
+
let opts = MigrateOptions {
|
|
180
|
+
root: td.path().to_path_buf(),
|
|
181
|
+
write_mode: WriteMode::Write,
|
|
182
|
+
output_mode: OutputMode::SummaryOnly,
|
|
183
|
+
cleanup: SourceCleanup::RenameSuffix("/missing/subdir".to_string()),
|
|
184
|
+
};
|
|
185
|
+
let err = migrate_configs(&opts).unwrap_err();
|
|
186
|
+
assert!(err.contains("failed to rename migrated source config"));
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
#[test]
|
|
190
|
+
fn apply_entries_delete_mode_propagates_delete_failures() {
|
|
191
|
+
let td = tempdir().unwrap();
|
|
192
|
+
let target = td.path().join(".ryl.toml");
|
|
193
|
+
let source = td.path().join(".yamllint");
|
|
194
|
+
let entries = vec![MigrationEntry {
|
|
195
|
+
source: source.clone(),
|
|
196
|
+
target,
|
|
197
|
+
toml: "[rules]\n".to_string(),
|
|
198
|
+
}];
|
|
199
|
+
let err =
|
|
200
|
+
apply_migration_entries(&entries, &[], &SourceCleanup::Delete).unwrap_err();
|
|
201
|
+
assert!(err.contains("failed to delete migrated source config"));
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
#[test]
|
|
205
|
+
fn apply_entries_delete_mode_cleans_up_cleanup_only_sources() {
|
|
206
|
+
let td = tempdir().unwrap();
|
|
207
|
+
let skipped = td.path().join(".yamllint.yml");
|
|
208
|
+
fs::write(&skipped, "rules: {}\n").unwrap();
|
|
209
|
+
apply_migration_entries(
|
|
210
|
+
&[],
|
|
211
|
+
std::slice::from_ref(&skipped),
|
|
212
|
+
&SourceCleanup::Delete,
|
|
213
|
+
)
|
|
214
|
+
.unwrap();
|
|
215
|
+
assert!(!skipped.exists());
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
#[test]
|
|
219
|
+
fn migrate_delete_mode_removes_lower_precedence_skipped_configs() {
|
|
220
|
+
let td = tempdir().unwrap();
|
|
221
|
+
let primary = td.path().join(".yamllint");
|
|
222
|
+
let skipped = td.path().join(".yamllint.yml");
|
|
223
|
+
fs::write(&primary, "rules: { document-start: disable }\n").unwrap();
|
|
224
|
+
fs::write(&skipped, "rules: {}\n").unwrap();
|
|
225
|
+
let opts = MigrateOptions {
|
|
226
|
+
root: td.path().to_path_buf(),
|
|
227
|
+
write_mode: WriteMode::Write,
|
|
228
|
+
output_mode: OutputMode::SummaryOnly,
|
|
229
|
+
cleanup: SourceCleanup::Delete,
|
|
230
|
+
};
|
|
231
|
+
let res = migrate_configs(&opts).unwrap();
|
|
232
|
+
assert_eq!(res.entries.len(), 1);
|
|
233
|
+
assert_eq!(res.cleanup_only_sources, vec![skipped.clone()]);
|
|
234
|
+
assert!(!primary.exists());
|
|
235
|
+
assert!(!skipped.exists());
|
|
236
|
+
assert!(td.path().join(".ryl.toml").exists());
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
#[test]
|
|
240
|
+
fn migrate_rename_mode_renames_lower_precedence_skipped_configs() {
|
|
241
|
+
let td = tempdir().unwrap();
|
|
242
|
+
let primary = td.path().join(".yamllint");
|
|
243
|
+
let skipped = td.path().join(".yamllint.yml");
|
|
244
|
+
fs::write(&primary, "rules: { document-start: disable }\n").unwrap();
|
|
245
|
+
fs::write(&skipped, "rules: {}\n").unwrap();
|
|
246
|
+
let opts = MigrateOptions {
|
|
247
|
+
root: td.path().to_path_buf(),
|
|
248
|
+
write_mode: WriteMode::Write,
|
|
249
|
+
output_mode: OutputMode::SummaryOnly,
|
|
250
|
+
cleanup: SourceCleanup::RenameSuffix(".bak".to_string()),
|
|
251
|
+
};
|
|
252
|
+
let res = migrate_configs(&opts).unwrap();
|
|
253
|
+
assert_eq!(res.entries.len(), 1);
|
|
254
|
+
assert_eq!(res.cleanup_only_sources, vec![skipped.clone()]);
|
|
255
|
+
assert!(!primary.exists());
|
|
256
|
+
assert!(td.path().join(".yamllint.bak").exists());
|
|
257
|
+
assert!(!skipped.exists());
|
|
258
|
+
assert!(td.path().join(".yamllint.yml.bak").exists());
|
|
259
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
use std::collections::HashMap;
|
|
2
|
+
use std::path::{Path, PathBuf};
|
|
3
|
+
|
|
4
|
+
use ryl::cli_support::resolve_ctx;
|
|
5
|
+
use ryl::config::YamlLintConfig;
|
|
6
|
+
|
|
7
|
+
#[test]
|
|
8
|
+
fn resolve_ctx_handles_path_without_parent() {
|
|
9
|
+
let mut cache: HashMap<PathBuf, (PathBuf, YamlLintConfig)> = HashMap::new();
|
|
10
|
+
let (base_dir, cfg, notices) = resolve_ctx(Path::new(""), None, &mut cache)
|
|
11
|
+
.expect("resolve_ctx should fall back to current directory");
|
|
12
|
+
assert_eq!(base_dir, PathBuf::from("."));
|
|
13
|
+
assert!(notices.is_empty());
|
|
14
|
+
assert!(cache.contains_key(&PathBuf::from(".")));
|
|
15
|
+
assert!(cfg.rule_names().iter().any(|r| r == "anchors"));
|
|
16
|
+
}
|