Git Product home page Git Product logo

clang-tidy-linter's Introduction

Clang Tidy Linter

This extension uses clang-tidy to lint C/C++ files.

This extension is in a very early stage of development. You will need to do some configuration before you can use it. But this extension is still kind of "usable".

Features

Basic diagnostic(linter) and quick fixes for the C/C++ source files with the clang-tidy.

Requirements

As for now you have to download/compile the clang-tidy executable. Maybe executables will be shipped with this extension in the future. The download link for official prebuilt binaries is http://releases.llvm.org/download.html.

Extension Settings

You may need to modify some default settings to get this extension to work for now.

clangTidy.executable: You need to manually set this to your clang-tidy executable file.

clangTidy.systemIncludePath: If you use the downloaded prebuilt binaries, it may fail to find some system headers. So put the system include paths here.

clangTidy.lintLanguages: What languages do you want to lint?

clangTidy.extraCompilerArgs: Extra arguments that pass to the compiler (not clang-tidy).

clangTidy.headerFilter: Value for -header-filter command line argument.

clangTidy.args: Additional arguments to pass to clang-tidy

If you want to configure the checks of clang tidy, create a .clang-tidy file in your working directory (please refer to the clang-tidy's document for detail).

Known Issues

Source files can only be lint when you save or open it.

You have to modify clangTidy.extraCompilerArgs setting if your C/C++ project has custom include paths.

Contribution

Repository: https://github.com/alesiong/clang-tidy-linter

I'm a beginner to vscode extension development, so if you have any suggestions, don't hesitate to post issues and/or pull requests.

Road Map (TODOs)

  1. Refactor server.ts, it is now in a very bad structure (with lots of functions and global variables)

  2. Write tests

  3. Support for on-the-fly linting (if possible)

  4. Support for custom include paths through settings and by reading .vscode/c_cpp_properties.json

  5. Ship clang-tidy binaries

Know Issues

  • When using -p compile_commands.json, saving a header or opening a header file for the first time can clear existing quick fixes for that file.
    • To regenerate the fixes, touch a cpp file which includes that header file.
    • compile_commands.json can be generated from CMake when CMAKE_EXPORT_COMPILE_COMMANDS is on.

Release Notes

0.0.1

The very first beta version published to the market.

0.0.2

Support Windows (not tested). Add code actions(quick fixes) support.

clang-tidy-linter's People

Contributors

alesiong avatar jomiller avatar softwareape avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

clang-tidy-linter's Issues

Wrong behaviour

This code is valid
image

I'm removing the include statement and of course it throws a lot of errors
image

But after I place include statement again (e.g. undo action)
image

Developer: Reload window solves the problem and this code becomes like at the first picture

Last warning never removed

When fixing clang-tidy warnings, the last warning is never removed. It requires closing vscode and reopening to make it disappear.

Errors not redirecting to original file line [Windows]

Hi, i realized that this plugin is very useful when you want to improve code quality.
But it has a very annoying problem.
when you click on an error you get "file not found"
This plugin becomes unusable as a result since it just ends up using alot of cpu resources and in the end you don't get much out of it.
Kindly help us fix this error, i've tried going through the source code , attempted to modify diagnostic report to change file lines and even tried out some pull requests which were better but none of them fixes that bug.

FIlter for lint files

I'd be nice to have an option to filter-out files that shall not be lint, e.g. generated files, 3rd party files etc. They're commonly opened but never edited hence there's no option to actually change them

Clang-tidy does not find stdlib.h even though stdlib.h is in one of the paths of "clangTidy.systemIncludePath"

the specific error:
"'stdlib.h' file not found (clang-diagnostic-error)"

{
	"resource": "/c:/Users/MassiveAtoms/Desktop/misc-lang/dailyprogrammer374/easy/additive_persistence.cpp",
	"owner": "_generated_diagnostic_collection_name_#3",
	"severity": 8,
	"message": "'stdlib.h' file not found (clang-diagnostic-error)",
	"source": "Clang Tidy",
	"startLineNumber": 50,
	"startColumn": 1,
	"endLineNumber": 50,
	"endColumn": 1
}

vscode setup

Version: 1.31.1 (user setup)
Commit: 1b8e8302e405050205e69b59abb3559592bb9e60
Date: 2019-02-12T02:20:54.427Z
Electron: 3.1.2
Chrome: 66.0.3359.181
Node.js: 10.2.0
V8: 6.6.346.32
OS: Windows_NT x64 10.0.17763

here are the used clangTidy entries in my settings.json:

    "clangTidy.executable": "C:\\msys64(4clang)\\mingw64\\bin\\clang-tidy.exe",
    "clangTidy.systemIncludePath": [
        "C:\\msys64(4clang)\\mingw64\\lib\\clang\\7.0.1\\include",
        "C:\\msys64(4clang)\\mingw64\\x86_64-w64-mingw32\\include",
        "C:\\msys64(4clang)\\mingw64\\include",
        "C:/msys64(4clang)/mingw64/include/c++"
    ],
    "clangTidy.lintLanguages": [
        "cpp"
    ],

A quick search with everything from voidtools shows that there is indeed a stdlib.h in
C:\msys64(4clang)\mingw64\x86_64-w64-mingw32\include , which is one of the paths in "clangTidy.systemIncludePath" and in "C_Cpp.default.systemIncludePath"

C:\Users\MassiveAtoms>es stdlib.h path:C:\msys64(4clang)\mingw64\
C:\msys64(4clang)\mingw64\include\c++\8.2.1\stdlib.h
C:\msys64(4clang)\mingw64\include\c++\8.2.1\tr1\stdlib.h
C:\msys64(4clang)\mingw64\x86_64-w64-mingw32\include\stdlib.h

auto fix error when containing chinese character

when my source file contains some character like chinese word "哈",it will be recognized by clang-tidy as three bytes offset, but when fix some naming error in vscode ediator, the offset will be calculated into start:{line:, character:} . but at this time, "哈" will only be recognized as one bytes offset, which results replace bias error.

Additional clang-tidy argument support (e.g, -p)

Hi,

The "clangTidy.xxx" settings do not provide adequate support for configuring clang-tidy for a workspace. In particular, I need support for clang-tidy "-p" option to point it at the "compile_commands.json" file generated by CMake. More broadly speaking, there should be settings to control additional arguments passed to clang-tidy; akin to "clangTidy.extraCompilerArgs", but for clang-tidy, not the compiler.

This boils down to the following command line:
clang-tidy -p <cmake-buid-directory> <target-source-file>

Thanks.

Resolve variables for executable path.

If you use ${workspaceFolder} when specifying the clangTidy.executable path the variable is not resolved, for example ${workspaceFolder}/tools/llvm/bin/clang-tidy. This is useful for cases when clang-tidy is installed locally within the work-space. The list of variables that are usable are defined here.

I believe the change is done by calling resolve() here:

const childProcess = spawn(configuration.executable, args);

It looks like resolve() is defined here, but this is a base class and I'm unsure of the proper way to access it in vs-code extensions.

Limit clang-tidy instances

The plugin should only launch a new instance of clangtidy if the previous one has finished to reduce cpu usage when user saves a file multiple times in succession.

Setup Donation for devs

Hi, This extension would be very useful in vs-code.
If we can setup a donation system so that devs can spare sometime to actually work on it and get something for using their time.

Filter header warnings

One major thing missing from the extension is the ability to ignore warnings from included files. If you try using it on any project that includes Gtk+ or Gtkmm headers, you can easily have over 20000 warnings on what amounts to basically system headers.

Considering that the extension runs clang-tidy on the currently opened files, maybe it would make sense to pass -line-filter='[{"name":"<filename>"}]' to clang-tidy (where <filename> is the file's name) to filter out everything at once.

Remove old errors on save/open

Issue: when clang-tidy finds an issue, it is printed to the 'problems' tab in visual studio code. Once the issue is resolved, the issue is still visible in the 'problems' view.

Proposed resolution: remove existing issues for the file being analyzed before analyze. If the issue was resolved, it will not be presented to the user. If the issue is still there, the clang-tidy will raise the issue. According to vscode team, this is responsibility of the plugin to remove old 'issues in 'problems' window (see microsoft/vscode#15524)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.