/flycheck-clang-tidy

Flycheck syntax checker using clang-tidy

Primary LanguageEmacs LispMIT LicenseMIT

flycheck-clang-tidy

Flycheck syntax checker using clang-tidy

This library provides a flycheck checker for C/C++ source code using clang-tidy.

Installation

You'll need Emacs 24 for flycheck, so the recommended way to get flycheck-clang-tidy is as a package from the MELPA repository.

Alternatively you have to ensure flycheck is installed, then download this code and add the directory to your Emacs load-path.

Then, in your init.el:

(eval-after-load 'flycheck
  '(add-hook 'flycheck-mode-hook #'flycheck-clang-tidy-setup))

Or, if you use use-package:

(use-package flycheck-clang-tidy
  :after flycheck
  :hook
  (flycheck-mode . flycheck-clang-tidy-setup)
  )

Make sure that the clang-tidy binary is present on Emacs' exec-path, or customize flycheck-clang-tidy-executable to point to the clang-tidy binary.

Usage

When flycheck is enabled (e.g. with global-flycheck-mode), c-mode and c++-mode buffers will be automatically checked using this checker.

To have clang-tidy work correctly, you usally require a compile command database as described in clang-tidy --help. For example using CMake a file named compile_commands.json can be created using -DCMAKE_EXPORT_COMPILE_COMMANDS=ON. flycheck-clang-tidy then looks for this file via variable flycheck-clang-tidy-build-path which defaults to build.

You can pass additional options to clang-tidy using the variable flycheck-clang-tidy-extra-options.