@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,83 @@
|
|
|
1
|
+
use std::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 child_ignore_patterns_replace_parent_entries() {
|
|
11
|
+
let root = PathBuf::from("/workspace");
|
|
12
|
+
let base_cfg = root.join("base.yml");
|
|
13
|
+
let child_cfg = root.join("child.yml");
|
|
14
|
+
|
|
15
|
+
let env = FakeEnv::new()
|
|
16
|
+
.with_cwd(root.clone())
|
|
17
|
+
.with_file(base_cfg.clone(), "rules: {}\nignore: ['parent.yaml']\n")
|
|
18
|
+
.with_file(
|
|
19
|
+
child_cfg.clone(),
|
|
20
|
+
"extends: base.yml\nignore: ['child.yaml']\nrules: {}\n",
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
let ctx = discover_config_with(
|
|
24
|
+
&[],
|
|
25
|
+
&Overrides {
|
|
26
|
+
config_file: Some(child_cfg),
|
|
27
|
+
config_data: None,
|
|
28
|
+
},
|
|
29
|
+
&env,
|
|
30
|
+
)
|
|
31
|
+
.expect("child config should parse");
|
|
32
|
+
|
|
33
|
+
let base_dir = ctx.base_dir.clone();
|
|
34
|
+
assert!(
|
|
35
|
+
ctx.config
|
|
36
|
+
.is_file_ignored(&base_dir.join("child.yaml"), &base_dir),
|
|
37
|
+
"child.yaml should be ignored by child config"
|
|
38
|
+
);
|
|
39
|
+
assert!(
|
|
40
|
+
!ctx.config
|
|
41
|
+
.is_file_ignored(&base_dir.join("parent.yaml"), &base_dir),
|
|
42
|
+
"parent.yaml should not use parent ignore entries"
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
#[test]
|
|
47
|
+
fn child_ignore_from_file_replaces_parent_patterns() {
|
|
48
|
+
let root = PathBuf::from("/workspace");
|
|
49
|
+
let base_cfg = root.join("base.yml");
|
|
50
|
+
let child_cfg = root.join("child.yml");
|
|
51
|
+
let ignore_file = root.join("child.ignore");
|
|
52
|
+
|
|
53
|
+
let env = FakeEnv::new()
|
|
54
|
+
.with_cwd(root.clone())
|
|
55
|
+
.with_file(base_cfg.clone(), "rules: {}\nignore: ['parent.yaml']\n")
|
|
56
|
+
.with_file(
|
|
57
|
+
child_cfg.clone(),
|
|
58
|
+
"extends: base.yml\nignore-from-file: child.ignore\nrules: {}\n",
|
|
59
|
+
)
|
|
60
|
+
.with_file(ignore_file.clone(), "child.yaml\n");
|
|
61
|
+
|
|
62
|
+
let ctx = discover_config_with(
|
|
63
|
+
&[],
|
|
64
|
+
&Overrides {
|
|
65
|
+
config_file: Some(child_cfg),
|
|
66
|
+
config_data: None,
|
|
67
|
+
},
|
|
68
|
+
&env,
|
|
69
|
+
)
|
|
70
|
+
.expect("child config should parse");
|
|
71
|
+
|
|
72
|
+
let base_dir = ctx.base_dir.clone();
|
|
73
|
+
assert!(
|
|
74
|
+
ctx.config
|
|
75
|
+
.is_file_ignored(&base_dir.join("child.yaml"), &base_dir),
|
|
76
|
+
"child.yaml should respect child ignore-from-file entries"
|
|
77
|
+
);
|
|
78
|
+
assert!(
|
|
79
|
+
!ctx.config
|
|
80
|
+
.is_file_ignored(&base_dir.join("parent.yaml"), &base_dir),
|
|
81
|
+
"parent ignores should be replaced by child ignore-from-file"
|
|
82
|
+
);
|
|
83
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
use ryl::config::YamlLintConfig;
|
|
2
|
+
|
|
3
|
+
#[test]
|
|
4
|
+
fn rejects_invalid_spaces_type() {
|
|
5
|
+
let err =
|
|
6
|
+
YamlLintConfig::from_yaml_str("rules:\n indentation:\n spaces: foo\n")
|
|
7
|
+
.unwrap_err();
|
|
8
|
+
assert_eq!(
|
|
9
|
+
err,
|
|
10
|
+
"invalid config: option \"spaces\" of \"indentation\" should be in (<class 'int'>, 'consistent')"
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
#[test]
|
|
15
|
+
fn rejects_invalid_indent_sequences_type() {
|
|
16
|
+
let err = YamlLintConfig::from_yaml_str(
|
|
17
|
+
"rules:\n indentation:\n indent-sequences: 1\n",
|
|
18
|
+
)
|
|
19
|
+
.unwrap_err();
|
|
20
|
+
assert_eq!(
|
|
21
|
+
err,
|
|
22
|
+
"invalid config: option \"indent-sequences\" of \"indentation\" should be in (<class 'bool'>, 'whatever', 'consistent')"
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
#[test]
|
|
27
|
+
fn rejects_invalid_multiline_flag() {
|
|
28
|
+
let err = YamlLintConfig::from_yaml_str(
|
|
29
|
+
"rules:\n indentation:\n check-multi-line-strings: []\n",
|
|
30
|
+
)
|
|
31
|
+
.unwrap_err();
|
|
32
|
+
assert_eq!(
|
|
33
|
+
err,
|
|
34
|
+
"invalid config: option \"check-multi-line-strings\" of \"indentation\" should be bool"
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
#[test]
|
|
39
|
+
fn accepts_full_configuration() {
|
|
40
|
+
let cfg = YamlLintConfig::from_yaml_str(
|
|
41
|
+
"rules:\n indentation:\n spaces: 2\n indent-sequences: consistent\n check-multi-line-strings: true\n",
|
|
42
|
+
)
|
|
43
|
+
.expect("configuration should parse");
|
|
44
|
+
assert!(cfg.rule_names().iter().any(|name| name == "indentation"));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
#[test]
|
|
48
|
+
fn rejects_unknown_option_key() {
|
|
49
|
+
let err =
|
|
50
|
+
YamlLintConfig::from_yaml_str("rules:\n indentation:\n unexpected: true\n")
|
|
51
|
+
.unwrap_err();
|
|
52
|
+
assert_eq!(
|
|
53
|
+
err,
|
|
54
|
+
"invalid config: unknown option \"unexpected\" for rule \"indentation\""
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
#[test]
|
|
59
|
+
fn accepts_whatever_sequence_setting() {
|
|
60
|
+
let cfg = YamlLintConfig::from_yaml_str(
|
|
61
|
+
"rules:\n indentation:\n indent-sequences: whatever\n",
|
|
62
|
+
)
|
|
63
|
+
.expect("configuration should parse");
|
|
64
|
+
assert!(cfg.rule_names().iter().any(|name| name == "indentation"));
|
|
65
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
use ryl::config::{Overrides, discover_config};
|
|
2
|
+
|
|
3
|
+
#[test]
|
|
4
|
+
fn invalid_ignore_and_yaml_file_patterns_error() {
|
|
5
|
+
// '[' is an invalid glob; configuration should fail to parse.
|
|
6
|
+
let cfg = "ignore: ['[']\nyaml-files: ['[']\n";
|
|
7
|
+
let err = discover_config(
|
|
8
|
+
&[],
|
|
9
|
+
&Overrides {
|
|
10
|
+
config_file: None,
|
|
11
|
+
config_data: Some(cfg.into()),
|
|
12
|
+
},
|
|
13
|
+
)
|
|
14
|
+
.unwrap_err();
|
|
15
|
+
assert!(err.contains("invalid config"));
|
|
16
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
use ryl::config::{Overrides, discover_config};
|
|
2
|
+
|
|
3
|
+
#[test]
|
|
4
|
+
fn invalid_types_for_ignore_and_yaml_files_error() {
|
|
5
|
+
let yaml = r#"
|
|
6
|
+
ignore: { bad: 1 }
|
|
7
|
+
yaml-files: { bad: 2 }
|
|
8
|
+
rules: {}
|
|
9
|
+
"#;
|
|
10
|
+
let err = discover_config(
|
|
11
|
+
&[],
|
|
12
|
+
&Overrides {
|
|
13
|
+
config_file: None,
|
|
14
|
+
config_data: Some(yaml.into()),
|
|
15
|
+
},
|
|
16
|
+
)
|
|
17
|
+
.unwrap_err();
|
|
18
|
+
assert!(err.contains("invalid config"));
|
|
19
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
use ryl::config::YamlLintConfig;
|
|
2
|
+
|
|
3
|
+
#[test]
|
|
4
|
+
fn error_on_non_bool_for_forbid_merge_keys() {
|
|
5
|
+
let err = YamlLintConfig::from_yaml_str(
|
|
6
|
+
"rules:\n key-duplicates:\n forbid-duplicated-merge-keys: 1\n",
|
|
7
|
+
)
|
|
8
|
+
.unwrap_err();
|
|
9
|
+
assert_eq!(
|
|
10
|
+
err,
|
|
11
|
+
"invalid config: option \"forbid-duplicated-merge-keys\" of \"key-duplicates\" should be bool"
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
#[test]
|
|
16
|
+
fn error_on_unknown_option() {
|
|
17
|
+
let err =
|
|
18
|
+
YamlLintConfig::from_yaml_str("rules:\n key-duplicates:\n foo: true\n")
|
|
19
|
+
.unwrap_err();
|
|
20
|
+
assert_eq!(
|
|
21
|
+
err,
|
|
22
|
+
"invalid config: unknown option \"foo\" for rule \"key-duplicates\""
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
#[test]
|
|
27
|
+
fn error_on_non_string_option_key() {
|
|
28
|
+
let err = YamlLintConfig::from_yaml_str("rules:\n key-duplicates:\n 1: true\n")
|
|
29
|
+
.unwrap_err();
|
|
30
|
+
assert_eq!(
|
|
31
|
+
err,
|
|
32
|
+
"invalid config: unknown option \"1\" for rule \"key-duplicates\""
|
|
33
|
+
);
|
|
34
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
use ryl::config::YamlLintConfig;
|
|
2
|
+
|
|
3
|
+
#[test]
|
|
4
|
+
fn ignored_keys_sequence_accepts_valid_entries() {
|
|
5
|
+
let cfg = YamlLintConfig::from_yaml_str(
|
|
6
|
+
"rules:\n key-ordering:\n ignored-keys: [\"name\", \"^b\"]\n",
|
|
7
|
+
)
|
|
8
|
+
.expect("config should parse");
|
|
9
|
+
let resolved = ryl::rules::key_ordering::Config::resolve(&cfg);
|
|
10
|
+
let hits = ryl::rules::key_ordering::check("b: 1\na: 1\n", &resolved);
|
|
11
|
+
assert!(
|
|
12
|
+
hits.is_empty(),
|
|
13
|
+
"ignored keys should skip enforcement: {hits:?}"
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
#[test]
|
|
18
|
+
fn ignored_keys_sequence_non_string_errors() {
|
|
19
|
+
let err = YamlLintConfig::from_yaml_str(
|
|
20
|
+
"rules:\n key-ordering:\n ignored-keys: [1]\n",
|
|
21
|
+
)
|
|
22
|
+
.expect_err("non-string sequence entries should error");
|
|
23
|
+
assert!(
|
|
24
|
+
err.contains("ignored-keys"),
|
|
25
|
+
"error should mention ignored-keys: {err}"
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
#[test]
|
|
30
|
+
fn ignored_keys_sequence_invalid_regex_errors() {
|
|
31
|
+
let err = YamlLintConfig::from_yaml_str(
|
|
32
|
+
"rules:\n key-ordering:\n ignored-keys: [\"[\"]\n",
|
|
33
|
+
)
|
|
34
|
+
.expect_err("invalid regex should error");
|
|
35
|
+
assert!(err.contains("invalid regex"), "unexpected message: {err}");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
#[test]
|
|
39
|
+
fn ignored_keys_scalar_invalid_regex_errors() {
|
|
40
|
+
let err = YamlLintConfig::from_yaml_str(
|
|
41
|
+
"rules:\n key-ordering:\n ignored-keys: \"[\"\n",
|
|
42
|
+
)
|
|
43
|
+
.expect_err("invalid scalar regex should error");
|
|
44
|
+
assert!(err.contains("invalid regex"), "unexpected message: {err}");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
#[test]
|
|
48
|
+
fn ignored_keys_invalid_type_errors() {
|
|
49
|
+
let err = YamlLintConfig::from_yaml_str(
|
|
50
|
+
"rules:\n key-ordering:\n ignored-keys: {bad: true}\n",
|
|
51
|
+
)
|
|
52
|
+
.expect_err("non sequence/string should error");
|
|
53
|
+
assert!(err.contains("should contain regex strings"), "{err}");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
#[test]
|
|
57
|
+
fn key_ordering_unknown_option_errors() {
|
|
58
|
+
let err = YamlLintConfig::from_yaml_str(
|
|
59
|
+
"rules:\n key-ordering:\n unexpected: true\n",
|
|
60
|
+
)
|
|
61
|
+
.expect_err("unknown option should error");
|
|
62
|
+
assert!(err.contains("unknown option \"unexpected\""), "{err}");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
#[test]
|
|
66
|
+
fn key_ordering_non_string_key_errors() {
|
|
67
|
+
let err = YamlLintConfig::from_yaml_str("rules:\n key-ordering:\n 1: true\n")
|
|
68
|
+
.expect_err("non-string key should error");
|
|
69
|
+
assert!(err.contains("unknown option"), "{err}");
|
|
70
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
use ryl::config::YamlLintConfig;
|
|
2
|
+
|
|
3
|
+
#[test]
|
|
4
|
+
fn rejects_unknown_option() {
|
|
5
|
+
let err =
|
|
6
|
+
YamlLintConfig::from_yaml_str("rules:\n line-length:\n unexpected: true\n")
|
|
7
|
+
.unwrap_err();
|
|
8
|
+
assert_eq!(
|
|
9
|
+
err,
|
|
10
|
+
"invalid config: unknown option \"unexpected\" for rule \"line-length\""
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
#[test]
|
|
15
|
+
fn rejects_non_integer_max() {
|
|
16
|
+
let err = YamlLintConfig::from_yaml_str("rules:\n line-length:\n max: []\n")
|
|
17
|
+
.unwrap_err();
|
|
18
|
+
assert_eq!(
|
|
19
|
+
err,
|
|
20
|
+
"invalid config: option \"max\" of \"line-length\" should be int"
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
#[test]
|
|
25
|
+
fn rejects_non_boolean_allow_words() {
|
|
26
|
+
let err = YamlLintConfig::from_yaml_str(
|
|
27
|
+
"rules:\n line-length:\n allow-non-breakable-words: []\n",
|
|
28
|
+
)
|
|
29
|
+
.unwrap_err();
|
|
30
|
+
assert_eq!(
|
|
31
|
+
err,
|
|
32
|
+
"invalid config: option \"allow-non-breakable-words\" of \"line-length\" should be bool"
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
#[test]
|
|
37
|
+
fn rejects_non_boolean_allow_inline() {
|
|
38
|
+
let err = YamlLintConfig::from_yaml_str(
|
|
39
|
+
"rules:\n line-length:\n allow-non-breakable-inline-mappings: 1\n",
|
|
40
|
+
)
|
|
41
|
+
.unwrap_err();
|
|
42
|
+
assert_eq!(
|
|
43
|
+
err,
|
|
44
|
+
"invalid config: option \"allow-non-breakable-inline-mappings\" of \"line-length\" should be bool"
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
#[test]
|
|
49
|
+
fn accepts_valid_configuration() {
|
|
50
|
+
let cfg = YamlLintConfig::from_yaml_str(
|
|
51
|
+
"rules:\n line-length:\n max: 100\n allow-non-breakable-words: false\n allow-non-breakable-inline-mappings: true\n",
|
|
52
|
+
)
|
|
53
|
+
.expect("configuration should parse");
|
|
54
|
+
assert!(cfg.rule_names().iter().any(|name| name == "line-length"));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
#[test]
|
|
58
|
+
fn rejects_non_string_option_key() {
|
|
59
|
+
let err = YamlLintConfig::from_yaml_str("rules:\n line-length:\n 1: true\n")
|
|
60
|
+
.unwrap_err();
|
|
61
|
+
assert_eq!(
|
|
62
|
+
err,
|
|
63
|
+
"invalid config: unknown option \"1\" for rule \"line-length\""
|
|
64
|
+
);
|
|
65
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
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 locale_value_is_parsed() {
|
|
11
|
+
let ctx = discover_config(
|
|
12
|
+
&[],
|
|
13
|
+
&Overrides {
|
|
14
|
+
config_file: None,
|
|
15
|
+
config_data: Some("locale: en_US.UTF-8\nrules: {}\n".into()),
|
|
16
|
+
},
|
|
17
|
+
)
|
|
18
|
+
.expect("locale should parse");
|
|
19
|
+
assert_eq!(ctx.config.locale(), Some("en_US.UTF-8"));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
#[test]
|
|
23
|
+
fn locale_from_child_overrides_base() {
|
|
24
|
+
let root = PathBuf::from("/workspace");
|
|
25
|
+
let child = root.join("child.yml");
|
|
26
|
+
let base = root.join("base.yml");
|
|
27
|
+
let env = FakeEnv::new()
|
|
28
|
+
.with_cwd(root.clone())
|
|
29
|
+
.with_file(child.clone(), "locale: fr_FR.UTF-8\nextends: base.yml\n")
|
|
30
|
+
.with_exists(child.clone())
|
|
31
|
+
.with_file(base.clone(), "locale: en_US.UTF-8\n")
|
|
32
|
+
.with_exists(base.clone());
|
|
33
|
+
|
|
34
|
+
let ctx = discover_config_with(
|
|
35
|
+
&[],
|
|
36
|
+
&Overrides {
|
|
37
|
+
config_file: Some(child),
|
|
38
|
+
config_data: None,
|
|
39
|
+
},
|
|
40
|
+
&env,
|
|
41
|
+
)
|
|
42
|
+
.expect("child locale should win");
|
|
43
|
+
assert_eq!(ctx.config.locale(), Some("fr_FR.UTF-8"));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
#[test]
|
|
47
|
+
fn locale_falls_back_to_base_when_missing() {
|
|
48
|
+
let root = PathBuf::from("/workspace");
|
|
49
|
+
let child = root.join("child.yml");
|
|
50
|
+
let base = root.join("base.yml");
|
|
51
|
+
let env = FakeEnv::new()
|
|
52
|
+
.with_cwd(root.clone())
|
|
53
|
+
.with_file(child.clone(), "extends: base.yml\n")
|
|
54
|
+
.with_exists(child.clone())
|
|
55
|
+
.with_file(base.clone(), "locale: en_US.UTF-8\n")
|
|
56
|
+
.with_exists(base.clone());
|
|
57
|
+
|
|
58
|
+
let ctx = discover_config_with(
|
|
59
|
+
&[],
|
|
60
|
+
&Overrides {
|
|
61
|
+
config_file: Some(child),
|
|
62
|
+
config_data: None,
|
|
63
|
+
},
|
|
64
|
+
&env,
|
|
65
|
+
)
|
|
66
|
+
.expect("locale should bubble from base");
|
|
67
|
+
assert_eq!(ctx.config.locale(), Some("en_US.UTF-8"));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
#[test]
|
|
71
|
+
fn locale_non_string_errors() {
|
|
72
|
+
let err = discover_config(
|
|
73
|
+
&[],
|
|
74
|
+
&Overrides {
|
|
75
|
+
config_file: None,
|
|
76
|
+
config_data: Some("locale: [1]\n".into()),
|
|
77
|
+
},
|
|
78
|
+
)
|
|
79
|
+
.expect_err("non-string locale should error");
|
|
80
|
+
assert!(err.contains("locale should be a string"));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
#[test]
|
|
84
|
+
fn locale_survives_additional_extends() {
|
|
85
|
+
let root = PathBuf::from("/workspace");
|
|
86
|
+
let cfg = root.join("config.yml");
|
|
87
|
+
let first = root.join("first.yml");
|
|
88
|
+
let second = root.join("second.yml");
|
|
89
|
+
let env = FakeEnv::new()
|
|
90
|
+
.with_cwd(root.clone())
|
|
91
|
+
.with_file(first.clone(), "locale: en_US.UTF-8\n")
|
|
92
|
+
.with_exists(first.clone())
|
|
93
|
+
.with_file(second.clone(), "rules: { extra: enable }\n")
|
|
94
|
+
.with_exists(second.clone())
|
|
95
|
+
.with_file(
|
|
96
|
+
cfg.clone(),
|
|
97
|
+
format!("extends: ['{}', '{}']\n", first.display(), second.display()),
|
|
98
|
+
)
|
|
99
|
+
.with_exists(cfg.clone());
|
|
100
|
+
|
|
101
|
+
let ctx = discover_config_with(
|
|
102
|
+
&[],
|
|
103
|
+
&Overrides {
|
|
104
|
+
config_file: Some(cfg),
|
|
105
|
+
config_data: None,
|
|
106
|
+
},
|
|
107
|
+
&env,
|
|
108
|
+
)
|
|
109
|
+
.expect("multiple extends should parse");
|
|
110
|
+
assert_eq!(ctx.config.locale(), Some("en_US.UTF-8"));
|
|
111
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
use ryl::config::{Overrides, discover_config};
|
|
2
|
+
|
|
3
|
+
#[test]
|
|
4
|
+
fn rules_merge_deep_and_replace_scalars() {
|
|
5
|
+
// Start from default (anchors: enable [scalar], comments: { level: warning } [map])
|
|
6
|
+
// Then replace anchors with a mapping and extend comments with an extra key.
|
|
7
|
+
let cfg = r#"
|
|
8
|
+
extends: default
|
|
9
|
+
rules:
|
|
10
|
+
anchors:
|
|
11
|
+
forbid-duplicated-anchors: true
|
|
12
|
+
comments:
|
|
13
|
+
min-spaces-from-content: 1
|
|
14
|
+
level: error
|
|
15
|
+
"#;
|
|
16
|
+
let ctx = discover_config(
|
|
17
|
+
&[],
|
|
18
|
+
&Overrides {
|
|
19
|
+
config_file: None,
|
|
20
|
+
config_data: Some(cfg.into()),
|
|
21
|
+
},
|
|
22
|
+
)
|
|
23
|
+
.expect("parse");
|
|
24
|
+
assert!(ctx.config.rule_names().contains(&"anchors".to_string()));
|
|
25
|
+
assert!(ctx.config.rule_names().contains(&"comments".to_string()));
|
|
26
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
use ryl::config::{Overrides, discover_config};
|
|
2
|
+
|
|
3
|
+
fn discover_with_yaml(yaml: &str) -> Result<(), String> {
|
|
4
|
+
discover_config(
|
|
5
|
+
&[],
|
|
6
|
+
&Overrides {
|
|
7
|
+
config_file: None,
|
|
8
|
+
config_data: Some(yaml.to_string()),
|
|
9
|
+
},
|
|
10
|
+
)
|
|
11
|
+
.map(|_| ())
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
#[test]
|
|
15
|
+
fn unknown_option_errors() {
|
|
16
|
+
let err = discover_with_yaml("rules:\n new-lines:\n foo: bar\n").unwrap_err();
|
|
17
|
+
assert_eq!(
|
|
18
|
+
err,
|
|
19
|
+
"invalid config: unknown option \"foo\" for rule \"new-lines\""
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
#[test]
|
|
24
|
+
fn invalid_type_value_errors() {
|
|
25
|
+
let err =
|
|
26
|
+
discover_with_yaml("rules:\n new-lines:\n type: invalid\n").unwrap_err();
|
|
27
|
+
assert_eq!(
|
|
28
|
+
err,
|
|
29
|
+
"invalid config: option \"type\" of \"new-lines\" should be in ('unix', 'dos', 'platform')"
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
#[test]
|
|
34
|
+
fn invalid_type_kind_errors_on_non_string() {
|
|
35
|
+
let err =
|
|
36
|
+
discover_with_yaml("rules:\n new-lines:\n type: [unix]\n").unwrap_err();
|
|
37
|
+
assert_eq!(
|
|
38
|
+
err,
|
|
39
|
+
"invalid config: option \"type\" of \"new-lines\" should be in ('unix', 'dos', 'platform')"
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
#[test]
|
|
44
|
+
fn unknown_option_reports_numeric_key() {
|
|
45
|
+
let err = discover_with_yaml("rules:\n new-lines:\n 1: value\n").unwrap_err();
|
|
46
|
+
assert_eq!(
|
|
47
|
+
err,
|
|
48
|
+
"invalid config: unknown option \"1\" for rule \"new-lines\""
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
#[test]
|
|
53
|
+
fn unknown_option_reports_boolean_key() {
|
|
54
|
+
let err =
|
|
55
|
+
discover_with_yaml("rules:\n new-lines:\n true: value\n").unwrap_err();
|
|
56
|
+
assert_eq!(
|
|
57
|
+
err,
|
|
58
|
+
"invalid config: unknown option \"true\" for rule \"new-lines\""
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
#[test]
|
|
63
|
+
fn unknown_option_reports_float_key() {
|
|
64
|
+
let err = discover_with_yaml("rules:\n new-lines:\n 1.5: value\n").unwrap_err();
|
|
65
|
+
assert_eq!(
|
|
66
|
+
err,
|
|
67
|
+
"invalid config: unknown option \"1.5\" for rule \"new-lines\""
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
#[test]
|
|
72
|
+
fn unknown_option_reports_tagged_key() {
|
|
73
|
+
let err =
|
|
74
|
+
discover_with_yaml("rules:\n new-lines:\n !foo bar: value\n").unwrap_err();
|
|
75
|
+
assert_eq!(
|
|
76
|
+
err,
|
|
77
|
+
"invalid config: unknown option \"Tagged(Tag { handle: \"!\", suffix: \"foo\" }, Value(String(\"bar\")))\" for rule \"new-lines\""
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
#[test]
|
|
82
|
+
fn unknown_option_reports_null_key() {
|
|
83
|
+
let err =
|
|
84
|
+
discover_with_yaml("rules:\n new-lines:\n null: value\n").unwrap_err();
|
|
85
|
+
assert_eq!(
|
|
86
|
+
err,
|
|
87
|
+
"invalid config: unknown option \"None\" for rule \"new-lines\""
|
|
88
|
+
);
|
|
89
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
use ryl::config::YamlLintConfig;
|
|
2
|
+
|
|
3
|
+
#[test]
|
|
4
|
+
fn error_on_non_bool_for_forbid_implicit() {
|
|
5
|
+
let err = YamlLintConfig::from_yaml_str(
|
|
6
|
+
"rules:\n octal-values:\n forbid-implicit-octal: 1\n",
|
|
7
|
+
)
|
|
8
|
+
.unwrap_err();
|
|
9
|
+
assert_eq!(
|
|
10
|
+
err,
|
|
11
|
+
"invalid config: option \"forbid-implicit-octal\" of \"octal-values\" should be bool"
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
#[test]
|
|
16
|
+
fn error_on_unknown_option() {
|
|
17
|
+
let err = YamlLintConfig::from_yaml_str("rules:\n octal-values:\n foo: true\n")
|
|
18
|
+
.unwrap_err();
|
|
19
|
+
assert_eq!(
|
|
20
|
+
err,
|
|
21
|
+
"invalid config: unknown option \"foo\" for rule \"octal-values\""
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
#[test]
|
|
26
|
+
fn error_on_non_string_option_key() {
|
|
27
|
+
let err = YamlLintConfig::from_yaml_str("rules:\n octal-values:\n 1: true\n")
|
|
28
|
+
.unwrap_err();
|
|
29
|
+
assert_eq!(
|
|
30
|
+
err,
|
|
31
|
+
"invalid config: unknown option \"1\" for rule \"octal-values\""
|
|
32
|
+
);
|
|
33
|
+
}
|