@owenlamont/ryl 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (216) hide show
  1. package/README.md +13 -0
  2. package/bin/ryl.js +195 -1
  3. package/package.json +35 -13
  4. package/.github/CODEOWNERS +0 -1
  5. package/.github/dependabot.yml +0 -13
  6. package/.github/workflows/ci.yml +0 -107
  7. package/.github/workflows/release.yml +0 -613
  8. package/.github/workflows/update_dependencies.yml +0 -61
  9. package/.github/workflows/update_linters.yml +0 -56
  10. package/.pre-commit-config.yaml +0 -87
  11. package/.yamllint +0 -4
  12. package/AGENTS.md +0 -200
  13. package/Cargo.lock +0 -908
  14. package/Cargo.toml +0 -32
  15. package/clippy.toml +0 -1
  16. package/docs/config-presets.md +0 -100
  17. package/img/benchmark-5x5-5runs.svg +0 -2176
  18. package/pyproject.toml +0 -42
  19. package/ruff.toml +0 -107
  20. package/rumdl.toml +0 -20
  21. package/rust-toolchain.toml +0 -3
  22. package/rustfmt.toml +0 -3
  23. package/scripts/benchmark_perf_vs_yamllint.py +0 -400
  24. package/scripts/coverage-missing.ps1 +0 -80
  25. package/scripts/coverage-missing.sh +0 -60
  26. package/src/bin/discover_config_bin.rs +0 -24
  27. package/src/cli_support.rs +0 -33
  28. package/src/conf/mod.rs +0 -85
  29. package/src/config.rs +0 -2099
  30. package/src/decoder.rs +0 -326
  31. package/src/discover.rs +0 -31
  32. package/src/lib.rs +0 -19
  33. package/src/lint.rs +0 -558
  34. package/src/main.rs +0 -535
  35. package/src/migrate.rs +0 -233
  36. package/src/rules/anchors.rs +0 -517
  37. package/src/rules/braces.rs +0 -77
  38. package/src/rules/brackets.rs +0 -77
  39. package/src/rules/colons.rs +0 -475
  40. package/src/rules/commas.rs +0 -372
  41. package/src/rules/comments.rs +0 -299
  42. package/src/rules/comments_indentation.rs +0 -243
  43. package/src/rules/document_end.rs +0 -175
  44. package/src/rules/document_start.rs +0 -84
  45. package/src/rules/empty_lines.rs +0 -152
  46. package/src/rules/empty_values.rs +0 -255
  47. package/src/rules/float_values.rs +0 -259
  48. package/src/rules/flow_collection.rs +0 -562
  49. package/src/rules/hyphens.rs +0 -104
  50. package/src/rules/indentation.rs +0 -803
  51. package/src/rules/key_duplicates.rs +0 -218
  52. package/src/rules/key_ordering.rs +0 -303
  53. package/src/rules/line_length.rs +0 -326
  54. package/src/rules/mod.rs +0 -25
  55. package/src/rules/new_line_at_end_of_file.rs +0 -23
  56. package/src/rules/new_lines.rs +0 -95
  57. package/src/rules/octal_values.rs +0 -121
  58. package/src/rules/quoted_strings.rs +0 -577
  59. package/src/rules/span_utils.rs +0 -37
  60. package/src/rules/trailing_spaces.rs +0 -65
  61. package/src/rules/truthy.rs +0 -420
  62. package/tests/brackets_carriage_return.rs +0 -114
  63. package/tests/build_global_cfg_error.rs +0 -23
  64. package/tests/cli_anchors_rule.rs +0 -143
  65. package/tests/cli_braces_rule.rs +0 -104
  66. package/tests/cli_brackets_rule.rs +0 -104
  67. package/tests/cli_colons_rule.rs +0 -65
  68. package/tests/cli_commas_rule.rs +0 -104
  69. package/tests/cli_comments_indentation_rule.rs +0 -61
  70. package/tests/cli_comments_rule.rs +0 -67
  71. package/tests/cli_config_data_error.rs +0 -30
  72. package/tests/cli_config_flags.rs +0 -66
  73. package/tests/cli_config_migrate.rs +0 -229
  74. package/tests/cli_document_end_rule.rs +0 -92
  75. package/tests/cli_document_start_rule.rs +0 -92
  76. package/tests/cli_empty_lines_rule.rs +0 -87
  77. package/tests/cli_empty_values_rule.rs +0 -68
  78. package/tests/cli_env_config.rs +0 -34
  79. package/tests/cli_exit_and_errors.rs +0 -41
  80. package/tests/cli_file_encoding.rs +0 -203
  81. package/tests/cli_float_values_rule.rs +0 -64
  82. package/tests/cli_format_options.rs +0 -316
  83. package/tests/cli_global_cfg_relaxed.rs +0 -20
  84. package/tests/cli_hyphens_rule.rs +0 -104
  85. package/tests/cli_indentation_rule.rs +0 -65
  86. package/tests/cli_invalid_project_config.rs +0 -39
  87. package/tests/cli_key_duplicates_rule.rs +0 -104
  88. package/tests/cli_key_ordering_rule.rs +0 -59
  89. package/tests/cli_line_length_rule.rs +0 -85
  90. package/tests/cli_list_files.rs +0 -29
  91. package/tests/cli_new_line_rule.rs +0 -141
  92. package/tests/cli_new_lines_rule.rs +0 -119
  93. package/tests/cli_octal_values_rule.rs +0 -60
  94. package/tests/cli_quoted_strings_rule.rs +0 -47
  95. package/tests/cli_toml_config.rs +0 -119
  96. package/tests/cli_trailing_spaces_rule.rs +0 -77
  97. package/tests/cli_truthy_rule.rs +0 -83
  98. package/tests/cli_yaml_files_negation.rs +0 -45
  99. package/tests/colons_rule.rs +0 -303
  100. package/tests/common/compat.rs +0 -114
  101. package/tests/common/fake_env.rs +0 -93
  102. package/tests/common/mod.rs +0 -1
  103. package/tests/conf_builtin.rs +0 -9
  104. package/tests/config_anchors.rs +0 -84
  105. package/tests/config_braces.rs +0 -121
  106. package/tests/config_brackets.rs +0 -127
  107. package/tests/config_commas.rs +0 -79
  108. package/tests/config_comments.rs +0 -65
  109. package/tests/config_comments_indentation.rs +0 -20
  110. package/tests/config_deep_merge_nonstring_key.rs +0 -24
  111. package/tests/config_document_end.rs +0 -54
  112. package/tests/config_document_start.rs +0 -55
  113. package/tests/config_empty_lines.rs +0 -48
  114. package/tests/config_empty_values.rs +0 -35
  115. package/tests/config_env_errors.rs +0 -23
  116. package/tests/config_env_invalid_inline.rs +0 -15
  117. package/tests/config_env_missing.rs +0 -63
  118. package/tests/config_env_shim.rs +0 -301
  119. package/tests/config_explicit_file_parse_error.rs +0 -55
  120. package/tests/config_extended_features.rs +0 -225
  121. package/tests/config_extends_inline.rs +0 -185
  122. package/tests/config_extends_sequence.rs +0 -18
  123. package/tests/config_find_project_home_boundary.rs +0 -54
  124. package/tests/config_find_project_two_files_in_cwd.rs +0 -47
  125. package/tests/config_float_values.rs +0 -34
  126. package/tests/config_from_yaml_paths.rs +0 -32
  127. package/tests/config_hyphens.rs +0 -51
  128. package/tests/config_ignore_errors.rs +0 -243
  129. package/tests/config_ignore_overrides.rs +0 -83
  130. package/tests/config_indentation.rs +0 -65
  131. package/tests/config_invalid_globs.rs +0 -16
  132. package/tests/config_invalid_types.rs +0 -19
  133. package/tests/config_key_duplicates.rs +0 -34
  134. package/tests/config_key_ordering.rs +0 -70
  135. package/tests/config_line_length.rs +0 -65
  136. package/tests/config_locale.rs +0 -111
  137. package/tests/config_merge.rs +0 -26
  138. package/tests/config_new_lines.rs +0 -89
  139. package/tests/config_octal_values.rs +0 -33
  140. package/tests/config_quoted_strings.rs +0 -195
  141. package/tests/config_rule_level.rs +0 -147
  142. package/tests/config_rules_non_string_keys.rs +0 -23
  143. package/tests/config_scalar_overrides.rs +0 -27
  144. package/tests/config_to_toml.rs +0 -110
  145. package/tests/config_toml_coverage.rs +0 -80
  146. package/tests/config_toml_discovery.rs +0 -304
  147. package/tests/config_trailing_spaces.rs +0 -152
  148. package/tests/config_truthy.rs +0 -77
  149. package/tests/config_yaml_files.rs +0 -62
  150. package/tests/config_yaml_files_all_non_string.rs +0 -15
  151. package/tests/config_yaml_files_empty.rs +0 -30
  152. package/tests/coverage_commas.rs +0 -46
  153. package/tests/decoder_decode.rs +0 -338
  154. package/tests/discover_config_bin_all.rs +0 -66
  155. package/tests/discover_config_bin_env_invalid_yaml.rs +0 -26
  156. package/tests/discover_config_bin_project_config_parse_error.rs +0 -24
  157. package/tests/discover_config_bin_user_global_error.rs +0 -26
  158. package/tests/discover_module.rs +0 -30
  159. package/tests/discover_per_file_dir.rs +0 -10
  160. package/tests/discover_per_file_project_config_error.rs +0 -21
  161. package/tests/float_values.rs +0 -43
  162. package/tests/lint_multi_errors.rs +0 -32
  163. package/tests/main_yaml_ok_filtering.rs +0 -30
  164. package/tests/migrate_module.rs +0 -259
  165. package/tests/resolve_ctx_empty_parent.rs +0 -16
  166. package/tests/rule_anchors.rs +0 -442
  167. package/tests/rule_braces.rs +0 -258
  168. package/tests/rule_brackets.rs +0 -217
  169. package/tests/rule_commas.rs +0 -205
  170. package/tests/rule_comments.rs +0 -197
  171. package/tests/rule_comments_indentation.rs +0 -127
  172. package/tests/rule_document_end.rs +0 -118
  173. package/tests/rule_document_start.rs +0 -60
  174. package/tests/rule_empty_lines.rs +0 -96
  175. package/tests/rule_empty_values.rs +0 -102
  176. package/tests/rule_float_values.rs +0 -109
  177. package/tests/rule_hyphens.rs +0 -65
  178. package/tests/rule_indentation.rs +0 -455
  179. package/tests/rule_key_duplicates.rs +0 -76
  180. package/tests/rule_key_ordering.rs +0 -207
  181. package/tests/rule_line_length.rs +0 -200
  182. package/tests/rule_new_lines.rs +0 -51
  183. package/tests/rule_octal_values.rs +0 -53
  184. package/tests/rule_quoted_strings.rs +0 -290
  185. package/tests/rule_trailing_spaces.rs +0 -41
  186. package/tests/rule_truthy.rs +0 -236
  187. package/tests/user_global_invalid_yaml.rs +0 -32
  188. package/tests/yamllint_compat_anchors.rs +0 -280
  189. package/tests/yamllint_compat_braces.rs +0 -411
  190. package/tests/yamllint_compat_brackets.rs +0 -364
  191. package/tests/yamllint_compat_colons.rs +0 -298
  192. package/tests/yamllint_compat_colors.rs +0 -80
  193. package/tests/yamllint_compat_commas.rs +0 -375
  194. package/tests/yamllint_compat_comments.rs +0 -167
  195. package/tests/yamllint_compat_comments_indentation.rs +0 -281
  196. package/tests/yamllint_compat_config.rs +0 -170
  197. package/tests/yamllint_compat_document_end.rs +0 -243
  198. package/tests/yamllint_compat_document_start.rs +0 -136
  199. package/tests/yamllint_compat_empty_lines.rs +0 -117
  200. package/tests/yamllint_compat_empty_values.rs +0 -179
  201. package/tests/yamllint_compat_float_values.rs +0 -216
  202. package/tests/yamllint_compat_hyphens.rs +0 -223
  203. package/tests/yamllint_compat_indentation.rs +0 -398
  204. package/tests/yamllint_compat_key_duplicates.rs +0 -139
  205. package/tests/yamllint_compat_key_ordering.rs +0 -170
  206. package/tests/yamllint_compat_line_length.rs +0 -375
  207. package/tests/yamllint_compat_list.rs +0 -127
  208. package/tests/yamllint_compat_new_line.rs +0 -133
  209. package/tests/yamllint_compat_newline_types.rs +0 -185
  210. package/tests/yamllint_compat_octal_values.rs +0 -172
  211. package/tests/yamllint_compat_quoted_strings.rs +0 -154
  212. package/tests/yamllint_compat_syntax.rs +0 -200
  213. package/tests/yamllint_compat_trailing_spaces.rs +0 -162
  214. package/tests/yamllint_compat_truthy.rs +0 -130
  215. package/tests/yamllint_compat_yaml_files.rs +0 -81
  216. package/typos.toml +0 -2
@@ -1,290 +0,0 @@
1
- use ryl::config::YamlLintConfig;
2
- use ryl::rules::quoted_strings::{self, Config};
3
-
4
- fn build_config(yaml: &str) -> Config {
5
- let cfg = YamlLintConfig::from_yaml_str(yaml).expect("config should parse");
6
- Config::resolve(&cfg)
7
- }
8
-
9
- #[test]
10
- fn required_true_flags_plain_values() {
11
- let cfg =
12
- build_config("rules:\n document-start: disable\n quoted-strings: enable\n");
13
- let hits = quoted_strings::check("foo: bar\n", &cfg);
14
- assert_eq!(hits.len(), 1);
15
- assert_eq!(hits[0].line, 1);
16
- assert_eq!(hits[0].column, 6);
17
- assert_eq!(
18
- hits[0].message,
19
- "string value is not quoted with any quotes"
20
- );
21
- }
22
-
23
- #[test]
24
- fn quote_type_single_requires_single_quotes() {
25
- let cfg = build_config(
26
- "rules:\n document-start: disable\n quoted-strings:\n quote-type: single\n",
27
- );
28
- let hits = quoted_strings::check("foo: \"bar\"\n", &cfg);
29
- assert_eq!(hits.len(), 1);
30
- assert_eq!(
31
- hits[0].message,
32
- "string value is not quoted with single quotes"
33
- );
34
- }
35
-
36
- #[test]
37
- fn non_string_plain_values_are_ignored() {
38
- let cfg =
39
- build_config("rules:\n document-start: disable\n quoted-strings: enable\n");
40
- let hits = quoted_strings::check("foo: 123\n", &cfg);
41
- assert!(hits.is_empty(), "numeric scalars should be skipped");
42
- }
43
-
44
- #[test]
45
- fn required_false_respects_extra_required() {
46
- let cfg = build_config(
47
- "rules:\n document-start: disable\n quoted-strings:\n required: false\n extra-required: ['^http']\n",
48
- );
49
- let hits = quoted_strings::check("- http://example.com\n", &cfg);
50
- assert_eq!(hits.len(), 1);
51
- assert_eq!(hits[0].message, "string value is not quoted");
52
- }
53
-
54
- #[test]
55
- fn only_when_needed_flags_redundant_quotes() {
56
- let cfg = build_config(
57
- "rules:\n document-start: disable\n quoted-strings:\n required: only-when-needed\n",
58
- );
59
- let hits = quoted_strings::check("foo: \"bar\"\n", &cfg);
60
- assert_eq!(hits.len(), 1);
61
- assert_eq!(
62
- hits[0].message,
63
- "string value is redundantly quoted with any quotes"
64
- );
65
- }
66
-
67
- #[test]
68
- fn only_when_needed_respects_extra_allowed() {
69
- let cfg = build_config(
70
- "rules:\n document-start: disable\n quoted-strings:\n required: only-when-needed\n extra-allowed: ['^http']\n",
71
- );
72
- let hits = quoted_strings::check("foo: \"http://example\"\n", &cfg);
73
- assert!(hits.is_empty(), "quoted URL should be allowed");
74
- }
75
-
76
- #[test]
77
- fn required_false_flags_mismatched_quotes() {
78
- let cfg = build_config(
79
- "rules:\n document-start: disable\n quoted-strings:\n required: false\n quote-type: single\n",
80
- );
81
- let hits = quoted_strings::check("foo: \"bar\"\n", &cfg);
82
- assert_eq!(hits.len(), 1);
83
- assert!(hits[0].message.contains("single quotes"));
84
- }
85
-
86
- #[test]
87
- fn only_when_needed_extra_required_enforces_quoting() {
88
- let cfg = build_config(
89
- "rules:\n document-start: disable\n quoted-strings:\n required: only-when-needed\n extra-required: ['^foo']\n",
90
- );
91
- let hits = quoted_strings::check("foo: foo\n", &cfg);
92
- assert_eq!(hits.len(), 1);
93
- assert!(hits[0].message.contains("not quoted"));
94
- }
95
-
96
- #[test]
97
- fn only_when_needed_flags_mismatched_quote_type() {
98
- let cfg = build_config(
99
- "rules:\n document-start: disable\n quoted-strings:\n required: only-when-needed\n quote-type: single\n",
100
- );
101
- let hits = quoted_strings::check("foo: \"bar\"\n", &cfg);
102
- assert_eq!(hits.len(), 1);
103
- assert!(hits[0].message.contains("single quotes"));
104
- }
105
-
106
- #[test]
107
- fn only_when_needed_mismatched_quote_type_when_quotes_required() {
108
- let cfg = build_config(
109
- "rules:\n document-start: disable\n quoted-strings:\n required: only-when-needed\n quote-type: single\n",
110
- );
111
- let hits = quoted_strings::check("foo: \"!bar\"\n", &cfg);
112
- assert_eq!(hits.len(), 1);
113
- assert_eq!(
114
- hits[0].message,
115
- "string value is not quoted with single quotes"
116
- );
117
- }
118
-
119
- #[test]
120
- fn tagged_scalars_are_skipped() {
121
- let cfg =
122
- build_config("rules:\n document-start: disable\n quoted-strings: enable\n");
123
- let hits = quoted_strings::check("foo: !!str yes\n", &cfg);
124
- assert!(
125
- hits.is_empty(),
126
- "explicitly tagged scalars should be ignored"
127
- );
128
- }
129
-
130
- #[test]
131
- fn literal_block_is_ignored() {
132
- let cfg =
133
- build_config("rules:\n document-start: disable\n quoted-strings: enable\n");
134
- let hits = quoted_strings::check("foo: |\n line\n", &cfg);
135
- assert!(hits.is_empty(), "literal blocks are outside rule scope");
136
- }
137
-
138
- #[test]
139
- fn double_quoted_non_printable_is_considered_needed() {
140
- let cfg = build_config(
141
- "rules:\n document-start: disable\n quoted-strings:\n required: only-when-needed\n",
142
- );
143
- let yaml = "foo: \"\u{0007}\"\n";
144
- let hits = quoted_strings::check(yaml, &cfg);
145
- assert!(hits.is_empty(), "non-printable characters require quotes");
146
- }
147
-
148
- #[test]
149
- fn quoted_value_starting_with_bang_keeps_quotes() {
150
- let cfg = build_config(
151
- "rules:\n document-start: disable\n quoted-strings:\n required: only-when-needed\n",
152
- );
153
- let hits = quoted_strings::check("foo: \"!foo\"\n", &cfg);
154
- assert!(hits.is_empty(), "values starting with bang need quotes");
155
- }
156
-
157
- #[test]
158
- fn required_false_allows_plain_strings_without_extras() {
159
- let cfg = build_config(
160
- "rules:\n document-start: disable\n quoted-strings:\n required: false\n",
161
- );
162
- let hits = quoted_strings::check("foo: bar\n", &cfg);
163
- assert!(hits.is_empty(), "plain values should be allowed");
164
- }
165
-
166
- #[test]
167
- fn required_false_respects_matching_quote_type() {
168
- let cfg = build_config(
169
- "rules:\n document-start: disable\n quoted-strings:\n required: false\n quote-type: double\n",
170
- );
171
- let hits = quoted_strings::check("foo: \"bar\"\n", &cfg);
172
- assert!(hits.is_empty(), "matching quotes should be permitted");
173
- }
174
-
175
- #[test]
176
- fn complex_keys_do_not_suppress_value_diagnostics() {
177
- let cfg =
178
- build_config("rules:\n document-start: disable\n quoted-strings: enable\n");
179
- let yaml = "? { key: value }\n: data\n";
180
- let hits = quoted_strings::check(yaml, &cfg);
181
- assert_eq!(hits.len(), 1, "expected value diagnostic, got: {:?}", hits);
182
- assert_eq!(hits[0].line, 2);
183
- assert_eq!(hits[0].column, 3);
184
- assert_eq!(
185
- hits[0].message,
186
- "string value is not quoted with any quotes"
187
- );
188
- }
189
-
190
- #[test]
191
- fn allow_quoted_quotes_permits_mismatched_quotes_with_inner_quote() {
192
- let cfg = build_config(
193
- "rules:\n document-start: disable\n quoted-strings:\n quote-type: double\n allow-quoted-quotes: true\n",
194
- );
195
- let hits = quoted_strings::check("foo: 'bar\"baz'\n", &cfg);
196
- assert!(hits.is_empty(), "mismatched quoting should be permitted");
197
- }
198
-
199
- #[test]
200
- fn check_keys_true_flags_keys() {
201
- let cfg = build_config(
202
- "rules:\n document-start: disable\n quoted-strings:\n required: only-when-needed\n check-keys: true\n extra-required: ['[:]']\n",
203
- );
204
- let hits = quoted_strings::check("foo:bar: baz\n", &cfg);
205
- assert_eq!(hits.len(), 1);
206
- assert_eq!(hits[0].line, 1);
207
- assert_eq!(hits[0].column, 1);
208
- assert_eq!(hits[0].message, "string key is not quoted");
209
- }
210
-
211
- #[test]
212
- fn flow_context_retain_quotes_when_needed() {
213
- let cfg = build_config(
214
- "rules:\n document-start: disable\n quoted-strings:\n required: only-when-needed\n",
215
- );
216
- let hits = quoted_strings::check("items: [\"a,b\"]\n", &cfg);
217
- assert!(
218
- hits.is_empty(),
219
- "quotes are required in flow contexts containing commas"
220
- );
221
- }
222
-
223
- #[test]
224
- fn flow_context_after_multibyte_key_retain_quotes() {
225
- let cfg = build_config(
226
- "rules:\n document-start: disable\n quoted-strings:\n required: only-when-needed\n",
227
- );
228
- let yaml = "\u{00E9}: [\"a,b\"]\n";
229
- let hits = quoted_strings::check(yaml, &cfg);
230
- assert!(
231
- hits.is_empty(),
232
- "flow context after multibyte key should keep quotes"
233
- );
234
- }
235
-
236
- #[test]
237
- fn multiline_backslash_requires_quotes() {
238
- let cfg = build_config(
239
- "rules:\n document-start: disable\n quoted-strings:\n required: only-when-needed\n",
240
- );
241
- let yaml = "foo: \"line1\\\n line2\"\n";
242
- let hits = quoted_strings::check(yaml, &cfg);
243
- assert!(
244
- hits.is_empty(),
245
- "backslash line continuations should require quotes"
246
- );
247
- }
248
-
249
- #[test]
250
- fn multiline_flow_tokens_require_quotes() {
251
- let cfg = build_config(
252
- "rules:\n document-start: disable\n quoted-strings:\n required: only-when-needed\n",
253
- );
254
- let yaml = "foo: \"{ missing\"\n";
255
- let hits = quoted_strings::check(yaml, &cfg);
256
- assert!(hits.is_empty(), "unbalanced flow tokens should keep quotes");
257
- }
258
-
259
- #[test]
260
- fn multiline_backslash_with_crlf_requires_quotes() {
261
- let cfg = build_config(
262
- "rules:\n document-start: disable\n quoted-strings:\n required: only-when-needed\n",
263
- );
264
- let yaml = "foo: \"line1\\\r\n line2\"\n";
265
- let hits = quoted_strings::check(yaml, &cfg);
266
- assert!(
267
- hits.is_empty(),
268
- "CRLF backslash continuations should require quotes"
269
- );
270
- }
271
-
272
- #[test]
273
- fn multiline_empty_double_quoted_value_is_handled() {
274
- let cfg = build_config(
275
- "rules:\n document-start: disable\n quoted-strings:\n required: only-when-needed\n",
276
- );
277
- let yaml = "foo: \"\n\"\n";
278
- let hits = quoted_strings::check(yaml, &cfg);
279
- assert!(hits.is_empty(), "blank multi-line content should not panic");
280
- }
281
-
282
- #[test]
283
- fn inner_double_quotes_are_preserved() {
284
- let cfg = build_config(
285
- "rules:\n document-start: disable\n quoted-strings:\n required: only-when-needed\n",
286
- );
287
- let yaml = "foo: \"\\\"bar\\\"\"\n";
288
- let hits = quoted_strings::check(yaml, &cfg);
289
- assert!(hits.is_empty(), "embedded quotes should keep outer quoting");
290
- }
@@ -1,41 +0,0 @@
1
- use ryl::rules::trailing_spaces::{self, Violation};
2
-
3
- #[test]
4
- fn reports_trailing_space() {
5
- let input = "---\nsome: text \n";
6
- let hits = trailing_spaces::check(input);
7
- assert_eq!(
8
- hits,
9
- vec![Violation {
10
- line: 2,
11
- column: 11,
12
- }]
13
- );
14
- }
15
-
16
- #[test]
17
- fn reports_trailing_tab() {
18
- let input = "key:\t\n";
19
- let hits = trailing_spaces::check(input);
20
- assert_eq!(hits, vec![Violation { line: 1, column: 5 }]);
21
- }
22
-
23
- #[test]
24
- fn ignores_clean_lines() {
25
- let input = "foo: bar\n";
26
- let hits = trailing_spaces::check(input);
27
- assert!(hits.is_empty());
28
- }
29
-
30
- #[test]
31
- fn handles_crlf_lines() {
32
- let input = "---\r\nsome: text \r\n";
33
- let hits = trailing_spaces::check(input);
34
- assert_eq!(
35
- hits,
36
- vec![Violation {
37
- line: 2,
38
- column: 11,
39
- }]
40
- );
41
- }
@@ -1,236 +0,0 @@
1
- use ryl::config::YamlLintConfig;
2
- use ryl::rules::truthy::{self, Config};
3
-
4
- fn build_config(yaml: &str) -> Config {
5
- let cfg = YamlLintConfig::from_yaml_str(yaml).expect("config parses");
6
- Config::resolve(&cfg)
7
- }
8
-
9
- #[test]
10
- fn flags_plain_truthy_values_in_values() {
11
- let resolved = build_config("rules:\n truthy: enable\n");
12
- let hits = truthy::check("key: True\nother: yes\n", &resolved);
13
- assert_eq!(hits.len(), 2, "expected to flag both values");
14
- assert_eq!(hits[0].line, 1);
15
- assert_eq!(hits[0].column, 6);
16
- assert_eq!(
17
- hits[0].message,
18
- "truthy value should be one of [false, true]"
19
- );
20
- assert_eq!(hits[1].line, 2);
21
- assert_eq!(hits[1].column, 8);
22
- }
23
-
24
- #[test]
25
- fn skips_quoted_or_explicitly_tagged_values() {
26
- let resolved = build_config("rules:\n truthy: enable\n");
27
- let hits = truthy::check(
28
- "---\nstring: \"True\"\nexplicit: !!str yes\nboolean: !!bool True\n",
29
- &resolved,
30
- );
31
- assert!(hits.is_empty(), "quoted/tagged values should be ignored");
32
- }
33
-
34
- #[test]
35
- fn respects_allowed_values_override() {
36
- let resolved =
37
- build_config("rules:\n truthy:\n allowed-values: [\"yes\", \"no\"]\n");
38
- let hits = truthy::check("key: yes\nkey2: true\n", &resolved);
39
- assert_eq!(hits.len(), 1);
40
- assert_eq!(hits[0].line, 2);
41
- assert_eq!(hits[0].column, 7);
42
- assert_eq!(hits[0].message, "truthy value should be one of [no, yes]");
43
- }
44
-
45
- #[test]
46
- fn respects_yaml_version_directive() {
47
- let resolved = build_config("rules:\n truthy: enable\n");
48
- let input = "yes: 1\n...\n%YAML 1.2\n---\nyes: 2\n...\n%YAML 1.1\n---\nyes: 3\n";
49
- let hits = truthy::check(input, &resolved);
50
- assert_eq!(hits.len(), 2, "only YAML 1.1 documents should flag 'yes'");
51
- assert_eq!(hits[0].line, 1);
52
- assert_eq!(hits[0].column, 1);
53
- assert_eq!(hits[1].line, 9);
54
- assert_eq!(hits[1].column, 1);
55
- }
56
-
57
- #[test]
58
- fn skips_keys_when_disabled() {
59
- let resolved = build_config(
60
- "rules:\n truthy:\n allowed-values: []\n check-keys: false\n",
61
- );
62
- let hits = truthy::check("True: yes\nvalue: True\n", &resolved);
63
- assert_eq!(hits.len(), 2, "keys should be skipped but values flagged");
64
- assert!(
65
- hits.iter().all(|hit| !(hit.line == 1 && hit.column == 1)),
66
- "key diagnostics should be suppressed: {hits:?}"
67
- );
68
- }
69
-
70
- #[test]
71
- fn flags_keys_when_enabled() {
72
- let resolved = build_config("rules:\n truthy:\n allowed-values: []\n");
73
- let hits = truthy::check("True: yes\n", &resolved);
74
- assert_eq!(hits.len(), 2);
75
- assert_eq!(hits[0].line, 1);
76
- assert_eq!(hits[0].column, 1);
77
- assert_eq!(hits[1].line, 1);
78
- assert_eq!(hits[1].column, 7);
79
- }
80
-
81
- #[test]
82
- fn handles_complex_keys_without_leaking_key_depth() {
83
- let resolved = build_config("rules:\n truthy: enable\n");
84
- let input = "? { mixed: True }\n: value\n";
85
- let hits = truthy::check(input, &resolved);
86
- assert_eq!(hits.len(), 1, "should flag nested truthy value once");
87
- assert_eq!(hits[0].line, 1);
88
- assert_eq!(hits[0].column, 12);
89
- }
90
-
91
- #[test]
92
- fn ignores_malformed_yaml_directive_without_version() {
93
- let resolved = build_config("rules:\n truthy: enable\n");
94
- let input = "%YAML\n---\nfoo: True\n";
95
- let hits = truthy::check(input, &resolved);
96
- assert!(
97
- hits.is_empty(),
98
- "malformed directive should be skipped: {hits:?}"
99
- );
100
- }
101
-
102
- #[test]
103
- fn ignores_yaml_directive_with_non_numeric_version() {
104
- let resolved = build_config("rules:\n truthy: enable\n");
105
- let input = "%YAML 1.x\n---\nfoo: True\n";
106
- let hits = truthy::check(input, &resolved);
107
- assert!(
108
- hits.is_empty(),
109
- "invalid directives should be ignored: {hits:?}"
110
- );
111
- }
112
-
113
- #[test]
114
- fn ignores_yaml_directive_missing_minor_version() {
115
- let resolved = build_config("rules:\n truthy: enable\n");
116
- let input = "%YAML 1\n---\nfoo: True\n";
117
- let hits = truthy::check(input, &resolved);
118
- assert!(
119
- hits.is_empty(),
120
- "directive without minor version should be ignored"
121
- );
122
- }
123
-
124
- #[test]
125
- fn ignores_yaml_directive_with_non_numeric_major() {
126
- let resolved = build_config("rules:\n truthy: enable\n");
127
- let input = "%YAML x.1\n---\nfoo: True\n";
128
- let hits = truthy::check(input, &resolved);
129
- assert!(
130
- hits.is_empty(),
131
- "directive with invalid major should be ignored"
132
- );
133
- }
134
-
135
- #[test]
136
- fn disable_line_inline_comment_suppresses_truthy() {
137
- let resolved = build_config("rules:\n truthy: enable\n");
138
- let input = "value: yes # yamllint disable-line rule:truthy\n";
139
- let hits = truthy::check(input, &resolved);
140
- assert!(
141
- hits.is_empty(),
142
- "inline disable-line should suppress diagnostics: {hits:?}"
143
- );
144
- }
145
-
146
- #[test]
147
- fn disable_line_without_rule_applies_to_next_line() {
148
- let resolved = build_config("rules:\n truthy: enable\n");
149
- let input = "# yamllint disable-line\nvalue: on\n";
150
- let hits = truthy::check(input, &resolved);
151
- assert!(
152
- hits.is_empty(),
153
- "global disable-line should apply to the next line: {hits:?}"
154
- );
155
- }
156
-
157
- #[test]
158
- fn disable_line_with_other_rule_does_not_affect_truthy() {
159
- let resolved = build_config("rules:\n truthy: enable\n");
160
- let input = "value: on # yamllint disable-line rule:comments\n";
161
- let hits = truthy::check(input, &resolved);
162
- assert_eq!(hits.len(), 1, "truthy diagnostics should remain: {hits:?}");
163
- }
164
-
165
- #[test]
166
- fn disable_line_without_rule_list_still_matches_truthy() {
167
- let resolved = build_config("rules:\n truthy: enable\n");
168
- let input = "# yamllint disable-line \nvalue: off\n";
169
- let hits = truthy::check(input, &resolved);
170
- assert!(
171
- hits.is_empty(),
172
- "implicit disable-line should apply to truthy rule: {hits:?}"
173
- );
174
- }
175
-
176
- #[test]
177
- fn disable_line_with_multiple_rules_including_truthy() {
178
- let resolved = build_config("rules:\n truthy: enable\n");
179
- let input = "value: on # yamllint disable-line rule:comments rule:truthy\n";
180
- let hits = truthy::check(input, &resolved);
181
- assert!(
182
- hits.is_empty(),
183
- "listing truthy rule should suppress diagnostics: {hits:?}"
184
- );
185
- }
186
-
187
- #[test]
188
- fn disable_line_without_rule_prefix_disables_truthy() {
189
- let resolved = build_config("rules:\n truthy: enable\n");
190
- let input = "value: on # yamllint disable-line truthy\n";
191
- let hits = truthy::check(input, &resolved);
192
- assert!(
193
- hits.is_empty(),
194
- "directive without rule: prefix should disable all rules: {hits:?}"
195
- );
196
- }
197
-
198
- #[test]
199
- fn disable_line_parsing_handles_quotes_and_escapes() {
200
- let resolved = build_config("rules:\n truthy: enable\n");
201
- let double_quoted =
202
- "value: \"hash # fragment\" # yamllint disable-line rule:truthy\n";
203
- assert!(truthy::check(double_quoted, &resolved).is_empty());
204
-
205
- let single_quoted =
206
- "value: 'path\\#fragment' # yamllint disable-line rule:truthy\n";
207
- assert!(truthy::check(single_quoted, &resolved).is_empty());
208
-
209
- let escaped_hash = "value: foo \\# not comment\n";
210
- assert!(truthy::check(escaped_hash, &resolved).is_empty());
211
- }
212
-
213
- #[test]
214
- fn regular_comment_does_not_disable_truthy() {
215
- let resolved = build_config("rules:\n truthy: enable\n");
216
- let input = "value: yes # regular comment\n";
217
- let hits = truthy::check(input, &resolved);
218
- assert_eq!(
219
- hits.len(),
220
- 1,
221
- "non-directive comment should not disable rule"
222
- );
223
- }
224
-
225
- #[test]
226
- fn disable_line_block_comment_with_truthy() {
227
- let resolved = build_config("rules:\n truthy: enable\n");
228
- let input = "# yamllint disable-line rule:truthy\nvalue: yes\nnext: On\n";
229
- let hits = truthy::check(input, &resolved);
230
- assert_eq!(
231
- hits.len(),
232
- 1,
233
- "only the immediately following line should be disabled"
234
- );
235
- assert_eq!(hits[0].line, 3);
236
- }
@@ -1,32 +0,0 @@
1
- use std::fs;
2
- use std::process::Command;
3
-
4
- use tempfile::tempdir;
5
-
6
- fn run(cmd: &mut Command) -> (i32, String, String) {
7
- let out = cmd.output().expect("failed to run ryl");
8
- let code = out.status.code().unwrap_or(-1);
9
- let stdout = String::from_utf8_lossy(&out.stdout).into_owned();
10
- let stderr = String::from_utf8_lossy(&out.stderr).into_owned();
11
- (code, stdout, stderr)
12
- }
13
-
14
- #[test]
15
- fn user_global_config_with_invalid_yaml_errors() {
16
- let td = tempdir().unwrap();
17
- let xdg = td.path().join("xdg").join("yamllint");
18
- fs::create_dir_all(&xdg).unwrap();
19
- fs::write(xdg.join("config"), "rules: {\n").unwrap();
20
-
21
- let proj = td.path().join("proj");
22
- fs::create_dir_all(&proj).unwrap();
23
- fs::write(proj.join("a.yaml"), "a: 1\n").unwrap();
24
-
25
- let exe = env!("CARGO_BIN_EXE_ryl");
26
- let (code, _out, err) = run(Command::new(exe)
27
- .env("XDG_CONFIG_HOME", td.path().join("xdg"))
28
- .arg("--list-files")
29
- .arg(&proj));
30
- assert_eq!(code, 2, "expected exit 2: {err}");
31
- assert!(err.contains("failed to parse config data"));
32
- }