Skip to content

Commit

Permalink
(#24378) [config] Relax yaml linters (valid yaml is valid)
Browse files Browse the repository at this point in the history
* [config] Remove yaml linter

* restore files

* relax yaml linter rules

* relax conandata.yml linter

* colons and empty-lines

---------

Co-authored-by: Luis Caro Campos <3535649+jcar87@users.noreply.github.com>
  • Loading branch information
danimtb and jcar87 committed Jun 20, 2024
1 parent bdada53 commit 52419bd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 33 deletions.
2 changes: 0 additions & 2 deletions .c3i/config_v1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ tasks:
# Requirements to merge a given pull-request:
# * check_runs refers to notifications from GH actions
# * status_checks refers to notifications coming from external tools (Jenkins, CLA,...)
check_runs:
- name: "Lint changed files (YAML files)"
status_checks:
- name: "license/cla"
- name: "continuous-integration/jenkins/pr-merge"
Expand Down
33 changes: 12 additions & 21 deletions linter/conandata_yaml_linter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import argparse
from strictyaml import (
load,
Map,
dirty_load,
MapCombined,
Str,
YAMLValidationError,
MapPattern,
Expand All @@ -28,30 +28,34 @@ def main():
)
args = parser.parse_args()

patch_fields = Map(
patch_fields = MapCombined(
{
"patch_file": Str(),
"patch_description": Str(),
"patch_type": Enum(
Optional("patch_type"): Enum(
["official", "conan", "portability", "bugfix", "vulnerability"]
),
Optional("patch_source"): Str(),
# No longer required for v2 recipes with layouts
Optional("base_path"): Str(),
}
},
Str(),
Any()
)
schema = Map(
schema = MapCombined(
{
"sources": MapPattern(Str(), Any(), minimum_keys=1),
Optional("patches"): MapPattern(Str(), Seq(Any()), minimum_keys=1),
}
},
Str(),
Any(),
)

with open(args.path, encoding="utf-8") as f:
content = f.read()

try:
parsed = load(content, schema)
parsed = dirty_load(content, schema, allow_flow_style=True)
except YAMLValidationError as error:
pretty_print_yaml_validate_error(args, error) # Error when "source" is missing or when "patches" has no versions
return
Expand All @@ -78,19 +82,6 @@ def main():
pretty_print_yaml_validate_warning(args, error) # Warning when patch fields are not followed
continue

# Make sure `patch_source` exists where it's encouraged
type = parsed["patches"][version][i]["patch_type"]
if (
type in ["official", "bugfix", "vulnerability"]
and not "patch_source" in patch
):
print(
f"::warning file={args.path},line={type.start_line},endline={type.end_line},"
f"title=conandata.yml schema warning"
f"::'patch_type' should have 'patch_source' as per {CONANDATA_YAML_URL}#patch_type"
" it is expected to have a source (e.g. a URL) to where it originates from to help with"
" reviewing and consumers to evaluate patches"
)


def pretty_print_yaml_validate_error(args, error):
Expand Down
17 changes: 7 additions & 10 deletions linter/yamllint_rules.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
extends: default
rules:
colons: disable
document-start:
level: error
present: false
document-end:
level: error
present: false
empty-lines: disable
empty-values:
forbid-in-block-mappings: true
forbid-in-flow-mappings: true
line-length: disable
indentation:
level: error
new-line-at-end-of-file:
level: error
trailing-spaces:
level: error
comments:
level: error
comments-indentation:
level: error
indentation: disable
new-line-at-end-of-file: disable
trailing-spaces: disable
comments: disable
comments-indentation: disable
new-lines:
type: unix
key-duplicates:
Expand Down

0 comments on commit 52419bd

Please sign in to comment.