@owenlamont/ryl 0.4.1 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -0
- package/bin/ryl.js +96 -1
- package/npm-platforms.json +124 -0
- package/package.json +46 -12
- 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
package/src/decoder.rs
DELETED
|
@@ -1,326 +0,0 @@
|
|
|
1
|
-
use std::char;
|
|
2
|
-
use std::env;
|
|
3
|
-
use std::path::Path;
|
|
4
|
-
|
|
5
|
-
use encoding_rs::Encoding;
|
|
6
|
-
|
|
7
|
-
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
8
|
-
enum Endian {
|
|
9
|
-
Big,
|
|
10
|
-
Little,
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
#[derive(Clone, Copy)]
|
|
14
|
-
enum EncodingKind {
|
|
15
|
-
Utf8,
|
|
16
|
-
Utf8WithBom,
|
|
17
|
-
Utf16 { endian: Endian, skip_bom: bool },
|
|
18
|
-
Utf32 { endian: Endian, skip_bom: bool },
|
|
19
|
-
Latin1,
|
|
20
|
-
Custom(&'static Encoding),
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
fn normalize_label(label: &str) -> String {
|
|
24
|
-
label.trim().to_ascii_lowercase().replace('_', "-")
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
fn decode_error(kind: &str, detail: impl Into<String>) -> String {
|
|
28
|
-
let detail = detail.into();
|
|
29
|
-
format!("invalid {kind}: {detail}")
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
fn parse_override(bytes: &[u8], label: &str) -> Result<EncodingKind, String> {
|
|
33
|
-
let normalized = normalize_label(label);
|
|
34
|
-
if normalized.is_empty() {
|
|
35
|
-
return Err(decode_error(
|
|
36
|
-
"encoding",
|
|
37
|
-
"YAMLLINT_FILE_ENCODING cannot be empty",
|
|
38
|
-
));
|
|
39
|
-
}
|
|
40
|
-
match normalized.as_str() {
|
|
41
|
-
"utf-8" => Ok(EncodingKind::Utf8),
|
|
42
|
-
"utf-8-sig" | "utf8-sig" => Ok(EncodingKind::Utf8WithBom),
|
|
43
|
-
"utf-16" => Ok(EncodingKind::Utf16 {
|
|
44
|
-
endian: detect_utf16_endian(bytes).unwrap_or(Endian::Little),
|
|
45
|
-
skip_bom: bytes.starts_with(&[0xFE, 0xFF])
|
|
46
|
-
|| bytes.starts_with(&[0xFF, 0xFE]),
|
|
47
|
-
}),
|
|
48
|
-
"utf-16le" | "utf-16-le" | "utf16le" => Ok(EncodingKind::Utf16 {
|
|
49
|
-
endian: Endian::Little,
|
|
50
|
-
skip_bom: false,
|
|
51
|
-
}),
|
|
52
|
-
"utf-16be" | "utf-16-be" | "utf16be" => Ok(EncodingKind::Utf16 {
|
|
53
|
-
endian: Endian::Big,
|
|
54
|
-
skip_bom: false,
|
|
55
|
-
}),
|
|
56
|
-
"utf-32" => Ok(EncodingKind::Utf32 {
|
|
57
|
-
endian: detect_utf32_endian(bytes).unwrap_or(Endian::Little),
|
|
58
|
-
skip_bom: bytes.starts_with(&[0x00, 0x00, 0xFE, 0xFF])
|
|
59
|
-
|| bytes.starts_with(&[0xFF, 0xFE, 0x00, 0x00]),
|
|
60
|
-
}),
|
|
61
|
-
"utf-32le" | "utf-32-le" | "utf32le" => Ok(EncodingKind::Utf32 {
|
|
62
|
-
endian: Endian::Little,
|
|
63
|
-
skip_bom: false,
|
|
64
|
-
}),
|
|
65
|
-
"utf-32be" | "utf-32-be" | "utf32be" => Ok(EncodingKind::Utf32 {
|
|
66
|
-
endian: Endian::Big,
|
|
67
|
-
skip_bom: false,
|
|
68
|
-
}),
|
|
69
|
-
"latin-1" | "latin1" | "iso-8859-1" | "iso8859-1" => Ok(EncodingKind::Latin1),
|
|
70
|
-
other => Encoding::for_label(other.as_bytes())
|
|
71
|
-
.map(EncodingKind::Custom)
|
|
72
|
-
.ok_or_else(|| {
|
|
73
|
-
decode_error("encoding", format!("unsupported label '{label}'"))
|
|
74
|
-
}),
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
fn detect_utf16_endian(bytes: &[u8]) -> Option<Endian> {
|
|
79
|
-
if bytes.starts_with(&[0xFE, 0xFF]) {
|
|
80
|
-
Some(Endian::Big)
|
|
81
|
-
} else if bytes.starts_with(&[0xFF, 0xFE]) {
|
|
82
|
-
Some(Endian::Little)
|
|
83
|
-
} else if bytes.len() >= 2 && bytes[0] == 0x00 {
|
|
84
|
-
Some(Endian::Big)
|
|
85
|
-
} else if bytes.len() >= 2 && bytes[1] == 0x00 {
|
|
86
|
-
Some(Endian::Little)
|
|
87
|
-
} else {
|
|
88
|
-
None
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
fn detect_utf32_endian(bytes: &[u8]) -> Option<Endian> {
|
|
93
|
-
if bytes.starts_with(&[0x00, 0x00, 0xFE, 0xFF]) {
|
|
94
|
-
Some(Endian::Big)
|
|
95
|
-
} else if bytes.starts_with(&[0xFF, 0xFE, 0x00, 0x00]) {
|
|
96
|
-
Some(Endian::Little)
|
|
97
|
-
} else if bytes.len() >= 4 && bytes[0..3] == [0x00, 0x00, 0x00] {
|
|
98
|
-
Some(Endian::Big)
|
|
99
|
-
} else if bytes.len() >= 4 && bytes[1..4] == [0x00, 0x00, 0x00] {
|
|
100
|
-
Some(Endian::Little)
|
|
101
|
-
} else {
|
|
102
|
-
None
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
fn detect_encoding(bytes: &[u8]) -> Result<EncodingKind, String> {
|
|
107
|
-
let override_label = env::var("YAMLLINT_FILE_ENCODING").map_or(None, |value| {
|
|
108
|
-
eprintln!(
|
|
109
|
-
"YAMLLINT_FILE_ENCODING is meant for temporary workarounds. It may be removed in a future version of yamllint."
|
|
110
|
-
);
|
|
111
|
-
Some(value)
|
|
112
|
-
});
|
|
113
|
-
detect_encoding_with_override(bytes, override_label.as_deref())
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
fn detect_encoding_with_override(
|
|
117
|
-
bytes: &[u8],
|
|
118
|
-
override_label: Option<&str>,
|
|
119
|
-
) -> Result<EncodingKind, String> {
|
|
120
|
-
if let Some(label) = override_label {
|
|
121
|
-
return parse_override(bytes, label);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if bytes.starts_with(&[0x00, 0x00, 0xFE, 0xFF]) {
|
|
125
|
-
return Ok(EncodingKind::Utf32 {
|
|
126
|
-
endian: Endian::Big,
|
|
127
|
-
skip_bom: true,
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
if bytes.len() >= 4 && bytes[0..3] == [0x00, 0x00, 0x00] {
|
|
131
|
-
return Ok(EncodingKind::Utf32 {
|
|
132
|
-
endian: Endian::Big,
|
|
133
|
-
skip_bom: false,
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
if bytes.starts_with(&[0xFF, 0xFE, 0x00, 0x00]) {
|
|
137
|
-
return Ok(EncodingKind::Utf32 {
|
|
138
|
-
endian: Endian::Little,
|
|
139
|
-
skip_bom: true,
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
if bytes.len() >= 4 && bytes[1..4] == [0x00, 0x00, 0x00] {
|
|
143
|
-
return Ok(EncodingKind::Utf32 {
|
|
144
|
-
endian: Endian::Little,
|
|
145
|
-
skip_bom: false,
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
if bytes.starts_with(&[0xFE, 0xFF]) {
|
|
149
|
-
return Ok(EncodingKind::Utf16 {
|
|
150
|
-
endian: Endian::Big,
|
|
151
|
-
skip_bom: true,
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
if bytes.len() >= 2 && bytes[0] == 0x00 {
|
|
155
|
-
return Ok(EncodingKind::Utf16 {
|
|
156
|
-
endian: Endian::Big,
|
|
157
|
-
skip_bom: false,
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
if bytes.starts_with(&[0xFF, 0xFE]) {
|
|
161
|
-
return Ok(EncodingKind::Utf16 {
|
|
162
|
-
endian: Endian::Little,
|
|
163
|
-
skip_bom: true,
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
if bytes.len() >= 2 && bytes[1] == 0x00 {
|
|
167
|
-
return Ok(EncodingKind::Utf16 {
|
|
168
|
-
endian: Endian::Little,
|
|
169
|
-
skip_bom: false,
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
if bytes.starts_with(&[0xEF, 0xBB, 0xBF]) {
|
|
173
|
-
return Ok(EncodingKind::Utf8WithBom);
|
|
174
|
-
}
|
|
175
|
-
Ok(EncodingKind::Utf8)
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
fn decode_utf8(bytes: &[u8]) -> Result<String, String> {
|
|
179
|
-
std::str::from_utf8(bytes)
|
|
180
|
-
.map(str::to_owned)
|
|
181
|
-
.map_err(|err| decode_error("utf-8 data", err.to_string()))
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
fn decode_utf8_bom(bytes: &[u8]) -> Result<String, String> {
|
|
185
|
-
let sliced = bytes.strip_prefix(&[0xEF, 0xBB, 0xBF]).unwrap_or(bytes);
|
|
186
|
-
decode_utf8(sliced)
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
fn decode_utf16(
|
|
190
|
-
bytes: &[u8],
|
|
191
|
-
endian: Endian,
|
|
192
|
-
skip_bom: bool,
|
|
193
|
-
) -> Result<String, String> {
|
|
194
|
-
if bytes.is_empty() {
|
|
195
|
-
return Ok(String::new());
|
|
196
|
-
}
|
|
197
|
-
let data = if skip_bom {
|
|
198
|
-
bytes.get(2..).unwrap_or(&[])
|
|
199
|
-
} else {
|
|
200
|
-
bytes
|
|
201
|
-
};
|
|
202
|
-
if data.len() % 2 != 0 {
|
|
203
|
-
return Err(decode_error(
|
|
204
|
-
"utf-16 data",
|
|
205
|
-
format!("length {} is not even", data.len()),
|
|
206
|
-
));
|
|
207
|
-
}
|
|
208
|
-
let mut units: Vec<u16> = Vec::with_capacity(data.len() / 2);
|
|
209
|
-
for chunk in data.chunks_exact(2) {
|
|
210
|
-
let value = match endian {
|
|
211
|
-
Endian::Big => u16::from_be_bytes([chunk[0], chunk[1]]),
|
|
212
|
-
Endian::Little => u16::from_le_bytes([chunk[0], chunk[1]]),
|
|
213
|
-
};
|
|
214
|
-
units.push(value);
|
|
215
|
-
}
|
|
216
|
-
String::from_utf16(&units)
|
|
217
|
-
.map_err(|err| decode_error("utf-16 data", err.to_string()))
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
fn decode_utf32(
|
|
221
|
-
bytes: &[u8],
|
|
222
|
-
endian: Endian,
|
|
223
|
-
skip_bom: bool,
|
|
224
|
-
) -> Result<String, String> {
|
|
225
|
-
if bytes.is_empty() {
|
|
226
|
-
return Ok(String::new());
|
|
227
|
-
}
|
|
228
|
-
let data = if skip_bom {
|
|
229
|
-
bytes.get(4..).unwrap_or(&[])
|
|
230
|
-
} else {
|
|
231
|
-
bytes
|
|
232
|
-
};
|
|
233
|
-
if data.len() % 4 != 0 {
|
|
234
|
-
return Err(decode_error(
|
|
235
|
-
"utf-32 data",
|
|
236
|
-
format!("length {} is not divisible by 4", data.len()),
|
|
237
|
-
));
|
|
238
|
-
}
|
|
239
|
-
let mut out = String::with_capacity(data.len() / 4);
|
|
240
|
-
for chunk in data.chunks_exact(4) {
|
|
241
|
-
let raw = match endian {
|
|
242
|
-
Endian::Big => u32::from_be_bytes([chunk[0], chunk[1], chunk[2], chunk[3]]),
|
|
243
|
-
Endian::Little => {
|
|
244
|
-
u32::from_le_bytes([chunk[0], chunk[1], chunk[2], chunk[3]])
|
|
245
|
-
}
|
|
246
|
-
};
|
|
247
|
-
match char::from_u32(raw) {
|
|
248
|
-
Some(ch) => out.push(ch),
|
|
249
|
-
None => {
|
|
250
|
-
return Err(decode_error(
|
|
251
|
-
"utf-32 data",
|
|
252
|
-
format!("invalid scalar value 0x{raw:08X}"),
|
|
253
|
-
));
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
Ok(out)
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
fn decode_latin1(bytes: &[u8]) -> String {
|
|
261
|
-
bytes
|
|
262
|
-
.iter()
|
|
263
|
-
.map(|&b| char::from_u32(u32::from(b)).unwrap())
|
|
264
|
-
.collect()
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
fn decode_with_custom(
|
|
268
|
-
bytes: &[u8],
|
|
269
|
-
encoding: &'static Encoding,
|
|
270
|
-
) -> Result<String, String> {
|
|
271
|
-
let (text, _encoding_used, had_errors) = encoding.decode(bytes);
|
|
272
|
-
if had_errors {
|
|
273
|
-
return Err(decode_error(
|
|
274
|
-
encoding.name(),
|
|
275
|
-
"decode error with replacement required",
|
|
276
|
-
));
|
|
277
|
-
}
|
|
278
|
-
Ok(text.into_owned())
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
fn decode_with_kind(bytes: &[u8], encoding: EncodingKind) -> Result<String, String> {
|
|
282
|
-
match encoding {
|
|
283
|
-
EncodingKind::Utf8 => decode_utf8(bytes),
|
|
284
|
-
EncodingKind::Utf8WithBom => decode_utf8_bom(bytes),
|
|
285
|
-
EncodingKind::Utf16 { endian, skip_bom } => {
|
|
286
|
-
decode_utf16(bytes, endian, skip_bom)
|
|
287
|
-
}
|
|
288
|
-
EncodingKind::Utf32 { endian, skip_bom } => {
|
|
289
|
-
decode_utf32(bytes, endian, skip_bom)
|
|
290
|
-
}
|
|
291
|
-
EncodingKind::Latin1 => Ok(decode_latin1(bytes)),
|
|
292
|
-
EncodingKind::Custom(enc) => decode_with_custom(bytes, enc),
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
/// Decode raw bytes using yamllint-compatible encoding detection.
|
|
297
|
-
///
|
|
298
|
-
/// # Errors
|
|
299
|
-
/// Returns an error string describing why decoding failed.
|
|
300
|
-
pub fn decode_bytes(bytes: &[u8]) -> Result<String, String> {
|
|
301
|
-
let encoding = detect_encoding(bytes)?;
|
|
302
|
-
decode_with_kind(bytes, encoding)
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
/// Decode bytes using an explicit encoding override, bypassing environment lookups.
|
|
306
|
-
///
|
|
307
|
-
/// # Errors
|
|
308
|
-
/// Returns an error string when the override label is unsupported or decoding fails.
|
|
309
|
-
pub fn decode_bytes_with_override(
|
|
310
|
-
bytes: &[u8],
|
|
311
|
-
override_label: Option<&str>,
|
|
312
|
-
) -> Result<String, String> {
|
|
313
|
-
let encoding = detect_encoding_with_override(bytes, override_label)?;
|
|
314
|
-
decode_with_kind(bytes, encoding)
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
/// Read a file from disk and decode it using yamllint-compatible detection.
|
|
318
|
-
///
|
|
319
|
-
/// # Errors
|
|
320
|
-
/// Returns an error string when the file cannot be read or decoded.
|
|
321
|
-
pub fn read_file(path: &Path) -> Result<String, String> {
|
|
322
|
-
let data = std::fs::read(path)
|
|
323
|
-
.map_err(|err| format!("failed to read {}: {err}", path.display()))?;
|
|
324
|
-
decode_bytes(&data)
|
|
325
|
-
.map_err(|err| format!("failed to read {}: {err}", path.display()))
|
|
326
|
-
}
|
package/src/discover.rs
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
use std::ffi::OsStr;
|
|
2
|
-
use std::path::{Path, PathBuf};
|
|
3
|
-
|
|
4
|
-
use ignore::WalkBuilder;
|
|
5
|
-
|
|
6
|
-
pub fn is_yaml_path(path: &Path) -> bool {
|
|
7
|
-
path.extension().and_then(OsStr::to_str).is_some_and(|ext| {
|
|
8
|
-
ext.eq_ignore_ascii_case("yml") || ext.eq_ignore_ascii_case("yaml")
|
|
9
|
-
})
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
#[must_use]
|
|
13
|
-
pub fn gather_yaml_from_dir(dir: &Path) -> Vec<PathBuf> {
|
|
14
|
-
let mut files = Vec::new();
|
|
15
|
-
let walker = WalkBuilder::new(dir)
|
|
16
|
-
.hidden(false)
|
|
17
|
-
.ignore(true)
|
|
18
|
-
.git_ignore(true)
|
|
19
|
-
.git_global(true)
|
|
20
|
-
.git_exclude(true)
|
|
21
|
-
.follow_links(false)
|
|
22
|
-
.build();
|
|
23
|
-
|
|
24
|
-
for entry in walker.flatten() {
|
|
25
|
-
let p = entry.path();
|
|
26
|
-
if p.is_file() && is_yaml_path(p) {
|
|
27
|
-
files.push(p.to_path_buf());
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
files
|
|
31
|
-
}
|
package/src/lib.rs
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
#![forbid(unsafe_code)]
|
|
2
|
-
#![deny(
|
|
3
|
-
clippy::all,
|
|
4
|
-
clippy::pedantic,
|
|
5
|
-
clippy::cargo,
|
|
6
|
-
clippy::cognitive_complexity
|
|
7
|
-
)]
|
|
8
|
-
|
|
9
|
-
pub mod cli_support;
|
|
10
|
-
pub mod conf;
|
|
11
|
-
pub mod config;
|
|
12
|
-
pub mod decoder;
|
|
13
|
-
pub mod discover;
|
|
14
|
-
pub mod lint;
|
|
15
|
-
pub mod migrate;
|
|
16
|
-
pub mod rules;
|
|
17
|
-
|
|
18
|
-
pub use discover::{gather_yaml_from_dir, is_yaml_path};
|
|
19
|
-
pub use lint::{LintProblem, Severity, lint_file};
|