@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.
- package/README.md +13 -0
- package/bin/ryl.js +195 -1
- package/package.json +35 -13
- package/.github/CODEOWNERS +0 -1
- package/.github/dependabot.yml +0 -13
- package/.github/workflows/ci.yml +0 -107
- package/.github/workflows/release.yml +0 -613
- package/.github/workflows/update_dependencies.yml +0 -61
- package/.github/workflows/update_linters.yml +0 -56
- package/.pre-commit-config.yaml +0 -87
- package/.yamllint +0 -4
- package/AGENTS.md +0 -200
- package/Cargo.lock +0 -908
- package/Cargo.toml +0 -32
- package/clippy.toml +0 -1
- package/docs/config-presets.md +0 -100
- package/img/benchmark-5x5-5runs.svg +0 -2176
- package/pyproject.toml +0 -42
- package/ruff.toml +0 -107
- package/rumdl.toml +0 -20
- package/rust-toolchain.toml +0 -3
- package/rustfmt.toml +0 -3
- package/scripts/benchmark_perf_vs_yamllint.py +0 -400
- package/scripts/coverage-missing.ps1 +0 -80
- package/scripts/coverage-missing.sh +0 -60
- package/src/bin/discover_config_bin.rs +0 -24
- package/src/cli_support.rs +0 -33
- package/src/conf/mod.rs +0 -85
- package/src/config.rs +0 -2099
- package/src/decoder.rs +0 -326
- package/src/discover.rs +0 -31
- package/src/lib.rs +0 -19
- package/src/lint.rs +0 -558
- package/src/main.rs +0 -535
- package/src/migrate.rs +0 -233
- package/src/rules/anchors.rs +0 -517
- package/src/rules/braces.rs +0 -77
- package/src/rules/brackets.rs +0 -77
- package/src/rules/colons.rs +0 -475
- package/src/rules/commas.rs +0 -372
- package/src/rules/comments.rs +0 -299
- package/src/rules/comments_indentation.rs +0 -243
- package/src/rules/document_end.rs +0 -175
- package/src/rules/document_start.rs +0 -84
- package/src/rules/empty_lines.rs +0 -152
- package/src/rules/empty_values.rs +0 -255
- package/src/rules/float_values.rs +0 -259
- package/src/rules/flow_collection.rs +0 -562
- package/src/rules/hyphens.rs +0 -104
- package/src/rules/indentation.rs +0 -803
- package/src/rules/key_duplicates.rs +0 -218
- package/src/rules/key_ordering.rs +0 -303
- package/src/rules/line_length.rs +0 -326
- package/src/rules/mod.rs +0 -25
- package/src/rules/new_line_at_end_of_file.rs +0 -23
- package/src/rules/new_lines.rs +0 -95
- package/src/rules/octal_values.rs +0 -121
- package/src/rules/quoted_strings.rs +0 -577
- package/src/rules/span_utils.rs +0 -37
- package/src/rules/trailing_spaces.rs +0 -65
- package/src/rules/truthy.rs +0 -420
- package/tests/brackets_carriage_return.rs +0 -114
- package/tests/build_global_cfg_error.rs +0 -23
- package/tests/cli_anchors_rule.rs +0 -143
- package/tests/cli_braces_rule.rs +0 -104
- package/tests/cli_brackets_rule.rs +0 -104
- package/tests/cli_colons_rule.rs +0 -65
- package/tests/cli_commas_rule.rs +0 -104
- package/tests/cli_comments_indentation_rule.rs +0 -61
- package/tests/cli_comments_rule.rs +0 -67
- package/tests/cli_config_data_error.rs +0 -30
- package/tests/cli_config_flags.rs +0 -66
- package/tests/cli_config_migrate.rs +0 -229
- package/tests/cli_document_end_rule.rs +0 -92
- package/tests/cli_document_start_rule.rs +0 -92
- package/tests/cli_empty_lines_rule.rs +0 -87
- package/tests/cli_empty_values_rule.rs +0 -68
- package/tests/cli_env_config.rs +0 -34
- package/tests/cli_exit_and_errors.rs +0 -41
- package/tests/cli_file_encoding.rs +0 -203
- package/tests/cli_float_values_rule.rs +0 -64
- package/tests/cli_format_options.rs +0 -316
- package/tests/cli_global_cfg_relaxed.rs +0 -20
- package/tests/cli_hyphens_rule.rs +0 -104
- package/tests/cli_indentation_rule.rs +0 -65
- package/tests/cli_invalid_project_config.rs +0 -39
- package/tests/cli_key_duplicates_rule.rs +0 -104
- package/tests/cli_key_ordering_rule.rs +0 -59
- package/tests/cli_line_length_rule.rs +0 -85
- package/tests/cli_list_files.rs +0 -29
- package/tests/cli_new_line_rule.rs +0 -141
- package/tests/cli_new_lines_rule.rs +0 -119
- package/tests/cli_octal_values_rule.rs +0 -60
- package/tests/cli_quoted_strings_rule.rs +0 -47
- package/tests/cli_toml_config.rs +0 -119
- package/tests/cli_trailing_spaces_rule.rs +0 -77
- package/tests/cli_truthy_rule.rs +0 -83
- package/tests/cli_yaml_files_negation.rs +0 -45
- package/tests/colons_rule.rs +0 -303
- package/tests/common/compat.rs +0 -114
- package/tests/common/fake_env.rs +0 -93
- package/tests/common/mod.rs +0 -1
- package/tests/conf_builtin.rs +0 -9
- package/tests/config_anchors.rs +0 -84
- package/tests/config_braces.rs +0 -121
- package/tests/config_brackets.rs +0 -127
- package/tests/config_commas.rs +0 -79
- package/tests/config_comments.rs +0 -65
- package/tests/config_comments_indentation.rs +0 -20
- package/tests/config_deep_merge_nonstring_key.rs +0 -24
- package/tests/config_document_end.rs +0 -54
- package/tests/config_document_start.rs +0 -55
- package/tests/config_empty_lines.rs +0 -48
- package/tests/config_empty_values.rs +0 -35
- package/tests/config_env_errors.rs +0 -23
- package/tests/config_env_invalid_inline.rs +0 -15
- package/tests/config_env_missing.rs +0 -63
- package/tests/config_env_shim.rs +0 -301
- package/tests/config_explicit_file_parse_error.rs +0 -55
- package/tests/config_extended_features.rs +0 -225
- package/tests/config_extends_inline.rs +0 -185
- package/tests/config_extends_sequence.rs +0 -18
- package/tests/config_find_project_home_boundary.rs +0 -54
- package/tests/config_find_project_two_files_in_cwd.rs +0 -47
- package/tests/config_float_values.rs +0 -34
- package/tests/config_from_yaml_paths.rs +0 -32
- package/tests/config_hyphens.rs +0 -51
- package/tests/config_ignore_errors.rs +0 -243
- package/tests/config_ignore_overrides.rs +0 -83
- package/tests/config_indentation.rs +0 -65
- package/tests/config_invalid_globs.rs +0 -16
- package/tests/config_invalid_types.rs +0 -19
- package/tests/config_key_duplicates.rs +0 -34
- package/tests/config_key_ordering.rs +0 -70
- package/tests/config_line_length.rs +0 -65
- package/tests/config_locale.rs +0 -111
- package/tests/config_merge.rs +0 -26
- package/tests/config_new_lines.rs +0 -89
- package/tests/config_octal_values.rs +0 -33
- package/tests/config_quoted_strings.rs +0 -195
- package/tests/config_rule_level.rs +0 -147
- package/tests/config_rules_non_string_keys.rs +0 -23
- package/tests/config_scalar_overrides.rs +0 -27
- package/tests/config_to_toml.rs +0 -110
- package/tests/config_toml_coverage.rs +0 -80
- package/tests/config_toml_discovery.rs +0 -304
- package/tests/config_trailing_spaces.rs +0 -152
- package/tests/config_truthy.rs +0 -77
- package/tests/config_yaml_files.rs +0 -62
- package/tests/config_yaml_files_all_non_string.rs +0 -15
- package/tests/config_yaml_files_empty.rs +0 -30
- package/tests/coverage_commas.rs +0 -46
- package/tests/decoder_decode.rs +0 -338
- package/tests/discover_config_bin_all.rs +0 -66
- package/tests/discover_config_bin_env_invalid_yaml.rs +0 -26
- package/tests/discover_config_bin_project_config_parse_error.rs +0 -24
- package/tests/discover_config_bin_user_global_error.rs +0 -26
- package/tests/discover_module.rs +0 -30
- package/tests/discover_per_file_dir.rs +0 -10
- package/tests/discover_per_file_project_config_error.rs +0 -21
- package/tests/float_values.rs +0 -43
- package/tests/lint_multi_errors.rs +0 -32
- package/tests/main_yaml_ok_filtering.rs +0 -30
- package/tests/migrate_module.rs +0 -259
- package/tests/resolve_ctx_empty_parent.rs +0 -16
- package/tests/rule_anchors.rs +0 -442
- package/tests/rule_braces.rs +0 -258
- package/tests/rule_brackets.rs +0 -217
- package/tests/rule_commas.rs +0 -205
- package/tests/rule_comments.rs +0 -197
- package/tests/rule_comments_indentation.rs +0 -127
- package/tests/rule_document_end.rs +0 -118
- package/tests/rule_document_start.rs +0 -60
- package/tests/rule_empty_lines.rs +0 -96
- package/tests/rule_empty_values.rs +0 -102
- package/tests/rule_float_values.rs +0 -109
- package/tests/rule_hyphens.rs +0 -65
- package/tests/rule_indentation.rs +0 -455
- package/tests/rule_key_duplicates.rs +0 -76
- package/tests/rule_key_ordering.rs +0 -207
- package/tests/rule_line_length.rs +0 -200
- package/tests/rule_new_lines.rs +0 -51
- package/tests/rule_octal_values.rs +0 -53
- package/tests/rule_quoted_strings.rs +0 -290
- package/tests/rule_trailing_spaces.rs +0 -41
- package/tests/rule_truthy.rs +0 -236
- package/tests/user_global_invalid_yaml.rs +0 -32
- package/tests/yamllint_compat_anchors.rs +0 -280
- package/tests/yamllint_compat_braces.rs +0 -411
- package/tests/yamllint_compat_brackets.rs +0 -364
- package/tests/yamllint_compat_colons.rs +0 -298
- package/tests/yamllint_compat_colors.rs +0 -80
- package/tests/yamllint_compat_commas.rs +0 -375
- package/tests/yamllint_compat_comments.rs +0 -167
- package/tests/yamllint_compat_comments_indentation.rs +0 -281
- package/tests/yamllint_compat_config.rs +0 -170
- package/tests/yamllint_compat_document_end.rs +0 -243
- package/tests/yamllint_compat_document_start.rs +0 -136
- package/tests/yamllint_compat_empty_lines.rs +0 -117
- package/tests/yamllint_compat_empty_values.rs +0 -179
- package/tests/yamllint_compat_float_values.rs +0 -216
- package/tests/yamllint_compat_hyphens.rs +0 -223
- package/tests/yamllint_compat_indentation.rs +0 -398
- package/tests/yamllint_compat_key_duplicates.rs +0 -139
- package/tests/yamllint_compat_key_ordering.rs +0 -170
- package/tests/yamllint_compat_line_length.rs +0 -375
- package/tests/yamllint_compat_list.rs +0 -127
- package/tests/yamllint_compat_new_line.rs +0 -133
- package/tests/yamllint_compat_newline_types.rs +0 -185
- package/tests/yamllint_compat_octal_values.rs +0 -172
- package/tests/yamllint_compat_quoted_strings.rs +0 -154
- package/tests/yamllint_compat_syntax.rs +0 -200
- package/tests/yamllint_compat_trailing_spaces.rs +0 -162
- package/tests/yamllint_compat_truthy.rs +0 -130
- package/tests/yamllint_compat_yaml_files.rs +0 -81
- package/typos.toml +0 -2
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
use std::fs;
|
|
2
|
-
|
|
3
|
-
use tempfile::tempdir;
|
|
4
|
-
|
|
5
|
-
#[path = "common/compat.rs"]
|
|
6
|
-
mod compat;
|
|
7
|
-
|
|
8
|
-
use compat::{
|
|
9
|
-
SCENARIOS, build_ryl_command, build_yamllint_command, capture_with_env,
|
|
10
|
-
ensure_yamllint_installed,
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
struct Case<'a> {
|
|
14
|
-
label: &'a str,
|
|
15
|
-
config: &'a std::path::Path,
|
|
16
|
-
file: &'a std::path::Path,
|
|
17
|
-
exit: i32,
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
#[test]
|
|
21
|
-
fn quoted_strings_rule_matches_yamllint() {
|
|
22
|
-
ensure_yamllint_installed();
|
|
23
|
-
|
|
24
|
-
let dir = tempdir().unwrap();
|
|
25
|
-
|
|
26
|
-
let default_cfg = dir.path().join("default.yaml");
|
|
27
|
-
fs::write(
|
|
28
|
-
&default_cfg,
|
|
29
|
-
"rules:\n document-start: disable\n quoted-strings: enable\n",
|
|
30
|
-
)
|
|
31
|
-
.unwrap();
|
|
32
|
-
|
|
33
|
-
let only_needed_cfg = dir.path().join("only-needed.yaml");
|
|
34
|
-
fs::write(
|
|
35
|
-
&only_needed_cfg,
|
|
36
|
-
"rules:\n document-start: disable\n quoted-strings:\n required: only-when-needed\n",
|
|
37
|
-
)
|
|
38
|
-
.unwrap();
|
|
39
|
-
|
|
40
|
-
let extra_required_cfg = dir.path().join("extra-required.yaml");
|
|
41
|
-
fs::write(
|
|
42
|
-
&extra_required_cfg,
|
|
43
|
-
"rules:\n document-start: disable\n quoted-strings:\n required: false\n extra-required: ['^http']\n",
|
|
44
|
-
)
|
|
45
|
-
.unwrap();
|
|
46
|
-
|
|
47
|
-
let extra_allowed_cfg = dir.path().join("extra-allowed.yaml");
|
|
48
|
-
fs::write(
|
|
49
|
-
&extra_allowed_cfg,
|
|
50
|
-
"rules:\n document-start: disable\n quoted-strings:\n required: only-when-needed\n extra-allowed: ['^http']\n",
|
|
51
|
-
)
|
|
52
|
-
.unwrap();
|
|
53
|
-
|
|
54
|
-
let double_allow_cfg = dir.path().join("double-allow.yaml");
|
|
55
|
-
fs::write(
|
|
56
|
-
&double_allow_cfg,
|
|
57
|
-
"rules:\n document-start: disable\n quoted-strings:\n quote-type: double\n allow-quoted-quotes: true\n",
|
|
58
|
-
)
|
|
59
|
-
.unwrap();
|
|
60
|
-
|
|
61
|
-
let check_keys_cfg = dir.path().join("check-keys.yaml");
|
|
62
|
-
fs::write(
|
|
63
|
-
&check_keys_cfg,
|
|
64
|
-
"rules:\n document-start: disable\n quoted-strings:\n required: only-when-needed\n check-keys: true\n extra-required: ['[:]']\n",
|
|
65
|
-
)
|
|
66
|
-
.unwrap();
|
|
67
|
-
|
|
68
|
-
let plain_file = dir.path().join("plain.yaml");
|
|
69
|
-
fs::write(&plain_file, "foo: bar\n").unwrap();
|
|
70
|
-
|
|
71
|
-
let quoted_file = dir.path().join("quoted.yaml");
|
|
72
|
-
fs::write("ed_file, "foo: \"bar\"\n").unwrap();
|
|
73
|
-
|
|
74
|
-
let url_file = dir.path().join("urls.yaml");
|
|
75
|
-
fs::write(&url_file, "- http://example.com\n").unwrap();
|
|
76
|
-
|
|
77
|
-
let allowed_url_file = dir.path().join("allowed-url.yaml");
|
|
78
|
-
fs::write(&allowed_url_file, "foo: \"http://example.com\"\n").unwrap();
|
|
79
|
-
|
|
80
|
-
let quoted_quotes_file = dir.path().join("quoted-quotes.yaml");
|
|
81
|
-
fs::write("ed_quotes_file, "foo: 'bar\"baz'\n").unwrap();
|
|
82
|
-
|
|
83
|
-
let key_file = dir.path().join("key.yaml");
|
|
84
|
-
fs::write(&key_file, "foo:bar: baz\n").unwrap();
|
|
85
|
-
|
|
86
|
-
let exe = env!("CARGO_BIN_EXE_ryl");
|
|
87
|
-
|
|
88
|
-
let cases = [
|
|
89
|
-
Case {
|
|
90
|
-
label: "default-plain",
|
|
91
|
-
config: &default_cfg,
|
|
92
|
-
file: &plain_file,
|
|
93
|
-
exit: 1,
|
|
94
|
-
},
|
|
95
|
-
Case {
|
|
96
|
-
label: "only-needed-quoted",
|
|
97
|
-
config: &only_needed_cfg,
|
|
98
|
-
file: "ed_file,
|
|
99
|
-
exit: 1,
|
|
100
|
-
},
|
|
101
|
-
Case {
|
|
102
|
-
label: "extra-required-url",
|
|
103
|
-
config: &extra_required_cfg,
|
|
104
|
-
file: &url_file,
|
|
105
|
-
exit: 1,
|
|
106
|
-
},
|
|
107
|
-
Case {
|
|
108
|
-
label: "extra-allowed-url",
|
|
109
|
-
config: &extra_allowed_cfg,
|
|
110
|
-
file: &allowed_url_file,
|
|
111
|
-
exit: 0,
|
|
112
|
-
},
|
|
113
|
-
Case {
|
|
114
|
-
label: "double-allow-quotes",
|
|
115
|
-
config: &double_allow_cfg,
|
|
116
|
-
file: "ed_quotes_file,
|
|
117
|
-
exit: 0,
|
|
118
|
-
},
|
|
119
|
-
Case {
|
|
120
|
-
label: "check-keys",
|
|
121
|
-
config: &check_keys_cfg,
|
|
122
|
-
file: &key_file,
|
|
123
|
-
exit: 1,
|
|
124
|
-
},
|
|
125
|
-
];
|
|
126
|
-
|
|
127
|
-
for scenario in SCENARIOS {
|
|
128
|
-
for case in &cases {
|
|
129
|
-
let mut ryl_cmd = build_ryl_command(exe, scenario.ryl_format);
|
|
130
|
-
ryl_cmd.arg("-c").arg(case.config).arg(case.file);
|
|
131
|
-
let (ryl_code, ryl_msg) = capture_with_env(ryl_cmd, scenario.envs);
|
|
132
|
-
|
|
133
|
-
let mut yam_cmd = build_yamllint_command(scenario.yam_format);
|
|
134
|
-
yam_cmd.arg("-c").arg(case.config).arg(case.file);
|
|
135
|
-
let (yam_code, yam_msg) = capture_with_env(yam_cmd, scenario.envs);
|
|
136
|
-
|
|
137
|
-
assert_eq!(
|
|
138
|
-
ryl_code, case.exit,
|
|
139
|
-
"ryl exit mismatch {} ({})",
|
|
140
|
-
case.label, scenario.label
|
|
141
|
-
);
|
|
142
|
-
assert_eq!(
|
|
143
|
-
yam_code, case.exit,
|
|
144
|
-
"yamllint exit mismatch {} ({})",
|
|
145
|
-
case.label, scenario.label
|
|
146
|
-
);
|
|
147
|
-
assert_eq!(
|
|
148
|
-
ryl_msg, yam_msg,
|
|
149
|
-
"diagnostics mismatch {} ({})",
|
|
150
|
-
case.label, scenario.label
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
use std::fs;
|
|
2
|
-
use std::path::PathBuf;
|
|
3
|
-
use std::process::Command;
|
|
4
|
-
|
|
5
|
-
use tempfile::tempdir;
|
|
6
|
-
|
|
7
|
-
fn run_cmd(cmd: &mut Command) -> (i32, String, String) {
|
|
8
|
-
let out = cmd.output().expect("failed to spawn process");
|
|
9
|
-
let code = out.status.code().unwrap_or(-1);
|
|
10
|
-
let stdout = String::from_utf8_lossy(&out.stdout).into_owned();
|
|
11
|
-
let stderr = String::from_utf8_lossy(&out.stderr).into_owned();
|
|
12
|
-
(code, stdout, stderr)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
fn run_with_env(
|
|
16
|
-
mut cmd: Command,
|
|
17
|
-
envs: &[(&str, Option<&str>)],
|
|
18
|
-
) -> (i32, String, String) {
|
|
19
|
-
cmd.env_remove("GITHUB_ACTIONS");
|
|
20
|
-
cmd.env_remove("GITHUB_WORKFLOW");
|
|
21
|
-
cmd.env_remove("CI");
|
|
22
|
-
for (key, value) in envs {
|
|
23
|
-
if let Some(val) = value {
|
|
24
|
-
cmd.env(key, val);
|
|
25
|
-
} else {
|
|
26
|
-
cmd.env_remove(key);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
run_cmd(&mut cmd)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
fn write_file(dir: &std::path::Path, name: &str, content: &str) -> PathBuf {
|
|
33
|
-
let p = dir.join(name);
|
|
34
|
-
fs::write(&p, content).expect("write file");
|
|
35
|
-
p
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
fn ensure_yamllint_installed() {
|
|
39
|
-
let ok = Command::new("yamllint")
|
|
40
|
-
.arg("--version")
|
|
41
|
-
.output()
|
|
42
|
-
.map(|o| o.status.success())
|
|
43
|
-
.unwrap_or(false);
|
|
44
|
-
assert!(
|
|
45
|
-
ok,
|
|
46
|
-
"yamllint must be installed and in PATH for parity tests"
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
#[test]
|
|
51
|
-
fn yamllint_exit_behavior_matches_for_syntax_only() {
|
|
52
|
-
ensure_yamllint_installed();
|
|
53
|
-
|
|
54
|
-
let dir = tempdir().unwrap();
|
|
55
|
-
let ok = write_file(dir.path(), "ok.yaml", "a: 1\n");
|
|
56
|
-
let bad = write_file(dir.path(), "bad.yaml", "a: [1, 2\n");
|
|
57
|
-
|
|
58
|
-
// Disable yamllint rules so we only compare syntax behavior.
|
|
59
|
-
let cfg = write_file(dir.path(), ".yamllint.yml", "rules: {}\n");
|
|
60
|
-
|
|
61
|
-
let ryl = env!("CARGO_BIN_EXE_ryl");
|
|
62
|
-
|
|
63
|
-
const STANDARD_ENV: &[(&str, Option<&str>)] = &[];
|
|
64
|
-
const GITHUB_ENV: &[(&str, Option<&str>)] = &[
|
|
65
|
-
("GITHUB_ACTIONS", Some("true")),
|
|
66
|
-
("GITHUB_WORKFLOW", Some("test-workflow")),
|
|
67
|
-
("CI", Some("true")),
|
|
68
|
-
];
|
|
69
|
-
|
|
70
|
-
#[derive(Clone, Copy)]
|
|
71
|
-
enum OutputKind {
|
|
72
|
-
Standard,
|
|
73
|
-
Github,
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
fn parse_loc(msg: &str, kind: OutputKind) -> Option<(String, usize, usize)> {
|
|
77
|
-
match kind {
|
|
78
|
-
OutputKind::Standard => {
|
|
79
|
-
let mut lines = msg.lines().filter(|l| !l.trim().is_empty());
|
|
80
|
-
let file = lines.next()?.trim().to_string();
|
|
81
|
-
let second = lines.next()?.trim_start();
|
|
82
|
-
let pos = second.split_whitespace().next()?;
|
|
83
|
-
let mut it = pos.split(':');
|
|
84
|
-
let line = it.next()?.parse().ok()?;
|
|
85
|
-
let col = it.next()?.parse().ok()?;
|
|
86
|
-
Some((file, line, col))
|
|
87
|
-
}
|
|
88
|
-
OutputKind::Github => {
|
|
89
|
-
let mut lines = msg.lines().filter(|l| !l.trim().is_empty());
|
|
90
|
-
let header = lines.next()?.trim();
|
|
91
|
-
let file = header.strip_prefix("::group::")?.to_string();
|
|
92
|
-
let detail = lines.next()?.trim();
|
|
93
|
-
let detail = detail.strip_prefix("::error ")?;
|
|
94
|
-
let mut parts = detail.splitn(2, "::");
|
|
95
|
-
let meta = parts.next()?; // file=...,line=...,col=...
|
|
96
|
-
let mut meta_parts = meta.split(',');
|
|
97
|
-
let file_part = meta_parts.next()?;
|
|
98
|
-
let line_part = meta_parts.next()?;
|
|
99
|
-
let col_part = meta_parts.next()?;
|
|
100
|
-
let file_path = file_part.strip_prefix("file=")?;
|
|
101
|
-
let line_str = line_part.strip_prefix("line=")?;
|
|
102
|
-
let col_str = col_part.strip_prefix("col=")?;
|
|
103
|
-
let line = line_str.parse().ok()?;
|
|
104
|
-
let col = col_str.parse().ok()?;
|
|
105
|
-
// Ensure metadata file matches header file after trimming.
|
|
106
|
-
if !file_path.ends_with(&file) {
|
|
107
|
-
return None;
|
|
108
|
-
}
|
|
109
|
-
Some((file_path.to_string(), line, col))
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
let scenarios = [
|
|
115
|
-
("standard", STANDARD_ENV, OutputKind::Standard, true),
|
|
116
|
-
("github", GITHUB_ENV, OutputKind::Github, false),
|
|
117
|
-
];
|
|
118
|
-
|
|
119
|
-
for (label, envs, kind, use_standard_format) in scenarios {
|
|
120
|
-
// Valid file should pass in both tools.
|
|
121
|
-
let mut ryl_ok_cmd = Command::new(ryl);
|
|
122
|
-
ryl_ok_cmd.arg(&ok);
|
|
123
|
-
let (ryl_ok, _, _) = run_with_env(ryl_ok_cmd, envs);
|
|
124
|
-
assert_eq!(ryl_ok, 0, "ryl should succeed for valid yaml ({label})");
|
|
125
|
-
|
|
126
|
-
let mut yam_ok_cmd = Command::new("yamllint");
|
|
127
|
-
if use_standard_format {
|
|
128
|
-
yam_ok_cmd.arg("-f").arg("standard");
|
|
129
|
-
}
|
|
130
|
-
yam_ok_cmd.arg("-c");
|
|
131
|
-
yam_ok_cmd.arg(&cfg);
|
|
132
|
-
yam_ok_cmd.arg(&ok);
|
|
133
|
-
let (yam_ok, _, yam_ok_err) = run_with_env(yam_ok_cmd, envs);
|
|
134
|
-
assert_eq!(
|
|
135
|
-
yam_ok, 0,
|
|
136
|
-
"yamllint should succeed for valid yaml ({label}): {yam_ok_err}"
|
|
137
|
-
);
|
|
138
|
-
|
|
139
|
-
// Invalid file should fail; capture whichever stream has content.
|
|
140
|
-
let mut ryl_bad_cmd = Command::new(ryl);
|
|
141
|
-
ryl_bad_cmd.arg(&bad);
|
|
142
|
-
let (ryl_bad_code, ryl_bad_out, ryl_bad_err) = run_with_env(ryl_bad_cmd, envs);
|
|
143
|
-
let mut yam_bad_cmd = Command::new("yamllint");
|
|
144
|
-
if use_standard_format {
|
|
145
|
-
yam_bad_cmd.arg("-f").arg("standard");
|
|
146
|
-
}
|
|
147
|
-
yam_bad_cmd.arg("-c");
|
|
148
|
-
yam_bad_cmd.arg(&cfg);
|
|
149
|
-
yam_bad_cmd.arg(&bad);
|
|
150
|
-
let (yam_bad_code, yam_bad_out, yam_bad_err) = run_with_env(yam_bad_cmd, envs);
|
|
151
|
-
|
|
152
|
-
assert_ne!(
|
|
153
|
-
ryl_bad_code, 0,
|
|
154
|
-
"ryl should fail for invalid yaml ({label})"
|
|
155
|
-
);
|
|
156
|
-
assert_ne!(
|
|
157
|
-
yam_bad_code, 0,
|
|
158
|
-
"yamllint should fail for invalid yaml ({label})"
|
|
159
|
-
);
|
|
160
|
-
|
|
161
|
-
let r_msg = if !ryl_bad_err.is_empty() {
|
|
162
|
-
ryl_bad_err
|
|
163
|
-
} else {
|
|
164
|
-
ryl_bad_out
|
|
165
|
-
};
|
|
166
|
-
let y_msg = if !yam_bad_out.is_empty() {
|
|
167
|
-
yam_bad_out
|
|
168
|
-
} else {
|
|
169
|
-
yam_bad_err
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
if let (Some((rf, rl, rc)), Some((yf, yl, yc))) =
|
|
173
|
-
(parse_loc(&r_msg, kind), parse_loc(&y_msg, kind))
|
|
174
|
-
{
|
|
175
|
-
assert!(
|
|
176
|
-
rf.ends_with("bad.yaml"),
|
|
177
|
-
"ryl location should reference bad.yaml ({label}): {rf}"
|
|
178
|
-
);
|
|
179
|
-
assert!(
|
|
180
|
-
yf.ends_with("bad.yaml"),
|
|
181
|
-
"yamllint location should reference bad.yaml ({label}): {yf}"
|
|
182
|
-
);
|
|
183
|
-
assert_eq!(rl, yl, "line numbers should match ({label})");
|
|
184
|
-
assert_eq!(rc, yc, "column numbers should match ({label})");
|
|
185
|
-
} else {
|
|
186
|
-
panic!(
|
|
187
|
-
"could not parse location ({label})\nryl:\n{r_msg}\nyamllint:\n{y_msg}"
|
|
188
|
-
);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
assert!(
|
|
192
|
-
r_msg.contains("syntax error"),
|
|
193
|
-
"ryl output should mention syntax error ({label}): {r_msg}"
|
|
194
|
-
);
|
|
195
|
-
assert!(
|
|
196
|
-
y_msg.contains("syntax error"),
|
|
197
|
-
"yamllint output should mention syntax error ({label}): {y_msg}"
|
|
198
|
-
);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
use std::fs;
|
|
2
|
-
|
|
3
|
-
use tempfile::tempdir;
|
|
4
|
-
|
|
5
|
-
#[path = "common/compat.rs"]
|
|
6
|
-
mod compat;
|
|
7
|
-
|
|
8
|
-
use compat::{
|
|
9
|
-
SCENARIOS, build_ryl_command, build_yamllint_command, capture_with_env,
|
|
10
|
-
ensure_yamllint_installed,
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
#[test]
|
|
14
|
-
fn trailing_spaces_rule_matches_yamllint() {
|
|
15
|
-
ensure_yamllint_installed();
|
|
16
|
-
|
|
17
|
-
let dir = tempdir().unwrap();
|
|
18
|
-
|
|
19
|
-
let default_cfg = dir.path().join("trailing-default.yml");
|
|
20
|
-
fs::write(
|
|
21
|
-
&default_cfg,
|
|
22
|
-
"rules:\n document-start: disable\n trailing-spaces: enable\n",
|
|
23
|
-
)
|
|
24
|
-
.unwrap();
|
|
25
|
-
|
|
26
|
-
let warning_cfg = dir.path().join("trailing-warning.yml");
|
|
27
|
-
fs::write(
|
|
28
|
-
&warning_cfg,
|
|
29
|
-
"rules:\n document-start: disable\n trailing-spaces:\n level: warning\n",
|
|
30
|
-
)
|
|
31
|
-
.unwrap();
|
|
32
|
-
|
|
33
|
-
let ignore_cfg = dir.path().join("trailing-ignore.yml");
|
|
34
|
-
fs::write(
|
|
35
|
-
&ignore_cfg,
|
|
36
|
-
"rules:\n document-start: disable\n trailing-spaces:\n ignore:\n - ignored.yaml\n",
|
|
37
|
-
)
|
|
38
|
-
.unwrap();
|
|
39
|
-
|
|
40
|
-
let ignore_list = dir.path().join("trailing-ignore.txt");
|
|
41
|
-
fs::write(&ignore_list, "ignored-from-file.yaml\n").unwrap();
|
|
42
|
-
|
|
43
|
-
let ignore_from_file_cfg = dir.path().join("trailing-ignore-from-file.yml");
|
|
44
|
-
let ignore_path = ignore_list.display().to_string().replace('\'', "''");
|
|
45
|
-
fs::write(
|
|
46
|
-
&ignore_from_file_cfg,
|
|
47
|
-
format!(
|
|
48
|
-
"rules:\n document-start: disable\n trailing-spaces:\n ignore-from-file: '{}'\n",
|
|
49
|
-
ignore_path
|
|
50
|
-
),
|
|
51
|
-
)
|
|
52
|
-
.unwrap();
|
|
53
|
-
|
|
54
|
-
let bad_file = dir.path().join("bad.yaml");
|
|
55
|
-
fs::write(&bad_file, "key: value \n").unwrap();
|
|
56
|
-
|
|
57
|
-
let ignored_file = dir.path().join("ignored.yaml");
|
|
58
|
-
fs::write(&ignored_file, "other: value \n").unwrap();
|
|
59
|
-
|
|
60
|
-
let ignored_from_file = dir.path().join("ignored-from-file.yaml");
|
|
61
|
-
fs::write(&ignored_from_file, "foo: bar \n").unwrap();
|
|
62
|
-
|
|
63
|
-
let exe = env!("CARGO_BIN_EXE_ryl");
|
|
64
|
-
|
|
65
|
-
for scenario in SCENARIOS {
|
|
66
|
-
// default configuration should produce an error
|
|
67
|
-
let mut ryl_default = build_ryl_command(exe, scenario.ryl_format);
|
|
68
|
-
ryl_default.arg("-c").arg(&default_cfg).arg(&bad_file);
|
|
69
|
-
let (ryl_code, ryl_output) = capture_with_env(ryl_default, scenario.envs);
|
|
70
|
-
|
|
71
|
-
let mut yam_default = build_yamllint_command(scenario.yam_format);
|
|
72
|
-
yam_default.arg("-c").arg(&default_cfg).arg(&bad_file);
|
|
73
|
-
let (yam_code, yam_output) = capture_with_env(yam_default, scenario.envs);
|
|
74
|
-
|
|
75
|
-
assert_eq!(ryl_code, 1, "ryl default exit ({})", scenario.label);
|
|
76
|
-
assert_eq!(yam_code, 1, "yamllint default exit ({})", scenario.label);
|
|
77
|
-
assert_eq!(
|
|
78
|
-
ryl_output, yam_output,
|
|
79
|
-
"default diagnostics mismatch ({})",
|
|
80
|
-
scenario.label
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
// warning configuration should keep diagnostics but exit 0
|
|
84
|
-
let mut ryl_warning = build_ryl_command(exe, scenario.ryl_format);
|
|
85
|
-
ryl_warning.arg("-c").arg(&warning_cfg).arg(&bad_file);
|
|
86
|
-
let (ryl_warn_code, ryl_warn_output) =
|
|
87
|
-
capture_with_env(ryl_warning, scenario.envs);
|
|
88
|
-
|
|
89
|
-
let mut yam_warning = build_yamllint_command(scenario.yam_format);
|
|
90
|
-
yam_warning.arg("-c").arg(&warning_cfg).arg(&bad_file);
|
|
91
|
-
let (yam_warn_code, yam_warn_output) =
|
|
92
|
-
capture_with_env(yam_warning, scenario.envs);
|
|
93
|
-
|
|
94
|
-
assert_eq!(ryl_warn_code, 0, "ryl warning exit ({})", scenario.label);
|
|
95
|
-
assert_eq!(
|
|
96
|
-
yam_warn_code, 0,
|
|
97
|
-
"yamllint warning exit ({})",
|
|
98
|
-
scenario.label
|
|
99
|
-
);
|
|
100
|
-
assert_eq!(
|
|
101
|
-
ryl_warn_output, yam_warn_output,
|
|
102
|
-
"warning diagnostics mismatch ({})",
|
|
103
|
-
scenario.label
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
// ignore pattern applied through inline config should skip diagnostics
|
|
107
|
-
let mut ryl_ignore = build_ryl_command(exe, scenario.ryl_format);
|
|
108
|
-
ryl_ignore.arg("-c").arg(&ignore_cfg).arg(&ignored_file);
|
|
109
|
-
let (ryl_ignore_code, ryl_ignore_output) =
|
|
110
|
-
capture_with_env(ryl_ignore, scenario.envs);
|
|
111
|
-
|
|
112
|
-
let mut yam_ignore = build_yamllint_command(scenario.yam_format);
|
|
113
|
-
yam_ignore.arg("-c").arg(&ignore_cfg).arg(&ignored_file);
|
|
114
|
-
let (yam_ignore_code, yam_ignore_output) =
|
|
115
|
-
capture_with_env(yam_ignore, scenario.envs);
|
|
116
|
-
|
|
117
|
-
assert_eq!(ryl_ignore_code, 0, "ryl ignore exit ({})", scenario.label);
|
|
118
|
-
assert_eq!(
|
|
119
|
-
yam_ignore_code, 0,
|
|
120
|
-
"yamllint ignore exit ({})",
|
|
121
|
-
scenario.label
|
|
122
|
-
);
|
|
123
|
-
assert_eq!(
|
|
124
|
-
ryl_ignore_output, yam_ignore_output,
|
|
125
|
-
"ignore diagnostics mismatch ({})",
|
|
126
|
-
scenario.label
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
// ignore-from-file should behave the same
|
|
130
|
-
let mut ryl_ignore_file = build_ryl_command(exe, scenario.ryl_format);
|
|
131
|
-
ryl_ignore_file
|
|
132
|
-
.arg("-c")
|
|
133
|
-
.arg(&ignore_from_file_cfg)
|
|
134
|
-
.arg(&ignored_from_file);
|
|
135
|
-
let (ryl_file_code, ryl_file_output) =
|
|
136
|
-
capture_with_env(ryl_ignore_file, scenario.envs);
|
|
137
|
-
|
|
138
|
-
let mut yam_ignore_file = build_yamllint_command(scenario.yam_format);
|
|
139
|
-
yam_ignore_file
|
|
140
|
-
.arg("-c")
|
|
141
|
-
.arg(&ignore_from_file_cfg)
|
|
142
|
-
.arg(&ignored_from_file);
|
|
143
|
-
let (yam_file_code, yam_file_output) =
|
|
144
|
-
capture_with_env(yam_ignore_file, scenario.envs);
|
|
145
|
-
|
|
146
|
-
assert_eq!(
|
|
147
|
-
ryl_file_code, 0,
|
|
148
|
-
"ryl ignore-from-file exit ({})",
|
|
149
|
-
scenario.label
|
|
150
|
-
);
|
|
151
|
-
assert_eq!(
|
|
152
|
-
yam_file_code, 0,
|
|
153
|
-
"yamllint ignore-from-file exit ({})",
|
|
154
|
-
scenario.label
|
|
155
|
-
);
|
|
156
|
-
assert_eq!(
|
|
157
|
-
ryl_file_output, yam_file_output,
|
|
158
|
-
"ignore-from-file diagnostics mismatch ({})",
|
|
159
|
-
scenario.label
|
|
160
|
-
);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
use std::fs;
|
|
2
|
-
|
|
3
|
-
use tempfile::tempdir;
|
|
4
|
-
|
|
5
|
-
#[path = "common/compat.rs"]
|
|
6
|
-
mod compat;
|
|
7
|
-
|
|
8
|
-
use compat::{
|
|
9
|
-
SCENARIOS, build_ryl_command, build_yamllint_command, capture_with_env,
|
|
10
|
-
ensure_yamllint_installed,
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
#[test]
|
|
14
|
-
fn truthy_rule_matches_yamllint() {
|
|
15
|
-
ensure_yamllint_installed();
|
|
16
|
-
|
|
17
|
-
let dir = tempdir().unwrap();
|
|
18
|
-
|
|
19
|
-
let default_cfg = dir.path().join("truthy-default.yml");
|
|
20
|
-
fs::write(
|
|
21
|
-
&default_cfg,
|
|
22
|
-
"rules:\n document-start: disable\n truthy: enable\n",
|
|
23
|
-
)
|
|
24
|
-
.unwrap();
|
|
25
|
-
|
|
26
|
-
let allowed_cfg = dir.path().join("truthy-allowed.yml");
|
|
27
|
-
fs::write(
|
|
28
|
-
&allowed_cfg,
|
|
29
|
-
"rules:\n document-start: disable\n truthy:\n allowed-values: [\"yes\", \"no\"]\n",
|
|
30
|
-
)
|
|
31
|
-
.unwrap();
|
|
32
|
-
|
|
33
|
-
let check_keys_cfg = dir.path().join("truthy-check-keys.yml");
|
|
34
|
-
fs::write(
|
|
35
|
-
&check_keys_cfg,
|
|
36
|
-
"rules:\n document-start: disable\n truthy:\n allowed-values: []\n check-keys: false\n",
|
|
37
|
-
)
|
|
38
|
-
.unwrap();
|
|
39
|
-
|
|
40
|
-
let bad_file = dir.path().join("bad.yaml");
|
|
41
|
-
fs::write(&bad_file, "foo: True\nbar: yes\nTrue: 1\non: off\n").unwrap();
|
|
42
|
-
|
|
43
|
-
let allowed_file = dir.path().join("allowed.yaml");
|
|
44
|
-
fs::write(&allowed_file, "- yes\n- no\n- true\n- on\n").unwrap();
|
|
45
|
-
|
|
46
|
-
let ok_file = dir.path().join("ok.yaml");
|
|
47
|
-
fs::write(&ok_file, "foo: false\nbar: true\n").unwrap();
|
|
48
|
-
|
|
49
|
-
let exe = env!("CARGO_BIN_EXE_ryl");
|
|
50
|
-
|
|
51
|
-
for scenario in SCENARIOS {
|
|
52
|
-
// default configuration, expect errors on keys and values
|
|
53
|
-
let mut ryl_default = build_ryl_command(exe, scenario.ryl_format);
|
|
54
|
-
ryl_default.arg("-c").arg(&default_cfg).arg(&bad_file);
|
|
55
|
-
let (ryl_code, ryl_msg) = capture_with_env(ryl_default, scenario.envs);
|
|
56
|
-
|
|
57
|
-
let mut yam_default = build_yamllint_command(scenario.yam_format);
|
|
58
|
-
yam_default.arg("-c").arg(&default_cfg).arg(&bad_file);
|
|
59
|
-
let (yam_code, yam_msg) = capture_with_env(yam_default, scenario.envs);
|
|
60
|
-
|
|
61
|
-
assert_eq!(ryl_code, 1, "ryl default exit ({})", scenario.label);
|
|
62
|
-
assert_eq!(yam_code, 1, "yamllint default exit ({})", scenario.label);
|
|
63
|
-
assert_eq!(
|
|
64
|
-
ryl_msg, yam_msg,
|
|
65
|
-
"default diagnostics mismatch ({})",
|
|
66
|
-
scenario.label
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
// allowed-values override keeps yes/no allowed
|
|
70
|
-
let mut ryl_allowed = build_ryl_command(exe, scenario.ryl_format);
|
|
71
|
-
ryl_allowed.arg("-c").arg(&allowed_cfg).arg(&allowed_file);
|
|
72
|
-
let (ryl_allowed_code, ryl_allowed_msg) =
|
|
73
|
-
capture_with_env(ryl_allowed, scenario.envs);
|
|
74
|
-
|
|
75
|
-
let mut yam_allowed = build_yamllint_command(scenario.yam_format);
|
|
76
|
-
yam_allowed.arg("-c").arg(&allowed_cfg).arg(&allowed_file);
|
|
77
|
-
let (yam_allowed_code, yam_allowed_msg) =
|
|
78
|
-
capture_with_env(yam_allowed, scenario.envs);
|
|
79
|
-
|
|
80
|
-
assert_eq!(ryl_allowed_code, 1, "ryl allowed exit ({})", scenario.label);
|
|
81
|
-
assert_eq!(
|
|
82
|
-
yam_allowed_code, 1,
|
|
83
|
-
"yamllint allowed exit ({})",
|
|
84
|
-
scenario.label
|
|
85
|
-
);
|
|
86
|
-
assert_eq!(
|
|
87
|
-
ryl_allowed_msg, yam_allowed_msg,
|
|
88
|
-
"allowed diagnostics mismatch ({})",
|
|
89
|
-
scenario.label
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
// check-keys=false should suppress key diagnostics
|
|
93
|
-
let mut ryl_check_keys = build_ryl_command(exe, scenario.ryl_format);
|
|
94
|
-
ryl_check_keys.arg("-c").arg(&check_keys_cfg).arg(&bad_file);
|
|
95
|
-
let (ryl_ck_code, ryl_ck_msg) = capture_with_env(ryl_check_keys, scenario.envs);
|
|
96
|
-
|
|
97
|
-
let mut yam_check_keys = build_yamllint_command(scenario.yam_format);
|
|
98
|
-
yam_check_keys.arg("-c").arg(&check_keys_cfg).arg(&bad_file);
|
|
99
|
-
let (yam_ck_code, yam_ck_msg) = capture_with_env(yam_check_keys, scenario.envs);
|
|
100
|
-
|
|
101
|
-
assert_eq!(ryl_ck_code, 1, "ryl check-keys exit ({})", scenario.label);
|
|
102
|
-
assert_eq!(
|
|
103
|
-
yam_ck_code, 1,
|
|
104
|
-
"yamllint check-keys exit ({})",
|
|
105
|
-
scenario.label
|
|
106
|
-
);
|
|
107
|
-
assert_eq!(
|
|
108
|
-
ryl_ck_msg, yam_ck_msg,
|
|
109
|
-
"check-keys diagnostics mismatch ({})",
|
|
110
|
-
scenario.label
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
// success scenario: default config but compliant file
|
|
114
|
-
let mut ryl_ok = build_ryl_command(exe, scenario.ryl_format);
|
|
115
|
-
ryl_ok.arg("-c").arg(&default_cfg).arg(&ok_file);
|
|
116
|
-
let (ryl_ok_code, ryl_ok_msg) = capture_with_env(ryl_ok, scenario.envs);
|
|
117
|
-
|
|
118
|
-
let mut yam_ok = build_yamllint_command(scenario.yam_format);
|
|
119
|
-
yam_ok.arg("-c").arg(&default_cfg).arg(&ok_file);
|
|
120
|
-
let (yam_ok_code, yam_ok_msg) = capture_with_env(yam_ok, scenario.envs);
|
|
121
|
-
|
|
122
|
-
assert_eq!(ryl_ok_code, 0, "ryl ok exit ({})", scenario.label);
|
|
123
|
-
assert_eq!(yam_ok_code, 0, "yamllint ok exit ({})", scenario.label);
|
|
124
|
-
assert_eq!(
|
|
125
|
-
ryl_ok_msg, yam_ok_msg,
|
|
126
|
-
"ok diagnostics mismatch ({})",
|
|
127
|
-
scenario.label
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
}
|