@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,83 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
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
|
-
}
|
package/tests/config_locale.rs
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
use std::path::PathBuf;
|
|
2
|
-
|
|
3
|
-
use ryl::config::{Overrides, discover_config, discover_config_with};
|
|
4
|
-
|
|
5
|
-
#[path = "common/mod.rs"]
|
|
6
|
-
mod common;
|
|
7
|
-
use common::fake_env::FakeEnv;
|
|
8
|
-
|
|
9
|
-
#[test]
|
|
10
|
-
fn 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
|
-
}
|
package/tests/config_merge.rs
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
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
|
-
}
|