@owenlamont/ryl 0.4.1 → 0.4.3

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/README.md +13 -0
  2. package/bin/ryl.js +96 -1
  3. package/npm-platforms.json +124 -0
  4. package/package.json +46 -12
  5. package/.github/CODEOWNERS +0 -1
  6. package/.github/dependabot.yml +0 -13
  7. package/.github/workflows/ci.yml +0 -107
  8. package/.github/workflows/release.yml +0 -613
  9. package/.github/workflows/update_dependencies.yml +0 -61
  10. package/.github/workflows/update_linters.yml +0 -56
  11. package/.pre-commit-config.yaml +0 -87
  12. package/.yamllint +0 -4
  13. package/AGENTS.md +0 -200
  14. package/Cargo.lock +0 -908
  15. package/Cargo.toml +0 -32
  16. package/clippy.toml +0 -1
  17. package/docs/config-presets.md +0 -100
  18. package/img/benchmark-5x5-5runs.svg +0 -2176
  19. package/pyproject.toml +0 -42
  20. package/ruff.toml +0 -107
  21. package/rumdl.toml +0 -20
  22. package/rust-toolchain.toml +0 -3
  23. package/rustfmt.toml +0 -3
  24. package/scripts/benchmark_perf_vs_yamllint.py +0 -400
  25. package/scripts/coverage-missing.ps1 +0 -80
  26. package/scripts/coverage-missing.sh +0 -60
  27. package/src/bin/discover_config_bin.rs +0 -24
  28. package/src/cli_support.rs +0 -33
  29. package/src/conf/mod.rs +0 -85
  30. package/src/config.rs +0 -2099
  31. package/src/decoder.rs +0 -326
  32. package/src/discover.rs +0 -31
  33. package/src/lib.rs +0 -19
  34. package/src/lint.rs +0 -558
  35. package/src/main.rs +0 -535
  36. package/src/migrate.rs +0 -233
  37. package/src/rules/anchors.rs +0 -517
  38. package/src/rules/braces.rs +0 -77
  39. package/src/rules/brackets.rs +0 -77
  40. package/src/rules/colons.rs +0 -475
  41. package/src/rules/commas.rs +0 -372
  42. package/src/rules/comments.rs +0 -299
  43. package/src/rules/comments_indentation.rs +0 -243
  44. package/src/rules/document_end.rs +0 -175
  45. package/src/rules/document_start.rs +0 -84
  46. package/src/rules/empty_lines.rs +0 -152
  47. package/src/rules/empty_values.rs +0 -255
  48. package/src/rules/float_values.rs +0 -259
  49. package/src/rules/flow_collection.rs +0 -562
  50. package/src/rules/hyphens.rs +0 -104
  51. package/src/rules/indentation.rs +0 -803
  52. package/src/rules/key_duplicates.rs +0 -218
  53. package/src/rules/key_ordering.rs +0 -303
  54. package/src/rules/line_length.rs +0 -326
  55. package/src/rules/mod.rs +0 -25
  56. package/src/rules/new_line_at_end_of_file.rs +0 -23
  57. package/src/rules/new_lines.rs +0 -95
  58. package/src/rules/octal_values.rs +0 -121
  59. package/src/rules/quoted_strings.rs +0 -577
  60. package/src/rules/span_utils.rs +0 -37
  61. package/src/rules/trailing_spaces.rs +0 -65
  62. package/src/rules/truthy.rs +0 -420
  63. package/tests/brackets_carriage_return.rs +0 -114
  64. package/tests/build_global_cfg_error.rs +0 -23
  65. package/tests/cli_anchors_rule.rs +0 -143
  66. package/tests/cli_braces_rule.rs +0 -104
  67. package/tests/cli_brackets_rule.rs +0 -104
  68. package/tests/cli_colons_rule.rs +0 -65
  69. package/tests/cli_commas_rule.rs +0 -104
  70. package/tests/cli_comments_indentation_rule.rs +0 -61
  71. package/tests/cli_comments_rule.rs +0 -67
  72. package/tests/cli_config_data_error.rs +0 -30
  73. package/tests/cli_config_flags.rs +0 -66
  74. package/tests/cli_config_migrate.rs +0 -229
  75. package/tests/cli_document_end_rule.rs +0 -92
  76. package/tests/cli_document_start_rule.rs +0 -92
  77. package/tests/cli_empty_lines_rule.rs +0 -87
  78. package/tests/cli_empty_values_rule.rs +0 -68
  79. package/tests/cli_env_config.rs +0 -34
  80. package/tests/cli_exit_and_errors.rs +0 -41
  81. package/tests/cli_file_encoding.rs +0 -203
  82. package/tests/cli_float_values_rule.rs +0 -64
  83. package/tests/cli_format_options.rs +0 -316
  84. package/tests/cli_global_cfg_relaxed.rs +0 -20
  85. package/tests/cli_hyphens_rule.rs +0 -104
  86. package/tests/cli_indentation_rule.rs +0 -65
  87. package/tests/cli_invalid_project_config.rs +0 -39
  88. package/tests/cli_key_duplicates_rule.rs +0 -104
  89. package/tests/cli_key_ordering_rule.rs +0 -59
  90. package/tests/cli_line_length_rule.rs +0 -85
  91. package/tests/cli_list_files.rs +0 -29
  92. package/tests/cli_new_line_rule.rs +0 -141
  93. package/tests/cli_new_lines_rule.rs +0 -119
  94. package/tests/cli_octal_values_rule.rs +0 -60
  95. package/tests/cli_quoted_strings_rule.rs +0 -47
  96. package/tests/cli_toml_config.rs +0 -119
  97. package/tests/cli_trailing_spaces_rule.rs +0 -77
  98. package/tests/cli_truthy_rule.rs +0 -83
  99. package/tests/cli_yaml_files_negation.rs +0 -45
  100. package/tests/colons_rule.rs +0 -303
  101. package/tests/common/compat.rs +0 -114
  102. package/tests/common/fake_env.rs +0 -93
  103. package/tests/common/mod.rs +0 -1
  104. package/tests/conf_builtin.rs +0 -9
  105. package/tests/config_anchors.rs +0 -84
  106. package/tests/config_braces.rs +0 -121
  107. package/tests/config_brackets.rs +0 -127
  108. package/tests/config_commas.rs +0 -79
  109. package/tests/config_comments.rs +0 -65
  110. package/tests/config_comments_indentation.rs +0 -20
  111. package/tests/config_deep_merge_nonstring_key.rs +0 -24
  112. package/tests/config_document_end.rs +0 -54
  113. package/tests/config_document_start.rs +0 -55
  114. package/tests/config_empty_lines.rs +0 -48
  115. package/tests/config_empty_values.rs +0 -35
  116. package/tests/config_env_errors.rs +0 -23
  117. package/tests/config_env_invalid_inline.rs +0 -15
  118. package/tests/config_env_missing.rs +0 -63
  119. package/tests/config_env_shim.rs +0 -301
  120. package/tests/config_explicit_file_parse_error.rs +0 -55
  121. package/tests/config_extended_features.rs +0 -225
  122. package/tests/config_extends_inline.rs +0 -185
  123. package/tests/config_extends_sequence.rs +0 -18
  124. package/tests/config_find_project_home_boundary.rs +0 -54
  125. package/tests/config_find_project_two_files_in_cwd.rs +0 -47
  126. package/tests/config_float_values.rs +0 -34
  127. package/tests/config_from_yaml_paths.rs +0 -32
  128. package/tests/config_hyphens.rs +0 -51
  129. package/tests/config_ignore_errors.rs +0 -243
  130. package/tests/config_ignore_overrides.rs +0 -83
  131. package/tests/config_indentation.rs +0 -65
  132. package/tests/config_invalid_globs.rs +0 -16
  133. package/tests/config_invalid_types.rs +0 -19
  134. package/tests/config_key_duplicates.rs +0 -34
  135. package/tests/config_key_ordering.rs +0 -70
  136. package/tests/config_line_length.rs +0 -65
  137. package/tests/config_locale.rs +0 -111
  138. package/tests/config_merge.rs +0 -26
  139. package/tests/config_new_lines.rs +0 -89
  140. package/tests/config_octal_values.rs +0 -33
  141. package/tests/config_quoted_strings.rs +0 -195
  142. package/tests/config_rule_level.rs +0 -147
  143. package/tests/config_rules_non_string_keys.rs +0 -23
  144. package/tests/config_scalar_overrides.rs +0 -27
  145. package/tests/config_to_toml.rs +0 -110
  146. package/tests/config_toml_coverage.rs +0 -80
  147. package/tests/config_toml_discovery.rs +0 -304
  148. package/tests/config_trailing_spaces.rs +0 -152
  149. package/tests/config_truthy.rs +0 -77
  150. package/tests/config_yaml_files.rs +0 -62
  151. package/tests/config_yaml_files_all_non_string.rs +0 -15
  152. package/tests/config_yaml_files_empty.rs +0 -30
  153. package/tests/coverage_commas.rs +0 -46
  154. package/tests/decoder_decode.rs +0 -338
  155. package/tests/discover_config_bin_all.rs +0 -66
  156. package/tests/discover_config_bin_env_invalid_yaml.rs +0 -26
  157. package/tests/discover_config_bin_project_config_parse_error.rs +0 -24
  158. package/tests/discover_config_bin_user_global_error.rs +0 -26
  159. package/tests/discover_module.rs +0 -30
  160. package/tests/discover_per_file_dir.rs +0 -10
  161. package/tests/discover_per_file_project_config_error.rs +0 -21
  162. package/tests/float_values.rs +0 -43
  163. package/tests/lint_multi_errors.rs +0 -32
  164. package/tests/main_yaml_ok_filtering.rs +0 -30
  165. package/tests/migrate_module.rs +0 -259
  166. package/tests/resolve_ctx_empty_parent.rs +0 -16
  167. package/tests/rule_anchors.rs +0 -442
  168. package/tests/rule_braces.rs +0 -258
  169. package/tests/rule_brackets.rs +0 -217
  170. package/tests/rule_commas.rs +0 -205
  171. package/tests/rule_comments.rs +0 -197
  172. package/tests/rule_comments_indentation.rs +0 -127
  173. package/tests/rule_document_end.rs +0 -118
  174. package/tests/rule_document_start.rs +0 -60
  175. package/tests/rule_empty_lines.rs +0 -96
  176. package/tests/rule_empty_values.rs +0 -102
  177. package/tests/rule_float_values.rs +0 -109
  178. package/tests/rule_hyphens.rs +0 -65
  179. package/tests/rule_indentation.rs +0 -455
  180. package/tests/rule_key_duplicates.rs +0 -76
  181. package/tests/rule_key_ordering.rs +0 -207
  182. package/tests/rule_line_length.rs +0 -200
  183. package/tests/rule_new_lines.rs +0 -51
  184. package/tests/rule_octal_values.rs +0 -53
  185. package/tests/rule_quoted_strings.rs +0 -290
  186. package/tests/rule_trailing_spaces.rs +0 -41
  187. package/tests/rule_truthy.rs +0 -236
  188. package/tests/user_global_invalid_yaml.rs +0 -32
  189. package/tests/yamllint_compat_anchors.rs +0 -280
  190. package/tests/yamllint_compat_braces.rs +0 -411
  191. package/tests/yamllint_compat_brackets.rs +0 -364
  192. package/tests/yamllint_compat_colons.rs +0 -298
  193. package/tests/yamllint_compat_colors.rs +0 -80
  194. package/tests/yamllint_compat_commas.rs +0 -375
  195. package/tests/yamllint_compat_comments.rs +0 -167
  196. package/tests/yamllint_compat_comments_indentation.rs +0 -281
  197. package/tests/yamllint_compat_config.rs +0 -170
  198. package/tests/yamllint_compat_document_end.rs +0 -243
  199. package/tests/yamllint_compat_document_start.rs +0 -136
  200. package/tests/yamllint_compat_empty_lines.rs +0 -117
  201. package/tests/yamllint_compat_empty_values.rs +0 -179
  202. package/tests/yamllint_compat_float_values.rs +0 -216
  203. package/tests/yamllint_compat_hyphens.rs +0 -223
  204. package/tests/yamllint_compat_indentation.rs +0 -398
  205. package/tests/yamllint_compat_key_duplicates.rs +0 -139
  206. package/tests/yamllint_compat_key_ordering.rs +0 -170
  207. package/tests/yamllint_compat_line_length.rs +0 -375
  208. package/tests/yamllint_compat_list.rs +0 -127
  209. package/tests/yamllint_compat_new_line.rs +0 -133
  210. package/tests/yamllint_compat_newline_types.rs +0 -185
  211. package/tests/yamllint_compat_octal_values.rs +0 -172
  212. package/tests/yamllint_compat_quoted_strings.rs +0 -154
  213. package/tests/yamllint_compat_syntax.rs +0 -200
  214. package/tests/yamllint_compat_trailing_spaces.rs +0 -162
  215. package/tests/yamllint_compat_truthy.rs +0 -130
  216. package/tests/yamllint_compat_yaml_files.rs +0 -81
  217. package/typos.toml +0 -2
@@ -1,154 +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
- 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
- }
@@ -1,200 +0,0 @@
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
- }
@@ -1,162 +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 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
- }
@@ -1,130 +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 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
- }