@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.
- package/.github/CODEOWNERS +1 -0
- package/.github/dependabot.yml +13 -0
- package/.github/workflows/ci.yml +107 -0
- package/.github/workflows/release.yml +613 -0
- package/.github/workflows/update_dependencies.yml +61 -0
- package/.github/workflows/update_linters.yml +56 -0
- package/.pre-commit-config.yaml +87 -0
- package/.yamllint +4 -0
- package/AGENTS.md +200 -0
- package/Cargo.lock +908 -0
- package/Cargo.toml +32 -0
- package/LICENSE +21 -0
- package/README.md +230 -0
- package/bin/ryl.js +1 -0
- package/clippy.toml +1 -0
- package/docs/config-presets.md +100 -0
- package/img/benchmark-5x5-5runs.svg +2176 -0
- package/package.json +28 -0
- package/pyproject.toml +42 -0
- package/ruff.toml +107 -0
- package/rumdl.toml +20 -0
- package/rust-toolchain.toml +3 -0
- package/rustfmt.toml +3 -0
- package/scripts/benchmark_perf_vs_yamllint.py +400 -0
- package/scripts/coverage-missing.ps1 +80 -0
- package/scripts/coverage-missing.sh +60 -0
- package/src/bin/discover_config_bin.rs +24 -0
- package/src/cli_support.rs +33 -0
- package/src/conf/mod.rs +85 -0
- package/src/config.rs +2099 -0
- package/src/decoder.rs +326 -0
- package/src/discover.rs +31 -0
- package/src/lib.rs +19 -0
- package/src/lint.rs +558 -0
- package/src/main.rs +535 -0
- package/src/migrate.rs +233 -0
- package/src/rules/anchors.rs +517 -0
- package/src/rules/braces.rs +77 -0
- package/src/rules/brackets.rs +77 -0
- package/src/rules/colons.rs +475 -0
- package/src/rules/commas.rs +372 -0
- package/src/rules/comments.rs +299 -0
- package/src/rules/comments_indentation.rs +243 -0
- package/src/rules/document_end.rs +175 -0
- package/src/rules/document_start.rs +84 -0
- package/src/rules/empty_lines.rs +152 -0
- package/src/rules/empty_values.rs +255 -0
- package/src/rules/float_values.rs +259 -0
- package/src/rules/flow_collection.rs +562 -0
- package/src/rules/hyphens.rs +104 -0
- package/src/rules/indentation.rs +803 -0
- package/src/rules/key_duplicates.rs +218 -0
- package/src/rules/key_ordering.rs +303 -0
- package/src/rules/line_length.rs +326 -0
- package/src/rules/mod.rs +25 -0
- package/src/rules/new_line_at_end_of_file.rs +23 -0
- package/src/rules/new_lines.rs +95 -0
- package/src/rules/octal_values.rs +121 -0
- package/src/rules/quoted_strings.rs +577 -0
- package/src/rules/span_utils.rs +37 -0
- package/src/rules/trailing_spaces.rs +65 -0
- package/src/rules/truthy.rs +420 -0
- package/tests/brackets_carriage_return.rs +114 -0
- package/tests/build_global_cfg_error.rs +23 -0
- package/tests/cli_anchors_rule.rs +143 -0
- package/tests/cli_braces_rule.rs +104 -0
- package/tests/cli_brackets_rule.rs +104 -0
- package/tests/cli_colons_rule.rs +65 -0
- package/tests/cli_commas_rule.rs +104 -0
- package/tests/cli_comments_indentation_rule.rs +61 -0
- package/tests/cli_comments_rule.rs +67 -0
- package/tests/cli_config_data_error.rs +30 -0
- package/tests/cli_config_flags.rs +66 -0
- package/tests/cli_config_migrate.rs +229 -0
- package/tests/cli_document_end_rule.rs +92 -0
- package/tests/cli_document_start_rule.rs +92 -0
- package/tests/cli_empty_lines_rule.rs +87 -0
- package/tests/cli_empty_values_rule.rs +68 -0
- package/tests/cli_env_config.rs +34 -0
- package/tests/cli_exit_and_errors.rs +41 -0
- package/tests/cli_file_encoding.rs +203 -0
- package/tests/cli_float_values_rule.rs +64 -0
- package/tests/cli_format_options.rs +316 -0
- package/tests/cli_global_cfg_relaxed.rs +20 -0
- package/tests/cli_hyphens_rule.rs +104 -0
- package/tests/cli_indentation_rule.rs +65 -0
- package/tests/cli_invalid_project_config.rs +39 -0
- package/tests/cli_key_duplicates_rule.rs +104 -0
- package/tests/cli_key_ordering_rule.rs +59 -0
- package/tests/cli_line_length_rule.rs +85 -0
- package/tests/cli_list_files.rs +29 -0
- package/tests/cli_new_line_rule.rs +141 -0
- package/tests/cli_new_lines_rule.rs +119 -0
- package/tests/cli_octal_values_rule.rs +60 -0
- package/tests/cli_quoted_strings_rule.rs +47 -0
- package/tests/cli_toml_config.rs +119 -0
- package/tests/cli_trailing_spaces_rule.rs +77 -0
- package/tests/cli_truthy_rule.rs +83 -0
- package/tests/cli_yaml_files_negation.rs +45 -0
- package/tests/colons_rule.rs +303 -0
- package/tests/common/compat.rs +114 -0
- package/tests/common/fake_env.rs +93 -0
- package/tests/common/mod.rs +1 -0
- package/tests/conf_builtin.rs +9 -0
- package/tests/config_anchors.rs +84 -0
- package/tests/config_braces.rs +121 -0
- package/tests/config_brackets.rs +127 -0
- package/tests/config_commas.rs +79 -0
- package/tests/config_comments.rs +65 -0
- package/tests/config_comments_indentation.rs +20 -0
- package/tests/config_deep_merge_nonstring_key.rs +24 -0
- package/tests/config_document_end.rs +54 -0
- package/tests/config_document_start.rs +55 -0
- package/tests/config_empty_lines.rs +48 -0
- package/tests/config_empty_values.rs +35 -0
- package/tests/config_env_errors.rs +23 -0
- package/tests/config_env_invalid_inline.rs +15 -0
- package/tests/config_env_missing.rs +63 -0
- package/tests/config_env_shim.rs +301 -0
- package/tests/config_explicit_file_parse_error.rs +55 -0
- package/tests/config_extended_features.rs +225 -0
- package/tests/config_extends_inline.rs +185 -0
- package/tests/config_extends_sequence.rs +18 -0
- package/tests/config_find_project_home_boundary.rs +54 -0
- package/tests/config_find_project_two_files_in_cwd.rs +47 -0
- package/tests/config_float_values.rs +34 -0
- package/tests/config_from_yaml_paths.rs +32 -0
- package/tests/config_hyphens.rs +51 -0
- package/tests/config_ignore_errors.rs +243 -0
- package/tests/config_ignore_overrides.rs +83 -0
- package/tests/config_indentation.rs +65 -0
- package/tests/config_invalid_globs.rs +16 -0
- package/tests/config_invalid_types.rs +19 -0
- package/tests/config_key_duplicates.rs +34 -0
- package/tests/config_key_ordering.rs +70 -0
- package/tests/config_line_length.rs +65 -0
- package/tests/config_locale.rs +111 -0
- package/tests/config_merge.rs +26 -0
- package/tests/config_new_lines.rs +89 -0
- package/tests/config_octal_values.rs +33 -0
- package/tests/config_quoted_strings.rs +195 -0
- package/tests/config_rule_level.rs +147 -0
- package/tests/config_rules_non_string_keys.rs +23 -0
- package/tests/config_scalar_overrides.rs +27 -0
- package/tests/config_to_toml.rs +110 -0
- package/tests/config_toml_coverage.rs +80 -0
- package/tests/config_toml_discovery.rs +304 -0
- package/tests/config_trailing_spaces.rs +152 -0
- package/tests/config_truthy.rs +77 -0
- package/tests/config_yaml_files.rs +62 -0
- package/tests/config_yaml_files_all_non_string.rs +15 -0
- package/tests/config_yaml_files_empty.rs +30 -0
- package/tests/coverage_commas.rs +46 -0
- package/tests/decoder_decode.rs +338 -0
- package/tests/discover_config_bin_all.rs +66 -0
- package/tests/discover_config_bin_env_invalid_yaml.rs +26 -0
- package/tests/discover_config_bin_project_config_parse_error.rs +24 -0
- package/tests/discover_config_bin_user_global_error.rs +26 -0
- package/tests/discover_module.rs +30 -0
- package/tests/discover_per_file_dir.rs +10 -0
- package/tests/discover_per_file_project_config_error.rs +21 -0
- package/tests/float_values.rs +43 -0
- package/tests/lint_multi_errors.rs +32 -0
- package/tests/main_yaml_ok_filtering.rs +30 -0
- package/tests/migrate_module.rs +259 -0
- package/tests/resolve_ctx_empty_parent.rs +16 -0
- package/tests/rule_anchors.rs +442 -0
- package/tests/rule_braces.rs +258 -0
- package/tests/rule_brackets.rs +217 -0
- package/tests/rule_commas.rs +205 -0
- package/tests/rule_comments.rs +197 -0
- package/tests/rule_comments_indentation.rs +127 -0
- package/tests/rule_document_end.rs +118 -0
- package/tests/rule_document_start.rs +60 -0
- package/tests/rule_empty_lines.rs +96 -0
- package/tests/rule_empty_values.rs +102 -0
- package/tests/rule_float_values.rs +109 -0
- package/tests/rule_hyphens.rs +65 -0
- package/tests/rule_indentation.rs +455 -0
- package/tests/rule_key_duplicates.rs +76 -0
- package/tests/rule_key_ordering.rs +207 -0
- package/tests/rule_line_length.rs +200 -0
- package/tests/rule_new_lines.rs +51 -0
- package/tests/rule_octal_values.rs +53 -0
- package/tests/rule_quoted_strings.rs +290 -0
- package/tests/rule_trailing_spaces.rs +41 -0
- package/tests/rule_truthy.rs +236 -0
- package/tests/user_global_invalid_yaml.rs +32 -0
- package/tests/yamllint_compat_anchors.rs +280 -0
- package/tests/yamllint_compat_braces.rs +411 -0
- package/tests/yamllint_compat_brackets.rs +364 -0
- package/tests/yamllint_compat_colons.rs +298 -0
- package/tests/yamllint_compat_colors.rs +80 -0
- package/tests/yamllint_compat_commas.rs +375 -0
- package/tests/yamllint_compat_comments.rs +167 -0
- package/tests/yamllint_compat_comments_indentation.rs +281 -0
- package/tests/yamllint_compat_config.rs +170 -0
- package/tests/yamllint_compat_document_end.rs +243 -0
- package/tests/yamllint_compat_document_start.rs +136 -0
- package/tests/yamllint_compat_empty_lines.rs +117 -0
- package/tests/yamllint_compat_empty_values.rs +179 -0
- package/tests/yamllint_compat_float_values.rs +216 -0
- package/tests/yamllint_compat_hyphens.rs +223 -0
- package/tests/yamllint_compat_indentation.rs +398 -0
- package/tests/yamllint_compat_key_duplicates.rs +139 -0
- package/tests/yamllint_compat_key_ordering.rs +170 -0
- package/tests/yamllint_compat_line_length.rs +375 -0
- package/tests/yamllint_compat_list.rs +127 -0
- package/tests/yamllint_compat_new_line.rs +133 -0
- package/tests/yamllint_compat_newline_types.rs +185 -0
- package/tests/yamllint_compat_octal_values.rs +172 -0
- package/tests/yamllint_compat_quoted_strings.rs +154 -0
- package/tests/yamllint_compat_syntax.rs +200 -0
- package/tests/yamllint_compat_trailing_spaces.rs +162 -0
- package/tests/yamllint_compat_truthy.rs +130 -0
- package/tests/yamllint_compat_yaml_files.rs +81 -0
- package/typos.toml +2 -0
|
@@ -0,0 +1,290 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,236 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
}
|