Skip to content

Lint-combine is a tool that lets you combine several linters and use them all in an IDE that supports only some (e.g. only one).

License

Notifications You must be signed in to change notification settings

WaveAccessEgorGabov/cpp-lint-combine

Repository files navigation

Cpp-lint-combine

  1. Overview

    1.1. Using Cpp-lint-combine

    1.2. Supported linters

    1.3. Supported IDEs/ IDE extensions

  2. Get the required tools

    2.1. Git

    2.2. CMake

    2.3. Ninja

    2.4. Boost

  3. Build Cpp-lint-combine

    3.1. Windows

    3.2. Linux

  4. Run tests

    4.1. Via Windows CLI

    4.2. Via Linux CLI

    4.3. Via Visual Studio

    4.4. Via ReSharper

    4.5. Via CLion

  5. Get Cpp-lint-combine in Visual Studio (Windows)

    5.1. Install Visual Studio

    5.2. Install supported linters

    5.3. Set up Visual Studio to use Cpp-lint-combine in applications with x64 target architecture

    5.4. Set up Visual Studio to use Cpp-lint-combine in applications with x86 target architecture

    5.5 Code analysis with cpp-lint-combine in Visual Studio

  6. Get Cpp-lint-combine in ReSharper via Visual Studio (Windows)

    6.1. Install Visual Studio and ReSharper C++

    6.2. Install supported linters

    6.3. Set up ReSharper to use Cpp-lint-combine

    6.4 Code analysis with cpp-lint-combine in ReSharper C++

  7. Get Cpp-lint-combine in CLion

    7.1. Install CLion

    7.2. Install supported linters

    7.3. Set up CLion to use Cpp-lint-combine

    7.4 Code analysis with cpp-lint-combine in CLion

  8. Configure the cpp-lint-combine(-msvc).sh bootstrapper script

    8.1. Choose IDE to run Cpp-lint-combine

    8.2. Set paths

    8.3. Configure Clazy's checks/levels

    8.4. Configure extra clang arguments

    8.5 Choose linters to use

  9. Q&A/ troubleshooting

    9.1. How to set up Cpp-lint-combine for both ReSharper and CLion on the same Windows machine?

    9.2. Issue: not seeing ANY inspection messages from clang-tidy among ReSharper's ones

1. Overview

lint, or a linter, is a tool that analyzes source code to flag programming errors, bugs, stylistic errors, and suspicious constructs.

Cpp-lint-combine is a tool that lets you combine several linters and use them all in an IDE that supports only some (e.g. only one).

1.1. Using Cpp-lint-combine

You can use Cpp-lint-combine as a command line tool or in IDEs/ IDE extensions.

1.2. Supported linters

1.3. Supported IDEs/ IDE extensions

2. Get the required tools

2.1. Git

Any recent version will do. Install from here.

On Windows ensure that Git's bin directory is listed in PATH earlier than any other directory containing sh.exe (or any other file invoked by the sh command).

2.2. CMake

Minimum required version is 3.17. Install from here.

2.3. Ninja (on Linux)

Install by your package manager (e.g. apt-get install ninja-build or yum install ninja-build).

2.4. Boost

Minimum required version is 1.69.0, but you cannot use version 1.72.0 because it contains an error in Boost.Process. You can get Boost on your computer in one of the following ways:

1. Download and build (at least Datetime, Regex, ProgramOptions, and FileSystem) from sources.

2. On Windows: download and install prebuilt Windows binaries into “<boost-dir>” (substitute a path of your choosing).

3. On Linux: install Boost by your package manager (e.g. apt-get install boost-devel or yum install boost-devel).

3. Build Cpp-lint-combine

3.1. Windows

git clone https://github.com/WaveAccessEgorGabov/cpp-lint-combine.git <cpp-lint-combine-source-dir>
pushd <cpp-lint-combine-source-dir>
git checkout develop
git submodule update --init --recursive yaml-cpp
popd
cmake -S <cpp-lint-combine-source-dir> -B <cpp-lint-combine-build-dir> -DBOOST_ROOT=<boost-dir>
cmake --build <cpp-lint-combine-build-dir> --config Release

3.2. Linux

git clone https://github.com/WaveAccessEgorGabov/cpp-lint-combine.git <cpp-lint-combine-source-dir>
pushd <cpp-lint-combine-source-dir>
git checkout develop
git submodule update --init --recursive yaml-cpp
popd
cmake -S <cpp-lint-combine-source-dir> -B <cpp-lint-combine-build-dir> -G "Ninja Multi-Config"
cmake --build <cpp-lint-combine-build-dir> --config Release

4. Run tests

Note: On Windows ensure that sh.exe is listed in PATH

You can ensure that Cpp-lint-combine built correctly in one of the following ways:

4.1. Via Windows CLI

1. Run <cpp-lint-combine-build-dir>\test\Release\cpp-lint-combine_tests.exe.

2. Tests passed successfully if the message *** No errors detected (green) was output.

4.2. Via Linux CLI

1. Run <cpp-lint-combine-build-dir>/test/Release/cpp-lint-combine_tests.

2. Tests passed successfully if the message *** No errors detected (green) was output.

4.3. Via Visual Studio

1. Run cmake --open <cpp-lint-combine-build-dir>Visual Studio opens the CMake-generated solution.

2. Choose Solution Configuration: Release (e.g. in the toolbar).

3. Choose Test→Run All Tests.

4. Tests passed successfully if the number of Failed Tests is zero.

4.4. Via ReSharper

1. Run cmake --open <cpp-lint-combine-build-dir>Visual Studio opens the CMake-generated solution.

2. Choose Solution Configuration: Release (e.g. in the toolbar).

3. Choose Extensions→ReSharper→Unit Tests→Run All Tests from Solution.

4. Tests passed successfully if the number of Failed Tests is zero.

4.5. Via CLion

1. Open the <cpp-lint-combine-source-dir> directory by CLion.

2. In Run/Debug Configuration choose the cpp-lint-combine_tests configuration.

3. Invoke the Run action (e.g. via the green Play-like button).

4. Tests passed successfully if the message *** No errors detected (surprisingly, dark red) was output.

5. Get Cpp-lint-combine in Visual Studio (Windows)

5.1. Install Visual Studio

Cpp-lint-combine works in Visual Studio, so you need to install it if you want to use Cpp-lint-combine via Visual Studio. You can install Visual Studio from here. Required Visual Studio version is 2019.

5.2. Install supported linters

  • Clazy — get pre-built binaries (v1.7+) from here.

  • clang-tidy — installed with Visual Studio 2019.

5.3. Set up Visual Studio to use Cpp-lint-combine in applications with x64 target architecture.

1. In directory %VCINSTALLDIR%\Llvm\x64\bin create directory named clang-tidy.

2. Move clang-tidy.exe from %VCINSTALLDIR%\Llvm\x64\bin to %VCINSTALLDIR%\Llvm\x64\bin\clang-tidy

3. Copy cpp-lint-combine.cmd and cpp-lint-combine.sh from <cpp-lint-combine-source-dir> to %VCINSTALLDIR%\Llvm\x64\bin\clang-tidy

4. In %VCINSTALLDIR%\Llvm\x64\bin\clang-tidy rename cpp-lint-combine.cmd to cpp-lint-combine-msvc.cmd, cpp-lint-combine.sh to cpp-lint-combine-msvc.sh

5. Copy msvc-shim.exe from cpp-lint-combine-build-dir>/Release/ to %VCINSTALLDIR%\Llvm\x64\bin\

6. In %VCINSTALLDIR%\Llvm\x64\bin\ rename msvc-shim.exe to clang-tidy.exe

7. In Visual Studio go to Property Pages of project which you want to analyze.

8. Choose Code Analysis→General and set property Enable Clang-Tidy to Yes

9. Choose Code Analysis→Clang-Tidy and specify the checks for clang-tidy as required, e.g. you can specify * to enable all clang-tidy checks

5.4. Set up Visual Studio to use Cpp-lint-combine in applications with x86 target architecture.

1. In directory %VCINSTALLDIR%\Llvm\bin create directory named clang-tidy.

2. Move clang-tidy.exe from %VCINSTALLDIR%\Llvm\bin to %VCINSTALLDIR%\Llvm\bin\clang-tidy

3. Copy cpp-lint-combine.cmd and cpp-lint-combine.sh from <cpp-lint-combine-source-dir> to %VCINSTALLDIR%\Llvm\bin\clang-tidy

4. In %VCINSTALLDIR%\Llvm\bin\clang-tidy rename cpp-lint-combine.cmd to cpp-lint-combine-msvc.cmd, cpp-lint-combine.sh to cpp-lint-combine-msvc.sh

5. Copy msvc-shim.exe from cpp-lint-combine-build-dir>/Release/ to %VCINSTALLDIR%\Llvm\bin\

6. In %VCINSTALLDIR%\Llvm\bin\ rename msvc-shim.exe to clang-tidy.exe

7. In Visual Studio go to Property Pages of project which you want to analyze.

8. Choose Code Analysis→General and set property Enable Clang-Tidy to Yes

9. Choose Code Analysis→Clang-Tidy and specify the checks for clang-tidy as required, e.g. you can specify * to enable all clang-tidy checks

5.5 Code analysis with cpp-lint-combine in Visual Studio

After setup you can use cpp-lint-combine to analyze your code in the Visual Studio, just like you use clang-tidy to analyze. You can known how to analyze your code with clang-tidy in Visual Studio from the arcticle Code analysis with clang-tidy in Visual Studio

6. Get Cpp-lint-combine in ReSharper via Visual Studio (Windows)

6.1. Install Visual Studio and ReSharper C++

Cpp-lint-combine works via Visual Studio extension ReSharper C++, so you need to install both Visual Studio and ReSharper C++ in this case.

Required Visual Studio version is 2017+. You can install Visual Studio 2019 from here.

You can install ReSharper C++ from here (free trial).

6.2. Install supported linters

  • Clazy — get pre-built binaries (v1.7+) from here.

  • clang-tidy — installed with ReSharper C++.

6.3. Set up ReSharper to use Cpp-lint-combine

1. In Visual Studio choose Extensions→ReSharper→Options→Code Editing→C++→Clang-Tidy.

2. Choose Custom in Clang-tidy executable to use.

3. Set path to <cpp-lint-combine-source-dir>/cpp-lint-combine.cmd (subject to customizations described below).

4. Tweak other ReSharper C++ clang-tidy settings as desired.

6.4 Code analysis with cpp-lint-combine in ReSharper C++

After setup you can use cpp-lint-combine to analyze your code in the ReSharper C++, just like you use clang-tidy to analyze. You can known how to analyze your code with clang-tidy in ReSharper C++ from the documantation page Clang-Tidy Integration

7. Get Cpp-lint-combine in CLion

7.1. Install CLion

Cpp-lint-combine works in CLion, so you need to install it if you want to use Cpp-lint-combine via CLion. You can install CLion from here (free trial).

7.2. Install supported linters

7.3. Set up CLion to use Cpp-lint-combine

1. In CLion choose Settings→Languages & Frameworks→C/C++→Clang-Tidy.

2. Tick Use external Clang-Tidy instead of the built-in one.

3. Set path to <cpp-lint-combine-source-dir>/cpp-lint-combine .cmd/.sh script on Windows/Linux respectively (subject to customizations described below).

4. Tweak other CLion clang-tidy settings as desired.

7.4 Code analysis with cpp-lint-combine in CLion

After setup you can use cpp-lint-combine to analyze your code in the CLion, just like you use clang-tidy to analyze. You can known how to analyze your code with clang-tidy in CLion from the documantation page Clang-Tidy Integration

8. Configure the cpp-lint-combine(-msvc).sh bootstrapper script

Notes for Windows:

1. Use Cygwin-style paths — with forward slashes, with a leading (root) slash, and without the colon after drive letters, e.g. /C/Program Files/Git.

2. Ensure that sh.exe is listed in PATH.

You need to configure cpp-lint-combine.sh before using Cpp-lint-combine.

8.1. Choose IDE to run Cpp-lint-combine

Assign a value to the script's variable IDE_PROFILE: choose either ReSharper, BareMSVC or CLion.

8.2. Set paths

1. Set path to the directory with the cpp-lint-combine executable to the script's variable CPP_LINT_COMBINE_PATH.

2. Set path to the directory with Clazy binaries to the script's variable CLAZY_PATH.

3. Set paths to directories with IDEs' clang-tidy executables to the script's variables <IDE_NAME>_CLANG_TIDY_PATH. If you don't have some IDE, just ignore it. Note that you don't need to set path to the Visual Studio's clang-tidy.

8.3. Configure Clazy's checks/levels

You can configure Clazy's checks/levels in the script's variable CLAZY_CHECKS. By default all Clazy's checks are included.

8.4. Configure extra clang arguments

You can add extra clang arguments to the script's variable CLANG_EXTRA_ARGS — they will be used by Clazy.
The default is "-w", see clang docs for (much) more details.

8.5. Choose linters to use

Set --sub-linter cpp-lint-combine's command line argument value. You can use this option several times to use multiple linters. All linters are used by default (if the option isn't set).

9. Q&A/ troubleshooting

9.1. How to set up Cpp-lint-combine for both ReSharper and CLion on the same Windows machine?

1. Copy cpp-lint-combine.sh and cpp-lint-combine.cmd under the same new base name (e.g. cpp-lint-combine-CLion.cmd and cpp-lint-combine-CLion.sh).

2. Configure distinct bootstrapper script for each IDE — please refer to the “Configure the cpp-lint-combine.sh bootstrapper script” section above.

9.2. Issue: not seeing ANY inspection messages from clang-tidy among ReSharper's ones

Check Cpp-lint-combine diagnostics:

1. Run Visual Studio (devenv.exe) with option /ReSharper.Internal.

2. Open the solution and the source file.

3. In Visual Studio choose: Extensions→ReSharper→Internal→C++→Dump clang-tidy output.

4. Wait a few seconds (till a text files opens externally) and check warning/errors in the file's “Clang-tidy stderr:” section.

About

Lint-combine is a tool that lets you combine several linters and use them all in an IDE that supports only some (e.g. only one).

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •