blob: f66285672d04aae69e6c687c5caf31b5ae01f859 [file] [log] [blame]
Salman Javed5da7c042022-01-27 01:02:35 +13001//===-- clang-tools-extra/clang-tidy/NoLintDirectiveHandler.h ----*- C++ *-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_NOLINTDIRECTIVEHANDLER_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_NOLINTDIRECTIVEHANDLER_H
11
12#include "clang/Basic/Diagnostic.h"
13#include "llvm/ADT/StringRef.h"
14#include <memory>
15
Carlos Galvez4718da52023-01-22 16:30:10 +000016namespace clang::tooling {
Salman Javed5da7c042022-01-27 01:02:35 +130017struct Diagnostic;
Carlos Galvez4718da52023-01-22 16:30:10 +000018} // namespace clang::tooling
Salman Javed5da7c042022-01-27 01:02:35 +130019
20namespace llvm {
21template <typename T> class SmallVectorImpl;
22} // namespace llvm
23
Carlos Galvez4718da52023-01-22 16:30:10 +000024namespace clang::tidy {
Salman Javed5da7c042022-01-27 01:02:35 +130025
26/// This class is used to locate NOLINT comments in the file being analyzed, to
27/// decide whether a diagnostic should be suppressed.
28/// This class keeps a cache of every NOLINT comment found so that files do not
29/// have to be repeatedly parsed each time a new diagnostic is raised.
30class NoLintDirectiveHandler {
31public:
32 NoLintDirectiveHandler();
33 ~NoLintDirectiveHandler();
Zahira Ammarguellatf59b6002024-12-05 07:16:51 -080034 NoLintDirectiveHandler(const NoLintDirectiveHandler &) = delete;
35 NoLintDirectiveHandler &operator=(const NoLintDirectiveHandler &) = delete;
Salman Javed5da7c042022-01-27 01:02:35 +130036
37 bool shouldSuppress(DiagnosticsEngine::Level DiagLevel,
38 const Diagnostic &Diag, llvm::StringRef DiagName,
39 llvm::SmallVectorImpl<tooling::Diagnostic> &NoLintErrors,
40 bool AllowIO, bool EnableNoLintBlocks);
41
42private:
43 class Impl;
44 std::unique_ptr<Impl> PImpl;
45};
46
Carlos Galvez4718da52023-01-22 16:30:10 +000047} // namespace clang::tidy
Salman Javed5da7c042022-01-27 01:02:35 +130048
49#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_NOLINTDIRECTIVEHANDLER_H