From: SONOLET Aymeric Date: Fri, 29 Dec 2023 15:53:40 +0000 (+0100) Subject: feat: Replace black and autoflake by ruff and add clang-tidy X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9a641b643f4e2a6edd8f6b78c4d817f1f6713114;p=modules%2Fshaper.git feat: Replace black and autoflake by ruff and add clang-tidy --- diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 000000000..ae75e965a --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,62 @@ +--- +Checks: 'clang-diagnostic-*,clang-analyzer-*,modernize-use-override,modernize-use-nullptr,modernize-use-using,modernize-use-default-member-init,modernize-loop-convert,modernize-use-auto,modernize-redundant-void-arg,modernize-type-traits,modernize-use-bool-literals,modernize-use-equals-default,modernize-use-equals-delete,misc-include-cleaner,misc-const-correctness,misc-unused-parameters' +WarningsAsErrors: '' +HeaderFilterRegex: '.*SHAPER.*' +AnalyzeTemporaryDtors: false +FormatStyle: none +User: as259691 +CheckOptions: + - key: cert-dcl16-c.NewSuffixes + value: 'L;LL;LU;LLU' + - key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField + value: '0' + - key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors + value: '1' + - key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic + value: '1' + - key: google-readability-braces-around-statements.ShortStatementLines + value: '1' + - key: google-readability-function-size.StatementThreshold + value: '800' + - key: google-readability-namespace-comments.ShortNamespaceLines + value: '10' + - key: google-readability-namespace-comments.SpacesBeforeComments + value: '2' + - key: misc-unused-parameters.StrictMode + value: '0' + - key: modernize-loop-convert.MaxCopySize + value: '16' + - key: modernize-loop-convert.MinConfidence + value: reasonable + - key: modernize-loop-convert.NamingStyle + value: CamelCase + - key: modernize-pass-by-value.IncludeStyle + value: llvm + - key: modernize-replace-auto-ptr.IncludeStyle + value: llvm + - key: modernize-use-auto.MinTypeNameLength + value: '5' + - key: modernize-use-auto.RemoveStars + value: '0' + - key: modernize-use-default-member-init.IgnoreMacros + value: '1' + - key: modernize-use-default-member-init.UseAssignment + value: '0' + - key: modernize-use-equals-default.IgnoreMacros + value: '1' + - key: modernize-use-equals-delete.IgnoreMacros + value: '1' + - key: modernize-use-nullptr.NullMacros + value: 'NULL' + - key: modernize-use-override.AllowOverrideAndFinal + value: '0' + - key: modernize-use-override.FinalSpelling + value: final + - key: modernize-use-override.IgnoreDestructors + value: '0' + - key: modernize-use-override.OverrideSpelling + value: override + - key: modernize-use-using.IgnoreMacros + value: '1' +... + diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 84aa35d20..2006960c0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,35 +1,74 @@ --- repos: - # Using this mirror lets us use mypyc-compiled black, which is about 2x faster - - repo: https://github.com/psf/black-pre-commit-mirror - rev: 23.11.0 - hooks: - - id: black - # It is recommended to specify the latest version of Python - # supported by your project here, or alternatively use - # pre-commit's default_language_version, see - # https://pre-commit.com/#top_level-default_language_version - # language_version: python3.8 - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.5.0 # Use the ref you want to point at hooks: - id: trailing-whitespace + exclude: | + (?x)^( + .*\.py| + .*\.cpp| + .*\.h| + .*\.hpp| + .*\.hxx| + .*\.cxx + )$ - id: check-added-large-files - id: debug-statements - id: detect-private-key - id: end-of-file-fixer - id: mixed-line-ending + exclude: | + (?x)^( + .*\.py| + .*\.cpp| + .*\.h| + .*\.hpp| + .*\.hxx| + .*\.cxx + )$ - id: check-case-conflict + exclude: | + (?x)^( + .*\.py| + .*\.cpp| + .*\.h| + .*\.hpp| + .*\.hxx| + .*\.cxx + )$ - id: check-json - id: pretty-format-json - id: check-merge-conflict - id: check-toml - id: check-xml - id: requirements-txt-fixer - - repo: https://github.com/pre-commit/mirrors-clang-format - rev: v14.0.0 # Use the sha / tag you want to point at + # Using this mirror lets us use mypyc-compiled black, which is about 2x faster + # - repo: https://github.com/psf/black-pre-commit-mirror + # rev: 23.11.0 + # hooks: + # - id: black + # # It is recommended to specify the latest version of Python + # # supported by your project here, or alternatively use + # # pre-commit's default_language_version, see + # # https://pre-commit.com/#top_level-default_language_version + # # language_version: python3.8 + - repo: https://github.com/astral-sh/ruff-pre-commit + # Ruff version. + rev: v0.1.9 + hooks: + # Run the linter. + - id: ruff + types_or: [python, pyi, jupyter] + args: [--fix] + # Run the formatter. + - id: ruff-format + types_or: [python, pyi, jupyter] + - repo: https://github.com/asonolet/clang-hooks + rev: v0.1 # Use the sha / tag you want to point at hooks: - id: clang-format + - id: clang-tidy - repo: https://github.com/scop/pre-commit-shfmt rev: v3.7.0-4 hooks: @@ -67,8 +106,3 @@ repos: hooks: - id: cmake-format # - id: cmake-lint - - repo: https://github.com/PyCQA/autoflake - rev: v2.2.1 - hooks: - - id: autoflake - # args: [--remove-all-unused-imports, --in-place] # is dangerous !!! diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 000000000..d28e492a4 --- /dev/null +++ b/ruff.toml @@ -0,0 +1,77 @@ +# Exclude a variety of commonly ignored directories. +exclude = [ + ".bzr", + ".direnv", + ".eggs", + ".git", + ".git-rewrite", + ".hg", + ".ipynb_checkpoints", + ".mypy_cache", + ".nox", + ".pants.d", + ".pyenv", + ".pytest_cache", + ".pytype", + ".ruff_cache", + ".svn", + ".tox", + ".venv", + ".vscode", + "__pypackages__", + "_build", + "buck-out", + "build", + "dist", + "node_modules", + "site-packages", + "venv", +] + +# Same as Black. +line-length = 88 +indent-width = 4 + +# Assume Python 3.8 +target-version = "py38" + +[lint] +# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default. +# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or +# McCabe complexity (`C901`) by default. +select = ["E4", "E7", "E9", "F"] +ignore = [] + +# Allow fix for all enabled rules (when `--fix`) is provided. +fixable = ["ALL"] +unfixable = [] + +# Allow unused variables when underscore-prefixed. +dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" + +[format] +# Like Black, use double quotes for strings. +quote-style = "double" + +# Like Black, indent with spaces, rather than tabs. +indent-style = "space" + +# Like Black, respect magic trailing commas. +skip-magic-trailing-comma = false + +# Like Black, automatically detect the appropriate line ending. +line-ending = "auto" + +# Enable auto-formatting of code examples in docstrings. Markdown, +# reStructuredText code/literal blocks and doctests are all supported. +# +# This is currently disabled by default, but it is planned for this +# to be opt-out in the future. +docstring-code-format = false + +# Set the line length limit used when formatting code snippets in +# docstrings. +# +# This only has an effect when the `docstring-code-format` setting is +# enabled. +docstring-code-line-length = "dynamic"