@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.
Files changed (217) hide show
  1. package/.github/CODEOWNERS +1 -0
  2. package/.github/dependabot.yml +13 -0
  3. package/.github/workflows/ci.yml +107 -0
  4. package/.github/workflows/release.yml +613 -0
  5. package/.github/workflows/update_dependencies.yml +61 -0
  6. package/.github/workflows/update_linters.yml +56 -0
  7. package/.pre-commit-config.yaml +87 -0
  8. package/.yamllint +4 -0
  9. package/AGENTS.md +200 -0
  10. package/Cargo.lock +908 -0
  11. package/Cargo.toml +32 -0
  12. package/LICENSE +21 -0
  13. package/README.md +230 -0
  14. package/bin/ryl.js +1 -0
  15. package/clippy.toml +1 -0
  16. package/docs/config-presets.md +100 -0
  17. package/img/benchmark-5x5-5runs.svg +2176 -0
  18. package/package.json +28 -0
  19. package/pyproject.toml +42 -0
  20. package/ruff.toml +107 -0
  21. package/rumdl.toml +20 -0
  22. package/rust-toolchain.toml +3 -0
  23. package/rustfmt.toml +3 -0
  24. package/scripts/benchmark_perf_vs_yamllint.py +400 -0
  25. package/scripts/coverage-missing.ps1 +80 -0
  26. package/scripts/coverage-missing.sh +60 -0
  27. package/src/bin/discover_config_bin.rs +24 -0
  28. package/src/cli_support.rs +33 -0
  29. package/src/conf/mod.rs +85 -0
  30. package/src/config.rs +2099 -0
  31. package/src/decoder.rs +326 -0
  32. package/src/discover.rs +31 -0
  33. package/src/lib.rs +19 -0
  34. package/src/lint.rs +558 -0
  35. package/src/main.rs +535 -0
  36. package/src/migrate.rs +233 -0
  37. package/src/rules/anchors.rs +517 -0
  38. package/src/rules/braces.rs +77 -0
  39. package/src/rules/brackets.rs +77 -0
  40. package/src/rules/colons.rs +475 -0
  41. package/src/rules/commas.rs +372 -0
  42. package/src/rules/comments.rs +299 -0
  43. package/src/rules/comments_indentation.rs +243 -0
  44. package/src/rules/document_end.rs +175 -0
  45. package/src/rules/document_start.rs +84 -0
  46. package/src/rules/empty_lines.rs +152 -0
  47. package/src/rules/empty_values.rs +255 -0
  48. package/src/rules/float_values.rs +259 -0
  49. package/src/rules/flow_collection.rs +562 -0
  50. package/src/rules/hyphens.rs +104 -0
  51. package/src/rules/indentation.rs +803 -0
  52. package/src/rules/key_duplicates.rs +218 -0
  53. package/src/rules/key_ordering.rs +303 -0
  54. package/src/rules/line_length.rs +326 -0
  55. package/src/rules/mod.rs +25 -0
  56. package/src/rules/new_line_at_end_of_file.rs +23 -0
  57. package/src/rules/new_lines.rs +95 -0
  58. package/src/rules/octal_values.rs +121 -0
  59. package/src/rules/quoted_strings.rs +577 -0
  60. package/src/rules/span_utils.rs +37 -0
  61. package/src/rules/trailing_spaces.rs +65 -0
  62. package/src/rules/truthy.rs +420 -0
  63. package/tests/brackets_carriage_return.rs +114 -0
  64. package/tests/build_global_cfg_error.rs +23 -0
  65. package/tests/cli_anchors_rule.rs +143 -0
  66. package/tests/cli_braces_rule.rs +104 -0
  67. package/tests/cli_brackets_rule.rs +104 -0
  68. package/tests/cli_colons_rule.rs +65 -0
  69. package/tests/cli_commas_rule.rs +104 -0
  70. package/tests/cli_comments_indentation_rule.rs +61 -0
  71. package/tests/cli_comments_rule.rs +67 -0
  72. package/tests/cli_config_data_error.rs +30 -0
  73. package/tests/cli_config_flags.rs +66 -0
  74. package/tests/cli_config_migrate.rs +229 -0
  75. package/tests/cli_document_end_rule.rs +92 -0
  76. package/tests/cli_document_start_rule.rs +92 -0
  77. package/tests/cli_empty_lines_rule.rs +87 -0
  78. package/tests/cli_empty_values_rule.rs +68 -0
  79. package/tests/cli_env_config.rs +34 -0
  80. package/tests/cli_exit_and_errors.rs +41 -0
  81. package/tests/cli_file_encoding.rs +203 -0
  82. package/tests/cli_float_values_rule.rs +64 -0
  83. package/tests/cli_format_options.rs +316 -0
  84. package/tests/cli_global_cfg_relaxed.rs +20 -0
  85. package/tests/cli_hyphens_rule.rs +104 -0
  86. package/tests/cli_indentation_rule.rs +65 -0
  87. package/tests/cli_invalid_project_config.rs +39 -0
  88. package/tests/cli_key_duplicates_rule.rs +104 -0
  89. package/tests/cli_key_ordering_rule.rs +59 -0
  90. package/tests/cli_line_length_rule.rs +85 -0
  91. package/tests/cli_list_files.rs +29 -0
  92. package/tests/cli_new_line_rule.rs +141 -0
  93. package/tests/cli_new_lines_rule.rs +119 -0
  94. package/tests/cli_octal_values_rule.rs +60 -0
  95. package/tests/cli_quoted_strings_rule.rs +47 -0
  96. package/tests/cli_toml_config.rs +119 -0
  97. package/tests/cli_trailing_spaces_rule.rs +77 -0
  98. package/tests/cli_truthy_rule.rs +83 -0
  99. package/tests/cli_yaml_files_negation.rs +45 -0
  100. package/tests/colons_rule.rs +303 -0
  101. package/tests/common/compat.rs +114 -0
  102. package/tests/common/fake_env.rs +93 -0
  103. package/tests/common/mod.rs +1 -0
  104. package/tests/conf_builtin.rs +9 -0
  105. package/tests/config_anchors.rs +84 -0
  106. package/tests/config_braces.rs +121 -0
  107. package/tests/config_brackets.rs +127 -0
  108. package/tests/config_commas.rs +79 -0
  109. package/tests/config_comments.rs +65 -0
  110. package/tests/config_comments_indentation.rs +20 -0
  111. package/tests/config_deep_merge_nonstring_key.rs +24 -0
  112. package/tests/config_document_end.rs +54 -0
  113. package/tests/config_document_start.rs +55 -0
  114. package/tests/config_empty_lines.rs +48 -0
  115. package/tests/config_empty_values.rs +35 -0
  116. package/tests/config_env_errors.rs +23 -0
  117. package/tests/config_env_invalid_inline.rs +15 -0
  118. package/tests/config_env_missing.rs +63 -0
  119. package/tests/config_env_shim.rs +301 -0
  120. package/tests/config_explicit_file_parse_error.rs +55 -0
  121. package/tests/config_extended_features.rs +225 -0
  122. package/tests/config_extends_inline.rs +185 -0
  123. package/tests/config_extends_sequence.rs +18 -0
  124. package/tests/config_find_project_home_boundary.rs +54 -0
  125. package/tests/config_find_project_two_files_in_cwd.rs +47 -0
  126. package/tests/config_float_values.rs +34 -0
  127. package/tests/config_from_yaml_paths.rs +32 -0
  128. package/tests/config_hyphens.rs +51 -0
  129. package/tests/config_ignore_errors.rs +243 -0
  130. package/tests/config_ignore_overrides.rs +83 -0
  131. package/tests/config_indentation.rs +65 -0
  132. package/tests/config_invalid_globs.rs +16 -0
  133. package/tests/config_invalid_types.rs +19 -0
  134. package/tests/config_key_duplicates.rs +34 -0
  135. package/tests/config_key_ordering.rs +70 -0
  136. package/tests/config_line_length.rs +65 -0
  137. package/tests/config_locale.rs +111 -0
  138. package/tests/config_merge.rs +26 -0
  139. package/tests/config_new_lines.rs +89 -0
  140. package/tests/config_octal_values.rs +33 -0
  141. package/tests/config_quoted_strings.rs +195 -0
  142. package/tests/config_rule_level.rs +147 -0
  143. package/tests/config_rules_non_string_keys.rs +23 -0
  144. package/tests/config_scalar_overrides.rs +27 -0
  145. package/tests/config_to_toml.rs +110 -0
  146. package/tests/config_toml_coverage.rs +80 -0
  147. package/tests/config_toml_discovery.rs +304 -0
  148. package/tests/config_trailing_spaces.rs +152 -0
  149. package/tests/config_truthy.rs +77 -0
  150. package/tests/config_yaml_files.rs +62 -0
  151. package/tests/config_yaml_files_all_non_string.rs +15 -0
  152. package/tests/config_yaml_files_empty.rs +30 -0
  153. package/tests/coverage_commas.rs +46 -0
  154. package/tests/decoder_decode.rs +338 -0
  155. package/tests/discover_config_bin_all.rs +66 -0
  156. package/tests/discover_config_bin_env_invalid_yaml.rs +26 -0
  157. package/tests/discover_config_bin_project_config_parse_error.rs +24 -0
  158. package/tests/discover_config_bin_user_global_error.rs +26 -0
  159. package/tests/discover_module.rs +30 -0
  160. package/tests/discover_per_file_dir.rs +10 -0
  161. package/tests/discover_per_file_project_config_error.rs +21 -0
  162. package/tests/float_values.rs +43 -0
  163. package/tests/lint_multi_errors.rs +32 -0
  164. package/tests/main_yaml_ok_filtering.rs +30 -0
  165. package/tests/migrate_module.rs +259 -0
  166. package/tests/resolve_ctx_empty_parent.rs +16 -0
  167. package/tests/rule_anchors.rs +442 -0
  168. package/tests/rule_braces.rs +258 -0
  169. package/tests/rule_brackets.rs +217 -0
  170. package/tests/rule_commas.rs +205 -0
  171. package/tests/rule_comments.rs +197 -0
  172. package/tests/rule_comments_indentation.rs +127 -0
  173. package/tests/rule_document_end.rs +118 -0
  174. package/tests/rule_document_start.rs +60 -0
  175. package/tests/rule_empty_lines.rs +96 -0
  176. package/tests/rule_empty_values.rs +102 -0
  177. package/tests/rule_float_values.rs +109 -0
  178. package/tests/rule_hyphens.rs +65 -0
  179. package/tests/rule_indentation.rs +455 -0
  180. package/tests/rule_key_duplicates.rs +76 -0
  181. package/tests/rule_key_ordering.rs +207 -0
  182. package/tests/rule_line_length.rs +200 -0
  183. package/tests/rule_new_lines.rs +51 -0
  184. package/tests/rule_octal_values.rs +53 -0
  185. package/tests/rule_quoted_strings.rs +290 -0
  186. package/tests/rule_trailing_spaces.rs +41 -0
  187. package/tests/rule_truthy.rs +236 -0
  188. package/tests/user_global_invalid_yaml.rs +32 -0
  189. package/tests/yamllint_compat_anchors.rs +280 -0
  190. package/tests/yamllint_compat_braces.rs +411 -0
  191. package/tests/yamllint_compat_brackets.rs +364 -0
  192. package/tests/yamllint_compat_colons.rs +298 -0
  193. package/tests/yamllint_compat_colors.rs +80 -0
  194. package/tests/yamllint_compat_commas.rs +375 -0
  195. package/tests/yamllint_compat_comments.rs +167 -0
  196. package/tests/yamllint_compat_comments_indentation.rs +281 -0
  197. package/tests/yamllint_compat_config.rs +170 -0
  198. package/tests/yamllint_compat_document_end.rs +243 -0
  199. package/tests/yamllint_compat_document_start.rs +136 -0
  200. package/tests/yamllint_compat_empty_lines.rs +117 -0
  201. package/tests/yamllint_compat_empty_values.rs +179 -0
  202. package/tests/yamllint_compat_float_values.rs +216 -0
  203. package/tests/yamllint_compat_hyphens.rs +223 -0
  204. package/tests/yamllint_compat_indentation.rs +398 -0
  205. package/tests/yamllint_compat_key_duplicates.rs +139 -0
  206. package/tests/yamllint_compat_key_ordering.rs +170 -0
  207. package/tests/yamllint_compat_line_length.rs +375 -0
  208. package/tests/yamllint_compat_list.rs +127 -0
  209. package/tests/yamllint_compat_new_line.rs +133 -0
  210. package/tests/yamllint_compat_newline_types.rs +185 -0
  211. package/tests/yamllint_compat_octal_values.rs +172 -0
  212. package/tests/yamllint_compat_quoted_strings.rs +154 -0
  213. package/tests/yamllint_compat_syntax.rs +200 -0
  214. package/tests/yamllint_compat_trailing_spaces.rs +162 -0
  215. package/tests/yamllint_compat_truthy.rs +130 -0
  216. package/tests/yamllint_compat_yaml_files.rs +81 -0
  217. package/typos.toml +2 -0
@@ -0,0 +1,455 @@
1
+ use ryl::config::YamlLintConfig;
2
+ use ryl::rules::indentation::{
3
+ self, Config, IndentSequencesSetting, SpacesSetting, Violation,
4
+ };
5
+
6
+ fn config(
7
+ spaces: SpacesSetting,
8
+ indent_sequences: IndentSequencesSetting,
9
+ multi: bool,
10
+ ) -> Config {
11
+ Config::new_for_tests(spaces, indent_sequences, multi)
12
+ }
13
+
14
+ fn parse_config(yaml: &str) -> Config {
15
+ let cfg = YamlLintConfig::from_yaml_str(yaml).expect("config should parse");
16
+ Config::resolve(&cfg)
17
+ }
18
+
19
+ #[test]
20
+ fn detects_unindented_sequence_in_mapping() {
21
+ let cfg = config(SpacesSetting::Fixed(2), IndentSequencesSetting::True, false);
22
+ let yaml = "root:\n- item\n";
23
+ let hits = indentation::check(yaml, &cfg);
24
+ assert_eq!(
25
+ hits,
26
+ vec![Violation {
27
+ line: 2,
28
+ column: 1,
29
+ message: "wrong indentation: expected 2 but found 0".to_string(),
30
+ }]
31
+ );
32
+ }
33
+
34
+ #[test]
35
+ fn allows_unindented_sequence_when_disabled() {
36
+ let cfg = config(
37
+ SpacesSetting::Fixed(2),
38
+ IndentSequencesSetting::False,
39
+ false,
40
+ );
41
+ let yaml = "root:\n- item\n";
42
+ let hits = indentation::check(yaml, &cfg);
43
+ assert!(hits.is_empty());
44
+ }
45
+
46
+ #[test]
47
+ fn detects_indented_sequence_when_disabled() {
48
+ let cfg = config(
49
+ SpacesSetting::Fixed(2),
50
+ IndentSequencesSetting::False,
51
+ false,
52
+ );
53
+ let yaml = "root:\n - item\n";
54
+ let hits = indentation::check(yaml, &cfg);
55
+ assert_eq!(
56
+ hits,
57
+ vec![Violation {
58
+ line: 2,
59
+ column: 3,
60
+ message: "wrong indentation: expected 0 but found 2".to_string(),
61
+ }]
62
+ );
63
+ }
64
+
65
+ #[test]
66
+ fn detects_over_indented_sequence_when_required() {
67
+ let cfg = config(SpacesSetting::Fixed(2), IndentSequencesSetting::True, false);
68
+ let yaml = "root:\n - item\n";
69
+ let hits = indentation::check(yaml, &cfg);
70
+ assert_eq!(
71
+ hits,
72
+ vec![Violation {
73
+ line: 2,
74
+ column: 7,
75
+ message: "wrong indentation: expected 2 but found 6".to_string(),
76
+ }]
77
+ );
78
+ }
79
+
80
+ #[test]
81
+ fn enforces_consistent_spacing() {
82
+ let cfg = config(SpacesSetting::Fixed(2), IndentSequencesSetting::True, false);
83
+ let yaml = "root:\n child: value\n";
84
+ let hits = indentation::check(yaml, &cfg);
85
+ assert_eq!(
86
+ hits,
87
+ vec![Violation {
88
+ line: 2,
89
+ column: 4,
90
+ message: "wrong indentation: expected 2 but found 3".to_string(),
91
+ }]
92
+ );
93
+ }
94
+
95
+ #[test]
96
+ fn checks_multiline_strings_when_enabled() {
97
+ let cfg = config(SpacesSetting::Fixed(4), IndentSequencesSetting::True, true);
98
+ let yaml = "quote: |\n good\n bad\n";
99
+ let hits = indentation::check(yaml, &cfg);
100
+ assert_eq!(
101
+ hits,
102
+ vec![Violation {
103
+ line: 3,
104
+ column: 6,
105
+ message: "wrong indentation: expected 4 but found 5".to_string(),
106
+ }]
107
+ );
108
+ }
109
+
110
+ #[test]
111
+ fn multiline_strings_ignored_when_disabled() {
112
+ let cfg = config(SpacesSetting::Fixed(4), IndentSequencesSetting::True, false);
113
+ let yaml = "quote: |\n good\n bad\n";
114
+ let hits = indentation::check(yaml, &cfg);
115
+ assert!(hits.is_empty());
116
+ }
117
+
118
+ #[test]
119
+ fn folded_multiline_reports_violation() {
120
+ let cfg = config(SpacesSetting::Fixed(4), IndentSequencesSetting::True, true);
121
+ let yaml = "quote: >\n good\n bad\n";
122
+ let hits = indentation::check(yaml, &cfg);
123
+ assert_eq!(
124
+ hits,
125
+ vec![Violation {
126
+ line: 3,
127
+ column: 6,
128
+ message: "wrong indentation: expected 4 but found 5".to_string(),
129
+ }]
130
+ );
131
+ }
132
+
133
+ #[test]
134
+ fn consistent_spaces_detects_violation() {
135
+ let cfg = config(
136
+ SpacesSetting::Consistent,
137
+ IndentSequencesSetting::True,
138
+ false,
139
+ );
140
+ let yaml = "root:\n child:\n grand: 1\n bad: 2\n";
141
+ let hits = indentation::check(yaml, &cfg);
142
+ assert_eq!(
143
+ hits,
144
+ vec![Violation {
145
+ line: 4,
146
+ column: 4,
147
+ message: "wrong indentation: expected 4 but found 3".to_string(),
148
+ }]
149
+ );
150
+ }
151
+
152
+ #[test]
153
+ fn multiline_resets_context_after_block() {
154
+ let cfg = config(SpacesSetting::Fixed(2), IndentSequencesSetting::True, true);
155
+ let yaml = "quote: |\n text\nnext: value\n";
156
+ let hits = indentation::check(yaml, &cfg);
157
+ assert!(hits.is_empty());
158
+ }
159
+
160
+ #[test]
161
+ fn indent_sequences_consistent_detects_mixed_styles() {
162
+ let cfg = config(
163
+ SpacesSetting::Fixed(2),
164
+ IndentSequencesSetting::Consistent,
165
+ false,
166
+ );
167
+ let yaml = "root:\n- top\nanother:\n - inner\n";
168
+ let hits = indentation::check(yaml, &cfg);
169
+ assert_eq!(
170
+ hits,
171
+ vec![Violation {
172
+ line: 4,
173
+ column: 3,
174
+ message: "wrong indentation: expected 0 but found 2".to_string(),
175
+ }]
176
+ );
177
+ }
178
+
179
+ #[test]
180
+ fn indent_sequences_whatever_allows_both_styles() {
181
+ let cfg = config(
182
+ SpacesSetting::Fixed(2),
183
+ IndentSequencesSetting::Whatever,
184
+ false,
185
+ );
186
+ let yaml = "root:\n- top\nanother:\n - inner\n";
187
+ let hits = indentation::check(yaml, &cfg);
188
+ assert!(hits.is_empty());
189
+ }
190
+
191
+ #[test]
192
+ fn tab_indentation_is_counted() {
193
+ let cfg = config(SpacesSetting::Fixed(2), IndentSequencesSetting::True, false);
194
+ let yaml = "root:\n\tchild: value\n";
195
+ let hits = indentation::check(yaml, &cfg);
196
+ assert_eq!(
197
+ hits,
198
+ vec![Violation {
199
+ line: 2,
200
+ column: 2,
201
+ message: "wrong indentation: expected 2 but found 1".to_string(),
202
+ }]
203
+ );
204
+ }
205
+
206
+ #[test]
207
+ fn resolve_indent_sequences_from_string_values() {
208
+ let cfg_whatever =
209
+ parse_config("rules:\n indentation:\n indent-sequences: whatever\n");
210
+ let yaml = "root:\n- top\n - inner\n";
211
+ assert!(indentation::check(yaml, &cfg_whatever).is_empty());
212
+
213
+ let cfg_consistent =
214
+ parse_config("rules:\n indentation:\n indent-sequences: consistent\n");
215
+ let unindented = "root:\n- first\n- second\n";
216
+ assert!(indentation::check(unindented, &cfg_consistent).is_empty());
217
+
218
+ let mixed = "root:\n - first\n- second\n";
219
+ let hits = indentation::check(mixed, &cfg_consistent);
220
+ assert_eq!(hits.len(), 1, "expected single violation: {hits:?}");
221
+ assert_eq!(hits[0].line, 3);
222
+ assert!(hits[0].message.contains("wrong indentation"));
223
+ }
224
+
225
+ #[test]
226
+ fn indentation_config_rejects_non_string_option_keys() {
227
+ let err =
228
+ YamlLintConfig::from_yaml_str("rules:\n indentation:\n true: false\n")
229
+ .expect_err("expected validation failure");
230
+ assert!(
231
+ err.contains("unknown option \"true\" for rule \"indentation\""),
232
+ "unexpected error: {err}"
233
+ );
234
+ }
235
+
236
+ #[test]
237
+ fn skips_blank_lines_and_top_level_sequence_entries() {
238
+ let cfg = config(SpacesSetting::Fixed(2), IndentSequencesSetting::True, false);
239
+ let yaml = "- first\n\nsecond\n";
240
+ assert!(indentation::check(yaml, &cfg).is_empty());
241
+ }
242
+
243
+ #[test]
244
+ fn reports_misaligned_mapping_with_consistent_spacing() {
245
+ let cfg = config(
246
+ SpacesSetting::Consistent,
247
+ IndentSequencesSetting::True,
248
+ false,
249
+ );
250
+ let yaml =
251
+ "root:\n child:\n nested: 1\n bad_child: 2\n repeated: 3\n wrong: 4\n";
252
+ let hits = indentation::check(yaml, &cfg);
253
+ assert_eq!(hits.len(), 3, "unexpected diagnostics: {hits:?}");
254
+ assert!(
255
+ hits.iter()
256
+ .any(|hit| hit.line == 4 && hit.message.contains("expected 4 but found 3"))
257
+ );
258
+ assert!(
259
+ hits.iter()
260
+ .any(|hit| hit.line == 5 && hit.message.contains("expected 2 but found 3"))
261
+ );
262
+ assert!(
263
+ hits.iter()
264
+ .any(|hit| hit.line == 6 && hit.message.contains("expected 2 but found 1"))
265
+ );
266
+ }
267
+
268
+ #[test]
269
+ fn consistent_indent_sequences_observe_initial_style() {
270
+ let cfg = config(
271
+ SpacesSetting::Fixed(2),
272
+ IndentSequencesSetting::Consistent,
273
+ false,
274
+ );
275
+ let yaml = "root:\n - first\n - second\n";
276
+ assert!(indentation::check(yaml, &cfg).is_empty());
277
+ }
278
+
279
+ #[test]
280
+ fn consistent_indent_sequences_detect_style_switch() {
281
+ let cfg = config(
282
+ SpacesSetting::Fixed(2),
283
+ IndentSequencesSetting::Consistent,
284
+ false,
285
+ );
286
+ let yaml = "root:\n - first\n- second\n";
287
+ let hits = indentation::check(yaml, &cfg);
288
+ assert_eq!(hits.len(), 1, "expected single violation: {hits:?}");
289
+ assert_eq!(hits[0].line, 3);
290
+ assert!(hits[0].message.contains("expected 2 but found 0"));
291
+ }
292
+
293
+ #[test]
294
+ fn multiline_blocks_reuse_consistent_spacing() {
295
+ let cfg = config(
296
+ SpacesSetting::Consistent,
297
+ IndentSequencesSetting::True,
298
+ true,
299
+ );
300
+ let yaml = "|\n ok\nsecond: |\n ok\n bad\n";
301
+ let hits = indentation::check(yaml, &cfg);
302
+ assert_eq!(hits.len(), 1, "expected single violation: {hits:?}");
303
+ assert_eq!(hits[0].line, 5);
304
+ assert!(hits[0].message.contains("expected 2 but found 1"));
305
+ }
306
+
307
+ #[test]
308
+ fn inline_structures_and_comments_preserve_mapping_detection() {
309
+ let cfg = config(SpacesSetting::Fixed(2), IndentSequencesSetting::True, false);
310
+ let yaml = "root:\n inline: { nested: [1, 2] } # trailing comment\n escaped: \"quote \\\" inside\" # trailing\n single: 'hash # inside' # trailing\n";
311
+ assert!(indentation::check(yaml, &cfg).is_empty());
312
+ }
313
+
314
+ #[test]
315
+ fn compact_flow_mapping_sequence_resets_after_dedent() {
316
+ let cfg = config(
317
+ SpacesSetting::Consistent,
318
+ IndentSequencesSetting::True,
319
+ false,
320
+ );
321
+ let yaml = "root:\n - {a: 1,\n b: 2}\nnext: value\n";
322
+ assert!(indentation::check(yaml, &cfg).is_empty());
323
+ }
324
+
325
+ #[test]
326
+ fn fixed_spacing_reports_repeated_misalignments() {
327
+ let cfg = config(SpacesSetting::Fixed(2), IndentSequencesSetting::True, false);
328
+ let yaml = "root:\n child_one: value\n child_two: value\n";
329
+ let hits = indentation::check(yaml, &cfg);
330
+ assert!(
331
+ hits.iter()
332
+ .any(|hit| hit.line == 2 && hit.message.contains("expected 2 but found 1"))
333
+ );
334
+ assert!(
335
+ hits.iter()
336
+ .any(|hit| hit.line == 3 && hit.message.contains("expected 0 but found 1"))
337
+ );
338
+ }
339
+
340
+ #[test]
341
+ fn plain_scalar_contexts_are_tracked() {
342
+ let cfg = config(SpacesSetting::Fixed(2), IndentSequencesSetting::True, false);
343
+ let yaml = "root:\n nested:\n value\n";
344
+ assert!(indentation::check(yaml, &cfg).is_empty());
345
+ }
346
+
347
+ #[test]
348
+ fn top_level_indented_plain_scalar_is_permitted() {
349
+ let cfg = config(SpacesSetting::Fixed(2), IndentSequencesSetting::True, false);
350
+ let yaml = " value\n deeper\n";
351
+ assert!(indentation::check(yaml, &cfg).is_empty());
352
+ }
353
+
354
+ #[test]
355
+ fn sequence_of_mappings_reports_incorrect_dedent() {
356
+ let cfg = config(SpacesSetting::Fixed(2), IndentSequencesSetting::True, false);
357
+ let yaml = "- key:\n - nested\n- other\n";
358
+ let hits = indentation::check(yaml, &cfg);
359
+ assert_eq!(hits.len(), 1, "unexpected diagnostics: {hits:?}");
360
+ assert!(hits[0].message.contains("expected 2 but found 0"));
361
+ }
362
+
363
+ #[test]
364
+ fn complex_mapping_keys_are_classified_correctly() {
365
+ let cfg = config(SpacesSetting::Fixed(2), IndentSequencesSetting::True, false);
366
+ let yaml = "root:\n key\\with: value\n 'single_quote': value\n \"double_quote\": value\n {braced}: value\n [bracketed]: value\n";
367
+ assert!(indentation::check(yaml, &cfg).is_empty());
368
+ }
369
+
370
+ #[test]
371
+ fn sequence_plain_scalar_creates_other_context() {
372
+ let cfg = config(SpacesSetting::Fixed(2), IndentSequencesSetting::True, false);
373
+ let yaml = "root:\n - item\n plain\n";
374
+ assert!(indentation::check(yaml, &cfg).is_empty());
375
+ }
376
+
377
+ #[test]
378
+ fn colon_without_key_is_not_considered_mapping() {
379
+ let cfg = config(SpacesSetting::Fixed(2), IndentSequencesSetting::True, false);
380
+ let yaml = ": value\n";
381
+ assert!(indentation::check(yaml, &cfg).is_empty());
382
+ }
383
+
384
+ #[test]
385
+ fn consistent_spacing_records_initial_delta() {
386
+ let cfg = config(
387
+ SpacesSetting::Consistent,
388
+ IndentSequencesSetting::True,
389
+ false,
390
+ );
391
+ let yaml = "root:\n child:\n grand: 1\n";
392
+ assert!(indentation::check(yaml, &cfg).is_empty());
393
+ }
394
+
395
+ #[test]
396
+ fn sequence_indented_under_mapping_finds_parent() {
397
+ let cfg = config(SpacesSetting::Fixed(2), IndentSequencesSetting::True, false);
398
+ let yaml = "root:\n - valid\n child: value\n";
399
+ assert!(indentation::check(yaml, &cfg).is_empty());
400
+ }
401
+
402
+ #[test]
403
+ fn consistent_sequence_spacing_obeys_fixed_step() {
404
+ let cfg = config(
405
+ SpacesSetting::Fixed(2),
406
+ IndentSequencesSetting::Consistent,
407
+ false,
408
+ );
409
+ let yaml = "root:\n - item\n";
410
+ let hits = indentation::check(yaml, &cfg);
411
+ assert_eq!(
412
+ hits,
413
+ vec![Violation {
414
+ line: 2,
415
+ column: 7,
416
+ message: "wrong indentation: expected 2 but found 6".to_string(),
417
+ }]
418
+ );
419
+ }
420
+
421
+ #[test]
422
+ fn dash_prefixed_scalar_not_sequence_entry() {
423
+ let cfg = config(SpacesSetting::Fixed(2), IndentSequencesSetting::True, false);
424
+ let yaml = "-foo: bar\n";
425
+ assert!(indentation::check(yaml, &cfg).is_empty());
426
+ }
427
+
428
+ #[test]
429
+ fn nested_mapping_sequence_resolves_parent_indent() {
430
+ let cfg = config(SpacesSetting::Fixed(2), IndentSequencesSetting::True, false);
431
+ let yaml = "root:\n child:\n - item\n";
432
+ assert!(indentation::check(yaml, &cfg).is_empty());
433
+ }
434
+
435
+ #[test]
436
+ fn detects_unindented_mapping_sequence_in_mapping() {
437
+ let cfg = config(SpacesSetting::Fixed(2), IndentSequencesSetting::True, false);
438
+ let yaml = "metadata:\n name: test\nsubjects:\n- apiGroup: rbac.authorization.k8s.io\n kind: User\n name: kubelet\n";
439
+ let hits = indentation::check(yaml, &cfg);
440
+ assert_eq!(
441
+ hits,
442
+ vec![Violation {
443
+ line: 4,
444
+ column: 1,
445
+ message: "wrong indentation: expected 2 but found 0".to_string(),
446
+ }]
447
+ );
448
+ }
449
+
450
+ #[test]
451
+ fn allows_indented_mapping_sequence_in_mapping() {
452
+ let cfg = config(SpacesSetting::Fixed(2), IndentSequencesSetting::True, false);
453
+ let yaml = "subjects:\n - apiGroup: rbac.authorization.k8s.io\n kind: User\n";
454
+ assert!(indentation::check(yaml, &cfg).is_empty());
455
+ }
@@ -0,0 +1,76 @@
1
+ use ryl::config::YamlLintConfig;
2
+ use ryl::rules::key_duplicates::{self, Config};
3
+
4
+ fn build_config(yaml: &str) -> Config {
5
+ let cfg = YamlLintConfig::from_yaml_str(yaml).expect("config parses");
6
+ Config::resolve(&cfg)
7
+ }
8
+
9
+ #[test]
10
+ fn reports_duplicate_scalar_keys() {
11
+ let cfg = build_config("rules:\n key-duplicates: enable\n");
12
+ let input = "first: 1\nsecond: 2\nfirst: 3\n";
13
+ let hits = key_duplicates::check(input, &cfg);
14
+ assert_eq!(hits.len(), 1, "expected single violation: {hits:?}");
15
+ let hit = &hits[0];
16
+ assert_eq!(hit.line, 3);
17
+ assert_eq!(hit.column, 1);
18
+ assert_eq!(hit.message, "duplication of key \"first\" in mapping");
19
+ }
20
+
21
+ #[test]
22
+ fn reports_duplicate_flow_keys() {
23
+ let cfg = build_config("rules:\n key-duplicates: enable\n");
24
+ let input = "{a: 1, b: 2, b: 3}\n";
25
+ let hits = key_duplicates::check(input, &cfg);
26
+ assert_eq!(hits.len(), 1, "expected single violation: {hits:?}");
27
+ let hit = &hits[0];
28
+ assert_eq!(hit.line, 1);
29
+ assert_eq!(hit.column, 14);
30
+ assert_eq!(hit.message, "duplication of key \"b\" in mapping");
31
+ }
32
+
33
+ #[test]
34
+ fn default_allows_merge_key_duplicates() {
35
+ let cfg = build_config("rules:\n key-duplicates: enable\n");
36
+ let input = "anchor: &a\n value: 1\nmerged:\n <<: *a\n <<: *a\n";
37
+ let hits = key_duplicates::check(input, &cfg);
38
+ assert!(hits.is_empty(), "merge keys allowed by default: {hits:?}");
39
+ }
40
+
41
+ #[test]
42
+ fn forbidding_merge_key_duplicates_reports_violation() {
43
+ let cfg = build_config(
44
+ "rules:\n key-duplicates:\n forbid-duplicated-merge-keys: true\n",
45
+ );
46
+ let input = "anchor: &a\n value: 1\nmerged:\n <<: *a\n <<: *a\n";
47
+ let hits = key_duplicates::check(input, &cfg);
48
+ assert_eq!(hits.len(), 1, "expected violation: {hits:?}");
49
+ let hit = &hits[0];
50
+ assert_eq!(hit.line, 5);
51
+ assert_eq!(hit.column, 3);
52
+ assert_eq!(hit.message, "duplication of key \"<<\" in mapping");
53
+ }
54
+
55
+ #[test]
56
+ fn nested_mappings_are_checked() {
57
+ let cfg = build_config("rules:\n key-duplicates: enable\n");
58
+ let input = "---\n- inner: 1\n inner: 2\n";
59
+ let hits = key_duplicates::check(input, &cfg);
60
+ assert_eq!(hits.len(), 1, "expected nested violation: {hits:?}");
61
+ let hit = &hits[0];
62
+ assert_eq!(hit.line, 3);
63
+ assert_eq!(hit.column, 3);
64
+ assert_eq!(hit.message, "duplication of key \"inner\" in mapping");
65
+ }
66
+
67
+ #[test]
68
+ fn complex_keys_are_ignored_without_panicking() {
69
+ let cfg = build_config("rules:\n key-duplicates: enable\n");
70
+ let input = "---\n? [alpha, beta]\n: value\n";
71
+ let hits = key_duplicates::check(input, &cfg);
72
+ assert!(
73
+ hits.is_empty(),
74
+ "complex keys should not produce diagnostics: {hits:?}"
75
+ );
76
+ }