@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
package/src/lint.rs
ADDED
|
@@ -0,0 +1,558 @@
|
|
|
1
|
+
use std::path::Path;
|
|
2
|
+
|
|
3
|
+
use crate::config::{RuleLevel, YamlLintConfig};
|
|
4
|
+
use crate::decoder;
|
|
5
|
+
use crate::rules::{
|
|
6
|
+
anchors, braces, brackets, colons, commas, comments, comments_indentation,
|
|
7
|
+
document_end, document_start, empty_lines, empty_values, float_values, hyphens,
|
|
8
|
+
indentation, key_duplicates, key_ordering, line_length, new_line_at_end_of_file,
|
|
9
|
+
new_lines, octal_values, quoted_strings, trailing_spaces, truthy,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
13
|
+
pub enum Severity {
|
|
14
|
+
Error,
|
|
15
|
+
Warning,
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
impl Severity {
|
|
19
|
+
#[must_use]
|
|
20
|
+
pub const fn as_str(self) -> &'static str {
|
|
21
|
+
match self {
|
|
22
|
+
Self::Error => "error",
|
|
23
|
+
Self::Warning => "warning",
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
impl From<RuleLevel> for Severity {
|
|
29
|
+
fn from(value: RuleLevel) -> Self {
|
|
30
|
+
match value {
|
|
31
|
+
RuleLevel::Error => Self::Error,
|
|
32
|
+
RuleLevel::Warning => Self::Warning,
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
#[derive(Debug, Clone)]
|
|
38
|
+
pub struct LintProblem {
|
|
39
|
+
pub line: usize,
|
|
40
|
+
pub column: usize,
|
|
41
|
+
pub level: Severity,
|
|
42
|
+
pub message: String,
|
|
43
|
+
pub rule: Option<&'static str>,
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
struct NullSink;
|
|
47
|
+
impl<'i> saphyr_parser::EventReceiver<'i> for NullSink {
|
|
48
|
+
fn on_event(&mut self, _ev: saphyr_parser::Event<'i>) {}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/// Lint a single YAML file and return diagnostics in yamllint format order.
|
|
52
|
+
///
|
|
53
|
+
/// # Errors
|
|
54
|
+
///
|
|
55
|
+
/// Returns `Err(String)` when the file cannot be read.
|
|
56
|
+
#[allow(clippy::too_many_lines)]
|
|
57
|
+
pub fn lint_file(
|
|
58
|
+
path: &Path,
|
|
59
|
+
cfg: &YamlLintConfig,
|
|
60
|
+
base_dir: &Path,
|
|
61
|
+
) -> Result<Vec<LintProblem>, String> {
|
|
62
|
+
let content = decoder::read_file(path)?;
|
|
63
|
+
|
|
64
|
+
let mut diagnostics: Vec<LintProblem> = Vec::new();
|
|
65
|
+
|
|
66
|
+
collect_document_start_diagnostics(&mut diagnostics, &content, cfg, path, base_dir);
|
|
67
|
+
|
|
68
|
+
collect_document_end_diagnostics(&mut diagnostics, &content, cfg, path, base_dir);
|
|
69
|
+
|
|
70
|
+
if let Some(level) = cfg.rule_level(new_line_at_end_of_file::ID)
|
|
71
|
+
&& !cfg.is_rule_ignored(new_line_at_end_of_file::ID, path, base_dir)
|
|
72
|
+
&& let Some(hit) = new_line_at_end_of_file::check(&content)
|
|
73
|
+
{
|
|
74
|
+
diagnostics.push(LintProblem {
|
|
75
|
+
line: hit.line,
|
|
76
|
+
column: hit.column,
|
|
77
|
+
level: level.into(),
|
|
78
|
+
message: new_line_at_end_of_file::MESSAGE.to_string(),
|
|
79
|
+
rule: Some(new_line_at_end_of_file::ID),
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if let Some(level) = cfg.rule_level(new_lines::ID)
|
|
84
|
+
&& !cfg.is_rule_ignored(new_lines::ID, path, base_dir)
|
|
85
|
+
{
|
|
86
|
+
let rule_cfg = new_lines::Config::resolve(cfg);
|
|
87
|
+
if let Some(hit) =
|
|
88
|
+
new_lines::check(&content, rule_cfg, new_lines::platform_newline())
|
|
89
|
+
{
|
|
90
|
+
diagnostics.push(LintProblem {
|
|
91
|
+
line: hit.line,
|
|
92
|
+
column: hit.column,
|
|
93
|
+
level: level.into(),
|
|
94
|
+
message: hit.message,
|
|
95
|
+
rule: Some(new_lines::ID),
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
collect_empty_lines_diagnostics(&mut diagnostics, &content, cfg, path, base_dir);
|
|
101
|
+
|
|
102
|
+
collect_commas_diagnostics(&mut diagnostics, &content, cfg, path, base_dir);
|
|
103
|
+
|
|
104
|
+
collect_colons_diagnostics(&mut diagnostics, &content, cfg, path, base_dir);
|
|
105
|
+
|
|
106
|
+
collect_braces_diagnostics(&mut diagnostics, &content, cfg, path, base_dir);
|
|
107
|
+
collect_brackets_diagnostics(&mut diagnostics, &content, cfg, path, base_dir);
|
|
108
|
+
|
|
109
|
+
collect_comments_diagnostics(&mut diagnostics, &content, cfg, path, base_dir);
|
|
110
|
+
|
|
111
|
+
collect_anchors_diagnostics(&mut diagnostics, &content, cfg, path, base_dir);
|
|
112
|
+
|
|
113
|
+
if let Some(level) = cfg.rule_level(octal_values::ID)
|
|
114
|
+
&& !cfg.is_rule_ignored(octal_values::ID, path, base_dir)
|
|
115
|
+
{
|
|
116
|
+
let rule_cfg = octal_values::Config::resolve(cfg);
|
|
117
|
+
for hit in octal_values::check(&content, &rule_cfg) {
|
|
118
|
+
diagnostics.push(LintProblem {
|
|
119
|
+
line: hit.line,
|
|
120
|
+
column: hit.column,
|
|
121
|
+
level: level.into(),
|
|
122
|
+
message: hit.message,
|
|
123
|
+
rule: Some(octal_values::ID),
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if let Some(level) = cfg.rule_level(float_values::ID)
|
|
129
|
+
&& !cfg.is_rule_ignored(float_values::ID, path, base_dir)
|
|
130
|
+
{
|
|
131
|
+
let rule_cfg = float_values::Config::resolve(cfg);
|
|
132
|
+
for hit in float_values::check(&content, &rule_cfg) {
|
|
133
|
+
diagnostics.push(LintProblem {
|
|
134
|
+
line: hit.line,
|
|
135
|
+
column: hit.column,
|
|
136
|
+
level: level.into(),
|
|
137
|
+
message: hit.message,
|
|
138
|
+
rule: Some(float_values::ID),
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if let Some(level) = cfg.rule_level(empty_values::ID)
|
|
144
|
+
&& !cfg.is_rule_ignored(empty_values::ID, path, base_dir)
|
|
145
|
+
{
|
|
146
|
+
let rule_cfg = empty_values::Config::resolve(cfg);
|
|
147
|
+
for hit in empty_values::check(&content, &rule_cfg) {
|
|
148
|
+
diagnostics.push(LintProblem {
|
|
149
|
+
line: hit.line,
|
|
150
|
+
column: hit.column,
|
|
151
|
+
level: level.into(),
|
|
152
|
+
message: hit.message,
|
|
153
|
+
rule: Some(empty_values::ID),
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if let Some(level) = cfg.rule_level(quoted_strings::ID)
|
|
159
|
+
&& !cfg.is_rule_ignored(quoted_strings::ID, path, base_dir)
|
|
160
|
+
{
|
|
161
|
+
let rule_cfg = quoted_strings::Config::resolve(cfg);
|
|
162
|
+
for hit in quoted_strings::check(&content, &rule_cfg) {
|
|
163
|
+
diagnostics.push(LintProblem {
|
|
164
|
+
line: hit.line,
|
|
165
|
+
column: hit.column,
|
|
166
|
+
level: level.into(),
|
|
167
|
+
message: hit.message,
|
|
168
|
+
rule: Some(quoted_strings::ID),
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if let Some(level) = cfg.rule_level(truthy::ID)
|
|
174
|
+
&& !cfg.is_rule_ignored(truthy::ID, path, base_dir)
|
|
175
|
+
{
|
|
176
|
+
let rule_cfg = truthy::Config::resolve(cfg);
|
|
177
|
+
for hit in truthy::check(&content, &rule_cfg) {
|
|
178
|
+
let truthy::Violation {
|
|
179
|
+
line,
|
|
180
|
+
column,
|
|
181
|
+
message,
|
|
182
|
+
} = hit;
|
|
183
|
+
diagnostics.push(LintProblem {
|
|
184
|
+
line,
|
|
185
|
+
column,
|
|
186
|
+
level: level.into(),
|
|
187
|
+
message,
|
|
188
|
+
rule: Some(truthy::ID),
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if let Some(level) = cfg.rule_level(key_duplicates::ID)
|
|
194
|
+
&& !cfg.is_rule_ignored(key_duplicates::ID, path, base_dir)
|
|
195
|
+
{
|
|
196
|
+
let rule_cfg = key_duplicates::Config::resolve(cfg);
|
|
197
|
+
for hit in key_duplicates::check(&content, &rule_cfg) {
|
|
198
|
+
diagnostics.push(LintProblem {
|
|
199
|
+
line: hit.line,
|
|
200
|
+
column: hit.column,
|
|
201
|
+
level: level.into(),
|
|
202
|
+
message: hit.message,
|
|
203
|
+
rule: Some(key_duplicates::ID),
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if let Some(level) = cfg.rule_level(key_ordering::ID)
|
|
209
|
+
&& !cfg.is_rule_ignored(key_ordering::ID, path, base_dir)
|
|
210
|
+
{
|
|
211
|
+
let rule_cfg = key_ordering::Config::resolve(cfg);
|
|
212
|
+
for hit in key_ordering::check(&content, &rule_cfg) {
|
|
213
|
+
diagnostics.push(LintProblem {
|
|
214
|
+
line: hit.line,
|
|
215
|
+
column: hit.column,
|
|
216
|
+
level: level.into(),
|
|
217
|
+
message: hit.message,
|
|
218
|
+
rule: Some(key_ordering::ID),
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if let Some(level) = cfg.rule_level(hyphens::ID)
|
|
224
|
+
&& !cfg.is_rule_ignored(hyphens::ID, path, base_dir)
|
|
225
|
+
{
|
|
226
|
+
let rule_cfg = hyphens::Config::resolve(cfg);
|
|
227
|
+
for hit in hyphens::check(&content, &rule_cfg) {
|
|
228
|
+
diagnostics.push(LintProblem {
|
|
229
|
+
line: hit.line,
|
|
230
|
+
column: hit.column,
|
|
231
|
+
level: level.into(),
|
|
232
|
+
message: hyphens::MESSAGE.to_string(),
|
|
233
|
+
rule: Some(hyphens::ID),
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
collect_comments_indentation_diagnostics(
|
|
239
|
+
&mut diagnostics,
|
|
240
|
+
&content,
|
|
241
|
+
cfg,
|
|
242
|
+
path,
|
|
243
|
+
base_dir,
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
if let Some(level) = cfg.rule_level(indentation::ID)
|
|
247
|
+
&& !cfg.is_rule_ignored(indentation::ID, path, base_dir)
|
|
248
|
+
{
|
|
249
|
+
let rule_cfg = indentation::Config::resolve(cfg);
|
|
250
|
+
for hit in indentation::check(&content, &rule_cfg) {
|
|
251
|
+
diagnostics.push(LintProblem {
|
|
252
|
+
line: hit.line,
|
|
253
|
+
column: hit.column,
|
|
254
|
+
level: level.into(),
|
|
255
|
+
message: hit.message,
|
|
256
|
+
rule: Some(indentation::ID),
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
collect_line_length_diagnostics(&mut diagnostics, &content, cfg, path, base_dir);
|
|
262
|
+
|
|
263
|
+
if let Some(level) = cfg.rule_level(trailing_spaces::ID)
|
|
264
|
+
&& !cfg.is_rule_ignored(trailing_spaces::ID, path, base_dir)
|
|
265
|
+
{
|
|
266
|
+
for hit in trailing_spaces::check(&content) {
|
|
267
|
+
diagnostics.push(LintProblem {
|
|
268
|
+
line: hit.line,
|
|
269
|
+
column: hit.column,
|
|
270
|
+
level: level.into(),
|
|
271
|
+
message: trailing_spaces::MESSAGE.to_string(),
|
|
272
|
+
rule: Some(trailing_spaces::ID),
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if let Some(syntax) = syntax_diagnostic(&content) {
|
|
278
|
+
diagnostics.clear();
|
|
279
|
+
diagnostics.push(syntax);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
Ok(diagnostics)
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
fn collect_document_end_diagnostics(
|
|
286
|
+
diagnostics: &mut Vec<LintProblem>,
|
|
287
|
+
content: &str,
|
|
288
|
+
cfg: &YamlLintConfig,
|
|
289
|
+
path: &Path,
|
|
290
|
+
base_dir: &Path,
|
|
291
|
+
) {
|
|
292
|
+
if let Some(level) = cfg.rule_level(document_end::ID)
|
|
293
|
+
&& !cfg.is_rule_ignored(document_end::ID, path, base_dir)
|
|
294
|
+
{
|
|
295
|
+
let rule_cfg = document_end::Config::resolve(cfg);
|
|
296
|
+
for hit in document_end::check(content, &rule_cfg) {
|
|
297
|
+
diagnostics.push(LintProblem {
|
|
298
|
+
line: hit.line,
|
|
299
|
+
column: hit.column,
|
|
300
|
+
level: level.into(),
|
|
301
|
+
message: hit.message,
|
|
302
|
+
rule: Some(document_end::ID),
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
fn collect_document_start_diagnostics(
|
|
309
|
+
diagnostics: &mut Vec<LintProblem>,
|
|
310
|
+
content: &str,
|
|
311
|
+
cfg: &YamlLintConfig,
|
|
312
|
+
path: &Path,
|
|
313
|
+
base_dir: &Path,
|
|
314
|
+
) {
|
|
315
|
+
if let Some(level) = cfg.rule_level(document_start::ID)
|
|
316
|
+
&& !cfg.is_rule_ignored(document_start::ID, path, base_dir)
|
|
317
|
+
{
|
|
318
|
+
let rule_cfg = document_start::Config::resolve(cfg);
|
|
319
|
+
for hit in document_start::check(content, &rule_cfg) {
|
|
320
|
+
diagnostics.push(LintProblem {
|
|
321
|
+
line: hit.line,
|
|
322
|
+
column: hit.column,
|
|
323
|
+
level: level.into(),
|
|
324
|
+
message: hit.message,
|
|
325
|
+
rule: Some(document_start::ID),
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
fn collect_empty_lines_diagnostics(
|
|
332
|
+
diagnostics: &mut Vec<LintProblem>,
|
|
333
|
+
content: &str,
|
|
334
|
+
cfg: &YamlLintConfig,
|
|
335
|
+
path: &Path,
|
|
336
|
+
base_dir: &Path,
|
|
337
|
+
) {
|
|
338
|
+
if let Some(level) = cfg.rule_level(empty_lines::ID)
|
|
339
|
+
&& !cfg.is_rule_ignored(empty_lines::ID, path, base_dir)
|
|
340
|
+
{
|
|
341
|
+
let rule_cfg = empty_lines::Config::resolve(cfg);
|
|
342
|
+
for hit in empty_lines::check(content, &rule_cfg) {
|
|
343
|
+
diagnostics.push(LintProblem {
|
|
344
|
+
line: hit.line,
|
|
345
|
+
column: hit.column,
|
|
346
|
+
level: level.into(),
|
|
347
|
+
message: hit.message,
|
|
348
|
+
rule: Some(empty_lines::ID),
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
fn collect_commas_diagnostics(
|
|
355
|
+
diagnostics: &mut Vec<LintProblem>,
|
|
356
|
+
content: &str,
|
|
357
|
+
cfg: &YamlLintConfig,
|
|
358
|
+
path: &Path,
|
|
359
|
+
base_dir: &Path,
|
|
360
|
+
) {
|
|
361
|
+
if let Some(level) = cfg.rule_level(commas::ID)
|
|
362
|
+
&& !cfg.is_rule_ignored(commas::ID, path, base_dir)
|
|
363
|
+
{
|
|
364
|
+
let rule_cfg = commas::Config::resolve(cfg);
|
|
365
|
+
for hit in commas::check(content, &rule_cfg) {
|
|
366
|
+
diagnostics.push(LintProblem {
|
|
367
|
+
line: hit.line,
|
|
368
|
+
column: hit.column,
|
|
369
|
+
level: level.into(),
|
|
370
|
+
message: hit.message,
|
|
371
|
+
rule: Some(commas::ID),
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
fn collect_colons_diagnostics(
|
|
378
|
+
diagnostics: &mut Vec<LintProblem>,
|
|
379
|
+
content: &str,
|
|
380
|
+
cfg: &YamlLintConfig,
|
|
381
|
+
path: &Path,
|
|
382
|
+
base_dir: &Path,
|
|
383
|
+
) {
|
|
384
|
+
if let Some(level) = cfg.rule_level(colons::ID)
|
|
385
|
+
&& !cfg.is_rule_ignored(colons::ID, path, base_dir)
|
|
386
|
+
{
|
|
387
|
+
let rule_cfg = colons::Config::resolve(cfg);
|
|
388
|
+
for hit in colons::check(content, &rule_cfg) {
|
|
389
|
+
diagnostics.push(LintProblem {
|
|
390
|
+
line: hit.line,
|
|
391
|
+
column: hit.column,
|
|
392
|
+
level: level.into(),
|
|
393
|
+
message: hit.message,
|
|
394
|
+
rule: Some(colons::ID),
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
fn collect_brackets_diagnostics(
|
|
401
|
+
diagnostics: &mut Vec<LintProblem>,
|
|
402
|
+
content: &str,
|
|
403
|
+
cfg: &YamlLintConfig,
|
|
404
|
+
path: &Path,
|
|
405
|
+
base_dir: &Path,
|
|
406
|
+
) {
|
|
407
|
+
if let Some(level) = cfg.rule_level(brackets::ID)
|
|
408
|
+
&& !cfg.is_rule_ignored(brackets::ID, path, base_dir)
|
|
409
|
+
{
|
|
410
|
+
let rule_cfg = brackets::Config::resolve(cfg);
|
|
411
|
+
for hit in brackets::check(content, &rule_cfg) {
|
|
412
|
+
diagnostics.push(LintProblem {
|
|
413
|
+
line: hit.line,
|
|
414
|
+
column: hit.column,
|
|
415
|
+
level: level.into(),
|
|
416
|
+
message: hit.message,
|
|
417
|
+
rule: Some(brackets::ID),
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
fn collect_braces_diagnostics(
|
|
424
|
+
diagnostics: &mut Vec<LintProblem>,
|
|
425
|
+
content: &str,
|
|
426
|
+
cfg: &YamlLintConfig,
|
|
427
|
+
path: &Path,
|
|
428
|
+
base_dir: &Path,
|
|
429
|
+
) {
|
|
430
|
+
if let Some(level) = cfg.rule_level(braces::ID)
|
|
431
|
+
&& !cfg.is_rule_ignored(braces::ID, path, base_dir)
|
|
432
|
+
{
|
|
433
|
+
let rule_cfg = braces::Config::resolve(cfg);
|
|
434
|
+
for hit in braces::check(content, &rule_cfg) {
|
|
435
|
+
diagnostics.push(LintProblem {
|
|
436
|
+
line: hit.line,
|
|
437
|
+
column: hit.column,
|
|
438
|
+
level: level.into(),
|
|
439
|
+
message: hit.message,
|
|
440
|
+
rule: Some(braces::ID),
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
fn collect_comments_diagnostics(
|
|
447
|
+
diagnostics: &mut Vec<LintProblem>,
|
|
448
|
+
content: &str,
|
|
449
|
+
cfg: &YamlLintConfig,
|
|
450
|
+
path: &Path,
|
|
451
|
+
base_dir: &Path,
|
|
452
|
+
) {
|
|
453
|
+
if let Some(level) = cfg.rule_level(comments::ID)
|
|
454
|
+
&& !cfg.is_rule_ignored(comments::ID, path, base_dir)
|
|
455
|
+
{
|
|
456
|
+
let rule_cfg = comments::Config::resolve(cfg);
|
|
457
|
+
for hit in comments::check(content, &rule_cfg) {
|
|
458
|
+
diagnostics.push(LintProblem {
|
|
459
|
+
line: hit.line,
|
|
460
|
+
column: hit.column,
|
|
461
|
+
level: level.into(),
|
|
462
|
+
message: hit.message,
|
|
463
|
+
rule: Some(comments::ID),
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
fn collect_anchors_diagnostics(
|
|
470
|
+
diagnostics: &mut Vec<LintProblem>,
|
|
471
|
+
content: &str,
|
|
472
|
+
cfg: &YamlLintConfig,
|
|
473
|
+
path: &Path,
|
|
474
|
+
base_dir: &Path,
|
|
475
|
+
) {
|
|
476
|
+
if let Some(level) = cfg.rule_level(anchors::ID)
|
|
477
|
+
&& !cfg.is_rule_ignored(anchors::ID, path, base_dir)
|
|
478
|
+
{
|
|
479
|
+
let rule_cfg = anchors::Config::resolve(cfg);
|
|
480
|
+
for hit in anchors::check(content, &rule_cfg) {
|
|
481
|
+
diagnostics.push(LintProblem {
|
|
482
|
+
line: hit.line,
|
|
483
|
+
column: hit.column,
|
|
484
|
+
level: level.into(),
|
|
485
|
+
message: hit.message,
|
|
486
|
+
rule: Some(anchors::ID),
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
fn collect_comments_indentation_diagnostics(
|
|
493
|
+
diagnostics: &mut Vec<LintProblem>,
|
|
494
|
+
content: &str,
|
|
495
|
+
cfg: &YamlLintConfig,
|
|
496
|
+
path: &Path,
|
|
497
|
+
base_dir: &Path,
|
|
498
|
+
) {
|
|
499
|
+
if let Some(level) = cfg.rule_level(comments_indentation::ID)
|
|
500
|
+
&& !cfg.is_rule_ignored(comments_indentation::ID, path, base_dir)
|
|
501
|
+
{
|
|
502
|
+
let rule_cfg = comments_indentation::Config::resolve(cfg);
|
|
503
|
+
for hit in comments_indentation::check(content, &rule_cfg) {
|
|
504
|
+
diagnostics.push(LintProblem {
|
|
505
|
+
line: hit.line,
|
|
506
|
+
column: hit.column,
|
|
507
|
+
level: level.into(),
|
|
508
|
+
message: comments_indentation::MESSAGE.to_string(),
|
|
509
|
+
rule: Some(comments_indentation::ID),
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
fn collect_line_length_diagnostics(
|
|
516
|
+
diagnostics: &mut Vec<LintProblem>,
|
|
517
|
+
content: &str,
|
|
518
|
+
cfg: &YamlLintConfig,
|
|
519
|
+
path: &Path,
|
|
520
|
+
base_dir: &Path,
|
|
521
|
+
) {
|
|
522
|
+
if let Some(level) = cfg.rule_level(line_length::ID)
|
|
523
|
+
&& !cfg.is_rule_ignored(line_length::ID, path, base_dir)
|
|
524
|
+
{
|
|
525
|
+
let rule_cfg = line_length::Config::resolve(cfg);
|
|
526
|
+
for hit in line_length::check(content, &rule_cfg) {
|
|
527
|
+
diagnostics.push(LintProblem {
|
|
528
|
+
line: hit.line,
|
|
529
|
+
column: hit.column,
|
|
530
|
+
level: level.into(),
|
|
531
|
+
message: hit.message,
|
|
532
|
+
rule: Some(line_length::ID),
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
fn syntax_diagnostic(content: &str) -> Option<LintProblem> {
|
|
539
|
+
let mut parser = saphyr_parser::Parser::new_from_str(content);
|
|
540
|
+
let mut sink = NullSink;
|
|
541
|
+
match parser.load(&mut sink, true) {
|
|
542
|
+
Ok(()) => None,
|
|
543
|
+
Err(err) => {
|
|
544
|
+
if err.info() == "while parsing node, found unknown anchor" {
|
|
545
|
+
return None;
|
|
546
|
+
}
|
|
547
|
+
let marker = err.marker();
|
|
548
|
+
let column = marker.col() + 1;
|
|
549
|
+
Some(LintProblem {
|
|
550
|
+
line: marker.line(),
|
|
551
|
+
column,
|
|
552
|
+
level: Severity::Error,
|
|
553
|
+
message: format!("syntax error: {} (syntax)", err.info()),
|
|
554
|
+
rule: None,
|
|
555
|
+
})
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
}
|