Skip to content

Commit 0e7a4e3

Browse files
vkuceraqgp
andauthored
Configure linters and formatters in MegaLinter and as pre-commit hooks (#970)
* Add pre-commit * Add default hooks * Add more hooks * Format * Update * Fix ruff * Sort imports with ruff * Add yaml hooks * Configure yaml format * Do not fail yamllint for indentation * Add yaml linters back and remove redundant python linters * Adjust yaml style * Disable prettier * Adjust comments * Add line * Rename yamllint config file * Rename yamlfmt config file * Remove pre-commit from requirements.txt --------- Co-authored-by: Jochen Klein <[email protected]>
1 parent 527329a commit 0e7a4e3

File tree

4 files changed

+71
-3
lines changed

4 files changed

+71
-3
lines changed

.mega-linter.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ DISABLE_LINTERS:
1414
- BASH_EXEC
1515
- BASH_SHFMT
1616
- JSON_PRETTIER
17+
- PYTHON_BLACK
18+
- PYTHON_FLAKE8
19+
- PYTHON_ISORT
1720
- REPOSITORY_DEVSKIM
1821
- REPOSITORY_GRYPE
1922
- REPOSITORY_KICS
2023
- REPOSITORY_SECRETLINT
2124
- REPOSITORY_TRIVY
22-
- YAML_YAMLLINT
2325
- YAML_PRETTIER
2426
- YAML_V8R
2527
DISABLE_ERRORS_LINTERS: # If errors are found by these linters, they will be considered as non blocking.
@@ -34,5 +36,7 @@ FLAVOR_SUGGESTIONS: false # Don't show suggestions about different MegaLinter fl
3436
PYTHON_ISORT_CONFIG_FILE: pyproject.toml
3537
PYTHON_PYRIGHT_CONFIG_FILE: pyproject.toml
3638
PYTHON_RUFF_CONFIG_FILE: pyproject.toml
37-
CPP_CPPLINT_FILE_EXTENSIONS: [".C", ".c", ".c++", ".cc", ".cl", ".cpp", ".cu", ".cuh", ".cxx", ".cxx.in", ".h", ".h++", ".hh", ".h.in", ".hpp", ".hxx", ".inc", ".inl", ".macro"]
38-
CPP_CLANG_FORMAT_FILE_EXTENSIONS: [".C", ".c", ".c++", ".cc", ".cl", ".cpp", ".cu", ".cuh", ".cxx", ".cxx.in", ".h", ".h++", ".hh", ".h.in", ".hpp", ".hxx", ".inc", ".inl", ".macro"]
39+
CPP_CPPLINT_FILE_EXTENSIONS: [".C", ".c", ".c++", ".cc", ".cl", ".cpp", ".cu", ".cuh", ".cxx", ".cxx.in", ".h", ".h++", ".hh",
40+
".h.in", ".hpp", ".hxx", ".inc", ".inl", ".macro"]
41+
CPP_CLANG_FORMAT_FILE_EXTENSIONS: [".C", ".c", ".c++", ".cc", ".cl", ".cpp", ".cu", ".cuh", ".cxx", ".cxx.in", ".h", ".h++",
42+
".hh", ".h.in", ".hpp", ".hxx", ".inc", ".inl", ".macro"]

.pre-commit-config.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
# See https://pre-commit.com for more information
3+
# See https://pre-commit.com/hooks.html for more hooks
4+
5+
repos:
6+
- repo: https://github.com/pre-commit/pre-commit-hooks
7+
rev: v5.0.0
8+
hooks:
9+
- id: trailing-whitespace
10+
- id: end-of-file-fixer
11+
- id: check-yaml
12+
- id: check-added-large-files
13+
- repo: https://github.com/astral-sh/ruff-pre-commit
14+
rev: v0.9.2 # ruff version
15+
hooks:
16+
- id: ruff # linter
17+
args: ["check", "--select", "I", "--fix"]
18+
- id: ruff-format # formatter
19+
- repo: https://github.com/asottile/pyupgrade
20+
rev: v3.19.1
21+
hooks:
22+
- id: pyupgrade
23+
- repo: https://github.com/shellcheck-py/shellcheck-py
24+
rev: v0.10.0.1
25+
hooks:
26+
- id: shellcheck
27+
- repo: https://github.com/google/yamlfmt
28+
rev: v0.14.0
29+
hooks:
30+
- id: yamlfmt
31+
- repo: https://github.com/adrienverge/yamllint
32+
rev: v1.35.1
33+
hooks:
34+
- id: yamllint

.yamlfmt.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
# yamlfmt configuration
3+
# Reference: https://github.com/google/yamlfmt/blob/main/docs/config-file.md#configuration-1
4+
5+
formatter:
6+
type: basic
7+
indent: 2
8+
include_document_start: true
9+
line_ending: lf
10+
retain_line_breaks_single: true
11+
max_line_length: 120
12+
drop_merge_tag: true
13+
pad_line_comments: 1
14+
trim_trailing_whitespace: true
15+
eof_newline: true

.yamllint.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
# yamllint configuration
3+
# Reference: https://yamllint.readthedocs.io/en/stable/rules.html
4+
5+
extends: default
6+
rules:
7+
line-length:
8+
max: 120
9+
level: warning
10+
indentation:
11+
spaces: 2
12+
level: warning
13+
comments:
14+
require-starting-space: true
15+
min-spaces-from-content: 1

0 commit comments

Comments
 (0)