├── .gitignore ├── .python-version ├── .travis.yml ├── LICENSE ├── README.md ├── linter.py ├── messages.json └── messages └── install.txt /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /.python-version: -------------------------------------------------------------------------------- 1 | 3.8 2 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /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-javac 2 | ========================= 3 | 4 | [![Build Status](https://travis-ci.org/SublimeLinter/SublimeLinter-javac.svg?branch=master)](https://travis-ci.org/SublimeLinter/SublimeLinter-javac) 5 | 6 | This linter plugin for [SublimeLinter](https://github.com/SublimeLinter/SublimeLinter) provides an interface to [javac](http://docs.oracle.com/javase/6/docs/technotes/tools/solaris/javac.html). 7 | It will be used with files that have the "Java" syntax. 8 | 9 | Please note that because `javac` requires a complete directory context in order to work, this linter plugin currently will only lint a file **when it has been saved**. 10 | 11 | 12 | ## Installation 13 | SublimeLinter must be installed in order to use this plugin. 14 | 15 | Please use [Package Control](https://packagecontrol.io) to install the linter plugin. 16 | 17 | Before using this plugin, ensure that `javac` (JDK 1.7+) is installed on your system. 18 | `javac` is part of the `java` developer SDK, which can be downloaded [here](http://www.oracle.com/technetwork/java/javase/downloads/index.html). 19 | 20 | Please make sure that the path to `javac` is available to SublimeLinter. 21 | The docs cover [troubleshooting PATH configuration](http://sublimelinter.com/en/latest/troubleshooting.html#finding-a-linter-executable). 22 | 23 | 24 | ## Settings 25 | - SublimeLinter settings: http://sublimelinter.com/en/latest/settings.html 26 | - Linter settings: http://sublimelinter.com/en/latest/linter_settings.html 27 | 28 | Additional SublimeLinter-javac settings: 29 | 30 | |Setting|Description| 31 | |:------|:----------| 32 | |lint|A comma-delimited list of rules to apply.| 33 | 34 | Valid rule names are: all, cast, classfile, deprecation, dep-ann, divzero, empty, fallthrough, finally, options, overrides, path, processing, rawtypes, serial, static, try, unchecked, varargs, -cast, -classfile, -deprecation, -dep-ann, -divzero, -empty, -fallthrough, -finally, -options, -overrides, -path, -processing, -rawtypes, -serial, -static, -try, -unchecked, -varargs, none. 35 | 36 | For example, to ignore deprecation warnings for all files in a project, you would add this to the linter settings: 37 | 38 | ``` 39 | "javac": { 40 | "lint": "all,-deprecation" 41 | } 42 | ``` 43 | 44 | ### Passing options to `javac` 45 | 46 | In order to configure `javac` options like the class path, source path, or file encoding, 47 | the `args` setting can be used. 48 | 49 | |Setting|Description| 50 | |:------|:----------| 51 | |`args`|An array of strings, alternating between an option and the corresponding value.| 52 | 53 | A full list of available options is given [here][1]. 54 | 55 | For example, the following configuration defines the source file encoding, 56 | includes the two libraries `lib/some_lib.jar` and `lib/some_other_lib.jar` 57 | in the classpath, 58 | and defines `src/` as the project's source path: 59 | 60 | ``` 61 | "args": [ 62 | "-encoding", "UTF8", 63 | "-cp", "${folder}/lib/some_lib.jar:${folder}/lib/some_other_lib.jar", 64 | "-sourcepath", "${folder}/src/" 65 | ] 66 | ``` 67 | 68 | Note that options and their values must be separate elements in the array 69 | (i.e. `"args": ["-sourcepath", "/path/to/src"]` does work, while 70 | `"args": ["-sourcepath /path/to/src"]` does not work). 71 | 72 | #### Classpath 73 | 74 | |Setting|Description| 75 | |:------|:----------| 76 | |`classpath`|Elements for the classpath. Accepts a list.| 77 | 78 | To configure classpaths with a lot of elements, the `classpath` setting may 79 | be used alternatively or in addition to `args`. 80 | 81 | If *`-sourcepath` is unspecified* (in `args`), `-classpath` can also be used to configure source paths. 82 | 83 | The above example would look like this: 84 | 85 | ``` 86 | "args": ["-encoding", "UTF8"], 87 | "classpath": [ 88 | "${folder}/lib/some_lib.jar", 89 | "${folder}/lib/some_other_lib.jar", 90 | "${folder}/src/", // sourcepath elements go here, too 91 | ] 92 | ``` 93 | 94 | 95 | #### Project-specific options 96 | 97 | Settings like the class path often only apply to one specific project. 98 | The general SublimeLinter documentation also [explains][3] how to specify 99 | project-specific settings in the `sublime-project` file. 100 | 101 | For the example above, such a project file could look like this: 102 | ``` 103 | { 104 | "folders": 105 | [ 106 | { 107 | "path": "." 108 | } 109 | ], 110 | "settings": 111 | { 112 | "SublimeLinter.linters.javac.lint": "all", 113 | "SublimeLinter.linters.javac.args": ["-encoding", "UTF8"], 114 | "SublimeLinter.linters.javac.classpath": [ 115 | "${folder}/lib/some_lib.jar", 116 | "${folder}/lib/some_other_lib.jar", 117 | "${folder}/src/", 118 | ] 119 | } 120 | } 121 | ``` 122 | 123 | 124 | [1]:http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html 125 | [2]:http://sublimelinter.com/en/latest/settings.html#settings 126 | [3]:http://sublimelinter.com/en/latest/settings.html#project-settings 127 | -------------------------------------------------------------------------------- /linter.py: -------------------------------------------------------------------------------- 1 | from SublimeLinter.lint import Linter, util 2 | 3 | 4 | class Javac(Linter): 5 | regex = ( 6 | r'^(?P.+?):(?P\d+): ' 7 | r'(?:(?Perror)|(?Pwarning)): ' 8 | r'(?:\[.+?\] )?(?P[^\r\n]+)\r?\n' 9 | r'[^\r\n]+\r?\n' 10 | r'(?P[^\^]*)\^' 11 | ) 12 | multiline = True 13 | tempfile_suffix = '-' 14 | error_stream = util.STREAM_STDERR 15 | defaults = { 16 | 'lint': '', 17 | '-classpath::': [], 18 | 'selector': 'source.java' 19 | } 20 | 21 | def cmd(self): 22 | """ 23 | Return the command line to execute. 24 | 25 | We override this because we have to munge the -Xlint argument 26 | based on the 'lint' setting. 27 | 28 | """ 29 | 30 | xlint = '-Xlint' 31 | settings = self.get_view_settings() 32 | options = settings.get('lint') 33 | 34 | if options: 35 | xlint += ':' + options 36 | 37 | return ('javac', xlint, '-encoding', 'UTF8', '${args}') 38 | -------------------------------------------------------------------------------- /messages.json: -------------------------------------------------------------------------------- 1 | { 2 | "install": "messages/install.txt" 3 | } 4 | -------------------------------------------------------------------------------- /messages/install.txt: -------------------------------------------------------------------------------- 1 | SublimeLinter-javac 2 | -------------------- 3 | This linter plugin for SublimeLinter provides an interface to javac. 4 | 5 | Please read the installation instructions at: 6 | 7 | https://github.com/SublimeLinter/SublimeLinter-javac 8 | --------------------------------------------------------------------------------