@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
package/tests/colons_rule.rs
DELETED
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
use ryl::rules::colons::{self, Config};
|
|
2
|
-
|
|
3
|
-
fn violation_points(content: &str, cfg: Config) -> Vec<(usize, usize, String)> {
|
|
4
|
-
let mut hits = colons::check(content, &cfg);
|
|
5
|
-
hits.sort_by(|a, b| a.line.cmp(&b.line).then(a.column.cmp(&b.column)));
|
|
6
|
-
hits.into_iter()
|
|
7
|
-
.map(|hit| (hit.line, hit.column, hit.message))
|
|
8
|
-
.collect()
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
#[test]
|
|
12
|
-
fn config_getters_return_values() {
|
|
13
|
-
let cfg = Config::new_for_tests(3, 4);
|
|
14
|
-
assert_eq!(cfg.max_spaces_before(), 3);
|
|
15
|
-
assert_eq!(cfg.max_spaces_after(), 4);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
#[test]
|
|
19
|
-
fn no_violation_with_defaults() {
|
|
20
|
-
let cfg = Config::new_for_tests(0, 1);
|
|
21
|
-
let points = violation_points("key: value\n", cfg);
|
|
22
|
-
assert!(points.is_empty());
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
#[test]
|
|
26
|
-
fn empty_input_returns_no_violations() {
|
|
27
|
-
let cfg = Config::new_for_tests(0, 1);
|
|
28
|
-
let points = violation_points("", cfg);
|
|
29
|
-
assert!(points.is_empty());
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
#[test]
|
|
33
|
-
fn detects_excess_spaces_before_colon() {
|
|
34
|
-
let cfg = Config::new_for_tests(0, -1);
|
|
35
|
-
let points = violation_points("key : value\n", cfg);
|
|
36
|
-
assert_eq!(
|
|
37
|
-
points,
|
|
38
|
-
vec![(1, 4, "too many spaces before colon".to_string())]
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
#[test]
|
|
43
|
-
fn detects_excess_spaces_after_colon() {
|
|
44
|
-
let cfg = Config::new_for_tests(-1, 1);
|
|
45
|
-
let points = violation_points("key: value\n", cfg);
|
|
46
|
-
assert_eq!(
|
|
47
|
-
points,
|
|
48
|
-
vec![(1, 6, "too many spaces after colon".to_string())]
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
#[test]
|
|
53
|
-
fn detects_excess_spaces_after_question_mark() {
|
|
54
|
-
let cfg = Config::new_for_tests(-1, 1);
|
|
55
|
-
let points = violation_points("? key\n: value\n", cfg);
|
|
56
|
-
assert_eq!(
|
|
57
|
-
points,
|
|
58
|
-
vec![(1, 3, "too many spaces after question mark".to_string())],
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
#[test]
|
|
63
|
-
fn ignores_alias_immediately_before_colon() {
|
|
64
|
-
let cfg = Config::new_for_tests(0, 1);
|
|
65
|
-
let points = violation_points("- anchor: &a key\n- *a: 42\n", cfg);
|
|
66
|
-
assert!(points.is_empty());
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
#[test]
|
|
70
|
-
fn flags_alias_with_extra_spaces() {
|
|
71
|
-
let cfg = Config::new_for_tests(0, 1);
|
|
72
|
-
let points = violation_points("- anchor: &a key\n- *a : 42\n", cfg);
|
|
73
|
-
assert_eq!(
|
|
74
|
-
points,
|
|
75
|
-
vec![(2, 6, "too many spaces before colon".to_string())]
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
#[test]
|
|
80
|
-
fn skips_colons_inside_comments() {
|
|
81
|
-
let cfg = Config::new_for_tests(0, 1);
|
|
82
|
-
let points = violation_points("# comment: text\nkey: value\n", cfg);
|
|
83
|
-
assert!(points.is_empty());
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
#[test]
|
|
87
|
-
fn handles_crlf_after_colon() {
|
|
88
|
-
let cfg = Config::new_for_tests(-1, 1);
|
|
89
|
-
let points = violation_points("key:\r\n value\rnext: pair\n", cfg);
|
|
90
|
-
assert!(points.is_empty());
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
#[test]
|
|
94
|
-
fn question_mark_not_explicit_is_ignored() {
|
|
95
|
-
let cfg = Config::new_for_tests(-1, 1);
|
|
96
|
-
let points = violation_points("value? trailing\n", cfg);
|
|
97
|
-
assert!(points.is_empty());
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
#[test]
|
|
101
|
-
fn sequence_question_mark_spacing_detected() {
|
|
102
|
-
let cfg = Config::new_for_tests(-1, 1);
|
|
103
|
-
let points = violation_points("- ? key\n : value\n", cfg);
|
|
104
|
-
assert_eq!(
|
|
105
|
-
points,
|
|
106
|
-
vec![
|
|
107
|
-
(1, 5, "too many spaces after question mark".to_string()),
|
|
108
|
-
(2, 5, "too many spaces after colon".to_string()),
|
|
109
|
-
]
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
#[test]
|
|
114
|
-
fn question_mark_spacing_disabled_skips_check() {
|
|
115
|
-
let cfg = Config::new_for_tests(-1, -1);
|
|
116
|
-
let points = violation_points("? key\n: value\n", cfg);
|
|
117
|
-
assert!(points.is_empty());
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
#[test]
|
|
121
|
-
fn comment_with_crlf_is_ignored() {
|
|
122
|
-
let cfg = Config::new_for_tests(0, 1);
|
|
123
|
-
let points = violation_points("# note: here\r\nkey: value\r\n", cfg);
|
|
124
|
-
assert!(points.is_empty());
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
#[test]
|
|
128
|
-
fn colon_at_line_start_reports_after_spacing() {
|
|
129
|
-
let cfg = Config::new_for_tests(-1, 1);
|
|
130
|
-
let points = violation_points(": value\n", cfg);
|
|
131
|
-
assert_eq!(
|
|
132
|
-
points,
|
|
133
|
-
vec![(1, 3, "too many spaces after colon".to_string())]
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
#[test]
|
|
138
|
-
fn colon_at_end_of_file_is_ignored() {
|
|
139
|
-
let cfg = Config::new_for_tests(-1, 1);
|
|
140
|
-
let points = violation_points("key:", cfg);
|
|
141
|
-
assert!(points.is_empty());
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
#[test]
|
|
145
|
-
fn colon_followed_by_carriage_return_is_ignored() {
|
|
146
|
-
let cfg = Config::new_for_tests(-1, 1);
|
|
147
|
-
let points = violation_points("key:\rvalue\n", cfg);
|
|
148
|
-
assert!(points.is_empty());
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
#[test]
|
|
152
|
-
fn flow_question_mark_spacing_detected() {
|
|
153
|
-
let cfg = Config::new_for_tests(-1, 1);
|
|
154
|
-
let points = violation_points("[? key: value]\n", cfg);
|
|
155
|
-
assert_eq!(
|
|
156
|
-
points,
|
|
157
|
-
vec![(1, 4, "too many spaces after question mark".to_string())]
|
|
158
|
-
);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
#[test]
|
|
162
|
-
fn indented_sequence_question_mark_spacing_detected() {
|
|
163
|
-
let cfg = Config::new_for_tests(-1, 1);
|
|
164
|
-
let points = violation_points("parent:\n - ? child\n : value\n", cfg);
|
|
165
|
-
assert_eq!(
|
|
166
|
-
points,
|
|
167
|
-
vec![
|
|
168
|
-
(2, 7, "too many spaces after question mark".to_string()),
|
|
169
|
-
(3, 7, "too many spaces after colon".to_string()),
|
|
170
|
-
]
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
#[test]
|
|
175
|
-
fn hyphen_not_sequence_does_not_trigger_question_mark_rule() {
|
|
176
|
-
let cfg = Config::new_for_tests(-1, 1);
|
|
177
|
-
let points = violation_points("a- ? key\n", cfg);
|
|
178
|
-
assert!(points.is_empty());
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
#[test]
|
|
182
|
-
fn question_mark_without_space_not_explicit() {
|
|
183
|
-
let cfg = Config::new_for_tests(-1, 1);
|
|
184
|
-
let points = violation_points("?key: value\n", cfg);
|
|
185
|
-
assert!(points.is_empty());
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
#[test]
|
|
189
|
-
fn dash_without_space_before_question_mark_is_ignored() {
|
|
190
|
-
let cfg = Config::new_for_tests(-1, 1);
|
|
191
|
-
let points = violation_points("-? key\n : value\n", cfg);
|
|
192
|
-
assert!(points.is_empty());
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
#[test]
|
|
196
|
-
fn colons_inside_scalars_with_multibyte_chars_are_ignored() {
|
|
197
|
-
let cfg = Config::new_for_tests(0, 1);
|
|
198
|
-
let points = violation_points("key: \"café: menu\"\n", cfg);
|
|
199
|
-
assert!(points.is_empty());
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
#[test]
|
|
203
|
-
fn inline_comment_after_colon_is_ignored_for_spacing() {
|
|
204
|
-
let cfg = Config::new_for_tests(-1, 0);
|
|
205
|
-
let points = violation_points("key: # note\n", cfg);
|
|
206
|
-
assert!(
|
|
207
|
-
points.is_empty(),
|
|
208
|
-
"inline comment should bypass spacing check: {points:?}"
|
|
209
|
-
);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
#[test]
|
|
213
|
-
fn coverage_explicit_question_mark_handles_non_whitespace_next() {
|
|
214
|
-
let chars: Vec<(usize, char)> = "?key".char_indices().collect();
|
|
215
|
-
assert!(!colons::coverage_is_explicit_question_mark(&chars, 0));
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
#[test]
|
|
219
|
-
fn coverage_explicit_question_mark_handles_sequence_indicator_branch() {
|
|
220
|
-
let chars: Vec<(usize, char)> = " - ? key".char_indices().collect();
|
|
221
|
-
assert!(colons::coverage_is_explicit_question_mark(&chars, 3));
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
#[test]
|
|
225
|
-
fn coverage_sequence_indicator_false_branch() {
|
|
226
|
-
let chars: Vec<(usize, char)> = "a-".char_indices().collect();
|
|
227
|
-
assert!(!colons::coverage_is_sequence_indicator(&chars, 1));
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
#[test]
|
|
231
|
-
fn coverage_explicit_question_mark_handles_regular_char_before() {
|
|
232
|
-
let chars: Vec<(usize, char)> = "a ? ".char_indices().collect();
|
|
233
|
-
assert!(!colons::coverage_is_explicit_question_mark(&chars, 2));
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
#[test]
|
|
237
|
-
fn coverage_evaluate_question_mark_reports_violation() {
|
|
238
|
-
let cfg = Config::new_for_tests(-1, 1);
|
|
239
|
-
let violations = colons::coverage_evaluate_question_mark("? key\n: value\n", &cfg);
|
|
240
|
-
assert!(
|
|
241
|
-
violations
|
|
242
|
-
.iter()
|
|
243
|
-
.any(|v| v.message.contains("too many spaces after question mark"))
|
|
244
|
-
);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
#[test]
|
|
248
|
-
fn coverage_explicit_question_mark_handles_flow_prefix_variants() {
|
|
249
|
-
let bracket_chars: Vec<(usize, char)> = "[ ? key".char_indices().collect();
|
|
250
|
-
assert!(colons::coverage_is_explicit_question_mark(
|
|
251
|
-
&bracket_chars,
|
|
252
|
-
2
|
|
253
|
-
));
|
|
254
|
-
let brace_chars: Vec<(usize, char)> = "{ ? key".char_indices().collect();
|
|
255
|
-
assert!(colons::coverage_is_explicit_question_mark(&brace_chars, 2));
|
|
256
|
-
let comma_chars: Vec<(usize, char)> = ", ? key".char_indices().collect();
|
|
257
|
-
assert!(colons::coverage_is_explicit_question_mark(&comma_chars, 2));
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
#[test]
|
|
261
|
-
fn coverage_question_mark_immediate_newline_is_ignored() {
|
|
262
|
-
let cfg = Config::new_for_tests(-1, 1);
|
|
263
|
-
let violations = colons::coverage_evaluate_question_mark("? \n: value\n", &cfg);
|
|
264
|
-
assert!(violations.is_empty());
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
#[test]
|
|
268
|
-
fn coverage_question_mark_crlf_is_ignored() {
|
|
269
|
-
let cfg = Config::new_for_tests(-1, 1);
|
|
270
|
-
let violations = colons::coverage_evaluate_question_mark("? \r\n: value\n", &cfg);
|
|
271
|
-
assert!(violations.is_empty());
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
#[test]
|
|
275
|
-
fn coverage_skip_comment_handles_crlf() {
|
|
276
|
-
assert!(colons::coverage_skip_comment("# comment\r\nrest"));
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
#[test]
|
|
280
|
-
fn coverage_skip_comment_handles_standalone_cr() {
|
|
281
|
-
assert!(!colons::coverage_skip_comment("# comment\rrest"));
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
#[test]
|
|
285
|
-
fn coverage_evaluate_question_mark_without_marker_is_noop() {
|
|
286
|
-
let cfg = Config::new_for_tests(-1, 1);
|
|
287
|
-
let violations = colons::coverage_evaluate_question_mark("key: value\n", &cfg);
|
|
288
|
-
assert!(violations.is_empty());
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
#[test]
|
|
292
|
-
fn coverage_question_mark_within_limit_on_same_line() {
|
|
293
|
-
let cfg = Config::new_for_tests(-1, 1);
|
|
294
|
-
let violations = colons::coverage_evaluate_question_mark("? key: value\n", &cfg);
|
|
295
|
-
assert!(violations.is_empty());
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
#[test]
|
|
299
|
-
fn coverage_check_handles_comment_crlf() {
|
|
300
|
-
let cfg = Config::new_for_tests(0, 1);
|
|
301
|
-
let result = colons::check("# heading\r\nkey: value\n", &cfg);
|
|
302
|
-
assert!(result.is_empty());
|
|
303
|
-
}
|
package/tests/common/compat.rs
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
use std::process::Command;
|
|
2
|
-
|
|
3
|
-
pub fn run(cmd: &mut Command) -> (i32, String, String) {
|
|
4
|
-
let out = cmd.output().expect("process");
|
|
5
|
-
let code = out.status.code().unwrap_or(-1);
|
|
6
|
-
let stdout = String::from_utf8_lossy(&out.stdout).into_owned();
|
|
7
|
-
let stderr = String::from_utf8_lossy(&out.stderr).into_owned();
|
|
8
|
-
(code, stdout, stderr)
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
pub fn ensure_yamllint_installed() {
|
|
12
|
-
let ok = Command::new("yamllint")
|
|
13
|
-
.arg("--version")
|
|
14
|
-
.output()
|
|
15
|
-
.map(|out| out.status.success())
|
|
16
|
-
.unwrap_or(false);
|
|
17
|
-
assert!(ok, "yamllint must be installed for compatibility tests");
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
pub fn normalize_output(stdout: String, stderr: String) -> String {
|
|
21
|
-
let output = if stderr.is_empty() { stdout } else { stderr };
|
|
22
|
-
// Normalize line endings to LF for cross-platform compatibility
|
|
23
|
-
output.replace("\r\n", "\n")
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
pub fn capture_with_env(
|
|
27
|
-
mut cmd: Command,
|
|
28
|
-
envs: &[(&str, Option<&str>)],
|
|
29
|
-
) -> (i32, String) {
|
|
30
|
-
cmd.env_remove("GITHUB_ACTIONS");
|
|
31
|
-
cmd.env_remove("GITHUB_WORKFLOW");
|
|
32
|
-
cmd.env_remove("CI");
|
|
33
|
-
cmd.env_remove("FORCE_COLOR");
|
|
34
|
-
cmd.env_remove("NO_COLOR");
|
|
35
|
-
for (key, value) in envs {
|
|
36
|
-
if let Some(v) = value {
|
|
37
|
-
cmd.env(key, v);
|
|
38
|
-
} else {
|
|
39
|
-
cmd.env_remove(key);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
let (code, stdout, stderr) = run(&mut cmd);
|
|
43
|
-
(code, normalize_output(stdout, stderr))
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
#[derive(Clone, Copy)]
|
|
47
|
-
pub struct Scenario {
|
|
48
|
-
pub label: &'static str,
|
|
49
|
-
pub envs: &'static [(&'static str, Option<&'static str>)],
|
|
50
|
-
pub ryl_format: Option<&'static str>,
|
|
51
|
-
pub yam_format: Option<&'static str>,
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
pub const STANDARD_ENV: &[(&str, Option<&str>)] = &[];
|
|
55
|
-
pub const GITHUB_ENV: &[(&str, Option<&str>)] = &[
|
|
56
|
-
("GITHUB_ACTIONS", Some("true")),
|
|
57
|
-
("GITHUB_WORKFLOW", Some("test-workflow")),
|
|
58
|
-
("CI", Some("true")),
|
|
59
|
-
];
|
|
60
|
-
|
|
61
|
-
pub const SCENARIOS: &[Scenario] = &[
|
|
62
|
-
Scenario {
|
|
63
|
-
label: "auto-standard",
|
|
64
|
-
envs: STANDARD_ENV,
|
|
65
|
-
ryl_format: None,
|
|
66
|
-
yam_format: None,
|
|
67
|
-
},
|
|
68
|
-
Scenario {
|
|
69
|
-
label: "auto-github",
|
|
70
|
-
envs: GITHUB_ENV,
|
|
71
|
-
ryl_format: None,
|
|
72
|
-
yam_format: None,
|
|
73
|
-
},
|
|
74
|
-
Scenario {
|
|
75
|
-
label: "format-standard",
|
|
76
|
-
envs: STANDARD_ENV,
|
|
77
|
-
ryl_format: Some("standard"),
|
|
78
|
-
yam_format: Some("standard"),
|
|
79
|
-
},
|
|
80
|
-
Scenario {
|
|
81
|
-
label: "format-colored",
|
|
82
|
-
envs: STANDARD_ENV,
|
|
83
|
-
ryl_format: Some("colored"),
|
|
84
|
-
yam_format: Some("colored"),
|
|
85
|
-
},
|
|
86
|
-
Scenario {
|
|
87
|
-
label: "format-github",
|
|
88
|
-
envs: STANDARD_ENV,
|
|
89
|
-
ryl_format: Some("github"),
|
|
90
|
-
yam_format: Some("github"),
|
|
91
|
-
},
|
|
92
|
-
Scenario {
|
|
93
|
-
label: "format-parsable",
|
|
94
|
-
envs: STANDARD_ENV,
|
|
95
|
-
ryl_format: Some("parsable"),
|
|
96
|
-
yam_format: Some("parsable"),
|
|
97
|
-
},
|
|
98
|
-
];
|
|
99
|
-
|
|
100
|
-
pub fn build_ryl_command(exe: &str, format: Option<&str>) -> Command {
|
|
101
|
-
let mut cmd = Command::new(exe);
|
|
102
|
-
if let Some(fmt) = format {
|
|
103
|
-
cmd.arg("--format").arg(fmt);
|
|
104
|
-
}
|
|
105
|
-
cmd
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
pub fn build_yamllint_command(format: Option<&str>) -> Command {
|
|
109
|
-
let mut cmd = Command::new("yamllint");
|
|
110
|
-
if let Some(fmt) = format {
|
|
111
|
-
cmd.arg("-f").arg(fmt);
|
|
112
|
-
}
|
|
113
|
-
cmd
|
|
114
|
-
}
|
package/tests/common/fake_env.rs
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
use std::collections::{HashMap, HashSet};
|
|
2
|
-
use std::path::{Path, PathBuf};
|
|
3
|
-
|
|
4
|
-
use ryl::config::Env;
|
|
5
|
-
|
|
6
|
-
#[derive(Clone, Default)]
|
|
7
|
-
pub struct FakeEnv {
|
|
8
|
-
cwd: PathBuf,
|
|
9
|
-
files: HashMap<PathBuf, String>,
|
|
10
|
-
exists: HashSet<PathBuf>,
|
|
11
|
-
vars: HashMap<String, String>,
|
|
12
|
-
config_dir: Option<PathBuf>,
|
|
13
|
-
home: Option<PathBuf>,
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
#[allow(dead_code)]
|
|
17
|
-
impl FakeEnv {
|
|
18
|
-
pub fn new() -> Self {
|
|
19
|
-
Self {
|
|
20
|
-
cwd: PathBuf::from("."),
|
|
21
|
-
..Self::default()
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
pub fn with_cwd(mut self, path: impl Into<PathBuf>) -> Self {
|
|
26
|
-
self.cwd = path.into();
|
|
27
|
-
self
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
pub fn with_config_dir(mut self, path: impl Into<PathBuf>) -> Self {
|
|
31
|
-
self.config_dir = Some(path.into());
|
|
32
|
-
self
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
pub fn with_file(
|
|
36
|
-
mut self,
|
|
37
|
-
path: impl Into<PathBuf>,
|
|
38
|
-
content: impl Into<String>,
|
|
39
|
-
) -> Self {
|
|
40
|
-
self.files.insert(path.into(), content.into());
|
|
41
|
-
self
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
pub fn with_exists(mut self, path: impl Into<PathBuf>) -> Self {
|
|
45
|
-
self.exists.insert(path.into());
|
|
46
|
-
self
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
pub fn with_var(
|
|
50
|
-
mut self,
|
|
51
|
-
key: impl Into<String>,
|
|
52
|
-
value: impl Into<String>,
|
|
53
|
-
) -> Self {
|
|
54
|
-
self.vars.insert(key.into(), value.into());
|
|
55
|
-
self
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
pub fn with_home(mut self, path: impl Into<PathBuf>) -> Self {
|
|
59
|
-
self.home = Some(path.into());
|
|
60
|
-
self
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
impl Env for FakeEnv {
|
|
65
|
-
fn current_dir(&self) -> PathBuf {
|
|
66
|
-
self.cwd.clone()
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
fn config_dir(&self) -> Option<PathBuf> {
|
|
70
|
-
self.config_dir.clone()
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
fn read_to_string(&self, p: &Path) -> Result<String, String> {
|
|
74
|
-
self.files.get(p).cloned().ok_or_else(|| {
|
|
75
|
-
format!("failed to read config file {}: not found", p.display())
|
|
76
|
-
})
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
fn path_exists(&self, p: &Path) -> bool {
|
|
80
|
-
self.files.contains_key(p) || self.exists.contains(p)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
fn env_var(&self, key: &str) -> Option<String> {
|
|
84
|
-
self.vars.get(key).cloned()
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
fn home_dir(&self) -> Option<PathBuf> {
|
|
88
|
-
self.home
|
|
89
|
-
.clone()
|
|
90
|
-
.or_else(|| self.vars.get("HOME").map(PathBuf::from))
|
|
91
|
-
.or_else(|| self.vars.get("USERPROFILE").map(PathBuf::from))
|
|
92
|
-
}
|
|
93
|
-
}
|
package/tests/common/mod.rs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
pub mod fake_env;
|
package/tests/conf_builtin.rs
DELETED
package/tests/config_anchors.rs
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
use ryl::config::{Overrides, discover_config};
|
|
2
|
-
|
|
3
|
-
#[test]
|
|
4
|
-
fn anchors_allows_boolean_options() {
|
|
5
|
-
let cfg = r#"
|
|
6
|
-
rules:
|
|
7
|
-
anchors:
|
|
8
|
-
forbid-undeclared-aliases: false
|
|
9
|
-
forbid-duplicated-anchors: true
|
|
10
|
-
forbid-unused-anchors: true
|
|
11
|
-
"#;
|
|
12
|
-
|
|
13
|
-
let ctx = discover_config(
|
|
14
|
-
&[],
|
|
15
|
-
&Overrides {
|
|
16
|
-
config_file: None,
|
|
17
|
-
config_data: Some(cfg.into()),
|
|
18
|
-
},
|
|
19
|
-
)
|
|
20
|
-
.expect("parse");
|
|
21
|
-
|
|
22
|
-
assert!(ctx.config.rule_names().iter().any(|r| r == "anchors"));
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
#[test]
|
|
26
|
-
fn anchors_rejects_non_bool_option() {
|
|
27
|
-
let cfg = r#"
|
|
28
|
-
rules:
|
|
29
|
-
anchors:
|
|
30
|
-
forbid-duplicated-anchors: "yes"
|
|
31
|
-
"#;
|
|
32
|
-
|
|
33
|
-
let err = discover_config(
|
|
34
|
-
&[],
|
|
35
|
-
&Overrides {
|
|
36
|
-
config_file: None,
|
|
37
|
-
config_data: Some(cfg.into()),
|
|
38
|
-
},
|
|
39
|
-
)
|
|
40
|
-
.expect_err("invalid value");
|
|
41
|
-
|
|
42
|
-
assert!(err.contains("forbid-duplicated-anchors"));
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
#[test]
|
|
46
|
-
fn anchors_rejects_unknown_option() {
|
|
47
|
-
let cfg = r#"
|
|
48
|
-
rules:
|
|
49
|
-
anchors:
|
|
50
|
-
unknown: true
|
|
51
|
-
"#;
|
|
52
|
-
|
|
53
|
-
let err = discover_config(
|
|
54
|
-
&[],
|
|
55
|
-
&Overrides {
|
|
56
|
-
config_file: None,
|
|
57
|
-
config_data: Some(cfg.into()),
|
|
58
|
-
},
|
|
59
|
-
)
|
|
60
|
-
.expect_err("unknown option");
|
|
61
|
-
|
|
62
|
-
assert!(err.contains("unknown option \"unknown\" for rule \"anchors\""));
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
#[test]
|
|
66
|
-
fn anchors_rejects_non_string_option_key() {
|
|
67
|
-
let cfg = r#"
|
|
68
|
-
rules:
|
|
69
|
-
anchors:
|
|
70
|
-
? [1, 2]
|
|
71
|
-
: true
|
|
72
|
-
"#;
|
|
73
|
-
|
|
74
|
-
let err = discover_config(
|
|
75
|
-
&[],
|
|
76
|
-
&Overrides {
|
|
77
|
-
config_file: None,
|
|
78
|
-
config_data: Some(cfg.into()),
|
|
79
|
-
},
|
|
80
|
-
)
|
|
81
|
-
.expect_err("non-string key");
|
|
82
|
-
|
|
83
|
-
assert!(err.contains("unknown option") && err.contains("anchors"));
|
|
84
|
-
}
|