@owenlamont/ryl 0.4.1 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/README.md +13 -0
  2. package/bin/ryl.js +96 -1
  3. package/npm-platforms.json +124 -0
  4. package/package.json +46 -12
  5. package/.github/CODEOWNERS +0 -1
  6. package/.github/dependabot.yml +0 -13
  7. package/.github/workflows/ci.yml +0 -107
  8. package/.github/workflows/release.yml +0 -613
  9. package/.github/workflows/update_dependencies.yml +0 -61
  10. package/.github/workflows/update_linters.yml +0 -56
  11. package/.pre-commit-config.yaml +0 -87
  12. package/.yamllint +0 -4
  13. package/AGENTS.md +0 -200
  14. package/Cargo.lock +0 -908
  15. package/Cargo.toml +0 -32
  16. package/clippy.toml +0 -1
  17. package/docs/config-presets.md +0 -100
  18. package/img/benchmark-5x5-5runs.svg +0 -2176
  19. package/pyproject.toml +0 -42
  20. package/ruff.toml +0 -107
  21. package/rumdl.toml +0 -20
  22. package/rust-toolchain.toml +0 -3
  23. package/rustfmt.toml +0 -3
  24. package/scripts/benchmark_perf_vs_yamllint.py +0 -400
  25. package/scripts/coverage-missing.ps1 +0 -80
  26. package/scripts/coverage-missing.sh +0 -60
  27. package/src/bin/discover_config_bin.rs +0 -24
  28. package/src/cli_support.rs +0 -33
  29. package/src/conf/mod.rs +0 -85
  30. package/src/config.rs +0 -2099
  31. package/src/decoder.rs +0 -326
  32. package/src/discover.rs +0 -31
  33. package/src/lib.rs +0 -19
  34. package/src/lint.rs +0 -558
  35. package/src/main.rs +0 -535
  36. package/src/migrate.rs +0 -233
  37. package/src/rules/anchors.rs +0 -517
  38. package/src/rules/braces.rs +0 -77
  39. package/src/rules/brackets.rs +0 -77
  40. package/src/rules/colons.rs +0 -475
  41. package/src/rules/commas.rs +0 -372
  42. package/src/rules/comments.rs +0 -299
  43. package/src/rules/comments_indentation.rs +0 -243
  44. package/src/rules/document_end.rs +0 -175
  45. package/src/rules/document_start.rs +0 -84
  46. package/src/rules/empty_lines.rs +0 -152
  47. package/src/rules/empty_values.rs +0 -255
  48. package/src/rules/float_values.rs +0 -259
  49. package/src/rules/flow_collection.rs +0 -562
  50. package/src/rules/hyphens.rs +0 -104
  51. package/src/rules/indentation.rs +0 -803
  52. package/src/rules/key_duplicates.rs +0 -218
  53. package/src/rules/key_ordering.rs +0 -303
  54. package/src/rules/line_length.rs +0 -326
  55. package/src/rules/mod.rs +0 -25
  56. package/src/rules/new_line_at_end_of_file.rs +0 -23
  57. package/src/rules/new_lines.rs +0 -95
  58. package/src/rules/octal_values.rs +0 -121
  59. package/src/rules/quoted_strings.rs +0 -577
  60. package/src/rules/span_utils.rs +0 -37
  61. package/src/rules/trailing_spaces.rs +0 -65
  62. package/src/rules/truthy.rs +0 -420
  63. package/tests/brackets_carriage_return.rs +0 -114
  64. package/tests/build_global_cfg_error.rs +0 -23
  65. package/tests/cli_anchors_rule.rs +0 -143
  66. package/tests/cli_braces_rule.rs +0 -104
  67. package/tests/cli_brackets_rule.rs +0 -104
  68. package/tests/cli_colons_rule.rs +0 -65
  69. package/tests/cli_commas_rule.rs +0 -104
  70. package/tests/cli_comments_indentation_rule.rs +0 -61
  71. package/tests/cli_comments_rule.rs +0 -67
  72. package/tests/cli_config_data_error.rs +0 -30
  73. package/tests/cli_config_flags.rs +0 -66
  74. package/tests/cli_config_migrate.rs +0 -229
  75. package/tests/cli_document_end_rule.rs +0 -92
  76. package/tests/cli_document_start_rule.rs +0 -92
  77. package/tests/cli_empty_lines_rule.rs +0 -87
  78. package/tests/cli_empty_values_rule.rs +0 -68
  79. package/tests/cli_env_config.rs +0 -34
  80. package/tests/cli_exit_and_errors.rs +0 -41
  81. package/tests/cli_file_encoding.rs +0 -203
  82. package/tests/cli_float_values_rule.rs +0 -64
  83. package/tests/cli_format_options.rs +0 -316
  84. package/tests/cli_global_cfg_relaxed.rs +0 -20
  85. package/tests/cli_hyphens_rule.rs +0 -104
  86. package/tests/cli_indentation_rule.rs +0 -65
  87. package/tests/cli_invalid_project_config.rs +0 -39
  88. package/tests/cli_key_duplicates_rule.rs +0 -104
  89. package/tests/cli_key_ordering_rule.rs +0 -59
  90. package/tests/cli_line_length_rule.rs +0 -85
  91. package/tests/cli_list_files.rs +0 -29
  92. package/tests/cli_new_line_rule.rs +0 -141
  93. package/tests/cli_new_lines_rule.rs +0 -119
  94. package/tests/cli_octal_values_rule.rs +0 -60
  95. package/tests/cli_quoted_strings_rule.rs +0 -47
  96. package/tests/cli_toml_config.rs +0 -119
  97. package/tests/cli_trailing_spaces_rule.rs +0 -77
  98. package/tests/cli_truthy_rule.rs +0 -83
  99. package/tests/cli_yaml_files_negation.rs +0 -45
  100. package/tests/colons_rule.rs +0 -303
  101. package/tests/common/compat.rs +0 -114
  102. package/tests/common/fake_env.rs +0 -93
  103. package/tests/common/mod.rs +0 -1
  104. package/tests/conf_builtin.rs +0 -9
  105. package/tests/config_anchors.rs +0 -84
  106. package/tests/config_braces.rs +0 -121
  107. package/tests/config_brackets.rs +0 -127
  108. package/tests/config_commas.rs +0 -79
  109. package/tests/config_comments.rs +0 -65
  110. package/tests/config_comments_indentation.rs +0 -20
  111. package/tests/config_deep_merge_nonstring_key.rs +0 -24
  112. package/tests/config_document_end.rs +0 -54
  113. package/tests/config_document_start.rs +0 -55
  114. package/tests/config_empty_lines.rs +0 -48
  115. package/tests/config_empty_values.rs +0 -35
  116. package/tests/config_env_errors.rs +0 -23
  117. package/tests/config_env_invalid_inline.rs +0 -15
  118. package/tests/config_env_missing.rs +0 -63
  119. package/tests/config_env_shim.rs +0 -301
  120. package/tests/config_explicit_file_parse_error.rs +0 -55
  121. package/tests/config_extended_features.rs +0 -225
  122. package/tests/config_extends_inline.rs +0 -185
  123. package/tests/config_extends_sequence.rs +0 -18
  124. package/tests/config_find_project_home_boundary.rs +0 -54
  125. package/tests/config_find_project_two_files_in_cwd.rs +0 -47
  126. package/tests/config_float_values.rs +0 -34
  127. package/tests/config_from_yaml_paths.rs +0 -32
  128. package/tests/config_hyphens.rs +0 -51
  129. package/tests/config_ignore_errors.rs +0 -243
  130. package/tests/config_ignore_overrides.rs +0 -83
  131. package/tests/config_indentation.rs +0 -65
  132. package/tests/config_invalid_globs.rs +0 -16
  133. package/tests/config_invalid_types.rs +0 -19
  134. package/tests/config_key_duplicates.rs +0 -34
  135. package/tests/config_key_ordering.rs +0 -70
  136. package/tests/config_line_length.rs +0 -65
  137. package/tests/config_locale.rs +0 -111
  138. package/tests/config_merge.rs +0 -26
  139. package/tests/config_new_lines.rs +0 -89
  140. package/tests/config_octal_values.rs +0 -33
  141. package/tests/config_quoted_strings.rs +0 -195
  142. package/tests/config_rule_level.rs +0 -147
  143. package/tests/config_rules_non_string_keys.rs +0 -23
  144. package/tests/config_scalar_overrides.rs +0 -27
  145. package/tests/config_to_toml.rs +0 -110
  146. package/tests/config_toml_coverage.rs +0 -80
  147. package/tests/config_toml_discovery.rs +0 -304
  148. package/tests/config_trailing_spaces.rs +0 -152
  149. package/tests/config_truthy.rs +0 -77
  150. package/tests/config_yaml_files.rs +0 -62
  151. package/tests/config_yaml_files_all_non_string.rs +0 -15
  152. package/tests/config_yaml_files_empty.rs +0 -30
  153. package/tests/coverage_commas.rs +0 -46
  154. package/tests/decoder_decode.rs +0 -338
  155. package/tests/discover_config_bin_all.rs +0 -66
  156. package/tests/discover_config_bin_env_invalid_yaml.rs +0 -26
  157. package/tests/discover_config_bin_project_config_parse_error.rs +0 -24
  158. package/tests/discover_config_bin_user_global_error.rs +0 -26
  159. package/tests/discover_module.rs +0 -30
  160. package/tests/discover_per_file_dir.rs +0 -10
  161. package/tests/discover_per_file_project_config_error.rs +0 -21
  162. package/tests/float_values.rs +0 -43
  163. package/tests/lint_multi_errors.rs +0 -32
  164. package/tests/main_yaml_ok_filtering.rs +0 -30
  165. package/tests/migrate_module.rs +0 -259
  166. package/tests/resolve_ctx_empty_parent.rs +0 -16
  167. package/tests/rule_anchors.rs +0 -442
  168. package/tests/rule_braces.rs +0 -258
  169. package/tests/rule_brackets.rs +0 -217
  170. package/tests/rule_commas.rs +0 -205
  171. package/tests/rule_comments.rs +0 -197
  172. package/tests/rule_comments_indentation.rs +0 -127
  173. package/tests/rule_document_end.rs +0 -118
  174. package/tests/rule_document_start.rs +0 -60
  175. package/tests/rule_empty_lines.rs +0 -96
  176. package/tests/rule_empty_values.rs +0 -102
  177. package/tests/rule_float_values.rs +0 -109
  178. package/tests/rule_hyphens.rs +0 -65
  179. package/tests/rule_indentation.rs +0 -455
  180. package/tests/rule_key_duplicates.rs +0 -76
  181. package/tests/rule_key_ordering.rs +0 -207
  182. package/tests/rule_line_length.rs +0 -200
  183. package/tests/rule_new_lines.rs +0 -51
  184. package/tests/rule_octal_values.rs +0 -53
  185. package/tests/rule_quoted_strings.rs +0 -290
  186. package/tests/rule_trailing_spaces.rs +0 -41
  187. package/tests/rule_truthy.rs +0 -236
  188. package/tests/user_global_invalid_yaml.rs +0 -32
  189. package/tests/yamllint_compat_anchors.rs +0 -280
  190. package/tests/yamllint_compat_braces.rs +0 -411
  191. package/tests/yamllint_compat_brackets.rs +0 -364
  192. package/tests/yamllint_compat_colons.rs +0 -298
  193. package/tests/yamllint_compat_colors.rs +0 -80
  194. package/tests/yamllint_compat_commas.rs +0 -375
  195. package/tests/yamllint_compat_comments.rs +0 -167
  196. package/tests/yamllint_compat_comments_indentation.rs +0 -281
  197. package/tests/yamllint_compat_config.rs +0 -170
  198. package/tests/yamllint_compat_document_end.rs +0 -243
  199. package/tests/yamllint_compat_document_start.rs +0 -136
  200. package/tests/yamllint_compat_empty_lines.rs +0 -117
  201. package/tests/yamllint_compat_empty_values.rs +0 -179
  202. package/tests/yamllint_compat_float_values.rs +0 -216
  203. package/tests/yamllint_compat_hyphens.rs +0 -223
  204. package/tests/yamllint_compat_indentation.rs +0 -398
  205. package/tests/yamllint_compat_key_duplicates.rs +0 -139
  206. package/tests/yamllint_compat_key_ordering.rs +0 -170
  207. package/tests/yamllint_compat_line_length.rs +0 -375
  208. package/tests/yamllint_compat_list.rs +0 -127
  209. package/tests/yamllint_compat_new_line.rs +0 -133
  210. package/tests/yamllint_compat_newline_types.rs +0 -185
  211. package/tests/yamllint_compat_octal_values.rs +0 -172
  212. package/tests/yamllint_compat_quoted_strings.rs +0 -154
  213. package/tests/yamllint_compat_syntax.rs +0 -200
  214. package/tests/yamllint_compat_trailing_spaces.rs +0 -162
  215. package/tests/yamllint_compat_truthy.rs +0 -130
  216. package/tests/yamllint_compat_yaml_files.rs +0 -81
  217. package/typos.toml +0 -2
@@ -1,185 +0,0 @@
1
- use std::path::PathBuf;
2
-
3
- use ryl::config::{Overrides, YamlLintConfig, discover_config, discover_config_with};
4
-
5
- #[path = "common/mod.rs"]
6
- mod common;
7
- use common::fake_env::FakeEnv;
8
-
9
- #[test]
10
- fn inline_extends_mapping_is_ignored() {
11
- let yaml = "extends:\n invalid: true\nrules: {}\n";
12
- let ctx = discover_config(
13
- &[],
14
- &Overrides {
15
- config_file: None,
16
- config_data: Some(yaml.into()),
17
- },
18
- )
19
- .expect("inline config should parse");
20
- assert!(ctx.config.rule_names().is_empty());
21
- }
22
-
23
- #[test]
24
- fn extends_requires_env_error() {
25
- let err = YamlLintConfig::from_yaml_str("extends: child.yml\n")
26
- .expect_err("extends without env should error");
27
- assert!(err.contains("requires filesystem access"));
28
- }
29
-
30
- #[test]
31
- fn extends_value_non_string_is_ignored() {
32
- let cfg = YamlLintConfig::from_yaml_str("extends: 123\nrules: {}\n")
33
- .expect("non-string extends should be ignored");
34
- assert!(cfg.rule_names().is_empty());
35
- }
36
-
37
- #[test]
38
- fn inline_extends_sequence_skips_non_strings() {
39
- let yaml = "extends: [default, 1]\n";
40
- let ctx = discover_config(
41
- &[],
42
- &Overrides {
43
- config_file: None,
44
- config_data: Some(yaml.into()),
45
- },
46
- )
47
- .expect("extends should allow mixed types");
48
- assert!(ctx.config.rule_names().iter().any(|r| r == "anchors"));
49
- }
50
-
51
- #[test]
52
- fn extends_sequence_missing_entry_errors() {
53
- let root = PathBuf::from("/workspace");
54
- let child = root.join("child.yml");
55
- let base = root.join("base.yml");
56
- let env = FakeEnv::new()
57
- .with_cwd(root.clone())
58
- .with_file(child.clone(), "extends: [base.yml, missing.yml]\n")
59
- .with_file(base.clone(), "rules: {}\n")
60
- .with_exists(child.clone())
61
- .with_exists(base);
62
-
63
- let err = discover_config_with(
64
- &[],
65
- &Overrides {
66
- config_file: Some(child),
67
- config_data: None,
68
- },
69
- &env,
70
- )
71
- .expect_err("missing extended file should error");
72
- assert!(err.contains("failed to read extended config"));
73
- }
74
-
75
- #[test]
76
- fn extends_invalid_yaml_propagates_error() {
77
- let root = PathBuf::from("/workspace");
78
- let child = root.join("child.yml");
79
- let base = root.join("base.yml");
80
- let env = FakeEnv::new()
81
- .with_cwd(root.clone())
82
- .with_file(child.clone(), "extends: base.yml\n")
83
- .with_file(base.clone(), "- not mapping\n")
84
- .with_exists(child)
85
- .with_exists(base.clone());
86
-
87
- let err = discover_config_with(
88
- &[],
89
- &Overrides {
90
- config_file: Some(root.join("child.yml")),
91
- config_data: None,
92
- },
93
- &env,
94
- )
95
- .expect_err("invalid yaml in extended file should propagate");
96
- assert!(err.contains("invalid config"));
97
- }
98
-
99
- #[test]
100
- fn extend_prefers_absolute_paths() {
101
- let root = PathBuf::from("/workspace");
102
- let abs = PathBuf::from("/configs/base.yml");
103
- let env = FakeEnv::new()
104
- .with_cwd(root.clone())
105
- .with_file(abs.clone(), "rules:\n abs_rule: enable\n")
106
- .with_exists(abs.clone());
107
-
108
- let ctx = discover_config_with(
109
- &[],
110
- &Overrides {
111
- config_file: None,
112
- config_data: Some(format!("extends: {}\n", abs.display())),
113
- },
114
- &env,
115
- )
116
- .expect("absolute extends should resolve");
117
- assert!(ctx.config.rule_names().iter().any(|r| r == "abs_rule"));
118
- }
119
-
120
- #[test]
121
- fn extend_falls_back_to_env_cwd_when_base_dir_missing_entry() {
122
- let cwd = PathBuf::from("/env-cwd");
123
- let project = PathBuf::from("/project");
124
- let cli_cfg = project.join("child.yml");
125
- let env = FakeEnv::new()
126
- .with_cwd(cwd.clone())
127
- .with_file(cli_cfg.clone(), "extends: config.yml\n")
128
- .with_exists(cli_cfg.clone())
129
- .with_file(cwd.join("config.yml"), "rules:\n cwd_rule: enable\n")
130
- .with_exists(cwd.join("config.yml"));
131
-
132
- let ctx = discover_config_with(
133
- &[],
134
- &Overrides {
135
- config_file: Some(cli_cfg),
136
- config_data: None,
137
- },
138
- &env,
139
- )
140
- .expect("extend should fall back to cwd");
141
- assert!(ctx.config.rule_names().iter().any(|r| r == "cwd_rule"));
142
- }
143
-
144
- #[test]
145
- fn extend_empty_entry_uses_candidate_path() {
146
- let root = PathBuf::from("/workspace");
147
- let env = FakeEnv::new()
148
- .with_cwd(root.clone())
149
- .with_file(PathBuf::from(""), "rules: {}\n");
150
-
151
- let ctx = discover_config_with(
152
- &[],
153
- &Overrides {
154
- config_file: None,
155
- config_data: Some("extends: ''\n".into()),
156
- },
157
- &env,
158
- )
159
- .expect("empty extends should resolve using candidate path");
160
- assert!(ctx.config.rule_names().is_empty());
161
- }
162
-
163
- #[test]
164
- fn extend_relative_entry_uses_base_directory() {
165
- let project = PathBuf::from("/workspace/project");
166
- let child = project.join("child.yml");
167
- let base = project.join("base.yml");
168
- let env = FakeEnv::new()
169
- .with_cwd(project.clone())
170
- .with_file(child.clone(), "extends: base.yml\n")
171
- .with_exists(child.clone())
172
- .with_file(base.clone(), "rules: { base_rule: enable }\n")
173
- .with_exists(base.clone());
174
-
175
- let ctx = discover_config_with(
176
- &[],
177
- &Overrides {
178
- config_file: Some(child),
179
- config_data: None,
180
- },
181
- &env,
182
- )
183
- .expect("relative extends should resolve using config directory");
184
- assert!(ctx.config.rule_names().iter().any(|r| r == "base_rule"));
185
- }
@@ -1,18 +0,0 @@
1
- use ryl::config::{Overrides, discover_config};
2
-
3
- #[test]
4
- fn extends_sequence_merges_presets_in_order() {
5
- let cfg = "extends: [default, relaxed]\n";
6
- let ctx = discover_config(
7
- &[],
8
- &Overrides {
9
- config_file: None,
10
- config_data: Some(cfg.into()),
11
- },
12
- )
13
- .expect("parse");
14
- // From default
15
- assert!(ctx.config.rule_names().contains(&"anchors".to_string()));
16
- // From relaxed override
17
- assert!(ctx.config.rule_names().contains(&"braces".to_string()));
18
- }
@@ -1,54 +0,0 @@
1
- use std::path::{Path, PathBuf};
2
-
3
- use ryl::config::{Overrides, discover_config_with};
4
-
5
- #[path = "common/mod.rs"]
6
- mod common;
7
- use common::fake_env::FakeEnv;
8
-
9
- #[test]
10
- fn project_search_respects_home_boundary() {
11
- let env = FakeEnv::new()
12
- .with_cwd(PathBuf::from("/workspace"))
13
- .with_var("HOME", "/workspace/userhome".to_string())
14
- .with_exists(PathBuf::from("/workspace/.yamllint"))
15
- .with_file(
16
- PathBuf::from("/workspace/.yamllint"),
17
- "rules: { custom: enable }\n",
18
- );
19
-
20
- let ctx = discover_config_with(
21
- &[PathBuf::from("/workspace/userhome/project/file.yaml")],
22
- &Overrides::default(),
23
- &env,
24
- )
25
- .expect("config discovery should succeed");
26
- assert!(ctx.source.is_none(), "project config should not cross HOME");
27
- assert!(ctx.config.rule_names().iter().any(|r| r == "anchors"));
28
- assert!(!ctx.config.rule_names().iter().any(|r| r == "custom"));
29
- }
30
-
31
- #[test]
32
- fn project_search_supports_relative_home() {
33
- let env = FakeEnv::new()
34
- .with_cwd(PathBuf::from("/workspace"))
35
- .with_var("HOME", "userhome".to_string())
36
- .with_file(
37
- PathBuf::from("/workspace/userhome/.yamllint"),
38
- "rules: { rel: enable }\n",
39
- )
40
- .with_exists(PathBuf::from("/workspace/userhome/.yamllint"))
41
- .with_exists(PathBuf::from("/workspace/userhome/project/file.yaml"));
42
-
43
- let ctx = discover_config_with(
44
- &[PathBuf::from("/workspace/userhome/project/file.yaml")],
45
- &Overrides::default(),
46
- &env,
47
- )
48
- .expect("relative HOME should be joined with cwd");
49
- assert_eq!(
50
- ctx.source.as_deref(),
51
- Some(Path::new("/workspace/userhome/.yamllint"))
52
- );
53
- assert!(ctx.config.rule_names().iter().any(|r| r == "rel"));
54
- }
@@ -1,47 +0,0 @@
1
- use std::collections::HashSet;
2
- use std::path::{Path, PathBuf};
3
-
4
- struct FakeEnv {
5
- exists: HashSet<PathBuf>,
6
- }
7
-
8
- impl ryl::config::Env for FakeEnv {
9
- fn current_dir(&self) -> PathBuf {
10
- PathBuf::from(".")
11
- }
12
- fn config_dir(&self) -> Option<PathBuf> {
13
- None
14
- }
15
- fn read_to_string(&self, p: &Path) -> Result<String, String> {
16
- if p == Path::new(".yamllint") {
17
- Ok("rules: {}\n".into())
18
- } else {
19
- Err("no".into())
20
- }
21
- }
22
- fn path_exists(&self, p: &Path) -> bool {
23
- self.exists.contains(p)
24
- }
25
- fn home_dir(&self) -> Option<PathBuf> {
26
- None
27
- }
28
- fn env_var(&self, _key: &str) -> Option<String> {
29
- None
30
- }
31
- }
32
-
33
- #[test]
34
- fn project_config_search_dedups_multiple_files_without_parent() {
35
- let mut envx = FakeEnv {
36
- exists: HashSet::new(),
37
- };
38
- envx.exists.insert(PathBuf::from(".yamllint"));
39
- let inputs = vec![PathBuf::from("a.yml"), PathBuf::from("b.yml")];
40
- let ctx = ryl::config::discover_config_with(
41
- &inputs,
42
- &ryl::config::Overrides::default(),
43
- &envx,
44
- )
45
- .expect("ok");
46
- assert_eq!(ctx.source.as_deref(), Some(Path::new(".yamllint")));
47
- }
@@ -1,34 +0,0 @@
1
- use ryl::config::YamlLintConfig;
2
-
3
- #[test]
4
- fn error_on_non_bool_require_numeral() {
5
- let err = YamlLintConfig::from_yaml_str(
6
- "rules:\n float-values:\n require-numeral-before-decimal: 1\n",
7
- )
8
- .unwrap_err();
9
- assert_eq!(
10
- err,
11
- "invalid config: option \"require-numeral-before-decimal\" of \"float-values\" should be bool"
12
- );
13
- }
14
-
15
- #[test]
16
- fn error_on_unknown_option() {
17
- let err =
18
- YamlLintConfig::from_yaml_str("rules:\n float-values:\n minimum: true\n")
19
- .unwrap_err();
20
- assert_eq!(
21
- err,
22
- "invalid config: unknown option \"minimum\" for rule \"float-values\""
23
- );
24
- }
25
-
26
- #[test]
27
- fn error_on_non_string_option_key() {
28
- let err = YamlLintConfig::from_yaml_str("rules:\n float-values:\n 1: true\n")
29
- .unwrap_err();
30
- assert_eq!(
31
- err,
32
- "invalid config: unknown option \"1\" for rule \"float-values\""
33
- );
34
- }
@@ -1,32 +0,0 @@
1
- use ryl::config::{Overrides, discover_config};
2
-
3
- #[test]
4
- fn from_yaml_str_covers_ignore_yamlfiles_and_rules_paths() {
5
- let yaml = r#"
6
- extends: default
7
- locale: en_US
8
- ignore:
9
- - "a.yml"
10
- - "b.yaml"
11
- yaml-files:
12
- - "*.yml"
13
- rules:
14
- new_rule: { enabled: true }
15
- "#;
16
- let ctx = discover_config(
17
- &[],
18
- &Overrides {
19
- config_file: None,
20
- config_data: Some(yaml.into()),
21
- },
22
- )
23
- .expect("config parse");
24
-
25
- let pats = ctx.config.ignore_patterns();
26
- assert!(pats.iter().any(|p| p == "a.yml"));
27
- assert!(pats.iter().any(|p| p == "b.yaml"));
28
-
29
- assert!(ctx.config.rule_names().iter().any(|n| n == "new_rule"));
30
- assert!(ctx.config.rule_names().iter().any(|n| n == "anchors"));
31
- assert_eq!(ctx.config.locale(), Some("en_US"));
32
- }
@@ -1,51 +0,0 @@
1
- use ryl::config::YamlLintConfig;
2
- use ryl::rules::hyphens::Config;
3
-
4
- #[test]
5
- fn rejects_unknown_option() {
6
- let err =
7
- YamlLintConfig::from_yaml_str("rules:\n hyphens:\n unexpected: true\n")
8
- .unwrap_err();
9
- assert_eq!(
10
- err,
11
- "invalid config: unknown option \"unexpected\" for rule \"hyphens\""
12
- );
13
- }
14
-
15
- #[test]
16
- fn rejects_non_integer_max_spaces_after() {
17
- let err =
18
- YamlLintConfig::from_yaml_str("rules:\n hyphens:\n max-spaces-after: []\n")
19
- .unwrap_err();
20
- assert_eq!(
21
- err,
22
- "invalid config: option \"max-spaces-after\" of \"hyphens\" should be int"
23
- );
24
- }
25
-
26
- #[test]
27
- fn resolve_uses_default_when_option_missing() {
28
- let cfg = YamlLintConfig::from_yaml_str("rules:\n hyphens: enable\n")
29
- .expect("parse config");
30
- let resolved = Config::resolve(&cfg);
31
- assert_eq!(resolved.max_spaces_after(), 1);
32
- }
33
-
34
- #[test]
35
- fn resolve_reads_configured_value() {
36
- let cfg =
37
- YamlLintConfig::from_yaml_str("rules:\n hyphens:\n max-spaces-after: 4\n")
38
- .expect("parse config");
39
- let resolved = Config::resolve(&cfg);
40
- assert_eq!(resolved.max_spaces_after(), 4);
41
- }
42
-
43
- #[test]
44
- fn rejects_non_string_option_key() {
45
- let err =
46
- YamlLintConfig::from_yaml_str("rules:\n hyphens:\n 1: true\n").unwrap_err();
47
- assert_eq!(
48
- err,
49
- "invalid config: unknown option \"1\" for rule \"hyphens\""
50
- );
51
- }
@@ -1,243 +0,0 @@
1
- use std::path::PathBuf;
2
-
3
- use ryl::config::{Overrides, discover_config, discover_config_with};
4
-
5
- #[path = "common/mod.rs"]
6
- mod common;
7
- use common::fake_env::FakeEnv;
8
-
9
- #[test]
10
- fn ignore_and_ignore_from_file_conflict_errors() {
11
- let yaml = "ignore: ['a']\nignore-from-file: ['b']\n";
12
- let err = discover_config(
13
- &[],
14
- &Overrides {
15
- config_file: None,
16
- config_data: Some(yaml.into()),
17
- },
18
- )
19
- .expect_err("conflicting ignore keys should error");
20
- assert!(err.contains("cannot be used together"));
21
- }
22
-
23
- #[test]
24
- fn ignore_from_file_non_string_errors() {
25
- let yaml = "ignore-from-file: [1]\n";
26
- let err = discover_config(
27
- &[],
28
- &Overrides {
29
- config_file: None,
30
- config_data: Some(yaml.into()),
31
- },
32
- )
33
- .expect_err("non-string ignore-from-file entries should fail");
34
- assert!(err.contains("ignore-from-file"));
35
- }
36
-
37
- #[test]
38
- fn ignore_from_file_invalid_mapping_errors() {
39
- let yaml = "ignore-from-file: { bad: 1 }\n";
40
- let err = discover_config(
41
- &[],
42
- &Overrides {
43
- config_file: None,
44
- config_data: Some(yaml.into()),
45
- },
46
- )
47
- .expect_err("mapping value should error");
48
- assert!(err.contains("ignore-from-file should contain"));
49
- }
50
-
51
- #[test]
52
- fn ignore_patterns_non_string_errors() {
53
- let yaml = "ignore: [1]\n";
54
- let err = discover_config(
55
- &[],
56
- &Overrides {
57
- config_file: None,
58
- config_data: Some(yaml.into()),
59
- },
60
- )
61
- .expect_err("non-string ignore pattern should error");
62
- assert!(err.contains("ignore should contain"));
63
- }
64
-
65
- #[test]
66
- fn ignore_from_file_patterns_are_loaded() {
67
- let root = PathBuf::from("/workspace");
68
- let env = FakeEnv::new()
69
- .with_cwd(root.clone())
70
- .with_file(root.join("cfg.yaml"), "ignore-from-file: .gitignore\n")
71
- .with_exists(root.join("cfg.yaml"))
72
- .with_file(root.join(".gitignore"), "vendor/**\n")
73
- .with_exists(root.join(".gitignore"));
74
-
75
- let ctx = discover_config_with(
76
- &[],
77
- &Overrides {
78
- config_file: Some(root.join("cfg.yaml")),
79
- config_data: None,
80
- },
81
- &env,
82
- )
83
- .expect("ignore-from-file should hydrate patterns");
84
- assert!(
85
- ctx.config
86
- .ignore_patterns()
87
- .iter()
88
- .any(|p| p == "vendor/**")
89
- );
90
- }
91
-
92
- #[test]
93
- fn missing_ignore_from_file_errors() {
94
- let root = PathBuf::from("/workspace");
95
- let env = FakeEnv::new()
96
- .with_cwd(root.clone())
97
- .with_file(root.join("cfg.yaml"), "ignore-from-file: missing.txt\n")
98
- .with_exists(root.join("cfg.yaml"));
99
-
100
- let err = discover_config_with(
101
- &[],
102
- &Overrides {
103
- config_file: Some(root.join("cfg.yaml")),
104
- config_data: None,
105
- },
106
- &env,
107
- )
108
- .expect_err("missing ignore file should error");
109
- assert!(err.contains("failed to read ignore-from-file"));
110
- }
111
-
112
- #[test]
113
- fn invalid_ignore_from_file_pattern_errors() {
114
- let root = PathBuf::from("/workspace");
115
- let ignore = root.join("rules.ignore");
116
- let env = FakeEnv::new()
117
- .with_cwd(root.clone())
118
- .with_file(root.join("cfg.yaml"), "ignore-from-file: rules.ignore\n")
119
- .with_exists(root.join("cfg.yaml"))
120
- .with_file(ignore.clone(), "[\n")
121
- .with_exists(ignore);
122
-
123
- let err = discover_config_with(
124
- &[],
125
- &Overrides {
126
- config_file: Some(root.join("cfg.yaml")),
127
- config_data: None,
128
- },
129
- &env,
130
- )
131
- .expect_err("invalid glob should bubble up");
132
- assert!(err.contains("invalid config: ignore-from-file pattern"));
133
- }
134
-
135
- #[test]
136
- fn ignore_block_scalar_skips_blank_lines() {
137
- let yaml = "ignore: |\n docs/**\n\n build/\nrules: {}\n";
138
- let ctx = discover_config(
139
- &[],
140
- &Overrides {
141
- config_file: None,
142
- config_data: Some(yaml.into()),
143
- },
144
- )
145
- .expect("block scalar ignore should parse");
146
- assert!(
147
- !ctx.config
148
- .ignore_patterns()
149
- .iter()
150
- .any(|p| p.trim().is_empty())
151
- );
152
- }
153
-
154
- #[test]
155
- fn ignore_blank_entries_are_removed() {
156
- let yaml = "ignore: [' ', 'tmp/**']\nrules: {}\n";
157
- let ctx = discover_config(
158
- &[],
159
- &Overrides {
160
- config_file: None,
161
- config_data: Some(yaml.into()),
162
- },
163
- )
164
- .expect("blank ignore entries should be skipped");
165
- assert_eq!(ctx.config.ignore_patterns().len(), 1);
166
- assert_eq!(ctx.config.ignore_patterns()[0], "tmp/**");
167
- }
168
-
169
- #[test]
170
- fn ignore_from_file_blank_lines_are_skipped() {
171
- let root = PathBuf::from("/workspace");
172
- let env = FakeEnv::new()
173
- .with_cwd(root.clone())
174
- .with_file(root.join("cfg.yaml"), "ignore-from-file: rules.ignore\n")
175
- .with_exists(root.join("cfg.yaml"))
176
- .with_file(root.join("rules.ignore"), "\nlogs/**\n\n")
177
- .with_exists(root.join("rules.ignore"));
178
-
179
- let ctx = discover_config_with(
180
- &[],
181
- &Overrides {
182
- config_file: Some(root.join("cfg.yaml")),
183
- config_data: None,
184
- },
185
- &env,
186
- )
187
- .expect("blank lines in ignore-from-file should be ignored");
188
- assert!(ctx.config.ignore_patterns().iter().any(|p| p == "logs/**"));
189
- }
190
-
191
- #[test]
192
- fn ignore_from_file_sequence_is_supported() {
193
- let root = PathBuf::from("/workspace");
194
- let env = FakeEnv::new()
195
- .with_cwd(root.clone())
196
- .with_file(
197
- root.join("cfg.yaml"),
198
- "ignore-from-file: ['a.ignore', 'b.ignore']\n",
199
- )
200
- .with_exists(root.join("cfg.yaml"))
201
- .with_file(root.join("a.ignore"), "a/**\n")
202
- .with_exists(root.join("a.ignore"))
203
- .with_file(root.join("b.ignore"), "b/**\n")
204
- .with_exists(root.join("b.ignore"));
205
-
206
- let ctx = discover_config_with(
207
- &[],
208
- &Overrides {
209
- config_file: Some(root.join("cfg.yaml")),
210
- config_data: None,
211
- },
212
- &env,
213
- )
214
- .expect("sequence of ignore-from-file entries should parse");
215
- assert!(ctx.config.ignore_patterns().iter().any(|p| p == "a/**"));
216
- assert!(ctx.config.ignore_patterns().iter().any(|p| p == "b/**"));
217
- }
218
-
219
- #[test]
220
- fn ignore_from_file_absolute_paths_are_supported() {
221
- let root = PathBuf::from("/workspace");
222
- let abs = PathBuf::from("/workspace/.abs-ignore");
223
- let env = FakeEnv::new()
224
- .with_cwd(root.clone())
225
- .with_file(
226
- root.join("cfg.yaml"),
227
- format!("ignore-from-file: {}\n", abs.display()),
228
- )
229
- .with_exists(root.join("cfg.yaml"))
230
- .with_file(abs.clone(), "abs/**\n")
231
- .with_exists(abs);
232
-
233
- let ctx = discover_config_with(
234
- &[],
235
- &Overrides {
236
- config_file: Some(root.join("cfg.yaml")),
237
- config_data: None,
238
- },
239
- &env,
240
- )
241
- .expect("absolute ignore-from-file paths should resolve");
242
- assert!(ctx.config.ignore_patterns().iter().any(|p| p == "abs/**"));
243
- }