@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,127 @@
1
+ use ryl::rules::comments_indentation::{self, Config, Violation};
2
+
3
+ fn run(input: &str) -> Vec<Violation> {
4
+ comments_indentation::check(input, &Config)
5
+ }
6
+
7
+ #[test]
8
+ fn empty_input_returns_no_hits() {
9
+ let hits = run("");
10
+ assert!(hits.is_empty());
11
+ }
12
+
13
+ #[test]
14
+ fn accepts_aligned_comment_inside_mapping() {
15
+ let input = "obj:\n # ok\n value: 1\n";
16
+ let hits = run(input);
17
+ assert!(hits.is_empty());
18
+ }
19
+
20
+ #[test]
21
+ fn rejects_comment_with_extra_indent() {
22
+ let input = "obj:\n # wrong\n value: 1\n";
23
+ let hits = run(input);
24
+ assert_eq!(hits, vec![Violation { line: 2, column: 2 }]);
25
+ }
26
+
27
+ #[test]
28
+ fn rejects_comment_after_comment_block_reset() {
29
+ let input = "obj1:\n a: 1\n# heading\n # misplaced\nobj2: no\n";
30
+ let hits = run(input);
31
+ assert_eq!(hits, vec![Violation { line: 4, column: 3 }]);
32
+ }
33
+
34
+ #[test]
35
+ fn rejects_comment_after_inline_comment() {
36
+ let input = "- a # inline\n # wrong\n";
37
+ let hits = run(input);
38
+ assert_eq!(hits, vec![Violation { line: 2, column: 2 }]);
39
+ }
40
+
41
+ #[test]
42
+ fn blank_line_keeps_comment_alignment() {
43
+ let input = "# top\n\n # wrong\nvalue: 1\n";
44
+ let hits = run(input);
45
+ assert_eq!(hits, vec![Violation { line: 3, column: 3 }]);
46
+ }
47
+
48
+ #[test]
49
+ fn allows_comment_inside_block_scalar_body() {
50
+ let input = "rule:\n - pattern: |\n body\n # example\n - other: value\n";
51
+ let hits = run(input);
52
+ assert!(
53
+ hits.is_empty(),
54
+ "block scalar comment should be ignored: {hits:?}"
55
+ );
56
+ }
57
+
58
+ #[test]
59
+ fn allows_comment_dedented_to_indicator_indent() {
60
+ let input = "rule:\n - pattern: |\n body\n # metadata\n - other: value\n";
61
+ let hits = run(input);
62
+ assert!(
63
+ hits.is_empty(),
64
+ "comment aligned with indicator should pass: {hits:?}"
65
+ );
66
+ }
67
+
68
+ #[test]
69
+ fn indicator_with_trailing_comment_is_supported() {
70
+ let input = "job:\n run: | # trailing comment\n step one\n next: value\n";
71
+ let hits = run(input);
72
+ assert!(
73
+ hits.is_empty(),
74
+ "inline comment on indicator should be ignored: {hits:?}"
75
+ );
76
+ }
77
+
78
+ #[test]
79
+ fn block_scalar_allows_blank_line() {
80
+ let input = "rule:\n - pattern: |\n alpha\n\n omega\n - other: value\n";
81
+ let hits = run(input);
82
+ assert!(
83
+ hits.is_empty(),
84
+ "blank lines inside block scalars should pass: {hits:?}"
85
+ );
86
+ }
87
+
88
+ #[test]
89
+ fn inline_quotes_and_escapes_before_comment_are_handled() {
90
+ let with_single = "value: 'quoted # fragment' # note\n # aligned\n";
91
+ let hits = run(with_single);
92
+ assert_eq!(hits, vec![Violation { line: 2, column: 3 }]);
93
+
94
+ let with_escape = "path: \"dir\\#name\" # note\n # aligned\n";
95
+ let hits = run(with_escape);
96
+ assert_eq!(hits, vec![Violation { line: 2, column: 3 }]);
97
+ }
98
+
99
+ #[test]
100
+ fn block_scalar_followed_by_mapping_is_handled() {
101
+ let input = "value: |\n text\nnext: 1\n";
102
+ let hits = run(input);
103
+ assert!(
104
+ hits.is_empty(),
105
+ "block scalar should reset tracker before next mapping: {hits:?}"
106
+ );
107
+ }
108
+
109
+ #[test]
110
+ fn folded_block_scalar_with_chomping_is_detected() {
111
+ let input = "rule:\n value: >-\n body\n # metadata\n next: value\n";
112
+ let hits = run(input);
113
+ assert!(
114
+ hits.is_empty(),
115
+ "folded block scalar with chomping should not flag comments: {hits:?}"
116
+ );
117
+ }
118
+
119
+ #[test]
120
+ fn empty_block_scalar_resets_state() {
121
+ let input = "value: |\nnext: item\n";
122
+ let hits = run(input);
123
+ assert!(
124
+ hits.is_empty(),
125
+ "empty block scalars should not cause diagnostics: {hits:?}"
126
+ );
127
+ }
@@ -0,0 +1,118 @@
1
+ use ryl::rules::document_end::{
2
+ self, Config, FORBIDDEN_MESSAGE, MISSING_MESSAGE,
3
+ classify_document_end_marker_bytes,
4
+ };
5
+
6
+ #[test]
7
+ fn reports_missing_marker_at_stream_end() {
8
+ let cfg = Config::new_for_tests(true);
9
+ let input = "---\nwithout:\n document: end\n";
10
+ let hits = document_end::check(input, &cfg);
11
+ assert_eq!(hits.len(), 1, "expected a violation: {hits:?}");
12
+ let hit = &hits[0];
13
+ assert_eq!(hit.line, 3);
14
+ assert_eq!(hit.column, 1);
15
+ assert_eq!(hit.message, MISSING_MESSAGE);
16
+ }
17
+
18
+ #[test]
19
+ fn reports_missing_marker_between_documents() {
20
+ let cfg = Config::new_for_tests(true);
21
+ let input = "---\nfirst: document\n---\nsecond: document\n";
22
+ let hits = document_end::check(input, &cfg);
23
+ assert_eq!(hits.len(), 2, "expected two violations: {hits:?}");
24
+ assert_eq!(hits[0].line, 3);
25
+ assert_eq!(hits[0].column, 1);
26
+ assert_eq!(hits[0].message, MISSING_MESSAGE);
27
+ assert_eq!(hits[1].line, 4);
28
+ assert_eq!(hits[1].column, 1);
29
+ assert_eq!(hits[1].message, MISSING_MESSAGE);
30
+ }
31
+
32
+ #[test]
33
+ fn explicit_marker_satisfies_requirement() {
34
+ let cfg = Config::new_for_tests(true);
35
+ let input = "---\nwith:\n document: end\n...\n";
36
+ let hits = document_end::check(input, &cfg);
37
+ assert!(hits.is_empty(), "explicit marker should pass: {hits:?}");
38
+ }
39
+
40
+ #[test]
41
+ fn forbidding_marker_flags_explicit_marker() {
42
+ let cfg = Config::new_for_tests(false);
43
+ let input = "---\nwith:\n document: end\n...\n";
44
+ let hits = document_end::check(input, &cfg);
45
+ assert_eq!(hits.len(), 1, "expected a violation: {hits:?}");
46
+ let hit = &hits[0];
47
+ assert_eq!(hit.line, 4);
48
+ assert_eq!(hit.column, 1);
49
+ assert_eq!(hit.message, FORBIDDEN_MESSAGE);
50
+ }
51
+
52
+ #[test]
53
+ fn forbidding_marker_allows_absent_marker() {
54
+ let cfg = Config::new_for_tests(false);
55
+ let input = "---\nwith:\n document: end\n";
56
+ let hits = document_end::check(input, &cfg);
57
+ assert!(
58
+ hits.is_empty(),
59
+ "missing marker allowed when forbidden: {hits:?}"
60
+ );
61
+ }
62
+
63
+ #[test]
64
+ fn empty_stream_has_no_diagnostics() {
65
+ let cfg = Config::new_for_tests(true);
66
+ let hits = document_end::check("", &cfg);
67
+ assert!(hits.is_empty(), "empty stream should not warn: {hits:?}");
68
+ }
69
+
70
+ #[test]
71
+ fn explicit_marker_with_trailing_spaces_is_still_detected() {
72
+ let cfg = Config::new_for_tests(false);
73
+ let input = "---\nwith:\n document: end\n... \n";
74
+ let hits = document_end::check(input, &cfg);
75
+ assert_eq!(
76
+ hits.len(),
77
+ 1,
78
+ "expected forbidden marker violation: {hits:?}"
79
+ );
80
+ let hit = &hits[0];
81
+ assert_eq!(hit.line, 4);
82
+ assert_eq!(hit.column, 1);
83
+ assert_eq!(hit.message, FORBIDDEN_MESSAGE);
84
+ }
85
+
86
+ #[test]
87
+ fn marker_with_leading_indent_is_allowed() {
88
+ let cfg = Config::new_for_tests(true);
89
+ let input = "---\nwith:\n document: end\n ...\n";
90
+ let hits = document_end::check(input, &cfg);
91
+ assert!(
92
+ hits.is_empty(),
93
+ "indented marker should satisfy requirement: {hits:?}"
94
+ );
95
+ }
96
+
97
+ #[test]
98
+ fn marker_with_inline_comment_is_allowed() {
99
+ let cfg = Config::new_for_tests(true);
100
+ let input = "---\nwith:\n document: end\n... # done\n";
101
+ let hits = document_end::check(input, &cfg);
102
+ assert!(
103
+ hits.is_empty(),
104
+ "marker followed by comment should satisfy requirement: {hits:?}"
105
+ );
106
+ }
107
+
108
+ #[test]
109
+ fn classify_marker_bytes_trims_whitespace() {
110
+ assert_eq!(classify_document_end_marker_bytes(b" ... "), Some("..."));
111
+ assert_eq!(classify_document_end_marker_bytes(b"\t---\r"), Some("---"));
112
+ }
113
+
114
+ #[test]
115
+ fn classify_marker_bytes_rejects_comments_and_empty() {
116
+ assert!(classify_document_end_marker_bytes(b"... # done").is_none());
117
+ assert!(classify_document_end_marker_bytes(b"").is_none());
118
+ }
@@ -0,0 +1,60 @@
1
+ use ryl::rules::document_start::{self, Config, FORBIDDEN_MESSAGE, MISSING_MESSAGE};
2
+
3
+ #[test]
4
+ fn reports_missing_marker_at_start_of_file() {
5
+ let cfg = Config::new_for_tests(true);
6
+ let input = "foo: bar\n";
7
+ let hits = document_start::check(input, &cfg);
8
+ assert_eq!(hits.len(), 1, "expected a violation: {hits:?}");
9
+ let hit = &hits[0];
10
+ assert_eq!(hit.line, 1);
11
+ assert_eq!(hit.column, 1);
12
+ assert_eq!(hit.message, MISSING_MESSAGE);
13
+ }
14
+
15
+ #[test]
16
+ fn reports_missing_marker_after_comment_block() {
17
+ let cfg = Config::new_for_tests(true);
18
+ let input = "# header\nfoo: bar\n";
19
+ let hits = document_start::check(input, &cfg);
20
+ assert_eq!(hits.len(), 1, "expected a violation: {hits:?}");
21
+ let hit = &hits[0];
22
+ assert_eq!(hit.line, 2);
23
+ assert_eq!(hit.column, 1);
24
+ assert_eq!(hit.message, MISSING_MESSAGE);
25
+ }
26
+
27
+ #[test]
28
+ fn explicit_marker_satisfies_requirement() {
29
+ let cfg = Config::new_for_tests(true);
30
+ let input = "---\nfoo: bar\n";
31
+ let hits = document_start::check(input, &cfg);
32
+ assert!(hits.is_empty(), "explicit marker should pass: {hits:?}");
33
+ }
34
+
35
+ #[test]
36
+ fn forbidding_marker_flags_explicit_documents() {
37
+ let cfg = Config::new_for_tests(false);
38
+ let input = "---\nfoo: bar\n";
39
+ let hits = document_start::check(input, &cfg);
40
+ assert_eq!(hits.len(), 1, "expected a violation: {hits:?}");
41
+ let hit = &hits[0];
42
+ assert_eq!(hit.line, 1);
43
+ assert_eq!(hit.column, 1);
44
+ assert_eq!(hit.message, FORBIDDEN_MESSAGE);
45
+ }
46
+
47
+ #[test]
48
+ fn implicit_documents_respected_when_forbidden() {
49
+ let cfg = Config::new_for_tests(false);
50
+ let input = "foo: bar\n";
51
+ let hits = document_start::check(input, &cfg);
52
+ assert!(hits.is_empty(), "implicit document start allowed: {hits:?}");
53
+ }
54
+
55
+ #[test]
56
+ fn empty_stream_has_no_diagnostics() {
57
+ let cfg = Config::new_for_tests(true);
58
+ let hits = document_start::check("", &cfg);
59
+ assert!(hits.is_empty(), "empty stream should not warn: {hits:?}");
60
+ }
@@ -0,0 +1,96 @@
1
+ use ryl::config::YamlLintConfig;
2
+ use ryl::rules::empty_lines::{self, Config};
3
+
4
+ fn resolve(contents: &str) -> Config {
5
+ let cfg = YamlLintConfig::from_yaml_str(contents).expect("config parses");
6
+ Config::resolve(&cfg)
7
+ }
8
+
9
+ #[test]
10
+ fn default_allows_two_blank_lines() {
11
+ let cfg = resolve("rules:\n empty-lines: enable\n");
12
+ let ok = "key: value\n\n\nnext: item\n";
13
+ let violations = empty_lines::check(ok, &cfg);
14
+ assert!(
15
+ violations.is_empty(),
16
+ "unexpected diagnostics: {violations:?}"
17
+ );
18
+
19
+ let bad = "key: value\n\n\n\nnext: item\n";
20
+ let hits = empty_lines::check(bad, &cfg);
21
+ assert_eq!(hits.len(), 1);
22
+ let hit = &hits[0];
23
+ assert_eq!(hit.line, 4);
24
+ assert_eq!(hit.column, 1);
25
+ assert_eq!(hit.message, "too many blank lines (3 > 2)");
26
+ }
27
+
28
+ #[test]
29
+ fn exceeds_max_reports_violation() {
30
+ let cfg = resolve(
31
+ "rules:\n empty-lines:\n max: 0\n max-start: 0\n max-end: 0\n",
32
+ );
33
+ let input = "---\nvalue: 1\n\nother: 2\n";
34
+ let hits = empty_lines::check(input, &cfg);
35
+ assert_eq!(hits.len(), 1);
36
+ let hit = &hits[0];
37
+ assert_eq!(hit.line, 3);
38
+ assert_eq!(hit.message, "too many blank lines (1 > 0)");
39
+ }
40
+
41
+ #[test]
42
+ fn start_limit_applied_before_general_max() {
43
+ let cfg = resolve(
44
+ "rules:\n empty-lines:\n max: 5\n max-start: 1\n max-end: 0\n",
45
+ );
46
+ let input = "\n\nkey: value\n";
47
+ let hits = empty_lines::check(input, &cfg);
48
+ assert_eq!(hits.len(), 1);
49
+ let hit = &hits[0];
50
+ assert_eq!(hit.line, 2);
51
+ assert_eq!(hit.message, "too many blank lines (2 > 1)");
52
+ }
53
+
54
+ #[test]
55
+ fn end_limit_overrides_general_max() {
56
+ let cfg = resolve(
57
+ "rules:\n empty-lines:\n max: 5\n max-start: 0\n max-end: 1\n",
58
+ );
59
+ let input = "key: value\n\n\n";
60
+ let hits = empty_lines::check(input, &cfg);
61
+ assert_eq!(hits.len(), 1);
62
+ let hit = &hits[0];
63
+ assert_eq!(hit.line, 3);
64
+ assert_eq!(hit.message, "too many blank lines (2 > 1)");
65
+ }
66
+
67
+ #[test]
68
+ fn single_newline_file_is_ignored() {
69
+ let cfg = resolve(
70
+ "rules:\n empty-lines:\n max: 0\n max-start: 0\n max-end: 0\n",
71
+ );
72
+ let hits = empty_lines::check("\n", &cfg);
73
+ assert!(
74
+ hits.is_empty(),
75
+ "single newline should not produce violations"
76
+ );
77
+
78
+ let crlf_hits = empty_lines::check("\r\n", &cfg);
79
+ assert!(
80
+ crlf_hits.is_empty(),
81
+ "single CRLF newline should not produce violations"
82
+ );
83
+ }
84
+
85
+ #[test]
86
+ fn space_only_lines_are_not_blank() {
87
+ let cfg = resolve(
88
+ "rules:\n empty-lines:\n max: 0\n max-start: 0\n max-end: 0\n",
89
+ );
90
+ let input = "---\nintro\n \nend\n";
91
+ let hits = empty_lines::check(input, &cfg);
92
+ assert!(
93
+ hits.is_empty(),
94
+ "space-only lines should not be treated as blank"
95
+ );
96
+ }
@@ -0,0 +1,102 @@
1
+ use ryl::config::YamlLintConfig;
2
+ use ryl::rules::empty_values::{self, Config, Violation};
3
+
4
+ fn resolve_config(data: &str) -> Config {
5
+ let cfg = YamlLintConfig::from_yaml_str(data).unwrap();
6
+ empty_values::Config::resolve(&cfg)
7
+ }
8
+
9
+ #[test]
10
+ fn reports_block_mapping_empty_value() {
11
+ let yaml = "block:\n missing:\n";
12
+ let cfg = resolve_config("rules:\n empty-values: enable\n");
13
+ let hits = empty_values::check(yaml, &cfg);
14
+ assert_eq!(
15
+ hits,
16
+ vec![Violation {
17
+ line: 2,
18
+ column: 11,
19
+ message: "empty value in block mapping".to_string(),
20
+ }]
21
+ );
22
+ }
23
+
24
+ #[test]
25
+ fn reports_flow_mapping_empty_value() {
26
+ let yaml = "root: { key: }\n";
27
+ let cfg = resolve_config("rules:\n empty-values: enable\n");
28
+ let hits = empty_values::check(yaml, &cfg);
29
+ assert_eq!(
30
+ hits,
31
+ vec![Violation {
32
+ line: 1,
33
+ column: 13,
34
+ message: "empty value in flow mapping".to_string(),
35
+ }]
36
+ );
37
+ }
38
+
39
+ #[test]
40
+ fn reports_block_sequence_empty_value() {
41
+ let yaml = "-\n";
42
+ let cfg = resolve_config("rules:\n empty-values: enable\n");
43
+ let hits = empty_values::check(yaml, &cfg);
44
+ assert_eq!(
45
+ hits,
46
+ vec![Violation {
47
+ line: 1,
48
+ column: 2,
49
+ message: "empty value in block sequence".to_string(),
50
+ }]
51
+ );
52
+ }
53
+
54
+ #[test]
55
+ fn respects_block_sequence_flag() {
56
+ let yaml = "-\n";
57
+ let cfg = resolve_config(
58
+ "rules:\n empty-values:\n forbid-in-block-sequences: false\n",
59
+ );
60
+ let hits = empty_values::check(yaml, &cfg);
61
+ assert!(hits.is_empty());
62
+ }
63
+
64
+ #[test]
65
+ fn respects_flow_mapping_flag() {
66
+ let yaml = "root: { key: }\n";
67
+ let cfg =
68
+ resolve_config("rules:\n empty-values:\n forbid-in-flow-mappings: false\n");
69
+ let hits = empty_values::check(yaml, &cfg);
70
+ assert!(hits.is_empty());
71
+ }
72
+
73
+ #[test]
74
+ fn respects_block_mapping_flag() {
75
+ let yaml = "key:\n";
76
+ let cfg = resolve_config(
77
+ "rules:\n empty-values:\n forbid-in-block-mappings: false\n",
78
+ );
79
+ let hits = empty_values::check(yaml, &cfg);
80
+ assert!(hits.is_empty());
81
+ }
82
+
83
+ #[test]
84
+ fn ignores_flow_sequences() {
85
+ let yaml = "seq: [ value ]\n";
86
+ let cfg = resolve_config("rules:\n empty-values: enable\n");
87
+ let hits = empty_values::check(yaml, &cfg);
88
+ assert!(hits.is_empty());
89
+ }
90
+
91
+ #[test]
92
+ fn handles_alias_nodes() {
93
+ let yaml = "anchors:\n value: &id 1\nusage:\n alias: *id\n";
94
+ let cfg = resolve_config("rules:\n empty-values: enable\n");
95
+ let hits = empty_values::check(yaml, &cfg);
96
+ assert!(hits.is_empty());
97
+ }
98
+
99
+ #[test]
100
+ fn covers_nothing_event_branch() {
101
+ empty_values::coverage_touch_nothing_branch();
102
+ }
@@ -0,0 +1,109 @@
1
+ use ryl::config::YamlLintConfig;
2
+ use ryl::rules::float_values::{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_forbidden_float_variants() {
11
+ let resolved = build_config(
12
+ "rules:\n float-values:\n require-numeral-before-decimal: true\n forbid-scientific-notation: true\n forbid-nan: true\n forbid-inf: true\n",
13
+ );
14
+
15
+ let hits = float_values::check("a: .5\nb: 1e2\nc: .nan\nd: .inf\n", &resolved);
16
+
17
+ assert_eq!(hits.len(), 4, "all variants should be flagged");
18
+ assert_eq!(hits[0].line, 1);
19
+ assert_eq!(hits[0].column, 4);
20
+ assert_eq!(hits[0].message, "forbidden decimal missing 0 prefix \".5\"");
21
+
22
+ assert_eq!(hits[1].line, 2);
23
+ assert_eq!(hits[1].column, 4);
24
+ assert_eq!(hits[1].message, "forbidden scientific notation \"1e2\"");
25
+
26
+ assert_eq!(hits[2].line, 3);
27
+ assert_eq!(hits[2].column, 4);
28
+ assert_eq!(hits[2].message, "forbidden not a number value \".nan\"");
29
+
30
+ assert_eq!(hits[3].line, 4);
31
+ assert_eq!(hits[3].column, 4);
32
+ assert_eq!(hits[3].message, "forbidden infinite value \".inf\"");
33
+ }
34
+
35
+ #[test]
36
+ fn skips_quoted_and_tagged_values() {
37
+ let resolved = build_config(
38
+ "rules:\n float-values:\n require-numeral-before-decimal: true\n",
39
+ );
40
+ let hits =
41
+ float_values::check("quoted: '.5'\ntagged: !!float .5\nplain: .5\n", &resolved);
42
+
43
+ assert_eq!(
44
+ hits.len(),
45
+ 1,
46
+ "only plain scalar without tag should be flagged"
47
+ );
48
+ assert_eq!(hits[0].line, 3);
49
+ assert_eq!(hits[0].column, 8);
50
+ assert_eq!(hits[0].message, "forbidden decimal missing 0 prefix \".5\"");
51
+ }
52
+
53
+ #[test]
54
+ fn scientific_notation_edge_cases() {
55
+ let resolved = build_config(
56
+ "rules:\n float-values:\n forbid-scientific-notation: true\n require-numeral-before-decimal: true\n",
57
+ );
58
+
59
+ let buffer = "\
60
+ scientific_lower: .5e+2
61
+ scientific_upper: -.5E-2
62
+ missing_mantissa: e3
63
+ invalid_mantissa: a.e2
64
+ invalid_fraction: 1.ae2
65
+ missing_digits_after_dot: .e2
66
+ bare_decimal: .
67
+ missing_exponent: .5e
68
+ signed_without_digits: .5e+
69
+ invalid_exponent_chars: 1e+Q
70
+ ";
71
+ let hits = float_values::check(buffer, &resolved);
72
+ let messages: Vec<_> = hits.iter().map(|d| d.message.as_str()).collect();
73
+
74
+ assert_eq!(
75
+ hits.len(),
76
+ 4,
77
+ "expected two diagnostics per scientific value"
78
+ );
79
+ assert!(
80
+ messages.contains(&"forbidden scientific notation \".5e+2\""),
81
+ "messages: {messages:?}"
82
+ );
83
+ assert!(
84
+ messages.contains(&"forbidden decimal missing 0 prefix \".5e+2\""),
85
+ "messages: {messages:?}"
86
+ );
87
+ assert!(
88
+ messages.contains(&"forbidden scientific notation \"-.5E-2\""),
89
+ "messages: {messages:?}"
90
+ );
91
+ assert!(
92
+ messages.contains(&"forbidden decimal missing 0 prefix \"-.5E-2\""),
93
+ "messages: {messages:?}"
94
+ );
95
+ let forbidden = [
96
+ "\"a.e2\"",
97
+ "\"1.ae2\"",
98
+ "\".e2\"",
99
+ "\".5e\"",
100
+ "\".5e+\"",
101
+ "\"1e+Q\"",
102
+ ];
103
+ assert!(
104
+ messages
105
+ .iter()
106
+ .all(|m| forbidden.iter().all(|value| !m.contains(value))),
107
+ "unexpected diagnostics: {messages:?}"
108
+ );
109
+ }
@@ -0,0 +1,65 @@
1
+ use ryl::rules::hyphens::{self, Config, Violation};
2
+
3
+ #[test]
4
+ fn allows_single_space_after_hyphen() {
5
+ let cfg = Config::new_for_tests(1);
6
+ let diagnostics = hyphens::check("- item\n", &cfg);
7
+ assert!(
8
+ diagnostics.is_empty(),
9
+ "unexpected diagnostics: {diagnostics:?}"
10
+ );
11
+ }
12
+
13
+ #[test]
14
+ fn reports_too_many_spaces_in_root_sequence() {
15
+ let cfg = Config::new_for_tests(1);
16
+ let diagnostics = hyphens::check("- item\n", &cfg);
17
+ assert_eq!(diagnostics, vec![Violation { line: 1, column: 3 }]);
18
+ }
19
+
20
+ #[test]
21
+ fn reports_too_many_spaces_with_indentation() {
22
+ let cfg = Config::new_for_tests(1);
23
+ let diagnostics = hyphens::check(" - item\n", &cfg);
24
+ assert_eq!(diagnostics, vec![Violation { line: 1, column: 5 }]);
25
+ }
26
+
27
+ #[test]
28
+ fn respects_configured_max_spaces() {
29
+ let cfg = Config::new_for_tests(3);
30
+ let diagnostics = hyphens::check("- item\n", &cfg);
31
+ assert_eq!(diagnostics, vec![Violation { line: 1, column: 5 }]);
32
+
33
+ let ok = hyphens::check("- item\n", &cfg);
34
+ assert!(ok.is_empty(), "unexpected diagnostics: {ok:?}");
35
+ }
36
+
37
+ #[test]
38
+ fn ignores_entries_with_comments_only() {
39
+ let cfg = Config::new_for_tests(1);
40
+ let diagnostics = hyphens::check("- # comment\n", &cfg);
41
+ assert!(
42
+ diagnostics.is_empty(),
43
+ "unexpected diagnostics: {diagnostics:?}"
44
+ );
45
+ }
46
+
47
+ #[test]
48
+ fn ignores_blank_lines() {
49
+ let cfg = Config::new_for_tests(1);
50
+ let diagnostics = hyphens::check("\n- item\n", &cfg);
51
+ assert!(
52
+ diagnostics.is_empty(),
53
+ "unexpected diagnostics: {diagnostics:?}"
54
+ );
55
+ }
56
+
57
+ #[test]
58
+ fn ignores_entries_without_inline_values() {
59
+ let cfg = Config::new_for_tests(1);
60
+ let diagnostics = hyphens::check("-\n key: value\n", &cfg);
61
+ assert!(
62
+ diagnostics.is_empty(),
63
+ "unexpected diagnostics: {diagnostics:?}"
64
+ );
65
+ }