@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,139 @@
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 key_duplicates_rule_matches_yamllint() {
15
+ ensure_yamllint_installed();
16
+
17
+ let dir = tempdir().unwrap();
18
+
19
+ let default_cfg = dir.path().join("key-duplicates-default.yml");
20
+ fs::write(
21
+ &default_cfg,
22
+ "rules:\n document-start: disable\n key-duplicates: enable\n",
23
+ )
24
+ .unwrap();
25
+
26
+ let forbid_cfg = dir.path().join("key-duplicates-forbid.yml");
27
+ fs::write(
28
+ &forbid_cfg,
29
+ "rules:\n document-start: disable\n key-duplicates:\n forbid-duplicated-merge-keys: true\n",
30
+ )
31
+ .unwrap();
32
+
33
+ let dup_bad = dir.path().join("dup-bad.yaml");
34
+ fs::write(&dup_bad, "foo: 1\nbar: 2\nfoo: 3\n").unwrap();
35
+
36
+ let dup_ok = dir.path().join("dup-ok.yaml");
37
+ fs::write(&dup_ok, "foo: 1\nbar: 2\n").unwrap();
38
+
39
+ let merge_dup = dir.path().join("merge-dup.yaml");
40
+ fs::write(
41
+ &merge_dup,
42
+ "anchor: &a\n value: 1\nmerged:\n <<: *a\n <<: *a\n",
43
+ )
44
+ .unwrap();
45
+
46
+ let exe = env!("CARGO_BIN_EXE_ryl");
47
+
48
+ for scenario in SCENARIOS {
49
+ let mut ryl_bad = build_ryl_command(exe, scenario.ryl_format);
50
+ ryl_bad.arg("-c").arg(&default_cfg).arg(&dup_bad);
51
+ let (ryl_bad_code, ryl_bad_msg) = capture_with_env(ryl_bad, scenario.envs);
52
+
53
+ let mut yam_bad = build_yamllint_command(scenario.yam_format);
54
+ yam_bad.arg("-c").arg(&default_cfg).arg(&dup_bad);
55
+ let (yam_bad_code, yam_bad_msg) = capture_with_env(yam_bad, scenario.envs);
56
+
57
+ assert_eq!(ryl_bad_code, 1, "ryl dup exit ({})", scenario.label);
58
+ assert_eq!(yam_bad_code, 1, "yamllint dup exit ({})", scenario.label);
59
+ assert_eq!(
60
+ ryl_bad_msg, yam_bad_msg,
61
+ "duplicate diagnostics mismatch ({})",
62
+ scenario.label
63
+ );
64
+
65
+ let mut ryl_ok = build_ryl_command(exe, scenario.ryl_format);
66
+ ryl_ok.arg("-c").arg(&default_cfg).arg(&dup_ok);
67
+ let (ryl_ok_code, ryl_ok_msg) = capture_with_env(ryl_ok, scenario.envs);
68
+
69
+ let mut yam_ok = build_yamllint_command(scenario.yam_format);
70
+ yam_ok.arg("-c").arg(&default_cfg).arg(&dup_ok);
71
+ let (yam_ok_code, yam_ok_msg) = capture_with_env(yam_ok, scenario.envs);
72
+
73
+ assert_eq!(ryl_ok_code, 0, "ryl ok exit ({})", scenario.label);
74
+ assert_eq!(yam_ok_code, 0, "yamllint ok exit ({})", scenario.label);
75
+ assert_eq!(
76
+ ryl_ok_msg, yam_ok_msg,
77
+ "ok diagnostics mismatch ({})",
78
+ scenario.label
79
+ );
80
+
81
+ let mut ryl_merge_default = build_ryl_command(exe, scenario.ryl_format);
82
+ ryl_merge_default
83
+ .arg("-c")
84
+ .arg(&default_cfg)
85
+ .arg(&merge_dup);
86
+ let (ryl_merge_def_code, ryl_merge_def_msg) =
87
+ capture_with_env(ryl_merge_default, scenario.envs);
88
+
89
+ let mut yam_merge_default = build_yamllint_command(scenario.yam_format);
90
+ yam_merge_default
91
+ .arg("-c")
92
+ .arg(&default_cfg)
93
+ .arg(&merge_dup);
94
+ let (yam_merge_def_code, yam_merge_def_msg) =
95
+ capture_with_env(yam_merge_default, scenario.envs);
96
+
97
+ assert_eq!(
98
+ ryl_merge_def_code, 0,
99
+ "ryl merge default exit ({})",
100
+ scenario.label
101
+ );
102
+ assert_eq!(
103
+ yam_merge_def_code, 0,
104
+ "yamllint merge default exit ({})",
105
+ scenario.label
106
+ );
107
+ assert_eq!(
108
+ ryl_merge_def_msg, yam_merge_def_msg,
109
+ "merge default diagnostics mismatch ({})",
110
+ scenario.label
111
+ );
112
+
113
+ let mut ryl_merge_forbid = build_ryl_command(exe, scenario.ryl_format);
114
+ ryl_merge_forbid.arg("-c").arg(&forbid_cfg).arg(&merge_dup);
115
+ let (ryl_merge_forbid_code, ryl_merge_forbid_msg) =
116
+ capture_with_env(ryl_merge_forbid, scenario.envs);
117
+
118
+ let mut yam_merge_forbid = build_yamllint_command(scenario.yam_format);
119
+ yam_merge_forbid.arg("-c").arg(&forbid_cfg).arg(&merge_dup);
120
+ let (yam_merge_forbid_code, yam_merge_forbid_msg) =
121
+ capture_with_env(yam_merge_forbid, scenario.envs);
122
+
123
+ assert_eq!(
124
+ ryl_merge_forbid_code, 1,
125
+ "ryl merge forbid exit ({})",
126
+ scenario.label
127
+ );
128
+ assert_eq!(
129
+ yam_merge_forbid_code, 1,
130
+ "yamllint merge forbid exit ({})",
131
+ scenario.label
132
+ );
133
+ assert_eq!(
134
+ ryl_merge_forbid_msg, yam_merge_forbid_msg,
135
+ "merge forbid diagnostics mismatch ({})",
136
+ scenario.label
137
+ );
138
+ }
139
+ }
@@ -0,0 +1,170 @@
1
+ use std::fs;
2
+ use std::process::Command;
3
+
4
+ use tempfile::tempdir;
5
+
6
+ #[path = "common/compat.rs"]
7
+ mod compat;
8
+
9
+ use compat::{
10
+ SCENARIOS, STANDARD_ENV, build_ryl_command, build_yamllint_command,
11
+ capture_with_env, ensure_yamllint_installed,
12
+ };
13
+
14
+ #[test]
15
+ fn key_ordering_matches_yamllint() {
16
+ ensure_yamllint_installed();
17
+
18
+ let dir = tempdir().unwrap();
19
+
20
+ let default_cfg = dir.path().join("key-ordering-default.yml");
21
+ fs::write(
22
+ &default_cfg,
23
+ "rules:\n document-start: disable\n key-ordering: enable\n",
24
+ )
25
+ .unwrap();
26
+
27
+ let ignored_cfg = dir.path().join("key-ordering-ignored.yml");
28
+ fs::write(
29
+ &ignored_cfg,
30
+ "rules:\n document-start: disable\n key-ordering:\n ignored-keys: [\"n(a|o)me\", \"^b\"]\n",
31
+ )
32
+ .unwrap();
33
+
34
+ let locale_cfg = dir.path().join("key-ordering-locale.yml");
35
+ fs::write(
36
+ &locale_cfg,
37
+ "locale: en_US.UTF-8\nrules:\n document-start: disable\n key-ordering: enable\n",
38
+ )
39
+ .unwrap();
40
+
41
+ let bad_block = dir.path().join("bad-block.yaml");
42
+ fs::write(
43
+ &bad_block,
44
+ "block mapping:\n second: value\n first: value\n",
45
+ )
46
+ .unwrap();
47
+
48
+ let good_block = dir.path().join("good-block.yaml");
49
+ fs::write(
50
+ &good_block,
51
+ "block mapping:\n first: value\n second: value\n third: v\n",
52
+ )
53
+ .unwrap();
54
+
55
+ let ignored_file = dir.path().join("ignored.yaml");
56
+ fs::write(
57
+ &ignored_file,
58
+ "a:\nb:\nc:\nname: ignored\nfirst-name: ignored\nnome: ignored\ngnomes: ignored\nd:\ne:\nboat: ignored\n.boat: ERROR\ncall: ERROR\nf:\ng:\n",
59
+ )
60
+ .unwrap();
61
+
62
+ let locale_file = dir.path().join("locale.yaml");
63
+ fs::write(
64
+ &locale_file,
65
+ "- t-shirt: 1\n T-shirt: 2\n t-shirts: 3\n T-shirts: 4\n- hair: true\n haïr: true\n hais: true\n haïssable: true\n",
66
+ )
67
+ .unwrap();
68
+
69
+ // Probe locale availability before running the full matrix. Skip locale comparison when
70
+ // yamllint cannot set the configured locale.
71
+ let mut locale_probe = Command::new("yamllint");
72
+ locale_probe.arg("-c").arg(&locale_cfg).arg(&locale_file);
73
+ let (probe_code, probe_output) = capture_with_env(locale_probe, STANDARD_ENV);
74
+ let skip_locale = if probe_code != 0
75
+ && (probe_output.contains("unsupported locale")
76
+ || probe_output.contains("unknown locale"))
77
+ {
78
+ eprintln!("skipping locale comparison: {probe_output}");
79
+ true
80
+ } else {
81
+ false
82
+ };
83
+
84
+ let exe = env!("CARGO_BIN_EXE_ryl");
85
+
86
+ for scenario in SCENARIOS {
87
+ // default configuration, expect violations on bad block
88
+ let mut ryl_bad = build_ryl_command(exe, scenario.ryl_format);
89
+ ryl_bad.arg("-c").arg(&default_cfg).arg(&bad_block);
90
+ let (ryl_bad_code, ryl_bad_msg) = capture_with_env(ryl_bad, scenario.envs);
91
+
92
+ let mut yam_bad = build_yamllint_command(scenario.yam_format);
93
+ yam_bad.arg("-c").arg(&default_cfg).arg(&bad_block);
94
+ let (yam_bad_code, yam_bad_msg) = capture_with_env(yam_bad, scenario.envs);
95
+
96
+ assert_eq!(ryl_bad_code, 1, "ryl bad exit ({})", scenario.label);
97
+ assert_eq!(yam_bad_code, 1, "yamllint bad exit ({})", scenario.label);
98
+ assert_eq!(
99
+ ryl_bad_msg, yam_bad_msg,
100
+ "bad block diagnostics mismatch ({})",
101
+ scenario.label
102
+ );
103
+
104
+ // good block should be clean
105
+ let mut ryl_good = build_ryl_command(exe, scenario.ryl_format);
106
+ ryl_good.arg("-c").arg(&default_cfg).arg(&good_block);
107
+ let (ryl_good_code, ryl_good_msg) = capture_with_env(ryl_good, scenario.envs);
108
+
109
+ let mut yam_good = build_yamllint_command(scenario.yam_format);
110
+ yam_good.arg("-c").arg(&default_cfg).arg(&good_block);
111
+ let (yam_good_code, yam_good_msg) = capture_with_env(yam_good, scenario.envs);
112
+
113
+ assert_eq!(ryl_good_code, 0, "ryl good exit ({})", scenario.label);
114
+ assert_eq!(yam_good_code, 0, "yamllint good exit ({})", scenario.label);
115
+ assert_eq!(
116
+ ryl_good_msg, yam_good_msg,
117
+ "good block diagnostics mismatch ({})",
118
+ scenario.label
119
+ );
120
+
121
+ // ignored-keys configuration should allow ignored patterns and flag others equally
122
+ let mut ryl_ignored = build_ryl_command(exe, scenario.ryl_format);
123
+ ryl_ignored.arg("-c").arg(&ignored_cfg).arg(&ignored_file);
124
+ let (ryl_ignored_code, ryl_ignored_msg) =
125
+ capture_with_env(ryl_ignored, scenario.envs);
126
+
127
+ let mut yam_ignored = build_yamllint_command(scenario.yam_format);
128
+ yam_ignored.arg("-c").arg(&ignored_cfg).arg(&ignored_file);
129
+ let (yam_ignored_code, yam_ignored_msg) =
130
+ capture_with_env(yam_ignored, scenario.envs);
131
+
132
+ assert_eq!(ryl_ignored_code, 1, "ryl ignored exit ({})", scenario.label);
133
+ assert_eq!(
134
+ yam_ignored_code, 1,
135
+ "yamllint ignored exit ({})",
136
+ scenario.label
137
+ );
138
+ assert_eq!(
139
+ ryl_ignored_msg, yam_ignored_msg,
140
+ "ignored diagnostics mismatch ({})",
141
+ scenario.label
142
+ );
143
+
144
+ if skip_locale {
145
+ continue;
146
+ }
147
+
148
+ let mut ryl_locale = build_ryl_command(exe, scenario.ryl_format);
149
+ ryl_locale.arg("-c").arg(&locale_cfg).arg(&locale_file);
150
+ let (ryl_locale_code, ryl_locale_msg) =
151
+ capture_with_env(ryl_locale, scenario.envs);
152
+
153
+ let mut yam_locale = build_yamllint_command(scenario.yam_format);
154
+ yam_locale.arg("-c").arg(&locale_cfg).arg(&locale_file);
155
+ let (yam_locale_code, yam_locale_msg) =
156
+ capture_with_env(yam_locale, scenario.envs);
157
+
158
+ assert_eq!(ryl_locale_code, 0, "ryl locale exit ({})", scenario.label);
159
+ assert_eq!(
160
+ yam_locale_code, 0,
161
+ "yamllint locale exit ({})",
162
+ scenario.label
163
+ );
164
+ assert_eq!(
165
+ ryl_locale_msg, yam_locale_msg,
166
+ "locale diagnostics mismatch ({})",
167
+ scenario.label
168
+ );
169
+ }
170
+ }
@@ -0,0 +1,375 @@
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 line_length_rule_matches_yamllint() {
15
+ ensure_yamllint_installed();
16
+
17
+ let dir = tempdir().unwrap();
18
+
19
+ let default_cfg = dir.path().join("line-default.yml");
20
+ fs::write(
21
+ &default_cfg,
22
+ "rules:\n document-start: disable\n empty-lines: disable\n new-line-at-end-of-file: disable\n line-length:\n max: 80\n",
23
+ )
24
+ .unwrap();
25
+
26
+ let warning_cfg = dir.path().join("line-warning.yml");
27
+ fs::write(
28
+ &warning_cfg,
29
+ "rules:\n document-start: disable\n empty-lines: disable\n new-line-at-end-of-file: disable\n line-length:\n max: 80\n level: warning\n",
30
+ )
31
+ .unwrap();
32
+
33
+ let strict_cfg = dir.path().join("line-strict.yml");
34
+ fs::write(
35
+ &strict_cfg,
36
+ "rules:\n document-start: disable\n line-length:\n max: 20\n allow-non-breakable-words: false\n",
37
+ )
38
+ .unwrap();
39
+
40
+ let inline_cfg = dir.path().join("line-inline.yml");
41
+ fs::write(
42
+ &inline_cfg,
43
+ "rules:\n document-start: disable\n line-length:\n max: 20\n allow-non-breakable-inline-mappings: true\n",
44
+ )
45
+ .unwrap();
46
+
47
+ let bad_file = dir.path().join("bad.yaml");
48
+ fs::write(
49
+ &bad_file,
50
+ "key: this line is definitely longer than eighty characters so yamllint and ryl should both flag it\n",
51
+ )
52
+ .unwrap();
53
+
54
+ let long_word_file = dir.path().join("long_word.yaml");
55
+ fs::write(&long_word_file, format!("{}\n", "A".repeat(50))).unwrap();
56
+
57
+ let inline_ok_file = dir.path().join("inline_ok.yaml");
58
+ fs::write(
59
+ &inline_ok_file,
60
+ "url: http://example.com/very/very/very/very/very/very/long/path\n",
61
+ )
62
+ .unwrap();
63
+
64
+ let inline_bad_file = dir.path().join("inline_bad.yaml");
65
+ fs::write(
66
+ &inline_bad_file,
67
+ "url: http://example.com/short + extra words to trigger the rule\n",
68
+ )
69
+ .unwrap();
70
+
71
+ let exe = env!("CARGO_BIN_EXE_ryl");
72
+
73
+ for scenario in SCENARIOS {
74
+ // default configuration should produce an error for spaced text
75
+ let mut ryl_default = build_ryl_command(exe, scenario.ryl_format);
76
+ ryl_default.arg("-c").arg(&default_cfg).arg(&bad_file);
77
+ let (ryl_code, ryl_output) = capture_with_env(ryl_default, scenario.envs);
78
+
79
+ let mut yam_default = build_yamllint_command(scenario.yam_format);
80
+ yam_default.arg("-c").arg(&default_cfg).arg(&bad_file);
81
+ let (yam_code, yam_output) = capture_with_env(yam_default, scenario.envs);
82
+
83
+ assert_eq!(ryl_code, 1, "ryl default exit ({})", scenario.label);
84
+ assert_eq!(yam_code, 1, "yamllint default exit ({})", scenario.label);
85
+ assert_eq!(
86
+ ryl_output, yam_output,
87
+ "default diagnostics mismatch ({})",
88
+ scenario.label
89
+ );
90
+
91
+ // warning configuration should keep diagnostics but exit 0
92
+ let mut ryl_warning = build_ryl_command(exe, scenario.ryl_format);
93
+ ryl_warning.arg("-c").arg(&warning_cfg).arg(&bad_file);
94
+ let (ryl_warn_code, ryl_warn_output) =
95
+ capture_with_env(ryl_warning, scenario.envs);
96
+
97
+ let mut yam_warning = build_yamllint_command(scenario.yam_format);
98
+ yam_warning.arg("-c").arg(&warning_cfg).arg(&bad_file);
99
+ let (yam_warn_code, yam_warn_output) =
100
+ capture_with_env(yam_warning, scenario.envs);
101
+
102
+ assert_eq!(ryl_warn_code, 0, "ryl warning exit ({})", scenario.label);
103
+ assert_eq!(
104
+ yam_warn_code, 0,
105
+ "yamllint warning exit ({})",
106
+ scenario.label
107
+ );
108
+ assert_eq!(
109
+ ryl_warn_output, yam_warn_output,
110
+ "warning diagnostics mismatch ({})",
111
+ scenario.label
112
+ );
113
+
114
+ // strict configuration should flag long non-breakable words
115
+ let mut ryl_strict = build_ryl_command(exe, scenario.ryl_format);
116
+ ryl_strict.arg("-c").arg(&strict_cfg).arg(&long_word_file);
117
+ let (ryl_strict_code, ryl_strict_output) =
118
+ capture_with_env(ryl_strict, scenario.envs);
119
+
120
+ let mut yam_strict = build_yamllint_command(scenario.yam_format);
121
+ yam_strict.arg("-c").arg(&strict_cfg).arg(&long_word_file);
122
+ let (yam_strict_code, yam_strict_output) =
123
+ capture_with_env(yam_strict, scenario.envs);
124
+
125
+ assert_eq!(ryl_strict_code, 1, "ryl strict exit ({})", scenario.label);
126
+ assert_eq!(
127
+ yam_strict_code, 1,
128
+ "yamllint strict exit ({})",
129
+ scenario.label
130
+ );
131
+ assert_eq!(
132
+ ryl_strict_output, yam_strict_output,
133
+ "strict diagnostics mismatch ({})",
134
+ scenario.label
135
+ );
136
+
137
+ // inline mapping allowance should let long URLs through
138
+ let mut ryl_inline_ok = build_ryl_command(exe, scenario.ryl_format);
139
+ ryl_inline_ok
140
+ .arg("-c")
141
+ .arg(&inline_cfg)
142
+ .arg(&inline_ok_file);
143
+ let (ryl_inline_code, ryl_inline_output) =
144
+ capture_with_env(ryl_inline_ok, scenario.envs);
145
+
146
+ let mut yam_inline_ok = build_yamllint_command(scenario.yam_format);
147
+ yam_inline_ok
148
+ .arg("-c")
149
+ .arg(&inline_cfg)
150
+ .arg(&inline_ok_file);
151
+ let (yam_inline_code, yam_inline_output) =
152
+ capture_with_env(yam_inline_ok, scenario.envs);
153
+
154
+ assert_eq!(
155
+ ryl_inline_code, 0,
156
+ "ryl inline-ok exit ({})",
157
+ scenario.label
158
+ );
159
+ assert_eq!(
160
+ yam_inline_code, 0,
161
+ "yamllint inline-ok exit ({})",
162
+ scenario.label
163
+ );
164
+ assert_eq!(
165
+ ryl_inline_output, yam_inline_output,
166
+ "inline ok diagnostics mismatch ({})",
167
+ scenario.label
168
+ );
169
+
170
+ // inline mapping option should still flag when spaces remain
171
+ let mut ryl_inline_bad = build_ryl_command(exe, scenario.ryl_format);
172
+ ryl_inline_bad
173
+ .arg("-c")
174
+ .arg(&inline_cfg)
175
+ .arg(&inline_bad_file);
176
+ let (ryl_inline_bad_code, ryl_inline_bad_output) =
177
+ capture_with_env(ryl_inline_bad, scenario.envs);
178
+
179
+ let mut yam_inline_bad = build_yamllint_command(scenario.yam_format);
180
+ yam_inline_bad
181
+ .arg("-c")
182
+ .arg(&inline_cfg)
183
+ .arg(&inline_bad_file);
184
+ let (yam_inline_bad_code, yam_inline_bad_output) =
185
+ capture_with_env(yam_inline_bad, scenario.envs);
186
+
187
+ assert_eq!(
188
+ ryl_inline_bad_code, 1,
189
+ "ryl inline-bad exit ({})",
190
+ scenario.label
191
+ );
192
+ assert_eq!(
193
+ yam_inline_bad_code, 1,
194
+ "yamllint inline-bad exit ({})",
195
+ scenario.label
196
+ );
197
+ assert_eq!(
198
+ ryl_inline_bad_output, yam_inline_bad_output,
199
+ "inline bad diagnostics mismatch ({})",
200
+ scenario.label
201
+ );
202
+ }
203
+ }
204
+
205
+ #[test]
206
+ fn line_length_disable_enable_comments_match_yamllint() {
207
+ ensure_yamllint_installed();
208
+
209
+ let dir = tempdir().unwrap();
210
+ let cfg = dir.path().join("line-110.yml");
211
+ fs::write(
212
+ &cfg,
213
+ "extends: default\nrules:\n line-length:\n max: 110\n",
214
+ )
215
+ .unwrap();
216
+
217
+ let input = dir.path().join("line-disable-comments.yaml");
218
+ fs::write(
219
+ &input,
220
+ "# yamllint disable rule:line-length\nmsg: \"This is a very very very very very very very very very very very very very very very long line that should be ignored\"\n# yamllint enable rule:line-length\n",
221
+ )
222
+ .unwrap();
223
+
224
+ let exe = env!("CARGO_BIN_EXE_ryl");
225
+
226
+ for scenario in SCENARIOS {
227
+ let mut ryl_cmd = build_ryl_command(exe, scenario.ryl_format);
228
+ ryl_cmd.arg("-c").arg(&cfg).arg(&input);
229
+ let (ryl_code, ryl_msg) = capture_with_env(ryl_cmd, scenario.envs);
230
+
231
+ let mut yam_cmd = build_yamllint_command(scenario.yam_format);
232
+ yam_cmd.arg("-c").arg(&cfg).arg(&input);
233
+ let (yam_code, yam_msg) = capture_with_env(yam_cmd, scenario.envs);
234
+
235
+ assert_eq!(
236
+ ryl_code, yam_code,
237
+ "exit mismatch for line-length disable comments ({})",
238
+ scenario.label
239
+ );
240
+ assert_eq!(
241
+ ryl_msg, yam_msg,
242
+ "diagnostics mismatch for line-length disable comments ({})",
243
+ scenario.label
244
+ );
245
+ }
246
+ }
247
+
248
+ #[test]
249
+ fn line_length_disable_line_applies_to_one_line_only() {
250
+ ensure_yamllint_installed();
251
+
252
+ let dir = tempdir().unwrap();
253
+ let cfg = dir.path().join("line-40.yml");
254
+ fs::write(
255
+ &cfg,
256
+ "extends: default\nrules:\n line-length:\n max: 40\n",
257
+ )
258
+ .unwrap();
259
+
260
+ let input = dir.path().join("line-disable-line.yaml");
261
+ fs::write(
262
+ &input,
263
+ "---\n# yamllint disable-line rule:line-length\nlong: \"01234567890123456789012345678901234567890123456789\"\nlong2: \"01234567890123456789012345678901234567890123456789\"\n",
264
+ )
265
+ .unwrap();
266
+
267
+ let exe = env!("CARGO_BIN_EXE_ryl");
268
+
269
+ for scenario in SCENARIOS {
270
+ let mut ryl_cmd = build_ryl_command(exe, scenario.ryl_format);
271
+ ryl_cmd.arg("-c").arg(&cfg).arg("--strict").arg(&input);
272
+ let (ryl_code, ryl_msg) = capture_with_env(ryl_cmd, scenario.envs);
273
+
274
+ let mut yam_cmd = build_yamllint_command(scenario.yam_format);
275
+ yam_cmd.arg("-c").arg(&cfg).arg("--strict").arg(&input);
276
+ let (yam_code, yam_msg) = capture_with_env(yam_cmd, scenario.envs);
277
+
278
+ assert_eq!(
279
+ ryl_code, yam_code,
280
+ "exit mismatch for line-length disable-line semantics ({})",
281
+ scenario.label
282
+ );
283
+ assert_eq!(
284
+ ryl_msg, yam_msg,
285
+ "diagnostics mismatch for line-length disable-line semantics ({})",
286
+ scenario.label
287
+ );
288
+ }
289
+ }
290
+
291
+ #[test]
292
+ fn line_length_disable_line_is_consumed_by_next_directive_line() {
293
+ ensure_yamllint_installed();
294
+
295
+ let dir = tempdir().unwrap();
296
+ let cfg = dir.path().join("line-40.yml");
297
+ fs::write(
298
+ &cfg,
299
+ "extends: default\nrules:\n line-length:\n max: 40\n",
300
+ )
301
+ .unwrap();
302
+
303
+ let input = dir.path().join("line-disable-line-directive.yaml");
304
+ fs::write(
305
+ &input,
306
+ "---\n# yamllint disable-line rule:line-length\n# yamllint enable rule:line-length\nlong: \"01234567890123456789012345678901234567890123456789\"\n",
307
+ )
308
+ .unwrap();
309
+
310
+ let exe = env!("CARGO_BIN_EXE_ryl");
311
+
312
+ for scenario in SCENARIOS {
313
+ let mut ryl_cmd = build_ryl_command(exe, scenario.ryl_format);
314
+ ryl_cmd.arg("-c").arg(&cfg).arg("--strict").arg(&input);
315
+ let (ryl_code, ryl_msg) = capture_with_env(ryl_cmd, scenario.envs);
316
+
317
+ let mut yam_cmd = build_yamllint_command(scenario.yam_format);
318
+ yam_cmd.arg("-c").arg(&cfg).arg("--strict").arg(&input);
319
+ let (yam_code, yam_msg) = capture_with_env(yam_cmd, scenario.envs);
320
+
321
+ assert_eq!(
322
+ ryl_code, yam_code,
323
+ "exit mismatch for disable-line consumed by directive line ({})",
324
+ scenario.label
325
+ );
326
+ assert_eq!(
327
+ ryl_msg, yam_msg,
328
+ "diagnostics mismatch for disable-line consumed by directive line ({})",
329
+ scenario.label
330
+ );
331
+ }
332
+ }
333
+
334
+ #[test]
335
+ fn line_length_disable_line_is_consumed_by_blank_line() {
336
+ ensure_yamllint_installed();
337
+
338
+ let dir = tempdir().unwrap();
339
+ let cfg = dir.path().join("line-40.yml");
340
+ fs::write(
341
+ &cfg,
342
+ "extends: default\nrules:\n line-length:\n max: 40\n",
343
+ )
344
+ .unwrap();
345
+
346
+ let input = dir.path().join("line-disable-line-blank.yaml");
347
+ fs::write(
348
+ &input,
349
+ "---\n# yamllint disable-line rule:line-length\n\nlong: \"01234567890123456789012345678901234567890123456789\"\n",
350
+ )
351
+ .unwrap();
352
+
353
+ let exe = env!("CARGO_BIN_EXE_ryl");
354
+
355
+ for scenario in SCENARIOS {
356
+ let mut ryl_cmd = build_ryl_command(exe, scenario.ryl_format);
357
+ ryl_cmd.arg("-c").arg(&cfg).arg("--strict").arg(&input);
358
+ let (ryl_code, ryl_msg) = capture_with_env(ryl_cmd, scenario.envs);
359
+
360
+ let mut yam_cmd = build_yamllint_command(scenario.yam_format);
361
+ yam_cmd.arg("-c").arg(&cfg).arg("--strict").arg(&input);
362
+ let (yam_code, yam_msg) = capture_with_env(yam_cmd, scenario.envs);
363
+
364
+ assert_eq!(
365
+ ryl_code, yam_code,
366
+ "exit mismatch for disable-line consumed by blank line ({})",
367
+ scenario.label
368
+ );
369
+ assert_eq!(
370
+ ryl_msg, yam_msg,
371
+ "diagnostics mismatch for disable-line consumed by blank line ({})",
372
+ scenario.label
373
+ );
374
+ }
375
+ }