├── .python-version ├── .gitignore ├── messages.json ├── .travis.yml ├── messages ├── install.txt └── 2.0.0.txt ├── LICENSE ├── linter.py └── README.md /.python-version: -------------------------------------------------------------------------------- 1 | 3.8 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /messages.json: -------------------------------------------------------------------------------- 1 | { 2 | "install": "messages/install.txt", 3 | "2.0.0": "messages/2.0.0.txt" 4 | } 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - "3.6" 4 | install: 5 | - pip install flake8 6 | script: 7 | - flake8 . --max-line-length=120 8 | -------------------------------------------------------------------------------- /messages/install.txt: -------------------------------------------------------------------------------- 1 | SublimeLinter-cppcheck 2 | ------------------------------- 3 | This linter plugin for SublimeLinter provides an interface to cppcheck. 4 | 5 | Please read the installation instructions at: 6 | 7 | https://github.com/SublimeLinter/SublimeLinter-cppcheck 8 | -------------------------------------------------------------------------------- /messages/2.0.0.txt: -------------------------------------------------------------------------------- 1 | SublimeLinter-cppcheck 2.0.0 2 | ---------------------------- 3 | 4 | 'c' and 'c++' files now have different settings sections, and you may 5 | have to adjust your settings. 6 | 7 | { 8 | "linters": { 9 | "cppcheck": { // <- for c files 10 | 11 | }, 12 | "cppcheck++": { // <- for c++ files 13 | 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Permission is hereby granted, free of charge, to any person obtaining a copy 2 | of this software and associated documentation files (the "Software"), to deal 3 | in the Software without restriction, including without limitation the rights 4 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 5 | copies of the Software, and to permit persons to whom the Software is 6 | furnished to do so, subject to the following conditions: 7 | 8 | The above copyright notice and this permission notice shall be included in 9 | all copies or substantial portions of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 12 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 14 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 15 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 16 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 17 | THE SOFTWARE. 18 | -------------------------------------------------------------------------------- /linter.py: -------------------------------------------------------------------------------- 1 | from SublimeLinter.lint import Linter, util 2 | 3 | CMD = ( 4 | "cppcheck", 5 | "--template={file}:{line}:{column}:{severity}:{id}:{message}", 6 | "--inline-suppr", 7 | "--quiet", 8 | "${args}", 9 | "${file}", 10 | ) 11 | 12 | REGEX = ( 13 | r"^(?P(:\\|[^:])+):(?P\d+):((?P\d+):)" 14 | r"((?Perror)|(?Pwarning|style|performance|portability|information)):" 15 | r"(?P\w+):(?P.+)" 16 | ) 17 | 18 | 19 | class Cppcheck(Linter): 20 | cmd = CMD 21 | regex = REGEX 22 | error_stream = util.STREAM_BOTH # linting errors are on stderr, exceptions like "file not found" on stdout 23 | on_stderr = None # handle stderr via split_match 24 | tempfile_suffix = "-" 25 | 26 | defaults = { 27 | "selector": "source.c", 28 | "--language=": "c", 29 | "--std=,+": [], # example ['c89', 'c99', 'c11'] 30 | "--enable=,": "style", 31 | } 32 | 33 | 34 | class CppcheckPlus(Linter): 35 | cmd = CMD 36 | regex = REGEX 37 | error_stream = util.STREAM_BOTH # linting errors are on stderr, exceptions like "file not found" on stdout 38 | on_stderr = None # handle stderr via split_match 39 | tempfile_suffix = "-" 40 | 41 | name = 'cppcheck++' 42 | defaults = { 43 | "selector": "source.c++", 44 | "--language=": "c++", 45 | "--std=,+": [], # example ['c++03', 'c++11', 'c++14', 'c++17', 'c++20'] 46 | "--enable=,": "style", 47 | } 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SublimeLinter-cppcheck 2 | ========================= 3 | 4 | [![Build Status](https://travis-ci.org/SublimeLinter/SublimeLinter-cppcheck.svg?branch=master)](https://travis-ci.org/SublimeLinter/SublimeLinter-cppcheck) 5 | 6 | This linter plugin for [SublimeLinter](https://github.com/SublimeLinter/SublimeLinter) provides an interface to [cppcheck](http://cppcheck.sourceforge.net/). 7 | It will be used with files that have the "C++" or "C" syntax. 8 | 9 | ## Installation 10 | 11 | SublimeLinter must be installed in order to use this plugin. 12 | 13 | Please use [Package Control](https://packagecontrol.io) to install the linter plugin. 14 | 15 | Before using this plugin, ensure that `cppcheck` is installed on your system. 16 | To install `cppcheck`, do one of the following: 17 | 18 | * Install `cppcheck` from your favorite package manager: 19 | ``` 20 | install cppcheck 21 | ``` 22 | 23 | * For Windows, you can download a copy from the [official site of cppcheck](http://cppcheck.sourceforge.net/). 24 | 25 | Once `cppcheck` is installed, ensure it is in your system PATH so that SublimeLinter can find it. 26 | The docs cover [troubleshooting PATH configuration](http://sublimelinter.com/en/latest/troubleshooting.html#finding-a-linter-executable). 27 | 28 | 29 | ## Settings 30 | 31 | We have two settings sections. 'cppcheck' for c files, and 'cppcheck++' to configure the linter for c++ files. E.g. 32 | 33 | ``` 34 | { 35 | "linters": 36 | { 37 | "cppcheck": { 38 | ... 39 | }, 40 | "cppcheck++": { 41 | ... 42 | } 43 | } 44 | }, 45 | ``` 46 | 47 | `--language=` is set automatically to `c` or `c++`. 48 | 49 | - SublimeLinter settings: http://sublimelinter.com/en/latest/settings.html 50 | - Linter settings: http://sublimelinter.com/en/latest/linter_settings.html 51 | 52 | Additional SublimeLinter-cppcheck settings: 53 | 54 | |Setting|Description| 55 | |:------|:----------| 56 | |std|Set the language standard used.| 57 | |enable|A comma-delimited list of checks to enable. Defaults to `style`.| 58 | 59 | 60 | ### Examples 61 | 62 | For ``enable``, you can use a single string (ex: ``"style,unusedFunction"``), or an array of strings if not inline (ex: ``["style", "unusedFunction"]``). 63 | 64 | For ``std``, you can use a single string for a single value, but you have to use an array of strings for multiple values (ex. ``["c89", "c99"]``), which means you can't use multiple values in inline settings. 65 | 66 | --------------------------------------------------------------------------------