@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.
Files changed (216) hide show
  1. package/README.md +13 -0
  2. package/bin/ryl.js +195 -1
  3. package/package.json +35 -13
  4. package/.github/CODEOWNERS +0 -1
  5. package/.github/dependabot.yml +0 -13
  6. package/.github/workflows/ci.yml +0 -107
  7. package/.github/workflows/release.yml +0 -613
  8. package/.github/workflows/update_dependencies.yml +0 -61
  9. package/.github/workflows/update_linters.yml +0 -56
  10. package/.pre-commit-config.yaml +0 -87
  11. package/.yamllint +0 -4
  12. package/AGENTS.md +0 -200
  13. package/Cargo.lock +0 -908
  14. package/Cargo.toml +0 -32
  15. package/clippy.toml +0 -1
  16. package/docs/config-presets.md +0 -100
  17. package/img/benchmark-5x5-5runs.svg +0 -2176
  18. package/pyproject.toml +0 -42
  19. package/ruff.toml +0 -107
  20. package/rumdl.toml +0 -20
  21. package/rust-toolchain.toml +0 -3
  22. package/rustfmt.toml +0 -3
  23. package/scripts/benchmark_perf_vs_yamllint.py +0 -400
  24. package/scripts/coverage-missing.ps1 +0 -80
  25. package/scripts/coverage-missing.sh +0 -60
  26. package/src/bin/discover_config_bin.rs +0 -24
  27. package/src/cli_support.rs +0 -33
  28. package/src/conf/mod.rs +0 -85
  29. package/src/config.rs +0 -2099
  30. package/src/decoder.rs +0 -326
  31. package/src/discover.rs +0 -31
  32. package/src/lib.rs +0 -19
  33. package/src/lint.rs +0 -558
  34. package/src/main.rs +0 -535
  35. package/src/migrate.rs +0 -233
  36. package/src/rules/anchors.rs +0 -517
  37. package/src/rules/braces.rs +0 -77
  38. package/src/rules/brackets.rs +0 -77
  39. package/src/rules/colons.rs +0 -475
  40. package/src/rules/commas.rs +0 -372
  41. package/src/rules/comments.rs +0 -299
  42. package/src/rules/comments_indentation.rs +0 -243
  43. package/src/rules/document_end.rs +0 -175
  44. package/src/rules/document_start.rs +0 -84
  45. package/src/rules/empty_lines.rs +0 -152
  46. package/src/rules/empty_values.rs +0 -255
  47. package/src/rules/float_values.rs +0 -259
  48. package/src/rules/flow_collection.rs +0 -562
  49. package/src/rules/hyphens.rs +0 -104
  50. package/src/rules/indentation.rs +0 -803
  51. package/src/rules/key_duplicates.rs +0 -218
  52. package/src/rules/key_ordering.rs +0 -303
  53. package/src/rules/line_length.rs +0 -326
  54. package/src/rules/mod.rs +0 -25
  55. package/src/rules/new_line_at_end_of_file.rs +0 -23
  56. package/src/rules/new_lines.rs +0 -95
  57. package/src/rules/octal_values.rs +0 -121
  58. package/src/rules/quoted_strings.rs +0 -577
  59. package/src/rules/span_utils.rs +0 -37
  60. package/src/rules/trailing_spaces.rs +0 -65
  61. package/src/rules/truthy.rs +0 -420
  62. package/tests/brackets_carriage_return.rs +0 -114
  63. package/tests/build_global_cfg_error.rs +0 -23
  64. package/tests/cli_anchors_rule.rs +0 -143
  65. package/tests/cli_braces_rule.rs +0 -104
  66. package/tests/cli_brackets_rule.rs +0 -104
  67. package/tests/cli_colons_rule.rs +0 -65
  68. package/tests/cli_commas_rule.rs +0 -104
  69. package/tests/cli_comments_indentation_rule.rs +0 -61
  70. package/tests/cli_comments_rule.rs +0 -67
  71. package/tests/cli_config_data_error.rs +0 -30
  72. package/tests/cli_config_flags.rs +0 -66
  73. package/tests/cli_config_migrate.rs +0 -229
  74. package/tests/cli_document_end_rule.rs +0 -92
  75. package/tests/cli_document_start_rule.rs +0 -92
  76. package/tests/cli_empty_lines_rule.rs +0 -87
  77. package/tests/cli_empty_values_rule.rs +0 -68
  78. package/tests/cli_env_config.rs +0 -34
  79. package/tests/cli_exit_and_errors.rs +0 -41
  80. package/tests/cli_file_encoding.rs +0 -203
  81. package/tests/cli_float_values_rule.rs +0 -64
  82. package/tests/cli_format_options.rs +0 -316
  83. package/tests/cli_global_cfg_relaxed.rs +0 -20
  84. package/tests/cli_hyphens_rule.rs +0 -104
  85. package/tests/cli_indentation_rule.rs +0 -65
  86. package/tests/cli_invalid_project_config.rs +0 -39
  87. package/tests/cli_key_duplicates_rule.rs +0 -104
  88. package/tests/cli_key_ordering_rule.rs +0 -59
  89. package/tests/cli_line_length_rule.rs +0 -85
  90. package/tests/cli_list_files.rs +0 -29
  91. package/tests/cli_new_line_rule.rs +0 -141
  92. package/tests/cli_new_lines_rule.rs +0 -119
  93. package/tests/cli_octal_values_rule.rs +0 -60
  94. package/tests/cli_quoted_strings_rule.rs +0 -47
  95. package/tests/cli_toml_config.rs +0 -119
  96. package/tests/cli_trailing_spaces_rule.rs +0 -77
  97. package/tests/cli_truthy_rule.rs +0 -83
  98. package/tests/cli_yaml_files_negation.rs +0 -45
  99. package/tests/colons_rule.rs +0 -303
  100. package/tests/common/compat.rs +0 -114
  101. package/tests/common/fake_env.rs +0 -93
  102. package/tests/common/mod.rs +0 -1
  103. package/tests/conf_builtin.rs +0 -9
  104. package/tests/config_anchors.rs +0 -84
  105. package/tests/config_braces.rs +0 -121
  106. package/tests/config_brackets.rs +0 -127
  107. package/tests/config_commas.rs +0 -79
  108. package/tests/config_comments.rs +0 -65
  109. package/tests/config_comments_indentation.rs +0 -20
  110. package/tests/config_deep_merge_nonstring_key.rs +0 -24
  111. package/tests/config_document_end.rs +0 -54
  112. package/tests/config_document_start.rs +0 -55
  113. package/tests/config_empty_lines.rs +0 -48
  114. package/tests/config_empty_values.rs +0 -35
  115. package/tests/config_env_errors.rs +0 -23
  116. package/tests/config_env_invalid_inline.rs +0 -15
  117. package/tests/config_env_missing.rs +0 -63
  118. package/tests/config_env_shim.rs +0 -301
  119. package/tests/config_explicit_file_parse_error.rs +0 -55
  120. package/tests/config_extended_features.rs +0 -225
  121. package/tests/config_extends_inline.rs +0 -185
  122. package/tests/config_extends_sequence.rs +0 -18
  123. package/tests/config_find_project_home_boundary.rs +0 -54
  124. package/tests/config_find_project_two_files_in_cwd.rs +0 -47
  125. package/tests/config_float_values.rs +0 -34
  126. package/tests/config_from_yaml_paths.rs +0 -32
  127. package/tests/config_hyphens.rs +0 -51
  128. package/tests/config_ignore_errors.rs +0 -243
  129. package/tests/config_ignore_overrides.rs +0 -83
  130. package/tests/config_indentation.rs +0 -65
  131. package/tests/config_invalid_globs.rs +0 -16
  132. package/tests/config_invalid_types.rs +0 -19
  133. package/tests/config_key_duplicates.rs +0 -34
  134. package/tests/config_key_ordering.rs +0 -70
  135. package/tests/config_line_length.rs +0 -65
  136. package/tests/config_locale.rs +0 -111
  137. package/tests/config_merge.rs +0 -26
  138. package/tests/config_new_lines.rs +0 -89
  139. package/tests/config_octal_values.rs +0 -33
  140. package/tests/config_quoted_strings.rs +0 -195
  141. package/tests/config_rule_level.rs +0 -147
  142. package/tests/config_rules_non_string_keys.rs +0 -23
  143. package/tests/config_scalar_overrides.rs +0 -27
  144. package/tests/config_to_toml.rs +0 -110
  145. package/tests/config_toml_coverage.rs +0 -80
  146. package/tests/config_toml_discovery.rs +0 -304
  147. package/tests/config_trailing_spaces.rs +0 -152
  148. package/tests/config_truthy.rs +0 -77
  149. package/tests/config_yaml_files.rs +0 -62
  150. package/tests/config_yaml_files_all_non_string.rs +0 -15
  151. package/tests/config_yaml_files_empty.rs +0 -30
  152. package/tests/coverage_commas.rs +0 -46
  153. package/tests/decoder_decode.rs +0 -338
  154. package/tests/discover_config_bin_all.rs +0 -66
  155. package/tests/discover_config_bin_env_invalid_yaml.rs +0 -26
  156. package/tests/discover_config_bin_project_config_parse_error.rs +0 -24
  157. package/tests/discover_config_bin_user_global_error.rs +0 -26
  158. package/tests/discover_module.rs +0 -30
  159. package/tests/discover_per_file_dir.rs +0 -10
  160. package/tests/discover_per_file_project_config_error.rs +0 -21
  161. package/tests/float_values.rs +0 -43
  162. package/tests/lint_multi_errors.rs +0 -32
  163. package/tests/main_yaml_ok_filtering.rs +0 -30
  164. package/tests/migrate_module.rs +0 -259
  165. package/tests/resolve_ctx_empty_parent.rs +0 -16
  166. package/tests/rule_anchors.rs +0 -442
  167. package/tests/rule_braces.rs +0 -258
  168. package/tests/rule_brackets.rs +0 -217
  169. package/tests/rule_commas.rs +0 -205
  170. package/tests/rule_comments.rs +0 -197
  171. package/tests/rule_comments_indentation.rs +0 -127
  172. package/tests/rule_document_end.rs +0 -118
  173. package/tests/rule_document_start.rs +0 -60
  174. package/tests/rule_empty_lines.rs +0 -96
  175. package/tests/rule_empty_values.rs +0 -102
  176. package/tests/rule_float_values.rs +0 -109
  177. package/tests/rule_hyphens.rs +0 -65
  178. package/tests/rule_indentation.rs +0 -455
  179. package/tests/rule_key_duplicates.rs +0 -76
  180. package/tests/rule_key_ordering.rs +0 -207
  181. package/tests/rule_line_length.rs +0 -200
  182. package/tests/rule_new_lines.rs +0 -51
  183. package/tests/rule_octal_values.rs +0 -53
  184. package/tests/rule_quoted_strings.rs +0 -290
  185. package/tests/rule_trailing_spaces.rs +0 -41
  186. package/tests/rule_truthy.rs +0 -236
  187. package/tests/user_global_invalid_yaml.rs +0 -32
  188. package/tests/yamllint_compat_anchors.rs +0 -280
  189. package/tests/yamllint_compat_braces.rs +0 -411
  190. package/tests/yamllint_compat_brackets.rs +0 -364
  191. package/tests/yamllint_compat_colons.rs +0 -298
  192. package/tests/yamllint_compat_colors.rs +0 -80
  193. package/tests/yamllint_compat_commas.rs +0 -375
  194. package/tests/yamllint_compat_comments.rs +0 -167
  195. package/tests/yamllint_compat_comments_indentation.rs +0 -281
  196. package/tests/yamllint_compat_config.rs +0 -170
  197. package/tests/yamllint_compat_document_end.rs +0 -243
  198. package/tests/yamllint_compat_document_start.rs +0 -136
  199. package/tests/yamllint_compat_empty_lines.rs +0 -117
  200. package/tests/yamllint_compat_empty_values.rs +0 -179
  201. package/tests/yamllint_compat_float_values.rs +0 -216
  202. package/tests/yamllint_compat_hyphens.rs +0 -223
  203. package/tests/yamllint_compat_indentation.rs +0 -398
  204. package/tests/yamllint_compat_key_duplicates.rs +0 -139
  205. package/tests/yamllint_compat_key_ordering.rs +0 -170
  206. package/tests/yamllint_compat_line_length.rs +0 -375
  207. package/tests/yamllint_compat_list.rs +0 -127
  208. package/tests/yamllint_compat_new_line.rs +0 -133
  209. package/tests/yamllint_compat_newline_types.rs +0 -185
  210. package/tests/yamllint_compat_octal_values.rs +0 -172
  211. package/tests/yamllint_compat_quoted_strings.rs +0 -154
  212. package/tests/yamllint_compat_syntax.rs +0 -200
  213. package/tests/yamllint_compat_trailing_spaces.rs +0 -162
  214. package/tests/yamllint_compat_truthy.rs +0 -130
  215. package/tests/yamllint_compat_yaml_files.rs +0 -81
  216. package/typos.toml +0 -2
@@ -1,281 +0,0 @@
1
- use std::fs;
2
-
3
- use tempfile::tempdir;
4
-
5
- #[path = "common/compat.rs"]
6
- mod compat;
7
-
8
- use compat::{
9
- SCENARIOS, build_ryl_command, build_yamllint_command, capture_with_env,
10
- ensure_yamllint_installed,
11
- };
12
-
13
- #[test]
14
- fn comments_indentation_rule_matches_yamllint() {
15
- ensure_yamllint_installed();
16
-
17
- let dir = tempdir().unwrap();
18
-
19
- let enable_cfg = dir.path().join("comments-enable.yml");
20
- fs::write(
21
- &enable_cfg,
22
- "rules:\n document-start: disable\n comments-indentation: enable\n",
23
- )
24
- .unwrap();
25
-
26
- let warning_cfg = dir.path().join("comments-warning.yml");
27
- fs::write(
28
- &warning_cfg,
29
- "rules:\n document-start: disable\n comments-indentation:\n level: warning\n",
30
- )
31
- .unwrap();
32
-
33
- let ignore_cfg = dir.path().join("comments-ignore.yml");
34
- fs::write(
35
- &ignore_cfg,
36
- "rules:\n document-start: disable\n comments-indentation:\n ignore:\n - ignored.yaml\n",
37
- )
38
- .unwrap();
39
-
40
- let ignore_list = dir.path().join("comments-ignore.txt");
41
- fs::write(&ignore_list, "ignored-from-file.yaml\n").unwrap();
42
-
43
- let ignore_from_file_cfg = dir.path().join("comments-ignore-from-file.yml");
44
- let ignore_path = ignore_list.display().to_string().replace('\'', "''");
45
- fs::write(
46
- &ignore_from_file_cfg,
47
- format!(
48
- "rules:\n document-start: disable\n comments-indentation:\n ignore-from-file: '{}'\n",
49
- ignore_path
50
- ),
51
- )
52
- .unwrap();
53
-
54
- let bad_file = dir.path().join("bad.yaml");
55
- fs::write(&bad_file, "obj:\n # wrong\n value: 1\n").unwrap();
56
-
57
- let ignored_file = dir.path().join("ignored.yaml");
58
- fs::write(&ignored_file, "obj:\n # wrong\n value: 1\n").unwrap();
59
-
60
- let ignored_from_file = dir.path().join("ignored-from-file.yaml");
61
- fs::write(&ignored_from_file, "obj:\n # wrong\n value: 1\n").unwrap();
62
-
63
- let exe = env!("CARGO_BIN_EXE_ryl");
64
-
65
- for scenario in SCENARIOS {
66
- let mut ryl_enable = build_ryl_command(exe, scenario.ryl_format);
67
- ryl_enable.arg("-c").arg(&enable_cfg).arg(&bad_file);
68
- let (ryl_code, ryl_output) = capture_with_env(ryl_enable, scenario.envs);
69
-
70
- let mut yam_enable = build_yamllint_command(scenario.yam_format);
71
- yam_enable.arg("-c").arg(&enable_cfg).arg(&bad_file);
72
- let (yam_code, yam_output) = capture_with_env(yam_enable, scenario.envs);
73
-
74
- assert_eq!(ryl_code, 1, "ryl enable exit ({})", scenario.label);
75
- assert_eq!(yam_code, 1, "yamllint enable exit ({})", scenario.label);
76
- assert_eq!(
77
- ryl_output, yam_output,
78
- "enable diagnostics mismatch ({})",
79
- scenario.label
80
- );
81
-
82
- let mut ryl_warning = build_ryl_command(exe, scenario.ryl_format);
83
- ryl_warning.arg("-c").arg(&warning_cfg).arg(&bad_file);
84
- let (ryl_warn_code, ryl_warn_output) =
85
- capture_with_env(ryl_warning, scenario.envs);
86
-
87
- let mut yam_warning = build_yamllint_command(scenario.yam_format);
88
- yam_warning.arg("-c").arg(&warning_cfg).arg(&bad_file);
89
- let (yam_warn_code, yam_warn_output) =
90
- capture_with_env(yam_warning, scenario.envs);
91
-
92
- assert_eq!(ryl_warn_code, 0, "ryl warning exit ({})", scenario.label);
93
- assert_eq!(
94
- yam_warn_code, 0,
95
- "yamllint warning exit ({})",
96
- scenario.label
97
- );
98
- assert_eq!(
99
- ryl_warn_output, yam_warn_output,
100
- "warning diagnostics mismatch ({})",
101
- scenario.label
102
- );
103
-
104
- let mut ryl_ignore = build_ryl_command(exe, scenario.ryl_format);
105
- ryl_ignore.arg("-c").arg(&ignore_cfg).arg(&ignored_file);
106
- let (ryl_ignore_code, ryl_ignore_output) =
107
- capture_with_env(ryl_ignore, scenario.envs);
108
-
109
- let mut yam_ignore = build_yamllint_command(scenario.yam_format);
110
- yam_ignore.arg("-c").arg(&ignore_cfg).arg(&ignored_file);
111
- let (yam_ignore_code, yam_ignore_output) =
112
- capture_with_env(yam_ignore, scenario.envs);
113
-
114
- assert_eq!(ryl_ignore_code, 0, "ryl ignore exit ({})", scenario.label);
115
- assert_eq!(
116
- yam_ignore_code, 0,
117
- "yamllint ignore exit ({})",
118
- scenario.label
119
- );
120
- assert_eq!(
121
- ryl_ignore_output, yam_ignore_output,
122
- "ignore diagnostics mismatch ({})",
123
- scenario.label
124
- );
125
-
126
- let mut ryl_ignore_file = build_ryl_command(exe, scenario.ryl_format);
127
- ryl_ignore_file
128
- .arg("-c")
129
- .arg(&ignore_from_file_cfg)
130
- .arg(&ignored_from_file);
131
- let (ryl_file_code, ryl_file_output) =
132
- capture_with_env(ryl_ignore_file, scenario.envs);
133
-
134
- let mut yam_ignore_file = build_yamllint_command(scenario.yam_format);
135
- yam_ignore_file
136
- .arg("-c")
137
- .arg(&ignore_from_file_cfg)
138
- .arg(&ignored_from_file);
139
- let (yam_file_code, yam_file_output) =
140
- capture_with_env(yam_ignore_file, scenario.envs);
141
-
142
- assert_eq!(
143
- ryl_file_code, 0,
144
- "ryl ignore-from-file exit ({})",
145
- scenario.label
146
- );
147
- assert_eq!(
148
- yam_file_code, 0,
149
- "yamllint ignore-from-file exit ({})",
150
- scenario.label
151
- );
152
- assert_eq!(
153
- ryl_file_output, yam_file_output,
154
- "ignore-from-file diagnostics mismatch ({})",
155
- scenario.label
156
- );
157
- }
158
- }
159
-
160
- #[test]
161
- fn comments_around_line_length_toggle_match_yamllint() {
162
- ensure_yamllint_installed();
163
-
164
- let dir = tempdir().unwrap();
165
- let cfg = dir.path().join("cfg.yml");
166
- fs::write(
167
- &cfg,
168
- "extends: default\nrules:\n line-length:\n max: 110\n",
169
- )
170
- .unwrap();
171
-
172
- let input = dir.path().join("input.yml");
173
- fs::write(
174
- &input,
175
- "body:\n - type: markdown\n attributes:\n # yamllint disable rule:line-length\n value: |\n hello\n # yamllint enable rule:line-length\n",
176
- )
177
- .unwrap();
178
-
179
- let exe = env!("CARGO_BIN_EXE_ryl");
180
-
181
- for scenario in SCENARIOS {
182
- let mut ryl_cmd = build_ryl_command(exe, scenario.ryl_format);
183
- ryl_cmd.arg("-c").arg(&cfg).arg(&input);
184
- let (ryl_code, ryl_msg) = capture_with_env(ryl_cmd, scenario.envs);
185
-
186
- let mut yam_cmd = build_yamllint_command(scenario.yam_format);
187
- yam_cmd.arg("-c").arg(&cfg).arg(&input);
188
- let (yam_code, yam_msg) = capture_with_env(yam_cmd, scenario.envs);
189
-
190
- assert_eq!(
191
- ryl_code, yam_code,
192
- "exit mismatch for comments around line-length toggle ({})",
193
- scenario.label
194
- );
195
- assert_eq!(
196
- ryl_msg, yam_msg,
197
- "diagnostics mismatch for comments around line-length toggle ({})",
198
- scenario.label
199
- );
200
- }
201
- }
202
-
203
- #[test]
204
- fn comment_after_block_scalar_pattern_matches_yamllint() {
205
- ensure_yamllint_installed();
206
-
207
- let dir = tempdir().unwrap();
208
- let cfg = dir.path().join("cfg.yml");
209
- fs::write(
210
- &cfg,
211
- "extends: default\nrules:\n line-length:\n max: 110\n",
212
- )
213
- .unwrap();
214
-
215
- let input = dir.path().join("input.yml");
216
- fs::write(
217
- &input,
218
- "---\nhooks:\n - id: x\n files: >\n (?x)\n ^a$|\n ^b$\n ## ONLY ADD PREK HOOKS HERE THAT REQUIRE CI IMAGE\n - id: y\n",
219
- )
220
- .unwrap();
221
-
222
- let exe = env!("CARGO_BIN_EXE_ryl");
223
- for scenario in SCENARIOS {
224
- let mut ryl_cmd = build_ryl_command(exe, scenario.ryl_format);
225
- ryl_cmd.arg("-c").arg(&cfg).arg("--strict").arg(&input);
226
- let (ryl_code, ryl_msg) = capture_with_env(ryl_cmd, scenario.envs);
227
-
228
- let mut yam_cmd = build_yamllint_command(scenario.yam_format);
229
- yam_cmd.arg("-c").arg(&cfg).arg("--strict").arg(&input);
230
- let (yam_code, yam_msg) = capture_with_env(yam_cmd, scenario.envs);
231
-
232
- assert_eq!(
233
- ryl_code, yam_code,
234
- "exit mismatch for comment after block scalar pattern ({})",
235
- scenario.label
236
- );
237
- assert_eq!(
238
- ryl_msg, yam_msg,
239
- "diagnostics mismatch for comment after block scalar pattern ({})",
240
- scenario.label
241
- );
242
- }
243
- }
244
-
245
- #[test]
246
- fn explicit_key_block_scalar_comment_content_matches_yamllint() {
247
- ensure_yamllint_installed();
248
-
249
- let dir = tempdir().unwrap();
250
- let cfg = dir.path().join("cfg.yml");
251
- fs::write(
252
- &cfg,
253
- "rules:\n document-start: disable\n comments-indentation: enable\n",
254
- )
255
- .unwrap();
256
-
257
- let input = dir.path().join("input.yml");
258
- fs::write(&input, "? |\n # block scalar content\n: value\n").unwrap();
259
-
260
- let exe = env!("CARGO_BIN_EXE_ryl");
261
- for scenario in SCENARIOS {
262
- let mut ryl_cmd = build_ryl_command(exe, scenario.ryl_format);
263
- ryl_cmd.arg("-c").arg(&cfg).arg(&input);
264
- let (ryl_code, ryl_msg) = capture_with_env(ryl_cmd, scenario.envs);
265
-
266
- let mut yam_cmd = build_yamllint_command(scenario.yam_format);
267
- yam_cmd.arg("-c").arg(&cfg).arg(&input);
268
- let (yam_code, yam_msg) = capture_with_env(yam_cmd, scenario.envs);
269
-
270
- assert_eq!(
271
- ryl_code, yam_code,
272
- "exit mismatch for explicit-key block scalar comment content ({})",
273
- scenario.label
274
- );
275
- assert_eq!(
276
- ryl_msg, yam_msg,
277
- "diagnostics mismatch for explicit-key block scalar comment content ({})",
278
- scenario.label
279
- );
280
- }
281
- }
@@ -1,170 +0,0 @@
1
- use std::fs;
2
- use std::process::Command;
3
-
4
- use tempfile::tempdir;
5
-
6
- fn ensure_yamllint_installed() {
7
- let ok = Command::new("yamllint")
8
- .arg("--version")
9
- .output()
10
- .map(|o| o.status.success())
11
- .unwrap_or(false);
12
- assert!(
13
- ok,
14
- "yamllint must be installed and in PATH for parity tests"
15
- );
16
- }
17
-
18
- fn run(cmd: &mut Command) -> (i32, String, String) {
19
- let out = cmd.output().expect("failed to run command");
20
- let code = out.status.code().unwrap_or(-1);
21
- let stdout = String::from_utf8_lossy(&out.stdout).into_owned();
22
- let stderr = String::from_utf8_lossy(&out.stderr).into_owned();
23
- (code, stdout, stderr)
24
- }
25
-
26
- #[test]
27
- fn yamllint_and_ryl_honor_ignore_from_file() {
28
- ensure_yamllint_installed();
29
-
30
- let td = tempdir().unwrap();
31
- let root = td.path();
32
- fs::write(
33
- root.join(".yamllint"),
34
- "ignore-from-file: patterns.ignore\nrules: {}\n",
35
- )
36
- .unwrap();
37
- fs::write(root.join("patterns.ignore"), "*.skip.yaml\n").unwrap();
38
- fs::write(root.join("keep.yaml"), "ok: 1\n").unwrap();
39
- fs::write(root.join("skip.yaml"), "bad: [1\n").unwrap();
40
-
41
- let ryl = env!("CARGO_BIN_EXE_ryl");
42
- let (_code, ryl_out, ryl_err) = run(Command::new(ryl)
43
- .current_dir(root)
44
- .arg("--list-files")
45
- .arg("."));
46
- assert!(ryl_err.is_empty(), "unexpected stderr from ryl: {ryl_err}");
47
- let mut ryl_list: Vec<_> = ryl_out.lines().map(|s| s.to_string()).collect();
48
- ryl_list.sort();
49
-
50
- let (_yc, y_out, y_err) = run(Command::new("yamllint")
51
- .current_dir(root)
52
- .arg("--list-files")
53
- .arg("."));
54
- assert!(y_err.is_empty(), "unexpected stderr from yamllint: {y_err}");
55
- let mut y_list: Vec<_> = y_out.lines().map(|s| s.to_string()).collect();
56
- y_list.sort();
57
-
58
- assert_eq!(ryl_list, y_list, "file lists should match");
59
- }
60
-
61
- #[test]
62
- fn project_config_precedence_over_env_matches_yamllint() {
63
- ensure_yamllint_installed();
64
-
65
- let td = tempdir().unwrap();
66
- let root = td.path();
67
- fs::write(
68
- root.join(".yamllint"),
69
- "ignore: ['ignored.yaml']\nrules: {}\n",
70
- )
71
- .unwrap();
72
- let env_cfg = root.join("env.yaml");
73
- fs::write(&env_cfg, "rules: {}\n").unwrap();
74
- fs::write(root.join("ignored.yaml"), "ok: 1\n").unwrap();
75
- fs::write(root.join("keep.yaml"), "ok: 1\n").unwrap();
76
-
77
- let ryl = env!("CARGO_BIN_EXE_ryl");
78
- let (_code, ryl_out, ryl_err) = run(Command::new(ryl)
79
- .current_dir(root)
80
- .env("YAMLLINT_CONFIG_FILE", env_cfg.display().to_string())
81
- .arg("--list-files")
82
- .arg("."));
83
- assert!(ryl_err.is_empty(), "unexpected stderr from ryl: {ryl_err}");
84
- let mut ryl_list: Vec<_> = ryl_out.lines().map(|s| s.to_string()).collect();
85
- ryl_list.sort();
86
-
87
- let (_yc, y_out, y_err) = run(Command::new("yamllint")
88
- .current_dir(root)
89
- .env("YAMLLINT_CONFIG_FILE", env_cfg.display().to_string())
90
- .arg("--list-files")
91
- .arg("."));
92
- assert!(y_err.is_empty(), "unexpected stderr from yamllint: {y_err}");
93
- let mut y_list: Vec<_> = y_out.lines().map(|s| s.to_string()).collect();
94
- y_list.sort();
95
-
96
- assert_eq!(ryl_list, y_list, "project config should take precedence");
97
- }
98
-
99
- #[test]
100
- fn ignore_can_reinclude_file_from_excluded_directory_matches_yamllint() {
101
- ensure_yamllint_installed();
102
-
103
- let td = tempdir().unwrap();
104
- let root = td.path();
105
- fs::write(
106
- root.join(".yamllint"),
107
- "ignore: |\n build/\n !build/keep.yaml\nrules: {}\n",
108
- )
109
- .unwrap();
110
- fs::create_dir_all(root.join("build")).unwrap();
111
- fs::write(root.join("build/keep.yaml"), "ok: 1\n").unwrap();
112
- fs::write(root.join("build/drop.yaml"), "ok: 1\n").unwrap();
113
- fs::write(root.join("top.yaml"), "ok: 1\n").unwrap();
114
-
115
- let ryl = env!("CARGO_BIN_EXE_ryl");
116
- let (_code, ryl_out, ryl_err) = run(Command::new(ryl)
117
- .current_dir(root)
118
- .arg("--list-files")
119
- .arg("."));
120
- assert!(ryl_err.is_empty(), "unexpected stderr from ryl: {ryl_err}");
121
- let mut ryl_list: Vec<_> = ryl_out.lines().map(|s| s.to_string()).collect();
122
- ryl_list.sort();
123
-
124
- let (_yc, y_out, y_err) = run(Command::new("yamllint")
125
- .current_dir(root)
126
- .arg("--list-files")
127
- .arg("."));
128
- assert!(y_err.is_empty(), "unexpected stderr from yamllint: {y_err}");
129
- let mut y_list: Vec<_> = y_out.lines().map(|s| s.to_string()).collect();
130
- y_list.sort();
131
-
132
- assert_eq!(ryl_list, y_list, "file lists should match");
133
- }
134
-
135
- #[test]
136
- fn ignore_from_file_can_reinclude_file_from_excluded_directory_matches_yamllint() {
137
- ensure_yamllint_installed();
138
-
139
- let td = tempdir().unwrap();
140
- let root = td.path();
141
- fs::write(
142
- root.join(".yamllint"),
143
- "ignore-from-file: patterns.ignore\nrules: {}\n",
144
- )
145
- .unwrap();
146
- fs::write(root.join("patterns.ignore"), "build/\n!build/keep.yaml\n").unwrap();
147
- fs::create_dir_all(root.join("build")).unwrap();
148
- fs::write(root.join("build/keep.yaml"), "ok: 1\n").unwrap();
149
- fs::write(root.join("build/drop.yaml"), "ok: 1\n").unwrap();
150
- fs::write(root.join("top.yaml"), "ok: 1\n").unwrap();
151
-
152
- let ryl = env!("CARGO_BIN_EXE_ryl");
153
- let (_code, ryl_out, ryl_err) = run(Command::new(ryl)
154
- .current_dir(root)
155
- .arg("--list-files")
156
- .arg("."));
157
- assert!(ryl_err.is_empty(), "unexpected stderr from ryl: {ryl_err}");
158
- let mut ryl_list: Vec<_> = ryl_out.lines().map(|s| s.to_string()).collect();
159
- ryl_list.sort();
160
-
161
- let (_yc, y_out, y_err) = run(Command::new("yamllint")
162
- .current_dir(root)
163
- .arg("--list-files")
164
- .arg("."));
165
- assert!(y_err.is_empty(), "unexpected stderr from yamllint: {y_err}");
166
- let mut y_list: Vec<_> = y_out.lines().map(|s| s.to_string()).collect();
167
- y_list.sort();
168
-
169
- assert_eq!(ryl_list, y_list, "file lists should match");
170
- }
@@ -1,243 +0,0 @@
1
- use std::fs;
2
-
3
- use tempfile::tempdir;
4
-
5
- #[path = "common/compat.rs"]
6
- mod compat;
7
-
8
- use compat::{
9
- SCENARIOS, build_ryl_command, build_yamllint_command, capture_with_env,
10
- ensure_yamllint_installed,
11
- };
12
-
13
- #[test]
14
- fn document_end_rule_matches_yamllint() {
15
- ensure_yamllint_installed();
16
-
17
- let dir = tempdir().unwrap();
18
-
19
- let missing = dir.path().join("missing.yaml");
20
- fs::write(&missing, "---\nfoo: bar\n").unwrap();
21
-
22
- let explicit = dir.path().join("explicit.yaml");
23
- fs::write(&explicit, "---\nfoo: bar\n...\n").unwrap();
24
-
25
- let explicit_with_comment = dir.path().join("explicit_with_comment.yaml");
26
- fs::write(&explicit_with_comment, "---\nfoo: bar\n... # done\n").unwrap();
27
-
28
- let require_cfg = dir.path().join("require.yml");
29
- fs::write(
30
- &require_cfg,
31
- "rules:\n document-end:\n level: error\n present: true\n",
32
- )
33
- .unwrap();
34
-
35
- let forbid_cfg = dir.path().join("forbid.yml");
36
- fs::write(
37
- &forbid_cfg,
38
- "rules:\n document-end:\n level: error\n present: false\n",
39
- )
40
- .unwrap();
41
-
42
- let exe = env!("CARGO_BIN_EXE_ryl");
43
-
44
- for scenario in SCENARIOS {
45
- let mut ryl_require = build_ryl_command(exe, scenario.ryl_format);
46
- ryl_require.arg("-c").arg(&require_cfg).arg(&missing);
47
- let (ryl_req_code, ryl_req_msg) = capture_with_env(ryl_require, scenario.envs);
48
-
49
- let mut yam_require = build_yamllint_command(scenario.yam_format);
50
- yam_require.arg("-c").arg(&require_cfg).arg(&missing);
51
- let (yam_req_code, yam_req_msg) = capture_with_env(yam_require, scenario.envs);
52
-
53
- assert_eq!(ryl_req_code, 1, "ryl require exit ({})", scenario.label);
54
- assert_eq!(
55
- yam_req_code, 1,
56
- "yamllint require exit ({})",
57
- scenario.label
58
- );
59
- assert_eq!(
60
- ryl_req_msg, yam_req_msg,
61
- "missing marker diagnostics mismatch ({})",
62
- scenario.label
63
- );
64
-
65
- let mut ryl_require_ok = build_ryl_command(exe, scenario.ryl_format);
66
- ryl_require_ok.arg("-c").arg(&require_cfg).arg(&explicit);
67
- let (ryl_req_ok_code, ryl_req_ok_msg) =
68
- capture_with_env(ryl_require_ok, scenario.envs);
69
-
70
- let mut yam_require_ok = build_yamllint_command(scenario.yam_format);
71
- yam_require_ok.arg("-c").arg(&require_cfg).arg(&explicit);
72
- let (yam_req_ok_code, yam_req_ok_msg) =
73
- capture_with_env(yam_require_ok, scenario.envs);
74
-
75
- assert_eq!(
76
- ryl_req_ok_code, 0,
77
- "ryl require pass exit ({})",
78
- scenario.label
79
- );
80
- assert_eq!(
81
- yam_req_ok_code, 0,
82
- "yamllint require pass exit ({})",
83
- scenario.label
84
- );
85
- assert_eq!(
86
- ryl_req_ok_msg, yam_req_ok_msg,
87
- "require pass diagnostics mismatch ({})",
88
- scenario.label
89
- );
90
-
91
- let mut ryl_require_comment = build_ryl_command(exe, scenario.ryl_format);
92
- ryl_require_comment
93
- .arg("-c")
94
- .arg(&require_cfg)
95
- .arg(&explicit_with_comment);
96
- let (ryl_req_comment_code, ryl_req_comment_msg) =
97
- capture_with_env(ryl_require_comment, scenario.envs);
98
-
99
- let mut yam_require_comment = build_yamllint_command(scenario.yam_format);
100
- yam_require_comment
101
- .arg("-c")
102
- .arg(&require_cfg)
103
- .arg(&explicit_with_comment);
104
- let (yam_req_comment_code, yam_req_comment_msg) =
105
- capture_with_env(yam_require_comment, scenario.envs);
106
-
107
- assert_eq!(
108
- ryl_req_comment_code, 0,
109
- "ryl require pass (with comment) exit ({})",
110
- scenario.label
111
- );
112
- assert_eq!(
113
- yam_req_comment_code, 0,
114
- "yamllint require pass (with comment) exit ({})",
115
- scenario.label
116
- );
117
- assert_eq!(
118
- ryl_req_comment_msg, yam_req_comment_msg,
119
- "require comment diagnostics mismatch ({})",
120
- scenario.label
121
- );
122
-
123
- let mut ryl_forbid = build_ryl_command(exe, scenario.ryl_format);
124
- ryl_forbid.arg("-c").arg(&forbid_cfg).arg(&explicit);
125
- let (ryl_forbid_code, ryl_forbid_msg) =
126
- capture_with_env(ryl_forbid, scenario.envs);
127
-
128
- let mut yam_forbid = build_yamllint_command(scenario.yam_format);
129
- yam_forbid.arg("-c").arg(&forbid_cfg).arg(&explicit);
130
- let (yam_forbid_code, yam_forbid_msg) =
131
- capture_with_env(yam_forbid, scenario.envs);
132
-
133
- assert_eq!(ryl_forbid_code, 1, "ryl forbid exit ({})", scenario.label);
134
- assert_eq!(
135
- yam_forbid_code, 1,
136
- "yamllint forbid exit ({})",
137
- scenario.label
138
- );
139
- assert_eq!(
140
- ryl_forbid_msg, yam_forbid_msg,
141
- "forbid diagnostics mismatch ({})",
142
- scenario.label
143
- );
144
-
145
- let mut ryl_forbid_comment = build_ryl_command(exe, scenario.ryl_format);
146
- ryl_forbid_comment
147
- .arg("-c")
148
- .arg(&forbid_cfg)
149
- .arg(&explicit_with_comment);
150
- let (ryl_forbid_comment_code, ryl_forbid_comment_msg) =
151
- capture_with_env(ryl_forbid_comment, scenario.envs);
152
-
153
- let mut yam_forbid_comment = build_yamllint_command(scenario.yam_format);
154
- yam_forbid_comment
155
- .arg("-c")
156
- .arg(&forbid_cfg)
157
- .arg(&explicit_with_comment);
158
- let (yam_forbid_comment_code, yam_forbid_comment_msg) =
159
- capture_with_env(yam_forbid_comment, scenario.envs);
160
-
161
- assert_eq!(
162
- ryl_forbid_comment_code, 1,
163
- "ryl forbid comment exit ({})",
164
- scenario.label
165
- );
166
- assert_eq!(
167
- yam_forbid_comment_code, 1,
168
- "yamllint forbid comment exit ({})",
169
- scenario.label
170
- );
171
- assert_eq!(
172
- ryl_forbid_comment_msg, yam_forbid_comment_msg,
173
- "forbid comment diagnostics mismatch ({})",
174
- scenario.label
175
- );
176
-
177
- let mut ryl_forbid_ok = build_ryl_command(exe, scenario.ryl_format);
178
- ryl_forbid_ok.arg("-c").arg(&forbid_cfg).arg(&missing);
179
- let (ryl_forbid_ok_code, ryl_forbid_ok_msg) =
180
- capture_with_env(ryl_forbid_ok, scenario.envs);
181
-
182
- let mut yam_forbid_ok = build_yamllint_command(scenario.yam_format);
183
- yam_forbid_ok.arg("-c").arg(&forbid_cfg).arg(&missing);
184
- let (yam_forbid_ok_code, yam_forbid_ok_msg) =
185
- capture_with_env(yam_forbid_ok, scenario.envs);
186
-
187
- assert_eq!(
188
- ryl_forbid_ok_code, 0,
189
- "ryl forbid pass exit ({})",
190
- scenario.label
191
- );
192
- assert_eq!(
193
- yam_forbid_ok_code, 0,
194
- "yamllint forbid pass exit ({})",
195
- scenario.label
196
- );
197
- assert_eq!(
198
- ryl_forbid_ok_msg, yam_forbid_ok_msg,
199
- "forbid pass diagnostics mismatch ({})",
200
- scenario.label
201
- );
202
- }
203
- }
204
-
205
- #[test]
206
- fn document_end_handles_unicode_scalars() {
207
- ensure_yamllint_installed();
208
-
209
- let dir = tempdir().unwrap();
210
-
211
- let cfg_path = dir.path().join("config.yaml");
212
- fs::write(
213
- &cfg_path,
214
- "rules:\n document-start: disable\n document-end:\n level: error\n present: false\n",
215
- )
216
- .unwrap();
217
-
218
- let yaml_path = dir.path().join("unicode.yaml");
219
- fs::write(
220
- &yaml_path,
221
- "set_room_temperature:\n fields:\n comfort_temp:\n selector:\n number:\n min: 0\n max: 100\n unit_of_measurement: \"°\"\n",
222
- )
223
- .unwrap();
224
-
225
- let exe = env!("CARGO_BIN_EXE_ryl");
226
-
227
- for scenario in SCENARIOS {
228
- let mut ryl_cmd = build_ryl_command(exe, scenario.ryl_format);
229
- ryl_cmd.arg("-c").arg(&cfg_path).arg(&yaml_path);
230
- let (ryl_code, ryl_output) = capture_with_env(ryl_cmd, scenario.envs);
231
-
232
- let mut yam_cmd = build_yamllint_command(scenario.yam_format);
233
- yam_cmd.arg("-c").arg(&cfg_path).arg(&yaml_path);
234
- let (yam_code, yam_output) = capture_with_env(yam_cmd, scenario.envs);
235
-
236
- assert_eq!(ryl_code, yam_code, "exit mismatch ({})", scenario.label);
237
- assert_eq!(
238
- ryl_output, yam_output,
239
- "diagnostics mismatch ({})",
240
- scenario.label
241
- );
242
- }
243
- }