[clang-tools-extra] Add option to exclude headers from clang-tidy analysis (PR #91400)

2024-10-14 Thread SwanBai Lei27 via cfe-commits

Baiyi27 wrote:

> This feature works as intended, it is only for filtering out diagnosed 
> issues, not for skipping the analysis in those files. See #52959 for the 
> feature you are looking for. TLDR: clang-tidy currently does not skip the 
> analysis in (system) header files, `exclude-header-filter` is only filtering 
> out warnings you are not interested in (i.e., `Supppressed 3386 
> warnings...`)此功能按预期工作,它仅用于过滤诊断出的问题,而不是跳过这些文件中的分析。看 #52959 寻找您正在寻找的功能。 
> TLDR:clang-tidy 目前不会跳过(系统)头文件中的分析, 
> `exclude-header-filter`仅过滤掉您不感兴趣的警告(即`Supppressed 3386 warnings...` )

I have read the issues in detail and it doesn't look like it has been resolved? 
But just want to filter out the content not interested in, even if you don't 
use `exclude-header-filter` The output is the same as above,It will not expand 
the contents(`Supppressed 3386 warnings...`).

https://github.com/llvm/llvm-project/pull/91400
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Add option to exclude headers from clang-tidy analysis (PR #91400)

2024-10-14 Thread SwanBai Lei27 via cfe-commits

Baiyi27 wrote:

I found a problem. In my project, I used `vcpkg` to manage the qt5 library.
```c++
#include "qapplication.h"
#include "qpushbutton.h"
#include "qstring.h"
#include "fmt/format.h"

class MainWindow: public QWidget {
public:
MainWindow(QWidget *parent= nullptr)
: QWidget(parent)
{
auto testMsg= fmt::format("This is {1} test: {0},{1}\n", "Hello", 
"Qt5");
pButton_= new QPushButton(QString::fromStdString(testMsg), this);
resize(1000, 800);
}

protected:
void resizeEvent(QResizeEvent *event) override
{
int buttonWidth = width() / 4;
int buttonHeight= height() / 4;

pButton_->setGeometry((width() - buttonWidth) / 2,
  (height() - buttonHeight) / 2,
  buttonWidth,
  buttonHeight);

QWidget::resizeEvent(event);
}

private:
QPushButton *pButton_ { nullptr };
};

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

MainWindow mainWindow;
mainWindow.show();

return app.exec();
}
```
This is my `compile_commands.json` file configuration content:
```json
[{
  "directory": "D:/CXXProject/PlantSmash/build",
  "command": "D:\\Tools\\MSYS2\\mingw64\\bin\\c++.exe -DFMT_SHARED 
-DQT_CORE_LIB -DQT_GUI_LIB -DQT_WIDGETS_LIB -isystem 
D:/Tools/Vcpkg/installed/x64-mingw-dynamic/include/qt5 -isystem 
D:/Tools/Vcpkg/installed/x64-mingw-dynamic/include/qt5/QtCore -isystem 
D:/Tools/Vcpkg/installed/x64-mingw-dynamic/tools/qt5/mkspecs/win32-g++ -isystem 
D:/Tools/Vcpkg/installed/x64-mingw-dynamic/include/qt5/QtWidgets -isystem 
D:/Tools/Vcpkg/installed/x64-mingw-dynamic/include/qt5/QtGui -isystem 
D:/Tools/Vcpkg/installed/x64-mingw-dynamic/include -g 
-fdiagnostics-color=always -o 
tests\\Framework\\CMakeFiles\\Framework.dir\\Qt5Test.cc.obj -c 
D:\\CXXProject\\tests\\Framework\\Qt5Test.cc",
  "file": "D:\\CXXProject\\tests\\Framework\\Qt5Test.cc",
  "output": "tests\\Framework\\CMakeFiles\\Framework.dir\\Qt5Test.cc.obj"
}]
```
Use the command (clang-tidy-19) :
`clang-tidy -p .\build\ .\tests\Framework\Qt5Test.cc --header-filter='.*' 
--exclude-header-filter='.*\-q.*\.h'` This should correctly ignore the `q*.h` 
header files, and the output will not include diagnostic information about qt 
header files

Here is the output:
```diff
D:\CXXProject\tests\Framework\Qt5Test.cc:17:26: warning: no header providing 
"QWidget" is directly included [misc-include-cleaner]
   16 |
   17 | class MainWindow: public QWidget {
  |  ^
D:\CXXProject\tests\Framework\Qt5Test.cc:19:5: warning: single-argument 
constructors must be marked explicit to avoid unintentional implicit 
conversions [google-explicit-constructor]
   19 | MainWindow(QWidget *parent= nullptr)
  | ^
  | explicit
D:\CXXProject\tests\Framework\Qt5Test.cc:19:25: warning: invalid case style for 
pointer parameter 'parent' [readability-identifier-naming]
   19 | MainWindow(QWidget *parent= nullptr)
  | ^~
  | pArent
   20 | : QWidget(parent)
  |   ~~
  |   pArent
D:\CXXProject\tests\Framework\Qt5Test.cc:24:16: warning: 1000 is a magic 
number; consider replacing it with a named constant [readability-magic-numbers]
   24 | resize(1000, 800);
  |^
D:\CXXProject\tests\Framework\Qt5Test.cc:24:22: warning: 800 is a magic number; 
consider replacing it with a named constant [readability-magic-numbers]
   24 | resize(1000, 800);
  |  ^
D:\CXXProject\tests\Framework\Qt5Test.cc:28:22: warning: no header providing 
"QResizeEvent" is directly included [misc-include-cleaner]
   28 | void resizeEvent(QResizeEvent *event) override
  |  ^
D:\CXXProject\tests\Framework\Qt5Test.cc:28:36: warning: invalid case style for 
pointer parameter 'event' [readability-identifier-naming]
   28 | void resizeEvent(QResizeEvent *event) override
  |^
  |pEvent
   29 | {
   30 | int buttonWidth = width() / 4;
   31 | int buttonHeight= height() / 4;
   32 |
   33 | pButton_->setGeometry((width() - buttonWidth) / 2,
   34 |   (height() - buttonHeight) / 2,
   35 |   buttonWidth,
   36 |   buttonHeight);
   37 |
   38 | QWidget::resizeEvent(event);
  |  ~
  |  pEvent
D:\CXXProject\tests\Framework\Qt5Test.cc:42:18: warning: invalid case style for 
private member 'pButton_' [readability-identifier-naming]
   33 | pButton_->setGeometry((width() - buttonWidth) / 2,
  | 
  | PButton_
   34 |   (height() - buttonHeight) / 2,