From c3777c1536aa9d45a761b25d5dbb9b5b9338ad29 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Sat, 4 Jan 2025 23:05:44 +0400 Subject: [PATCH] ci: Extend spellcheck job with 'typos' tool Unlike the `codespell`, `typos` is capable of finding typos in combined identifiers (`CamelCase` or `snake_case`). --- .codespellrc | 3 + .gitlab/ci/typos.bash | 17 +++++ .gitlab/os-linux.yml | 1 + .typos.toml | 67 +++++++++++++++++++ Help/command/foreach.rst | 4 ++ Help/command/string.rst | 4 ++ Help/prop_sf/VS_SHADER_OBJECT_FILE_NAME.rst | 5 ++ ...CMakeCheckCompilerFlagCommonPatterns.cmake | 4 ++ Modules/FindICU.cmake | 2 +- Modules/FindMPI.cmake | 4 ++ Modules/FindRTI.cmake | 2 + Source/CMakeVersion.cmake | 2 + .../CPack/WiX/cmWIXRichTextFormatWriter.cxx | 2 +- Source/CTest/cmCTestBuildHandler.cxx | 2 +- Source/CTest/cmParseCoberturaCoverage.h | 2 + Source/cmExtraEclipseCDT4Generator.cxx | 4 +- Source/cmFunctionBlocker.cxx | 2 +- Source/cmGlobalVisualStudio10Generator.cxx | 2 + Source/cmGlobalVisualStudio8Generator.cxx | 3 +- Source/cmLocalVisualStudio7Generator.cxx | 2 + Source/cmcmd.cxx | 4 +- 21 files changed, 130 insertions(+), 8 deletions(-) create mode 100755 .gitlab/ci/typos.bash create mode 100644 .typos.toml diff --git a/.codespellrc b/.codespellrc index adc007f68b..08c6f532bc 100644 --- a/.codespellrc +++ b/.codespellrc @@ -8,6 +8,7 @@ builtin = clear,rare,en-GB_to_en-US # Skip paths matching fnmatch glob patterns. skip = .git, + .typos.toml, build, Copyright.txt, CTestCustom.cmake.in, @@ -20,6 +21,7 @@ skip = Utilities/cm*, *.pfx, +# noqa: spellcheck off ignore-words-list = aci, ags, @@ -56,3 +58,4 @@ ignore-words-list = varn, vas, wee, +# noqa: spellcheck on diff --git a/.gitlab/ci/typos.bash b/.gitlab/ci/typos.bash new file mode 100755 index 0000000000..d23928eceb --- /dev/null +++ b/.gitlab/ci/typos.bash @@ -0,0 +1,17 @@ +#!/bin/sh + +set -e + +result=0 + +echo "Running 'typos' on source code..." +typos || result=1 + +if [ -n "$CI_MERGE_REQUEST_DIFF_BASE_SHA" ]; then + for COMMIT in $(git rev-list "^$CI_MERGE_REQUEST_DIFF_BASE_SHA" "$CI_COMMIT_SHA"); do + echo "Running 'typos' on commit message of $COMMIT..." + git show --format=%B -s "$COMMIT" | typos - || result=1 + done +fi + +exit $result diff --git a/.gitlab/os-linux.yml b/.gitlab/os-linux.yml index be612953b6..c51a2ba230 100644 --- a/.gitlab/os-linux.yml +++ b/.gitlab/os-linux.yml @@ -585,6 +585,7 @@ extends: .fedora41 script: - .gitlab/ci/codespell.bash + - .gitlab/ci/typos.bash interruptible: true .cmake_build_linux: diff --git a/.typos.toml b/.typos.toml new file mode 100644 index 0000000000..c49476962f --- /dev/null +++ b/.typos.toml @@ -0,0 +1,67 @@ +# The manual about all configuration options is here: +# https://github.com/crate-ci/typos/blob/master/docs/reference.md + +[default] +check-file = true +check-filename = true +extend-ignore-re = [ + # NOTE Allow to mark a block of text to exclude from spellchecking + "(?s)(#|/(/|\\*)|\\.\\.)\\s*(NOQA|noqa):? spellcheck(: *|=| +)off.*?\\n\\s*(#|/(/|\\*)|\\.\\.)\\s*(NOQA|noqa):? spellcheck(: *|=| +)on" + # NOTE Allow to mark a line to exclude from spellchecking + , "(?Rm)^.*(#|/(/|\\*)|\\.\\.)\\s*(NOQA|noqa):? spellcheck(: *|=| +)disable-line$" + ] +locale = "en-us" + +# Add repo-wide false positives here in the form of `word = "word"`. +# Check the manual for details. +[default.extend-words] +HPE = "HPE" +# British spelling of `XCODE_SCHEME_UNDEFINED_BEHAVIOUR_SANITIZER` property name. +BEHAVIOUR = "BEHAVIOUR" +# Misspelled `Fortran_BUILDING_INSTRINSIC_MODULES` property name kept for compatibility: `INSTRINSIC` should be `INTRINSIC`. +INSTRINSIC = "INSTRINSIC" +# This is a file extension for `cobertura-merge` +ser = "ser" +# The Ninja option name +restat = "restat" +# SpectreMitigation +Spectre = "Spectre" + +[type.cmake.extend-identifiers] +COMMANDs = "COMMANDs" +xCOMMANDx = "xCOMMANDx" + +[type.cmake.extend-words] +# Some compiler's options trigger false-positives +Fo = "Fo" +ot = "ot" +# Part of compiler executable name, e.g., `arm-unknown-nto-qnx6`, but also could be in a literal string. +nto = "nto" + +[type.cpp.extend-identifiers] +APPENDed = "APPENDed" + +[type.json.extend-identifiers] +# Some compiler options from `Templates/MSBuild/FlagTables/*.json` trigger too many false-positives. +Fo = "Fo" +fo = "fo" +Ot = "Ot" +SEH = "SEH" + +[files] +ignore-hidden = false +ignore-dot = false +extend-exclude = [ + "Copyright.txt" + # Exclude third-party sources. + , "Source/CursesDialog/form/" + , "Source/kwsys/" + , "Source/bindexplib.cxx" + , "Source/cmcldeps.cxx" + , "Source/QtDialog/*.ui" + , "Utilities/cm*" + , "Utilities/ClangTidyModule" + , "Utilities/KWIML" + # FIXME: Fix spelling typos in tests. Exclude for now. + , "Tests" + ] diff --git a/Help/command/foreach.rst b/Help/command/foreach.rst index c3fdbf7abd..52ce7f4dfd 100644 --- a/Help/command/foreach.rst +++ b/Help/command/foreach.rst @@ -105,6 +105,8 @@ iteration variables as follows: - if any of the lists are shorter, the corresponding iteration variable is not defined for the current iteration. +.. noqa: spellcheck off + .. code-block:: cmake list(APPEND English one two three four) @@ -129,6 +131,8 @@ yields:: -- en=three, ba=tiga -- en=four, ba= +.. noqa: spellcheck on + See Also ^^^^^^^^ diff --git a/Help/command/string.rst b/Help/command/string.rst index 6bd56a1806..7f56ac0c96 100644 --- a/Help/command/string.rst +++ b/Help/command/string.rst @@ -163,11 +163,15 @@ The following characters have special meaning in regular expressions: :command:`if(MATCHES)`, save subgroup matches in the variables :variable:`CMAKE_MATCH_` for ```` 0..9. +.. noqa: spellcheck off + ``*``, ``+`` and ``?`` have higher precedence than concatenation. ``|`` has lower precedence than concatenation. This means that the regular expression ``^ab+d$`` matches ``abbd`` but not ``ababd``, and the regular expression ``^(ab|cd)$`` matches ``ab`` but not ``abd``. +.. noqa: spellcheck on + CMake language :ref:`Escape Sequences` such as ``\t``, ``\r``, ``\n``, and ``\\`` may be used to construct literal tabs, carriage returns, newlines, and backslashes (respectively) to pass in a regex. For example: diff --git a/Help/prop_sf/VS_SHADER_OBJECT_FILE_NAME.rst b/Help/prop_sf/VS_SHADER_OBJECT_FILE_NAME.rst index 3647a5ed3a..40eba1c82e 100644 --- a/Help/prop_sf/VS_SHADER_OBJECT_FILE_NAME.rst +++ b/Help/prop_sf/VS_SHADER_OBJECT_FILE_NAME.rst @@ -3,6 +3,11 @@ VS_SHADER_OBJECT_FILE_NAME .. versionadded:: 3.12 +.. noqa: spellcheck off +.. Ignore `-Fo` here + Specifies a file name for the compiled shader object file for an ``.hlsl`` source file. This adds the ``-Fo`` flag to the command line for the FxCompiler tool. + +.. noqa: spellcheck on diff --git a/Modules/CMakeCheckCompilerFlagCommonPatterns.cmake b/Modules/CMakeCheckCompilerFlagCommonPatterns.cmake index bda1d71110..c6402211ff 100644 --- a/Modules/CMakeCheckCompilerFlagCommonPatterns.cmake +++ b/Modules/CMakeCheckCompilerFlagCommonPatterns.cmake @@ -19,14 +19,18 @@ macro (CHECK_COMPILER_FLAG_COMMON_PATTERNS _VAR) FAIL_REGEX "invalid argument .*option" # Intel FAIL_REGEX "ignoring option .*argument required" # Intel FAIL_REGEX "ignoring option .*argument is of wrong type" # Intel + # noqa: spellcheck off FAIL_REGEX "[Uu]nknown option" # HP + # noqa: spellcheck on FAIL_REGEX "[Ww]arning: [Oo]ption" # SunPro FAIL_REGEX "command option .* is not recognized" # XL FAIL_REGEX "command option .* contains an incorrect subargument" # XL FAIL_REGEX "Option .* is not recognized. Option will be ignored." # XL FAIL_REGEX "not supported in this configuration. ignored" # AIX FAIL_REGEX "File with unknown suffix passed to linker" # PGI + # noqa: spellcheck off FAIL_REGEX "[Uu]nknown switch" # PGI + # noqa: spellcheck on FAIL_REGEX "WARNING: unknown flag:" # Open64 FAIL_REGEX "Incorrect command line option:" # Borland FAIL_REGEX "Warning: illegal option" # SunStudio 12 diff --git a/Modules/FindICU.cmake b/Modules/FindICU.cmake index 63c25760ec..6cfdb7d611 100644 --- a/Modules/FindICU.cmake +++ b/Modules/FindICU.cmake @@ -215,7 +215,7 @@ function(_ICU_FIND) endif() if(component STREQUAL "in") list(APPEND component_libnames "icui18n") - list(APPEND component_debug_libnames "icui18nd") + list(APPEND component_debug_libnames "icui18nd") # noqa: spellcheck disable-line endif() if(static_prefix) diff --git a/Modules/FindMPI.cmake b/Modules/FindMPI.cmake index a3cdf89396..124715df38 100644 --- a/Modules/FindMPI.cmake +++ b/Modules/FindMPI.cmake @@ -618,11 +618,13 @@ function (_MPI_interrogate_compiler LANG) # At this point, we obtained some output from a compiler wrapper that works. # We'll now try to parse it into variables with meaning to us. if(LANG STREQUAL "Fortran") + # noqa: spellcheck off # If MPICH (and derivates) didn't recognize the Fortran compiler include flag during configuration, # they'll return a set of three commands, consisting out of a symlink command for mpif.h, # the actual compiler command and deletion of the created symlink. # Especially with M(VA)PICH-1, this appears to happen erroneously, and therefore we should translate # this output into an additional include directory and then drop it from the output. + # noqa: spellcheck on if(MPI_COMPILE_CMDLINE MATCHES "^ln -s ([^\" ]+|\"[^\"]+\") mpif.h") get_filename_component(MPI_INCLUDE_DIRS_WORK "${CMAKE_MATCH_1}" DIRECTORY) string(REGEX REPLACE "^ln -s ([^\" ]+|\"[^\"]+\") mpif.h\n" "" MPI_COMPILE_CMDLINE "${MPI_COMPILE_CMDLINE}") @@ -955,6 +957,7 @@ function(_MPI_guess_settings LANG) # Should a user be employing PGI or have built its own set and provided it via cache variables, the # splitting routine would have located the module files. + # noqa: spellcheck off # For C and C++, we're done here (MSMPI does not ship the MPI-2 C++ bindings) - however, for Fortran # we need some extra library to glue Fortran support together: # MSMPI ships 2-4 Fortran libraries, each for different Fortran compiler behaviors. The library names @@ -964,6 +967,7 @@ function(_MPI_guess_settings LANG) # The second difference is the last but one letter, if it's an e(nd), the length of a string argument is # passed by the Fortran compiler after all other arguments on the parameter list, if it's an m(ixed), # it's passed immediately after the string address. + # noqa: spellcheck on # To summarize: # - msmpifec: CHARACTER length passed after the parameter list and using cdecl calling convention diff --git a/Modules/FindRTI.cmake b/Modules/FindRTI.cmake index 54d2bec9f8..5a92ee5acd 100644 --- a/Modules/FindRTI.cmake +++ b/Modules/FindRTI.cmake @@ -42,6 +42,7 @@ endmacro() set(RTI_DEFINITIONS "-DRTI_USES_STD_FSTREAM") +# noqa: spellcheck off # Detect the CERTI installation, http://www.cert.fr/CERTI # Detect the MAK Technologies RTI installation, http://www.mak.com/products/rti.php # note: the following list is ordered to find the most recent version first @@ -55,6 +56,7 @@ set(RTI_POSSIBLE_DIRS set(RTI_OLD_FIND_LIBRARY_PREFIXES "${CMAKE_FIND_LIBRARY_PREFIXES}") # The MAK RTI has the "lib" prefix even on Windows. set(CMAKE_FIND_LIBRARY_PREFIXES "lib" "") +# noqa: spellcheck on find_library(RTI_LIBRARY NAMES RTI RTI-NG diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 0998319f9e..ab27e1222f 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -52,9 +52,11 @@ if(NOT CMake_VERSION_NO_GIT) set(git_subject "${CMAKE_MATCH_2}") # If this is not the exact commit of a release, add dev info. + # noqa: spellcheck off if(NOT "${git_subject}" MATCHES "^[Cc][Mm]ake ${CMake_VERSION}$") string(APPEND CMake_VERSION "-g${git_hash}") endif() + # noqa: spellcheck on # If this is a work tree, check whether it is dirty. if(COMMAND _git) diff --git a/Source/CPack/WiX/cmWIXRichTextFormatWriter.cxx b/Source/CPack/WiX/cmWIXRichTextFormatWriter.cxx index 8a632399da..13fbdc0206 100644 --- a/Source/CPack/WiX/cmWIXRichTextFormatWriter.cxx +++ b/Source/CPack/WiX/cmWIXRichTextFormatWriter.cxx @@ -128,7 +128,7 @@ void cmWIXRichTextFormatWriter::WriteDocumentPrefix() { ControlWord("viewkind4"); ControlWord("uc1"); - ControlWord("pard"); + ControlWord("pard"); // noqa: spellcheck disable-line ControlWord("f0"); ControlWord("fs14"); } diff --git a/Source/CTest/cmCTestBuildHandler.cxx b/Source/CTest/cmCTestBuildHandler.cxx index d5d269e7cc..c3e5222734 100644 --- a/Source/CTest/cmCTestBuildHandler.cxx +++ b/Source/CTest/cmCTestBuildHandler.cxx @@ -34,7 +34,7 @@ #include "cmXMLWriter.h" static const char* cmCTestErrorMatches[] = { - "^[Bb]us [Ee]rror", + "^[Bb]us [Ee]rror", // noqa: spellcheck disable-line "^[Ss]egmentation [Vv]iolation", "^[Ss]egmentation [Ff]ault", ":.*[Pp]ermission [Dd]enied", diff --git a/Source/CTest/cmParseCoberturaCoverage.h b/Source/CTest/cmParseCoberturaCoverage.h index 0340433014..45b3f43ae7 100644 --- a/Source/CTest/cmParseCoberturaCoverage.h +++ b/Source/CTest/cmParseCoberturaCoverage.h @@ -10,6 +10,7 @@ class cmCTest; class cmCTestCoverageHandlerContainer; +// noqa: spellcheck off /** \class cmParsePythonCoverage * \brief Parse coverage.py Python coverage information * @@ -19,6 +20,7 @@ class cmCTestCoverageHandlerContainer; * Java-based Cobertura coverage application. This helper class parses * that XML file to fill the coverage-handler container. */ +// noqa: spellcheck on class cmParseCoberturaCoverage { public: diff --git a/Source/cmExtraEclipseCDT4Generator.cxx b/Source/cmExtraEclipseCDT4Generator.cxx index 6cba37b508..a11ed68ab4 100644 --- a/Source/cmExtraEclipseCDT4Generator.cxx +++ b/Source/cmExtraEclipseCDT4Generator.cxx @@ -626,7 +626,7 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const xml.StartElement("storageModule"); xml.Attribute("moduleId", "org.eclipse.cdt.core.settings"); - xml.StartElement("cconfiguration"); + xml.StartElement("cconfiguration"); // noqa: spellcheck disable-line xml.Attribute("id", "org.eclipse.cdt.core.default.config.1"); // Configuration settings... @@ -1018,7 +1018,9 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const cmExtraEclipseCDT4Generator::AppendStorageScanners(xml, *mf); + // noqa: spellcheck off xml.EndElement(); // cconfiguration + // noqa: spellcheck on xml.EndElement(); // storageModule xml.StartElement("storageModule"); diff --git a/Source/cmFunctionBlocker.cxx b/Source/cmFunctionBlocker.cxx index 523482a702..0ac9a63675 100644 --- a/Source/cmFunctionBlocker.cxx +++ b/Source/cmFunctionBlocker.cxx @@ -35,7 +35,7 @@ bool cmFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff, << " " << lfc << "\n" << "closes on the line\n" << " " << closingContext << "\n" - << "with mis-matching arguments."; + << "with mis-matching arguments."; // noqa: spellcheck disable-line /* clang-format on */ mf.IssueMessage(MessageType::AUTHOR_WARNING, e.str()); } else if (!this->EndCommandSupportsArguments() && diff --git a/Source/cmGlobalVisualStudio10Generator.cxx b/Source/cmGlobalVisualStudio10Generator.cxx index cca17e3259..1bba40bfdf 100644 --- a/Source/cmGlobalVisualStudio10Generator.cxx +++ b/Source/cmGlobalVisualStudio10Generator.cxx @@ -975,6 +975,7 @@ bool cmGlobalVisualStudio10Generator::FindVCTargetsPath(cmMakefile* mf) cmXMLElement epg(eprj, "PropertyGroup"); epg.Attribute("Label", "Configuration"); { + // noqa: spellcheck off cmXMLElement ect(epg, "ConfigurationType"); if (this->IsNsightTegra()) { // Tegra-Android platform does not understand "Utility". @@ -982,6 +983,7 @@ bool cmGlobalVisualStudio10Generator::FindVCTargetsPath(cmMakefile* mf) } else { ect.Content("Utility"); } + // noqa: spellcheck on } cmXMLElement(epg, "CharacterSet").Content("MultiByte"); if (this->IsNsightTegra()) { diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx index c7a3971680..59ba5265c2 100644 --- a/Source/cmGlobalVisualStudio8Generator.cxx +++ b/Source/cmGlobalVisualStudio8Generator.cxx @@ -518,8 +518,9 @@ static cmVS7FlagTable cmVS8ExtraFlagTable[] = { // Exception handling mode. If no entries match, it will be FALSE. { "ExceptionHandling", "GX", "enable c++ exceptions", "1", 0 }, { "ExceptionHandling", "EHsc", "enable c++ exceptions", "1", 0 }, + // noqa: spellcheck off { "ExceptionHandling", "EHa", "enable SEH exceptions", "2", 0 }, - + // noqa: spellcheck on { "EnablePREfast", "analyze", "", "true", 0 }, { "EnablePREfast", "analyze-", "", "false", 0 }, diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index e809a99bf3..1106244d38 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -389,7 +389,9 @@ cmVS7FlagTable cmLocalVisualStudio7GeneratorFlagTable[] = { { "FloatingPointModel", "fp:strict", "Use strict floating point model", "1", 0 }, { "FloatingPointModel", "fp:fast", "Use fast floating point model", "2", 0 }, + // noqa: spellcheck off { "FavorSizeOrSpeed", "Ot", "Favor fast code", "1", 0 }, + // noqa: spellcheck on { "FavorSizeOrSpeed", "Os", "Favor small code", "2", 0 }, { "CompileAs", "TC", "Compile as c code", "1", 0 }, { "CompileAs", "TP", "Compile as c++ code", "2", 0 }, diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 997c1a6509..bf6bcec15c 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -2033,7 +2033,7 @@ int cmcmd::RunLLVMRC(std::vector const& args) static const cmsys::RegularExpression llvm_rc_only_double_arg( "^[-/](C|LN|L)(.)?"); static const cmsys::RegularExpression common_double_arg( - "^[-/](D|U|I|FO|fo|Fo)(.)?"); + "^[-/](D|U|I|FO|fo|Fo)(.)?"); // noqa: spellcheck disable-line bool acceptNextArg = false; bool skipNextArg = false; for (std::string const& arg : cmMakeRange(args).advance(4)) { @@ -2448,7 +2448,7 @@ int cmVSLink::LinkIncremental() // Compile the resource file. std::vector rcCommand; rcCommand.push_back(this->RcPath.empty() ? "rc" : this->RcPath); - rcCommand.emplace_back("/fo"); + rcCommand.emplace_back("/fo"); // noqa: spellcheck disable-line rcCommand.push_back(this->ManifestFileRes); rcCommand.push_back(this->ManifestFileRC); if (!RunCommand("RC Pass 1", rcCommand, this->Verbose, FORMAT_DECIMAL)) {