Reputation: 116263
I am looking for something similar to the JavaScript linting tools JSHint or JSLint for C. My text editor (Sublime Text 2) has a JSHint pluggin that gives me real time feedback to my JavaScript code.
What is the best way to get feedback about the quality of my C code? Are there any tools that could give me real time linting?
Upvotes: 14
Views: 12708
Reputation: 180
Since this question was asked and answered, there are now some options for C/C++
linting in Sublime that are a bit more user friendly than the accepted answer. All of these are plugins for SublimeLinter. I recommend using Package Control as a package manager for Sublime Text (as do the plugin authors).
First, install Sublime Linter if you don't already have it (it's a pretty popular linting framework for multiple languages). It is most easily installed through package control, as the authors recommend, but more info is on the github site. Once Sublime Linter is installed, there are two to four different accessory packages that now exist for linting C
and C++
code.
Two of these use the C/C++
compiler itself for checking; these are SublimeLinter-gcc and SublimeLinter-clang. Both can be installed via Package Control, and provide SublimeLinter with an interface to the relevant underlying compiler. The gcc package makes it easy to specify which compiler executable you want to use, in case you might want to check code for cross-compilation.
The other two are interfaces to cpplint and cppcheck, respectively. These two are also available on Package Control, and despite the names it seems that both will lint C and C++ code.
Note that you probably only want one of these options enabled at a time, although the SublimeLinter setup allows you to have multiple options installed and only one enabled via the "linters": {...}
option stanza.
Upvotes: 1
Reputation: 572
I've concocted a way to drop some user-made linters written for SublimeText 2 into the mix to get the linting working with SublimeLinter and ANSI C. Also note, this is a slightly 'hacky' way of getting it to work.
You must have clang installed (for OS X you can use Apple's command line tools to install clang/the LLVM compiler, which requires only a developer account, which is free), you also must have SublimeLinter installed in Sublime Text 2
Navigate to this user's fork of SublimeLinter and proceed to download the 'c.py' module from the modules folder
Copy this module into SublimeLinter's working modules directory located under **your SublimeText 2 data directory**\Packages\SublimeLinter\sublimelinter\modules\
(see this for further information on the data directory)
Restart Sublime Text 2†
Upvotes: 5
Reputation: 60748
You have enough rep that I feel this might be too obvious of a suggestion, but it sounds like you would basically benefit from an IDE? e.g., Eclipse. I dev in Eclipse/Java and it's pretty aggressive regarding errors/warnings, certainly more than I've seen a compiler be.
Upvotes: 0
Reputation: 41170
Take a look at the Clang Static Analyzer and Gimpel's PC-lint and FlexeLint
Upvotes: 3
Reputation: 1069
Passing it through your compiler with full warnings is a pretty good basic lint. It will catch things like typoed variables and such. clang with optimizations off is fast enough to use as the basis of a real-time plugin, but I'm not aware of such for sublime text.
Upvotes: 0