From de5976533625f814e9e8308ddbd8deb10a9b9e74 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Sat, 4 Jan 2025 19:25:24 +0400 Subject: pre-commit: Add an initial configuration file Add (except some meta-hooks) the `check-case-conflict` hook to make sure the repo don't contain files that can cause a conflict on case-insensitive filesystems. Also, exclude third-party sources from further checks. --- .pre-commit-config.yaml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..4242774 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,34 @@ +# Read the docs here: https://pre-commit.com +# List of some available hooks: https://pre-commit.com/hooks.html +# +# Install `pre-commit`: +# +# $ pip install pre-commit +# +# Install hooks to your clone: +# $ pre-commit install +# + +default_stages: [pre-commit] +default_install_hook_types: [pre-commit] +fail_fast: false +# NOTE Exclude third-party sources and some files globally. +# See `Utilities/Scripts/update-*.bash` scripts and +# https://pre-commit.com/#regular-expressions +exclude: >- + (?x)Auxiliary/vim + | Licenses/.*\.txt$ + | Source/(CursesDialog/form|kwsys) + | Utilities/(cm.*|GitSetup|KWIML) + | .*\.patch$ + +repos: + - repo: meta + hooks: + - id: check-hooks-apply + - id: check-useless-excludes + + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: check-case-conflict -- cgit v0.12 From 8e832f0084d4107fa7a304e36fd3393a0a1be244 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Sat, 4 Jan 2025 19:55:53 +0400 Subject: pre-commit: Add a hook to check files for mixed line endings --- .pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4242774..708f97a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -32,3 +32,4 @@ repos: rev: v5.0.0 hooks: - id: check-case-conflict + - id: mixed-line-ending -- cgit v0.12 From 3a73e1b8f45ab561516bd2a32a61b1390060f408 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Sat, 4 Jan 2025 22:56:55 +0400 Subject: pre-commit: Add a hook to strip trailing whitespaces on commit --- .pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 708f97a..3745a70 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -33,3 +33,4 @@ repos: hooks: - id: check-case-conflict - id: mixed-line-ending + - id: trailing-whitespace -- cgit v0.12 From 4b34c07205f95d1b42ae2c9d890e159811c1bd2a Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Sat, 4 Jan 2025 20:40:53 +0400 Subject: pre-commit: Add a hook to check YAML files --- .pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3745a70..1364dc5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -32,5 +32,6 @@ repos: rev: v5.0.0 hooks: - id: check-case-conflict + - id: check-yaml - id: mixed-line-ending - id: trailing-whitespace -- cgit v0.12 From 1861948755e4facf255d4382349a0bb6e4df4536 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Sun, 5 Jan 2025 01:54:13 +0400 Subject: pre-commit: Add a hook to check JSON files --- .pre-commit-config.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1364dc5..50560be 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -32,6 +32,13 @@ repos: rev: v5.0.0 hooks: - id: check-case-conflict + - id: check-json + # NOTE Some tests have intentionally broken JSONs. + exclude: >- + (?x)Tests/( + CMakeLib/testCTestResourceSpec_data/spec13 + | RunCMake/CTestResourceAllocation/invalid + )\.json - id: check-yaml - id: mixed-line-ending - id: trailing-whitespace -- cgit v0.12 From 2c06b9f4290ccbedf3a6a506e17310b4e0f37d47 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Tue, 21 Jan 2025 00:00:07 +0400 Subject: pre-commit: Add a hook to fix missed EOL at the end of files For now some files from `Tests/` have been excluded. However, some files could be really fixed and removed from exclude list. --- .pre-commit-config.yaml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 50560be..bee105a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -40,5 +40,35 @@ repos: | RunCMake/CTestResourceAllocation/invalid )\.json - id: check-yaml + - id: end-of-file-fixer + # NOTE Exclude tests directory: some test files have no + # the trailing EOL in the file intentionally but some + # just missed it. + # TODO Add the missed trailing EOL in the following files + # if possible. + exclude: >- + (?x)Tests/( + DelphiCoverage/src/UTCovTest\.pas + | FortranModules/in_interface/module\.f90 + | JavascriptCoverage/output\.json\.in + | Module/ExternalData/Alt/( + MyAlgoMap1-md5/dded55e43cd6529ee35d24113dfc87a3 + | SHA1/85158f0c1996837976e858c42a9a7634bfe91b93 + ) + | RunCMake/( + CMP0055/CMP0055-(NEW|OLD)-Reject-Arguments\.cmake + | CommandLine/E_cat_good_binary_cat-stdout\.txt + | define_property/define_property-INITIALIZE_FROM_VARIABLE-invalid_[12]-result\.txt + | FindMatlab/MatlabTest2-stderr\.txt + | string/UTF-(16|32)LE\.txt + | Syntax/BOM-UTF-(16|32)-LE.cmake + | Syntax/CommandEOF\.cmake + | VS10Project/shader2?\.hlsl + ) + | SourceGroups/README\.txt + | StringFileTest/test\.utf8 + | VSWindowsFormsResx/WindowsFormsResx/MyForm\.resx + | VSXaml/Package\.appxmanifest + ) - id: mixed-line-ending - id: trailing-whitespace -- cgit v0.12 From efa7c6aedf0b38aab196fed167a1496d7e907ef7 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Sat, 4 Jan 2025 21:38:04 +0400 Subject: pre-commit: Add a hook to check whitespaces and conflict markers The hook uses settings from `.gitattributes`. --- .pre-commit-config.yaml | 6 +++++ .../query/generated/query-0.json.in | 6 ++--- .../query/generated/query-1.json.in | 18 +++++++-------- .../query/generated/query-2.json.in | 26 +++++++++++----------- 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bee105a..d861ebd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -72,3 +72,9 @@ repos: ) - id: mixed-line-ending - id: trailing-whitespace + + - repo: https://github.com/jumanjihouse/pre-commit-hooks + rev: 3.0.0 + hooks: + - id: git-check + pass_filenames: false diff --git a/Tests/RunCMake/Instrumentation/query/generated/query-0.json.in b/Tests/RunCMake/Instrumentation/query/generated/query-0.json.in index f3659f4..d6b0a1a 100644 --- a/Tests/RunCMake/Instrumentation/query/generated/query-0.json.in +++ b/Tests/RunCMake/Instrumentation/query/generated/query-0.json.in @@ -1,6 +1,6 @@ { - "callbacks" : [], - "hooks" : [], - "queries" : [], + "callbacks" : [], + "hooks" : [], + "queries" : [], "version": 1 } diff --git a/Tests/RunCMake/Instrumentation/query/generated/query-1.json.in b/Tests/RunCMake/Instrumentation/query/generated/query-1.json.in index 0a34392..996a91b 100644 --- a/Tests/RunCMake/Instrumentation/query/generated/query-1.json.in +++ b/Tests/RunCMake/Instrumentation/query/generated/query-1.json.in @@ -1,12 +1,12 @@ { - "callbacks" : - [ - "\"@CMAKE_COMMAND@\" -E echo callback1" - ], - "hooks" : - [ - "postGenerate" - ], - "queries" : [], + "callbacks" : + [ + "\"@CMAKE_COMMAND@\" -E echo callback1" + ], + "hooks" : + [ + "postGenerate" + ], + "queries" : [], "version" : 1 } diff --git a/Tests/RunCMake/Instrumentation/query/generated/query-2.json.in b/Tests/RunCMake/Instrumentation/query/generated/query-2.json.in index c29b4d4..0e2bd31 100644 --- a/Tests/RunCMake/Instrumentation/query/generated/query-2.json.in +++ b/Tests/RunCMake/Instrumentation/query/generated/query-2.json.in @@ -1,16 +1,16 @@ { - "callbacks" : - [ - "\"@CMAKE_COMMAND@\" -E echo callback2" - ], - "hooks" : - [ - "postCMakeBuild" - ], - "queries" : - [ - "staticSystemInformation", - "dynamicSystemInformation" - ], + "callbacks" : + [ + "\"@CMAKE_COMMAND@\" -E echo callback2" + ], + "hooks" : + [ + "postCMakeBuild" + ], + "queries" : + [ + "staticSystemInformation", + "dynamicSystemInformation" + ], "version": 1 } -- cgit v0.12 From 244e3d314c267361f3e69aab736e62d314cac9e6 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Sat, 4 Jan 2025 22:53:12 +0400 Subject: pre-commit: Add the `sphinx-lint` hook --- .pre-commit-config.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d861ebd..21e3db8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -78,3 +78,10 @@ repos: hooks: - id: git-check pass_filenames: false + + - repo: https://github.com/sphinx-contrib/sphinx-lint + rev: v1.0.0 + hooks: + - id: sphinx-lint + # NOTE Looks like `bad-dedent` gives too many false-positives. + args: ['--disable', 'bad-dedent'] -- cgit v0.12 From 54eba3a42a6885c83fd360b4ebba8255dd55082a Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Sun, 26 Jan 2025 05:29:21 +0400 Subject: pre-commit: Add the `codespell` hook Also, use it to spellcheck commit messages. --- .pre-commit-config.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 21e3db8..89253ce 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,7 +10,7 @@ # default_stages: [pre-commit] -default_install_hook_types: [pre-commit] +default_install_hook_types: [commit-msg, pre-commit] fail_fast: false # NOTE Exclude third-party sources and some files globally. # See `Utilities/Scripts/update-*.bash` scripts and @@ -85,3 +85,9 @@ repos: - id: sphinx-lint # NOTE Looks like `bad-dedent` gives too many false-positives. args: ['--disable', 'bad-dedent'] + + - repo: https://github.com/codespell-project/codespell + rev: v2.4.0 + hooks: + - id: codespell + stages: [commit-msg, pre-commit] -- cgit v0.12 From 8f4dd0558e102826744f3176df15dc90047517c1 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Sat, 4 Jan 2025 23:05:44 +0400 Subject: pre-commit: Add the `typos` hook for extra spellchecking Also, use it to spellcheck commit messages. --- .pre-commit-config.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 89253ce..a7ec222 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -91,3 +91,12 @@ repos: hooks: - id: codespell stages: [commit-msg, pre-commit] + + - repo: https://github.com/crate-ci/typos + rev: v1.29.4 + hooks: + - id: typos + # NOTE Override hook's default args to prevent automatic + # fixing of found typos. Let the dev decide what to fix! + args: ['--force-exclude'] + stages: [commit-msg, pre-commit] -- cgit v0.12 From abe46bf9e1343d8023c5c267f734d85cb930945b Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Sun, 5 Jan 2025 03:03:49 +0400 Subject: pre-commit: Add the `clang-format` hook The hook version is the same as the `.clang-format` config file. --- .pre-commit-config.yaml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a7ec222..29f9841 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -100,3 +100,32 @@ repos: # fixing of found typos. Let the dev decide what to fix! args: ['--force-exclude'] stages: [commit-msg, pre-commit] + + - repo: https://github.com/pre-commit/mirrors-clang-format + # ATTENTION CMake's `clang-format` is version 18. + # DO NOT UPDATE THIS VERSION unless officially supported + # `clang-format` get bumped. + rev: v18.1.8 + hooks: + - id: clang-format + types_or: [c, c++, cuda] + exclude_types: [objective-c++] + # The following exclude list based on the output of: + # $ git ls-files | git check-attr --stdin format.clang-format | grep ... + # and + # $ find -name .gitattributes -exec grep -Hn clang-format {} + + exclude: >- + (?x)( + Source/LexerParser + | Tests/( + CSharpLinkFromCxx/UsefulManagedCppClass.* + | CompileFeatures/cxx_right_angle_brackets\.cpp + | PositionIndependentTargets/pic_test\.h + | RunCMake/( + CommandLine/cmake_depends/test_UTF-16LE\.h + | CXXModules/examples/circular/circular-[ab]\.cppm + | GenerateExportHeader/reference + ) + | VSWinStorePhone/Direct3DApp1/Direct3DApp1\.cpp + ) + ) -- cgit v0.12 From b83c5b2c83967005819937c08159636faf04ebac Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Mon, 27 Jan 2025 02:04:43 +0400 Subject: pre-commit: Add `pygrep-hooks` repo and 3 hooks to check RST files --- .pre-commit-config.yaml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 29f9841..fccc0be 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -86,6 +86,21 @@ repos: # NOTE Looks like `bad-dedent` gives too many false-positives. args: ['--disable', 'bad-dedent'] + - repo: https://github.com/pre-commit/pygrep-hooks + rev: v1.10.0 + hooks: + - id: rst-backticks + # NOTE The `productionlist` directive can give false-positives + exclude: >- + (?x)Help/( + dev/maint\.rst + | manual/cmake-(developer|language)\.7\.rst + | variable/CMAKE_MESSAGE_CONTEXT\.rst + ) + | Tests/CMakeLib/testRST\.rst + - id: rst-directive-colons + - id: rst-inline-touching-normal + - repo: https://github.com/codespell-project/codespell rev: v2.4.0 hooks: -- cgit v0.12