@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,154 @@
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
+ struct Case<'a> {
14
+ label: &'a str,
15
+ config: &'a std::path::Path,
16
+ file: &'a std::path::Path,
17
+ exit: i32,
18
+ }
19
+
20
+ #[test]
21
+ fn quoted_strings_rule_matches_yamllint() {
22
+ ensure_yamllint_installed();
23
+
24
+ let dir = tempdir().unwrap();
25
+
26
+ let default_cfg = dir.path().join("default.yaml");
27
+ fs::write(
28
+ &default_cfg,
29
+ "rules:\n document-start: disable\n quoted-strings: enable\n",
30
+ )
31
+ .unwrap();
32
+
33
+ let only_needed_cfg = dir.path().join("only-needed.yaml");
34
+ fs::write(
35
+ &only_needed_cfg,
36
+ "rules:\n document-start: disable\n quoted-strings:\n required: only-when-needed\n",
37
+ )
38
+ .unwrap();
39
+
40
+ let extra_required_cfg = dir.path().join("extra-required.yaml");
41
+ fs::write(
42
+ &extra_required_cfg,
43
+ "rules:\n document-start: disable\n quoted-strings:\n required: false\n extra-required: ['^http']\n",
44
+ )
45
+ .unwrap();
46
+
47
+ let extra_allowed_cfg = dir.path().join("extra-allowed.yaml");
48
+ fs::write(
49
+ &extra_allowed_cfg,
50
+ "rules:\n document-start: disable\n quoted-strings:\n required: only-when-needed\n extra-allowed: ['^http']\n",
51
+ )
52
+ .unwrap();
53
+
54
+ let double_allow_cfg = dir.path().join("double-allow.yaml");
55
+ fs::write(
56
+ &double_allow_cfg,
57
+ "rules:\n document-start: disable\n quoted-strings:\n quote-type: double\n allow-quoted-quotes: true\n",
58
+ )
59
+ .unwrap();
60
+
61
+ let check_keys_cfg = dir.path().join("check-keys.yaml");
62
+ fs::write(
63
+ &check_keys_cfg,
64
+ "rules:\n document-start: disable\n quoted-strings:\n required: only-when-needed\n check-keys: true\n extra-required: ['[:]']\n",
65
+ )
66
+ .unwrap();
67
+
68
+ let plain_file = dir.path().join("plain.yaml");
69
+ fs::write(&plain_file, "foo: bar\n").unwrap();
70
+
71
+ let quoted_file = dir.path().join("quoted.yaml");
72
+ fs::write(&quoted_file, "foo: \"bar\"\n").unwrap();
73
+
74
+ let url_file = dir.path().join("urls.yaml");
75
+ fs::write(&url_file, "- http://example.com\n").unwrap();
76
+
77
+ let allowed_url_file = dir.path().join("allowed-url.yaml");
78
+ fs::write(&allowed_url_file, "foo: \"http://example.com\"\n").unwrap();
79
+
80
+ let quoted_quotes_file = dir.path().join("quoted-quotes.yaml");
81
+ fs::write(&quoted_quotes_file, "foo: 'bar\"baz'\n").unwrap();
82
+
83
+ let key_file = dir.path().join("key.yaml");
84
+ fs::write(&key_file, "foo:bar: baz\n").unwrap();
85
+
86
+ let exe = env!("CARGO_BIN_EXE_ryl");
87
+
88
+ let cases = [
89
+ Case {
90
+ label: "default-plain",
91
+ config: &default_cfg,
92
+ file: &plain_file,
93
+ exit: 1,
94
+ },
95
+ Case {
96
+ label: "only-needed-quoted",
97
+ config: &only_needed_cfg,
98
+ file: &quoted_file,
99
+ exit: 1,
100
+ },
101
+ Case {
102
+ label: "extra-required-url",
103
+ config: &extra_required_cfg,
104
+ file: &url_file,
105
+ exit: 1,
106
+ },
107
+ Case {
108
+ label: "extra-allowed-url",
109
+ config: &extra_allowed_cfg,
110
+ file: &allowed_url_file,
111
+ exit: 0,
112
+ },
113
+ Case {
114
+ label: "double-allow-quotes",
115
+ config: &double_allow_cfg,
116
+ file: &quoted_quotes_file,
117
+ exit: 0,
118
+ },
119
+ Case {
120
+ label: "check-keys",
121
+ config: &check_keys_cfg,
122
+ file: &key_file,
123
+ exit: 1,
124
+ },
125
+ ];
126
+
127
+ for scenario in SCENARIOS {
128
+ for case in &cases {
129
+ let mut ryl_cmd = build_ryl_command(exe, scenario.ryl_format);
130
+ ryl_cmd.arg("-c").arg(case.config).arg(case.file);
131
+ let (ryl_code, ryl_msg) = capture_with_env(ryl_cmd, scenario.envs);
132
+
133
+ let mut yam_cmd = build_yamllint_command(scenario.yam_format);
134
+ yam_cmd.arg("-c").arg(case.config).arg(case.file);
135
+ let (yam_code, yam_msg) = capture_with_env(yam_cmd, scenario.envs);
136
+
137
+ assert_eq!(
138
+ ryl_code, case.exit,
139
+ "ryl exit mismatch {} ({})",
140
+ case.label, scenario.label
141
+ );
142
+ assert_eq!(
143
+ yam_code, case.exit,
144
+ "yamllint exit mismatch {} ({})",
145
+ case.label, scenario.label
146
+ );
147
+ assert_eq!(
148
+ ryl_msg, yam_msg,
149
+ "diagnostics mismatch {} ({})",
150
+ case.label, scenario.label
151
+ );
152
+ }
153
+ }
154
+ }
@@ -0,0 +1,200 @@
1
+ use std::fs;
2
+ use std::path::PathBuf;
3
+ use std::process::Command;
4
+
5
+ use tempfile::tempdir;
6
+
7
+ fn run_cmd(cmd: &mut Command) -> (i32, String, String) {
8
+ let out = cmd.output().expect("failed to spawn process");
9
+ let code = out.status.code().unwrap_or(-1);
10
+ let stdout = String::from_utf8_lossy(&out.stdout).into_owned();
11
+ let stderr = String::from_utf8_lossy(&out.stderr).into_owned();
12
+ (code, stdout, stderr)
13
+ }
14
+
15
+ fn run_with_env(
16
+ mut cmd: Command,
17
+ envs: &[(&str, Option<&str>)],
18
+ ) -> (i32, String, String) {
19
+ cmd.env_remove("GITHUB_ACTIONS");
20
+ cmd.env_remove("GITHUB_WORKFLOW");
21
+ cmd.env_remove("CI");
22
+ for (key, value) in envs {
23
+ if let Some(val) = value {
24
+ cmd.env(key, val);
25
+ } else {
26
+ cmd.env_remove(key);
27
+ }
28
+ }
29
+ run_cmd(&mut cmd)
30
+ }
31
+
32
+ fn write_file(dir: &std::path::Path, name: &str, content: &str) -> PathBuf {
33
+ let p = dir.join(name);
34
+ fs::write(&p, content).expect("write file");
35
+ p
36
+ }
37
+
38
+ fn ensure_yamllint_installed() {
39
+ let ok = Command::new("yamllint")
40
+ .arg("--version")
41
+ .output()
42
+ .map(|o| o.status.success())
43
+ .unwrap_or(false);
44
+ assert!(
45
+ ok,
46
+ "yamllint must be installed and in PATH for parity tests"
47
+ );
48
+ }
49
+
50
+ #[test]
51
+ fn yamllint_exit_behavior_matches_for_syntax_only() {
52
+ ensure_yamllint_installed();
53
+
54
+ let dir = tempdir().unwrap();
55
+ let ok = write_file(dir.path(), "ok.yaml", "a: 1\n");
56
+ let bad = write_file(dir.path(), "bad.yaml", "a: [1, 2\n");
57
+
58
+ // Disable yamllint rules so we only compare syntax behavior.
59
+ let cfg = write_file(dir.path(), ".yamllint.yml", "rules: {}\n");
60
+
61
+ let ryl = env!("CARGO_BIN_EXE_ryl");
62
+
63
+ const STANDARD_ENV: &[(&str, Option<&str>)] = &[];
64
+ const GITHUB_ENV: &[(&str, Option<&str>)] = &[
65
+ ("GITHUB_ACTIONS", Some("true")),
66
+ ("GITHUB_WORKFLOW", Some("test-workflow")),
67
+ ("CI", Some("true")),
68
+ ];
69
+
70
+ #[derive(Clone, Copy)]
71
+ enum OutputKind {
72
+ Standard,
73
+ Github,
74
+ }
75
+
76
+ fn parse_loc(msg: &str, kind: OutputKind) -> Option<(String, usize, usize)> {
77
+ match kind {
78
+ OutputKind::Standard => {
79
+ let mut lines = msg.lines().filter(|l| !l.trim().is_empty());
80
+ let file = lines.next()?.trim().to_string();
81
+ let second = lines.next()?.trim_start();
82
+ let pos = second.split_whitespace().next()?;
83
+ let mut it = pos.split(':');
84
+ let line = it.next()?.parse().ok()?;
85
+ let col = it.next()?.parse().ok()?;
86
+ Some((file, line, col))
87
+ }
88
+ OutputKind::Github => {
89
+ let mut lines = msg.lines().filter(|l| !l.trim().is_empty());
90
+ let header = lines.next()?.trim();
91
+ let file = header.strip_prefix("::group::")?.to_string();
92
+ let detail = lines.next()?.trim();
93
+ let detail = detail.strip_prefix("::error ")?;
94
+ let mut parts = detail.splitn(2, "::");
95
+ let meta = parts.next()?; // file=...,line=...,col=...
96
+ let mut meta_parts = meta.split(',');
97
+ let file_part = meta_parts.next()?;
98
+ let line_part = meta_parts.next()?;
99
+ let col_part = meta_parts.next()?;
100
+ let file_path = file_part.strip_prefix("file=")?;
101
+ let line_str = line_part.strip_prefix("line=")?;
102
+ let col_str = col_part.strip_prefix("col=")?;
103
+ let line = line_str.parse().ok()?;
104
+ let col = col_str.parse().ok()?;
105
+ // Ensure metadata file matches header file after trimming.
106
+ if !file_path.ends_with(&file) {
107
+ return None;
108
+ }
109
+ Some((file_path.to_string(), line, col))
110
+ }
111
+ }
112
+ }
113
+
114
+ let scenarios = [
115
+ ("standard", STANDARD_ENV, OutputKind::Standard, true),
116
+ ("github", GITHUB_ENV, OutputKind::Github, false),
117
+ ];
118
+
119
+ for (label, envs, kind, use_standard_format) in scenarios {
120
+ // Valid file should pass in both tools.
121
+ let mut ryl_ok_cmd = Command::new(ryl);
122
+ ryl_ok_cmd.arg(&ok);
123
+ let (ryl_ok, _, _) = run_with_env(ryl_ok_cmd, envs);
124
+ assert_eq!(ryl_ok, 0, "ryl should succeed for valid yaml ({label})");
125
+
126
+ let mut yam_ok_cmd = Command::new("yamllint");
127
+ if use_standard_format {
128
+ yam_ok_cmd.arg("-f").arg("standard");
129
+ }
130
+ yam_ok_cmd.arg("-c");
131
+ yam_ok_cmd.arg(&cfg);
132
+ yam_ok_cmd.arg(&ok);
133
+ let (yam_ok, _, yam_ok_err) = run_with_env(yam_ok_cmd, envs);
134
+ assert_eq!(
135
+ yam_ok, 0,
136
+ "yamllint should succeed for valid yaml ({label}): {yam_ok_err}"
137
+ );
138
+
139
+ // Invalid file should fail; capture whichever stream has content.
140
+ let mut ryl_bad_cmd = Command::new(ryl);
141
+ ryl_bad_cmd.arg(&bad);
142
+ let (ryl_bad_code, ryl_bad_out, ryl_bad_err) = run_with_env(ryl_bad_cmd, envs);
143
+ let mut yam_bad_cmd = Command::new("yamllint");
144
+ if use_standard_format {
145
+ yam_bad_cmd.arg("-f").arg("standard");
146
+ }
147
+ yam_bad_cmd.arg("-c");
148
+ yam_bad_cmd.arg(&cfg);
149
+ yam_bad_cmd.arg(&bad);
150
+ let (yam_bad_code, yam_bad_out, yam_bad_err) = run_with_env(yam_bad_cmd, envs);
151
+
152
+ assert_ne!(
153
+ ryl_bad_code, 0,
154
+ "ryl should fail for invalid yaml ({label})"
155
+ );
156
+ assert_ne!(
157
+ yam_bad_code, 0,
158
+ "yamllint should fail for invalid yaml ({label})"
159
+ );
160
+
161
+ let r_msg = if !ryl_bad_err.is_empty() {
162
+ ryl_bad_err
163
+ } else {
164
+ ryl_bad_out
165
+ };
166
+ let y_msg = if !yam_bad_out.is_empty() {
167
+ yam_bad_out
168
+ } else {
169
+ yam_bad_err
170
+ };
171
+
172
+ if let (Some((rf, rl, rc)), Some((yf, yl, yc))) =
173
+ (parse_loc(&r_msg, kind), parse_loc(&y_msg, kind))
174
+ {
175
+ assert!(
176
+ rf.ends_with("bad.yaml"),
177
+ "ryl location should reference bad.yaml ({label}): {rf}"
178
+ );
179
+ assert!(
180
+ yf.ends_with("bad.yaml"),
181
+ "yamllint location should reference bad.yaml ({label}): {yf}"
182
+ );
183
+ assert_eq!(rl, yl, "line numbers should match ({label})");
184
+ assert_eq!(rc, yc, "column numbers should match ({label})");
185
+ } else {
186
+ panic!(
187
+ "could not parse location ({label})\nryl:\n{r_msg}\nyamllint:\n{y_msg}"
188
+ );
189
+ }
190
+
191
+ assert!(
192
+ r_msg.contains("syntax error"),
193
+ "ryl output should mention syntax error ({label}): {r_msg}"
194
+ );
195
+ assert!(
196
+ y_msg.contains("syntax error"),
197
+ "yamllint output should mention syntax error ({label}): {y_msg}"
198
+ );
199
+ }
200
+ }
@@ -0,0 +1,162 @@
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 trailing_spaces_rule_matches_yamllint() {
15
+ ensure_yamllint_installed();
16
+
17
+ let dir = tempdir().unwrap();
18
+
19
+ let default_cfg = dir.path().join("trailing-default.yml");
20
+ fs::write(
21
+ &default_cfg,
22
+ "rules:\n document-start: disable\n trailing-spaces: enable\n",
23
+ )
24
+ .unwrap();
25
+
26
+ let warning_cfg = dir.path().join("trailing-warning.yml");
27
+ fs::write(
28
+ &warning_cfg,
29
+ "rules:\n document-start: disable\n trailing-spaces:\n level: warning\n",
30
+ )
31
+ .unwrap();
32
+
33
+ let ignore_cfg = dir.path().join("trailing-ignore.yml");
34
+ fs::write(
35
+ &ignore_cfg,
36
+ "rules:\n document-start: disable\n trailing-spaces:\n ignore:\n - ignored.yaml\n",
37
+ )
38
+ .unwrap();
39
+
40
+ let ignore_list = dir.path().join("trailing-ignore.txt");
41
+ fs::write(&ignore_list, "ignored-from-file.yaml\n").unwrap();
42
+
43
+ let ignore_from_file_cfg = dir.path().join("trailing-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 trailing-spaces:\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, "key: value \n").unwrap();
56
+
57
+ let ignored_file = dir.path().join("ignored.yaml");
58
+ fs::write(&ignored_file, "other: value \n").unwrap();
59
+
60
+ let ignored_from_file = dir.path().join("ignored-from-file.yaml");
61
+ fs::write(&ignored_from_file, "foo: bar \n").unwrap();
62
+
63
+ let exe = env!("CARGO_BIN_EXE_ryl");
64
+
65
+ for scenario in SCENARIOS {
66
+ // default configuration should produce an error
67
+ let mut ryl_default = build_ryl_command(exe, scenario.ryl_format);
68
+ ryl_default.arg("-c").arg(&default_cfg).arg(&bad_file);
69
+ let (ryl_code, ryl_output) = capture_with_env(ryl_default, scenario.envs);
70
+
71
+ let mut yam_default = build_yamllint_command(scenario.yam_format);
72
+ yam_default.arg("-c").arg(&default_cfg).arg(&bad_file);
73
+ let (yam_code, yam_output) = capture_with_env(yam_default, scenario.envs);
74
+
75
+ assert_eq!(ryl_code, 1, "ryl default exit ({})", scenario.label);
76
+ assert_eq!(yam_code, 1, "yamllint default exit ({})", scenario.label);
77
+ assert_eq!(
78
+ ryl_output, yam_output,
79
+ "default diagnostics mismatch ({})",
80
+ scenario.label
81
+ );
82
+
83
+ // warning configuration should keep diagnostics but exit 0
84
+ let mut ryl_warning = build_ryl_command(exe, scenario.ryl_format);
85
+ ryl_warning.arg("-c").arg(&warning_cfg).arg(&bad_file);
86
+ let (ryl_warn_code, ryl_warn_output) =
87
+ capture_with_env(ryl_warning, scenario.envs);
88
+
89
+ let mut yam_warning = build_yamllint_command(scenario.yam_format);
90
+ yam_warning.arg("-c").arg(&warning_cfg).arg(&bad_file);
91
+ let (yam_warn_code, yam_warn_output) =
92
+ capture_with_env(yam_warning, scenario.envs);
93
+
94
+ assert_eq!(ryl_warn_code, 0, "ryl warning exit ({})", scenario.label);
95
+ assert_eq!(
96
+ yam_warn_code, 0,
97
+ "yamllint warning exit ({})",
98
+ scenario.label
99
+ );
100
+ assert_eq!(
101
+ ryl_warn_output, yam_warn_output,
102
+ "warning diagnostics mismatch ({})",
103
+ scenario.label
104
+ );
105
+
106
+ // ignore pattern applied through inline config should skip diagnostics
107
+ let mut ryl_ignore = build_ryl_command(exe, scenario.ryl_format);
108
+ ryl_ignore.arg("-c").arg(&ignore_cfg).arg(&ignored_file);
109
+ let (ryl_ignore_code, ryl_ignore_output) =
110
+ capture_with_env(ryl_ignore, scenario.envs);
111
+
112
+ let mut yam_ignore = build_yamllint_command(scenario.yam_format);
113
+ yam_ignore.arg("-c").arg(&ignore_cfg).arg(&ignored_file);
114
+ let (yam_ignore_code, yam_ignore_output) =
115
+ capture_with_env(yam_ignore, scenario.envs);
116
+
117
+ assert_eq!(ryl_ignore_code, 0, "ryl ignore exit ({})", scenario.label);
118
+ assert_eq!(
119
+ yam_ignore_code, 0,
120
+ "yamllint ignore exit ({})",
121
+ scenario.label
122
+ );
123
+ assert_eq!(
124
+ ryl_ignore_output, yam_ignore_output,
125
+ "ignore diagnostics mismatch ({})",
126
+ scenario.label
127
+ );
128
+
129
+ // ignore-from-file should behave the same
130
+ let mut ryl_ignore_file = build_ryl_command(exe, scenario.ryl_format);
131
+ ryl_ignore_file
132
+ .arg("-c")
133
+ .arg(&ignore_from_file_cfg)
134
+ .arg(&ignored_from_file);
135
+ let (ryl_file_code, ryl_file_output) =
136
+ capture_with_env(ryl_ignore_file, scenario.envs);
137
+
138
+ let mut yam_ignore_file = build_yamllint_command(scenario.yam_format);
139
+ yam_ignore_file
140
+ .arg("-c")
141
+ .arg(&ignore_from_file_cfg)
142
+ .arg(&ignored_from_file);
143
+ let (yam_file_code, yam_file_output) =
144
+ capture_with_env(yam_ignore_file, scenario.envs);
145
+
146
+ assert_eq!(
147
+ ryl_file_code, 0,
148
+ "ryl ignore-from-file exit ({})",
149
+ scenario.label
150
+ );
151
+ assert_eq!(
152
+ yam_file_code, 0,
153
+ "yamllint ignore-from-file exit ({})",
154
+ scenario.label
155
+ );
156
+ assert_eq!(
157
+ ryl_file_output, yam_file_output,
158
+ "ignore-from-file diagnostics mismatch ({})",
159
+ scenario.label
160
+ );
161
+ }
162
+ }
@@ -0,0 +1,130 @@
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 truthy_rule_matches_yamllint() {
15
+ ensure_yamllint_installed();
16
+
17
+ let dir = tempdir().unwrap();
18
+
19
+ let default_cfg = dir.path().join("truthy-default.yml");
20
+ fs::write(
21
+ &default_cfg,
22
+ "rules:\n document-start: disable\n truthy: enable\n",
23
+ )
24
+ .unwrap();
25
+
26
+ let allowed_cfg = dir.path().join("truthy-allowed.yml");
27
+ fs::write(
28
+ &allowed_cfg,
29
+ "rules:\n document-start: disable\n truthy:\n allowed-values: [\"yes\", \"no\"]\n",
30
+ )
31
+ .unwrap();
32
+
33
+ let check_keys_cfg = dir.path().join("truthy-check-keys.yml");
34
+ fs::write(
35
+ &check_keys_cfg,
36
+ "rules:\n document-start: disable\n truthy:\n allowed-values: []\n check-keys: false\n",
37
+ )
38
+ .unwrap();
39
+
40
+ let bad_file = dir.path().join("bad.yaml");
41
+ fs::write(&bad_file, "foo: True\nbar: yes\nTrue: 1\non: off\n").unwrap();
42
+
43
+ let allowed_file = dir.path().join("allowed.yaml");
44
+ fs::write(&allowed_file, "- yes\n- no\n- true\n- on\n").unwrap();
45
+
46
+ let ok_file = dir.path().join("ok.yaml");
47
+ fs::write(&ok_file, "foo: false\nbar: true\n").unwrap();
48
+
49
+ let exe = env!("CARGO_BIN_EXE_ryl");
50
+
51
+ for scenario in SCENARIOS {
52
+ // default configuration, expect errors on keys and values
53
+ let mut ryl_default = build_ryl_command(exe, scenario.ryl_format);
54
+ ryl_default.arg("-c").arg(&default_cfg).arg(&bad_file);
55
+ let (ryl_code, ryl_msg) = capture_with_env(ryl_default, scenario.envs);
56
+
57
+ let mut yam_default = build_yamllint_command(scenario.yam_format);
58
+ yam_default.arg("-c").arg(&default_cfg).arg(&bad_file);
59
+ let (yam_code, yam_msg) = capture_with_env(yam_default, scenario.envs);
60
+
61
+ assert_eq!(ryl_code, 1, "ryl default exit ({})", scenario.label);
62
+ assert_eq!(yam_code, 1, "yamllint default exit ({})", scenario.label);
63
+ assert_eq!(
64
+ ryl_msg, yam_msg,
65
+ "default diagnostics mismatch ({})",
66
+ scenario.label
67
+ );
68
+
69
+ // allowed-values override keeps yes/no allowed
70
+ let mut ryl_allowed = build_ryl_command(exe, scenario.ryl_format);
71
+ ryl_allowed.arg("-c").arg(&allowed_cfg).arg(&allowed_file);
72
+ let (ryl_allowed_code, ryl_allowed_msg) =
73
+ capture_with_env(ryl_allowed, scenario.envs);
74
+
75
+ let mut yam_allowed = build_yamllint_command(scenario.yam_format);
76
+ yam_allowed.arg("-c").arg(&allowed_cfg).arg(&allowed_file);
77
+ let (yam_allowed_code, yam_allowed_msg) =
78
+ capture_with_env(yam_allowed, scenario.envs);
79
+
80
+ assert_eq!(ryl_allowed_code, 1, "ryl allowed exit ({})", scenario.label);
81
+ assert_eq!(
82
+ yam_allowed_code, 1,
83
+ "yamllint allowed exit ({})",
84
+ scenario.label
85
+ );
86
+ assert_eq!(
87
+ ryl_allowed_msg, yam_allowed_msg,
88
+ "allowed diagnostics mismatch ({})",
89
+ scenario.label
90
+ );
91
+
92
+ // check-keys=false should suppress key diagnostics
93
+ let mut ryl_check_keys = build_ryl_command(exe, scenario.ryl_format);
94
+ ryl_check_keys.arg("-c").arg(&check_keys_cfg).arg(&bad_file);
95
+ let (ryl_ck_code, ryl_ck_msg) = capture_with_env(ryl_check_keys, scenario.envs);
96
+
97
+ let mut yam_check_keys = build_yamllint_command(scenario.yam_format);
98
+ yam_check_keys.arg("-c").arg(&check_keys_cfg).arg(&bad_file);
99
+ let (yam_ck_code, yam_ck_msg) = capture_with_env(yam_check_keys, scenario.envs);
100
+
101
+ assert_eq!(ryl_ck_code, 1, "ryl check-keys exit ({})", scenario.label);
102
+ assert_eq!(
103
+ yam_ck_code, 1,
104
+ "yamllint check-keys exit ({})",
105
+ scenario.label
106
+ );
107
+ assert_eq!(
108
+ ryl_ck_msg, yam_ck_msg,
109
+ "check-keys diagnostics mismatch ({})",
110
+ scenario.label
111
+ );
112
+
113
+ // success scenario: default config but compliant file
114
+ let mut ryl_ok = build_ryl_command(exe, scenario.ryl_format);
115
+ ryl_ok.arg("-c").arg(&default_cfg).arg(&ok_file);
116
+ let (ryl_ok_code, ryl_ok_msg) = capture_with_env(ryl_ok, scenario.envs);
117
+
118
+ let mut yam_ok = build_yamllint_command(scenario.yam_format);
119
+ yam_ok.arg("-c").arg(&default_cfg).arg(&ok_file);
120
+ let (yam_ok_code, yam_ok_msg) = capture_with_env(yam_ok, scenario.envs);
121
+
122
+ assert_eq!(ryl_ok_code, 0, "ryl ok exit ({})", scenario.label);
123
+ assert_eq!(yam_ok_code, 0, "yamllint ok exit ({})", scenario.label);
124
+ assert_eq!(
125
+ ryl_ok_msg, yam_ok_msg,
126
+ "ok diagnostics mismatch ({})",
127
+ scenario.label
128
+ );
129
+ }
130
+ }