├── .flake8 ├── .gitignore ├── .python-version ├── .travis.yml ├── LICENSE ├── README.md ├── linter.py ├── messages.json └── messages ├── 2.0.0.txt └── install.txt /.flake8: -------------------------------------------------------------------------------- 1 | [flake8] 2 | max-line-length = 120 3 | 4 | # D100 Missing docstring in public module 5 | # D101 Missing docstring in public class 6 | # D102 Missing docstring in public method 7 | # D103 Missing docstring in public function 8 | # D104 Missing docstring in public package 9 | # D105 Missing docstring in magic method 10 | # D107 Missing docstring in __init__ 11 | ignore = D100,D101,D102,D103,D105,D107 12 | 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /.python-version: -------------------------------------------------------------------------------- 1 | 3.8 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | 3 | python: 4 | - "3.6" 5 | 6 | install: 7 | - pip3 install flake8 8 | 9 | script: 10 | - flake8 11 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SublimeLinter-clang 2 | ========================= 3 | 4 | This linter plugin for [SublimeLinter](https://github.com/SublimeLinter/SublimeLinter3) provides an interface to [clang](http://clang.llvm.org/). 5 | It will be used with files that have the C/C Improved/C++ syntax. 6 | 7 | ## Installation 8 | SublimeLinter must be installed in order to use this plugin. 9 | 10 | Please use [Package Control](https://packagecontrol.io) to install the linter plugin. 11 | 12 | Before using this plugin, ensure that `clang` is installed on your system. 13 | - Mac OS X: clang should be already bundled. 14 | - Linux: clang can be easily installed using most package managers. 15 | - Windows: the situation is a little trickier, especially with C++. One way to go is to install [mingw with clang](http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/rubenvb/). Both gcc and clang packages should be installed into the same directory. 16 | 17 | Once `clang` is installed, ensure it is in your system PATH so that SublimeLinter can find it. 18 | The docs cover [troubleshooting PATH configuration](http://sublimelinter.com/en/latest/troubleshooting.html#finding-a-linter-executable) 19 | 20 | ## Settings 21 | 22 | We have two settings sections. 'clang' for c files, and 'clang++' to configure the linter for c++ files. E.g. 23 | 24 | ``` 25 | { 26 | "linters": 27 | { 28 | "clang": { 29 | "args": "-fvery-important", 30 | "I": [ 31 | "${folder}/3rdparty/bar/include", 32 | "${folder}/3rdparty/baz" 33 | ] 34 | }, 35 | "clang++": { 36 | "args": "-falso-important" 37 | } 38 | } 39 | }, 40 | ``` 41 | 42 | Note: 'args' has the default value '-Wall -fsyntax-only -fno-caret-diagnostics', so make sure to include them when overriding 'args'. 43 | 44 | All common settings information can be found here: 45 | 46 | - SublimeLinter settings: http://sublimelinter.com/en/latest/settings.html 47 | - Linter settings: http://sublimelinter.com/en/latest/linter_settings.html 48 | 49 | Additional settings for SublimeLinter-clang: 50 | 51 | |Setting|Description| 52 | |:------|:----------| 53 | |I|A list of directories to be added to the header search paths.| 54 | |isystem|A list of directories to be added to the system header search paths.| 55 | |x|Automatically set depending on the file type.| 56 | 57 | SublimeLinter allows [expansion variables](http://sublimelinter.readthedocs.io/en/latest/settings.html#settings-expansion). For example, '${folder}' can be used to specify a path relative to the project folder. 58 | 59 | ## Troubleshooting 60 | C/C++ linting is not always straightforward. A few things to try when there's (almost) no linting information available: 61 | - Try to compile from the command line, and verify it works. 62 | - The linter might be missing some header files. They can be added with "include_dirs". 63 | - Sometimes clang fails to locate the C++ standard library headers. 64 | Assuming the compilation works when executed via command line, try to compile with `clang++ -v`. 65 | This will display all of the hidden flags clang uses. As a last resort, they can all be added as "args". 66 | 67 | -------------------------------------------------------------------------------- /linter.py: -------------------------------------------------------------------------------- 1 | # 2 | # linter.py 3 | # Linter for SublimeLinter4, a code checking framework for Sublime Text 3 4 | # 5 | # Written by nirm03 6 | # Copyright (c) 2013 nirm03 7 | # 8 | # License: MIT 9 | # 10 | 11 | """This module exports the Clang plugin class.""" 12 | 13 | import re 14 | from SublimeLinter.lint import Linter 15 | 16 | 17 | OUTPUT_RE = re.compile( 18 | r':(?P\d+):' 19 | r'((?P\d*): )?' # column number, colon and space are only applicable for single line messages 20 | # several lines of anything followed by 21 | # either error/warning/note or newline (= irrelevant backtrace content) 22 | # (lazy quantifiers so we don’t skip what we seek) 23 | r'(.*?((?Perror)|(?Pwarning|note)|\r?\n))+?' 24 | r': (?P.+)', # match the remaining content of the current line for output 25 | re.MULTILINE 26 | ) 27 | 28 | 29 | class Clang(Linter): 30 | cmd = 'clang ${args} -' 31 | defaults = { 32 | 'selector': 'source.c', 33 | 'args': '-Wall -fsyntax-only -fno-caret-diagnostics', 34 | '-I +': [], 35 | '-isystem +': [], 36 | '-x': 'c' 37 | } 38 | regex = OUTPUT_RE 39 | multiline = True 40 | on_stderr = None 41 | 42 | 43 | class ClangPlus(Linter): 44 | name = 'clang++' 45 | cmd = 'clang ${args} -' 46 | defaults = { 47 | 'selector': 'source.c++', 48 | 'args': '-Wall -fsyntax-only -fno-caret-diagnostics', 49 | '-I +': [], 50 | '-isystem +': [], 51 | '-x': 'c++' 52 | } 53 | regex = OUTPUT_RE 54 | multiline = True 55 | on_stderr = None 56 | 57 | 58 | class ClangObjC(Linter): 59 | name = 'clang-objc' 60 | cmd = 'clang ${args} -' 61 | defaults = { 62 | 'selector': 'source.objc', 63 | 'args': '-Wall -fsyntax-only -fno-caret-diagnostics -fobjc-arc', 64 | '-I +': [], 65 | '-isystem +': [], 66 | '-x': 'objective-c' 67 | } 68 | regex = OUTPUT_RE 69 | multiline = True 70 | on_stderr = None 71 | 72 | 73 | class ClangObjCPlus(Linter): 74 | name = 'clang-objc++' 75 | cmd = 'clang ${args} -' 76 | defaults = { 77 | 'selector': 'source.objc++', 78 | 'args': '-Wall -fsyntax-only -fno-caret-diagnostics -fobjc-arc', 79 | '-I +': [], 80 | '-isystem +': [], 81 | '-x': 'objective-c++' 82 | } 83 | regex = OUTPUT_RE 84 | multiline = True 85 | on_stderr = None 86 | -------------------------------------------------------------------------------- /messages.json: -------------------------------------------------------------------------------- 1 | { 2 | "install": "messages/install.txt", 3 | "2.0.0": "messages/2.0.0.txt" 4 | } 5 | -------------------------------------------------------------------------------- /messages/2.0.0.txt: -------------------------------------------------------------------------------- 1 | SublimeLinter-clang 2.0.0 2 | ------------------------- 3 | 4 | 5 | We revamped the settings, and you probably have to make changes. 6 | 7 | * If you used 'include_dirs', it is now called 'I' (just like the arg 8 | on the command line). 9 | 10 | * 'extra_flags' is now 'args' (which is the standard name in the 11 | SublimeLinter world). Note that 'args' has the default value 12 | '-Wall -fsyntax-only -fno-caret-diagnostics'. 13 | 14 | 'c' and 'c++' files now have different settings sections. 15 | 16 | { 17 | "linters": { 18 | "clang": { // <- for c files 19 | 20 | }, 21 | "clang++": { // <- for c++ files 22 | 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /messages/install.txt: -------------------------------------------------------------------------------- 1 | SublimeLinter-clang 2 | ------------------------------- 3 | This linter plugin for SublimeLinter provides an interface to clang. 4 | 5 | Please read the installation instructions at: 6 | 7 | https://github.com/SublimeLinter/SublimeLinter-clang 8 | --------------------------------------------------------------------------------