@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,217 +0,0 @@
1
- use ryl::rules::brackets::{self, Config, Forbid, Violation};
2
-
3
- fn defaults() -> Config {
4
- Config::new_for_tests(Forbid::None, 0, 0, -1, -1)
5
- }
6
-
7
- #[test]
8
- fn empty_input_returns_no_diagnostics() {
9
- let cfg = defaults();
10
- let diagnostics = brackets::check("", &cfg);
11
- assert!(
12
- diagnostics.is_empty(),
13
- "unexpected diagnostics: {diagnostics:?}"
14
- );
15
- }
16
-
17
- #[test]
18
- fn accepts_compact_flow_sequence() {
19
- let cfg = defaults();
20
- let diagnostics = brackets::check("object: [1, 2]\n", &cfg);
21
- assert!(
22
- diagnostics.is_empty(),
23
- "unexpected diagnostics: {diagnostics:?}"
24
- );
25
- }
26
-
27
- #[test]
28
- fn reports_space_after_open_bracket() {
29
- let cfg = defaults();
30
- let diagnostics = brackets::check("object: [ 1, 2]\n", &cfg);
31
- assert_eq!(
32
- diagnostics,
33
- vec![Violation {
34
- line: 1,
35
- column: 10,
36
- message: "too many spaces inside brackets".to_string(),
37
- }]
38
- );
39
- }
40
-
41
- #[test]
42
- fn reports_space_before_closing_bracket() {
43
- let cfg = defaults();
44
- let diagnostics = brackets::check("object: [1, 2 ]\n", &cfg);
45
- assert_eq!(
46
- diagnostics,
47
- vec![Violation {
48
- line: 1,
49
- column: 14,
50
- message: "too many spaces inside brackets".to_string(),
51
- }]
52
- );
53
- }
54
-
55
- #[test]
56
- fn forbid_true_rejects_flow_sequence() {
57
- let cfg = Config::new_for_tests(Forbid::All, 0, 0, -1, -1);
58
- let diagnostics = brackets::check("object: [1, 2]\n", &cfg);
59
- assert_eq!(
60
- diagnostics,
61
- vec![Violation {
62
- line: 1,
63
- column: 10,
64
- message: "forbidden flow sequence".to_string(),
65
- }]
66
- );
67
- }
68
-
69
- #[test]
70
- fn forbid_non_empty_allows_empty_sequence() {
71
- let cfg = Config::new_for_tests(Forbid::NonEmpty, 0, 0, -1, -1);
72
- let diagnostics = brackets::check("object: []\n", &cfg);
73
- assert!(
74
- diagnostics.is_empty(),
75
- "unexpected diagnostics: {diagnostics:?}"
76
- );
77
- }
78
-
79
- #[test]
80
- fn forbid_non_empty_rejects_non_empty_sequence() {
81
- let cfg = Config::new_for_tests(Forbid::NonEmpty, 0, 0, -1, -1);
82
- let diagnostics = brackets::check("object: [1]\n", &cfg);
83
- assert_eq!(
84
- diagnostics,
85
- vec![Violation {
86
- line: 1,
87
- column: 10,
88
- message: "forbidden flow sequence".to_string(),
89
- }]
90
- );
91
- }
92
-
93
- #[test]
94
- fn min_spaces_inside_enforced_on_both_sides() {
95
- let cfg = Config::new_for_tests(Forbid::None, 1, -1, -1, -1);
96
- let diagnostics = brackets::check("object: [1, 2]\n", &cfg);
97
- assert_eq!(
98
- diagnostics,
99
- vec![
100
- Violation {
101
- line: 1,
102
- column: 10,
103
- message: "too few spaces inside brackets".to_string(),
104
- },
105
- Violation {
106
- line: 1,
107
- column: 14,
108
- message: "too few spaces inside brackets".to_string(),
109
- },
110
- ]
111
- );
112
- }
113
-
114
- #[test]
115
- fn max_spaces_inside_limits_padding() {
116
- let cfg = Config::new_for_tests(Forbid::None, 0, 1, -1, -1);
117
- let diagnostics = brackets::check("object: [ 1, 2 ]\n", &cfg);
118
- assert_eq!(
119
- diagnostics,
120
- vec![
121
- Violation {
122
- line: 1,
123
- column: 11,
124
- message: "too many spaces inside brackets".to_string(),
125
- },
126
- Violation {
127
- line: 1,
128
- column: 18,
129
- message: "too many spaces inside brackets".to_string(),
130
- },
131
- ]
132
- );
133
- }
134
-
135
- #[test]
136
- fn empty_sequence_spacing_overrides_defaults() {
137
- let cfg = Config::new_for_tests(Forbid::None, 0, 0, 1, 2);
138
- let diagnostics = brackets::check("object: []\n", &cfg);
139
- assert_eq!(
140
- diagnostics,
141
- vec![Violation {
142
- line: 1,
143
- column: 10,
144
- message: "too few spaces inside empty brackets".to_string(),
145
- }]
146
- );
147
-
148
- let diagnostics = brackets::check("object: [ ]\n", &cfg);
149
- assert_eq!(
150
- diagnostics,
151
- vec![Violation {
152
- line: 1,
153
- column: 13,
154
- message: "too many spaces inside empty brackets".to_string(),
155
- }]
156
- );
157
- }
158
-
159
- #[test]
160
- fn multiline_sequences_skip_spacing_checks() {
161
- let cfg = defaults();
162
- let diagnostics = brackets::check("seq: [\n 1,\n 2\n]\n", &cfg);
163
- assert!(
164
- diagnostics.is_empty(),
165
- "unexpected diagnostics: {diagnostics:?}"
166
- );
167
- }
168
-
169
- #[test]
170
- fn brackets_inside_scalars_are_ignored() {
171
- let cfg = defaults();
172
- let diagnostics = brackets::check("value: \"[ not a sequence ]\"\n", &cfg);
173
- assert!(
174
- diagnostics.is_empty(),
175
- "unexpected diagnostics: {diagnostics:?}"
176
- );
177
- }
178
-
179
- #[test]
180
- fn comments_inside_flow_sequences_are_ignored() {
181
- let cfg = defaults();
182
- let diagnostics = brackets::check("object: [1, # comment\n 2]\n", &cfg);
183
- assert!(
184
- diagnostics.is_empty(),
185
- "unexpected diagnostics: {diagnostics:?}"
186
- );
187
- }
188
-
189
- #[test]
190
- fn carriage_returns_inside_flow_are_ignored() {
191
- let cfg = defaults();
192
- let diagnostics = brackets::check("object: [1,\r\n 2]\r\n", &cfg);
193
- assert!(
194
- diagnostics.is_empty(),
195
- "unexpected diagnostics: {diagnostics:?}"
196
- );
197
- }
198
-
199
- #[test]
200
- fn nested_sequences_mark_outer_non_empty() {
201
- let cfg = defaults();
202
- let diagnostics = brackets::check("outer: [[1]]\n", &cfg);
203
- assert!(
204
- diagnostics.is_empty(),
205
- "unexpected diagnostics: {diagnostics:?}"
206
- );
207
- }
208
-
209
- #[test]
210
- fn unmatched_closing_bracket_is_ignored() {
211
- let cfg = defaults();
212
- let diagnostics = brackets::check("]\n", &cfg);
213
- assert!(
214
- diagnostics.is_empty(),
215
- "unexpected diagnostics: {diagnostics:?}"
216
- );
217
- }
@@ -1,205 +0,0 @@
1
- use ryl::rules::commas::{self, Config, Violation};
2
-
3
- fn defaults() -> Config {
4
- Config::new_for_tests(0, 1, 1)
5
- }
6
-
7
- #[test]
8
- fn empty_input_returns_no_diagnostics() {
9
- let cfg = defaults();
10
- let diagnostics = commas::check("", &cfg);
11
- assert!(
12
- diagnostics.is_empty(),
13
- "unexpected diagnostics: {diagnostics:?}"
14
- );
15
- }
16
-
17
- #[test]
18
- fn accepts_well_spaced_flow_sequence() {
19
- let cfg = defaults();
20
- let diagnostics = commas::check("[1, 2]\n", &cfg);
21
- assert!(
22
- diagnostics.is_empty(),
23
- "unexpected diagnostics: {diagnostics:?}"
24
- );
25
- }
26
-
27
- #[test]
28
- fn reports_space_before_comma() {
29
- let cfg = defaults();
30
- let diagnostics = commas::check("[1 ,2]\n", &cfg);
31
- assert_eq!(
32
- diagnostics,
33
- vec![
34
- Violation {
35
- line: 1,
36
- column: 3,
37
- message: "too many spaces before comma".to_string(),
38
- },
39
- Violation {
40
- line: 1,
41
- column: 5,
42
- message: "too few spaces after comma".to_string(),
43
- },
44
- ]
45
- );
46
- }
47
-
48
- #[test]
49
- fn reports_missing_space_after_comma() {
50
- let cfg = defaults();
51
- let diagnostics = commas::check("[1,2]\n", &cfg);
52
- assert_eq!(
53
- diagnostics,
54
- vec![Violation {
55
- line: 1,
56
- column: 4,
57
- message: "too few spaces after comma".to_string(),
58
- }]
59
- );
60
- }
61
-
62
- #[test]
63
- fn reports_excess_space_after_comma() {
64
- let cfg = defaults();
65
- let diagnostics = commas::check("[1, 2]\n", &cfg);
66
- assert_eq!(
67
- diagnostics,
68
- vec![Violation {
69
- line: 1,
70
- column: 5,
71
- message: "too many spaces after comma".to_string(),
72
- }]
73
- );
74
- }
75
-
76
- #[test]
77
- fn ignores_newline_after_comma() {
78
- let cfg = defaults();
79
- let diagnostics = commas::check("[1,\n 2]\n", &cfg);
80
- assert!(
81
- diagnostics.is_empty(),
82
- "unexpected diagnostics: {diagnostics:?}"
83
- );
84
- }
85
-
86
- #[test]
87
- fn ignores_comma_at_line_start() {
88
- let cfg = defaults();
89
- let diagnostics = commas::check("[\n 1\n, 2]\n", &cfg);
90
- assert!(
91
- diagnostics.is_empty(),
92
- "unexpected diagnostics: {diagnostics:?}"
93
- );
94
- }
95
-
96
- #[test]
97
- fn newline_before_comma_is_ignored() {
98
- let cfg = defaults();
99
- let diagnostics = commas::check("[1\n, 2]\n", &cfg);
100
- assert!(
101
- diagnostics.is_empty(),
102
- "unexpected diagnostics: {diagnostics:?}"
103
- );
104
- }
105
-
106
- #[test]
107
- fn ignores_commas_inside_scalars() {
108
- let cfg = defaults();
109
- let diagnostics = commas::check("[\"café, menu\", 3]\n", &cfg);
110
- assert!(
111
- diagnostics.is_empty(),
112
- "unexpected diagnostics: {diagnostics:?}"
113
- );
114
- }
115
-
116
- #[test]
117
- fn respects_relaxed_spacing_config() {
118
- let cfg = Config::new_for_tests(-1, 0, -1);
119
- let diagnostics = commas::check("[1 ,2]\n", &cfg);
120
- assert!(
121
- diagnostics.is_empty(),
122
- "unexpected diagnostics: {diagnostics:?}"
123
- );
124
- }
125
-
126
- #[test]
127
- fn handles_flow_mapping_entries() {
128
- let cfg = defaults();
129
- let diagnostics = commas::check("{foo: 1 ,bar: 2}\n", &cfg);
130
- assert_eq!(
131
- diagnostics,
132
- vec![
133
- Violation {
134
- line: 1,
135
- column: 8,
136
- message: "too many spaces before comma".to_string(),
137
- },
138
- Violation {
139
- line: 1,
140
- column: 10,
141
- message: "too few spaces after comma".to_string(),
142
- },
143
- ]
144
- );
145
- }
146
-
147
- #[test]
148
- fn allows_comment_after_comma_on_same_line() {
149
- let cfg = defaults();
150
- let diagnostics = commas::check("[1, # comment\n 2]\n", &cfg);
151
- assert!(
152
- diagnostics.is_empty(),
153
- "unexpected diagnostics: {diagnostics:?}"
154
- );
155
- }
156
-
157
- #[test]
158
- fn allows_comment_after_comma_with_crlf() {
159
- let cfg = defaults();
160
- let diagnostics = commas::check("[1, # comment\r\n 2]\r\n", &cfg);
161
- assert!(
162
- diagnostics.is_empty(),
163
- "unexpected diagnostics: {diagnostics:?}"
164
- );
165
- }
166
-
167
- #[test]
168
- fn carriage_return_after_comma_is_ignored() {
169
- let cfg = defaults();
170
- let diagnostics = commas::check("[1,\r\n 2]\r\n", &cfg);
171
- assert!(
172
- diagnostics.is_empty(),
173
- "unexpected diagnostics: {diagnostics:?}"
174
- );
175
- }
176
-
177
- #[test]
178
- fn trailing_spaces_without_next_token_do_not_panic() {
179
- let cfg = defaults();
180
- let diagnostics = commas::check("[1, ", &cfg);
181
- assert!(
182
- diagnostics.is_empty(),
183
- "unexpected diagnostics: {diagnostics:?}"
184
- );
185
- }
186
-
187
- #[test]
188
- fn bare_carriage_return_is_treated_as_line_break() {
189
- let cfg = defaults();
190
- let diagnostics = commas::check("[1, 2]\r", &cfg);
191
- assert!(
192
- diagnostics.is_empty(),
193
- "unexpected diagnostics: {diagnostics:?}"
194
- );
195
- }
196
-
197
- #[test]
198
- fn bare_carriage_return_before_comma_is_ignored() {
199
- let cfg = defaults();
200
- let diagnostics = commas::check("[1\r, 2]\r", &cfg);
201
- assert!(
202
- diagnostics.is_empty(),
203
- "unexpected diagnostics: {diagnostics:?}"
204
- );
205
- }
@@ -1,197 +0,0 @@
1
- use ryl::config::YamlLintConfig;
2
- use ryl::rules::comments::{self, Config, Violation};
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 missing_space_reports_violation() {
11
- let resolved = build_config("rules:\n comments: {}\n");
12
- let hits = comments::check("#comment\n", &resolved);
13
- assert_eq!(
14
- hits,
15
- vec![Violation {
16
- line: 1,
17
- column: 2,
18
- message: "missing starting space in comment".to_string(),
19
- }]
20
- );
21
- }
22
-
23
- #[test]
24
- fn allows_hash_art_lines() {
25
- let resolved = build_config("rules:\n comments: {}\n");
26
- let hits = comments::check("########################\n", &resolved);
27
- assert!(hits.is_empty(), "hash art should be allowed: {hits:?}");
28
- }
29
-
30
- #[test]
31
- fn enforces_min_spacing_for_inline_comments() {
32
- let resolved = build_config(
33
- "rules:\n comments:\n require-starting-space: true\n min-spaces-from-content: 2\n",
34
- );
35
- let hits = comments::check("key: value # comment\n", &resolved);
36
- assert_eq!(
37
- hits,
38
- vec![Violation {
39
- line: 1,
40
- column: 12,
41
- message: "too few spaces before comment: expected 2".to_string(),
42
- }]
43
- );
44
- }
45
-
46
- #[test]
47
- fn disables_min_spacing_with_negative_one() {
48
- let resolved = build_config(
49
- "rules:\n comments:\n require-starting-space: true\n min-spaces-from-content: -1\n",
50
- );
51
- let hits = comments::check("key: value # comment\n", &resolved);
52
- assert!(
53
- hits.is_empty(),
54
- "min spacing of -1 should disable the check: {hits:?}"
55
- );
56
- }
57
-
58
- #[test]
59
- fn shebang_respected_when_ignored() {
60
- let resolved = build_config(
61
- "rules:\n comments:\n require-starting-space: true\n ignore-shebangs: true\n",
62
- );
63
- let hits = comments::check("#!/usr/bin/env foo\n", &resolved);
64
- assert!(hits.is_empty(), "shebang should be ignored: {hits:?}");
65
- }
66
-
67
- #[test]
68
- fn shebang_flagged_when_not_ignored() {
69
- let resolved = build_config(
70
- "rules:\n comments:\n require-starting-space: true\n ignore-shebangs: false\n",
71
- );
72
- let hits = comments::check("#!/usr/bin/env foo\n", &resolved);
73
- assert_eq!(
74
- hits,
75
- vec![Violation {
76
- line: 1,
77
- column: 2,
78
- message: "missing starting space in comment".to_string(),
79
- }]
80
- );
81
- }
82
-
83
- #[test]
84
- fn inline_comment_reports_both_issues() {
85
- let resolved = build_config("rules:\n comments: {}\n");
86
- let hits = comments::check("value: foo #bar\n", &resolved);
87
- assert_eq!(
88
- hits,
89
- vec![
90
- Violation {
91
- line: 1,
92
- column: 12,
93
- message: "too few spaces before comment: expected 2".to_string(),
94
- },
95
- Violation {
96
- line: 1,
97
- column: 13,
98
- message: "missing starting space in comment".to_string(),
99
- },
100
- ]
101
- );
102
- }
103
-
104
- #[test]
105
- fn url_fragment_does_not_count_as_comment() {
106
- let resolved = build_config("rules:\n comments: {}\n");
107
- let hits = comments::check("link: https://example.com/#anchor\n", &resolved);
108
- assert!(
109
- hits.is_empty(),
110
- "URL fragments should not be treated as comments: {hits:?}"
111
- );
112
- }
113
-
114
- #[test]
115
- fn ignores_hash_characters_inside_quotes() {
116
- let resolved = build_config("rules:\n comments: {}\n");
117
- let hits = comments::check("string: \"value #not comment\" # comment\n", &resolved);
118
- assert_eq!(
119
- hits,
120
- vec![Violation {
121
- line: 1,
122
- column: 30,
123
- message: "too few spaces before comment: expected 2".to_string(),
124
- }]
125
- );
126
- }
127
-
128
- #[test]
129
- fn ignores_hash_inside_single_quotes() {
130
- let resolved = build_config("rules:\n comments: {}\n");
131
- let hits = comments::check("string: 'value #not comment' # comment\n", &resolved);
132
- assert_eq!(
133
- hits,
134
- vec![Violation {
135
- line: 1,
136
- column: 30,
137
- message: "too few spaces before comment: expected 2".to_string(),
138
- }]
139
- );
140
- }
141
-
142
- #[test]
143
- fn handles_escaped_hash_inside_double_quotes() {
144
- let resolved = build_config("rules:\n comments: {}\n");
145
- let hits = comments::check("string: \"path\\#not comment\" # comment\n", &resolved);
146
- assert_eq!(
147
- hits,
148
- vec![Violation {
149
- line: 1,
150
- column: 29,
151
- message: "too few spaces before comment: expected 2".to_string(),
152
- }]
153
- );
154
- }
155
-
156
- #[test]
157
- fn handles_crlf_newlines() {
158
- let resolved = build_config("rules:\n comments: {}\n");
159
- let hits = comments::check("key: value # comment\r\n#comment\r\n", &resolved);
160
- assert_eq!(hits.len(), 2, "expected two violations: {hits:?}");
161
- assert_eq!(hits[0].line, 1);
162
- assert_eq!(hits[1].line, 2);
163
- }
164
-
165
- #[test]
166
- fn multiline_quoted_scalars_ignore_hashes() {
167
- let resolved = build_config("rules:\n comments: {}\n");
168
- let input = "value: \"first line\\n second # still scalar\\n third\"\n";
169
- let hits = comments::check(input, &resolved);
170
- assert!(
171
- hits.is_empty(),
172
- "quoted scalar hash should not be comment: {hits:?}"
173
- );
174
- }
175
-
176
- #[test]
177
- fn block_scalar_lines_do_not_trigger_comment_checks() {
178
- let resolved = build_config("rules:\n comments: {}\n");
179
- let input =
180
- "job:\n run: |\n line one\n line two\n line three\n next: value\n";
181
- let hits = comments::check(input, &resolved);
182
- assert!(
183
- hits.is_empty(),
184
- "block scalar content must be ignored: {hits:?}"
185
- );
186
- }
187
-
188
- #[test]
189
- fn empty_block_scalar_is_ignored() {
190
- let resolved = build_config("rules:\n comments: {}\n");
191
- let input = "job:\n run: |\n next: value\n";
192
- let hits = comments::check(input, &resolved);
193
- assert!(
194
- hits.is_empty(),
195
- "empty block scalar should reset tracker: {hits:?}"
196
- );
197
- }