Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions HOWTO.md

This file was deleted.

63 changes: 51 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,69 @@
This is a template. For "how to make a linter", please check [the HOWTO](HOWTO.md).

-----------------------------------------------------------------

SublimeLinter-contrib-__linter__
SublimeLinter-contrib-groovyc
================================

[![Build Status](https://travis-ci.org/SublimeLinter/SublimeLinter-contrib-__linter__.svg?branch=master)](https://travis-ci.org/SublimeLinter/SublimeLinter-contrib-__linter__)
[![Build Status](https://travis-ci.org/SublimeLinter/SublimeLinter-contrib-groovyc.svg?branch=master)](https://travis-ci.org/SublimeLinter/SublimeLinter-contrib-groovyc)

This linter plugin for [SublimeLinter](https://github.com/SublimeLinter/SublimeLinter) provides an interface to [__linter__](__linter_homepage__). It will be used with files that have the “__syntax__” syntax.
This linter plugin for [SublimeLinter](https://github.com/SublimeLinter/SublimeLinter) provides an interface to [groovyc](http://www.groovy-lang.org/download.html). It will be used with files that have the “.groovy” syntax.

## Installation
SublimeLinter must be installed in order to use this plugin.

Please use [Package Control](https://packagecontrol.io) to install the linter plugin.

Before installing this plugin, you must ensure that `__linter__` is installed on your system.
Before installing this plugin, you must ensure that `groovyc` is installed on your system.

In order for `__linter__` to be executed by SublimeLinter, you must ensure that its path is available to SublimeLinter. The docs cover [troubleshooting PATH configuration](http://sublimelinter.readthedocs.io/en/latest/troubleshooting.html#finding-a-linter-executable).
In order for `groovyc` to be executed by SublimeLinter, you must ensure that its path is available to SublimeLinter. The docs cover [troubleshooting PATH configuration](http://sublimelinter.readthedocs.io/en/latest/troubleshooting.html#finding-a-linter-executable).

- `GROOVY_HOME` environment variable has to be set to main groovy folder (inside this folder you can find directories like `bin`, `lib` and `conf`)

## Settings
- SublimeLinter settings: http://sublimelinter.readthedocs.org/en/latest/settings.html
- Linter settings: http://sublimelinter.readthedocs.org/en/latest/linter_settings.html

Additional SublimeLinter-__linter__ settings:
Additional SublimeLinter-groovyc settings:

|Setting|Description |
|:------|:--------------|
|foo |Something. |
|bar |Something else.|
|classpath |directories to add to classpath (dependencies), project folder is added automatically|
|sourcepath |directories to add as source path|

# Example SublimeLinter settings

## Global Settings
```json
{
"linters":
{
"groovy":{
"env": {
"GROOVY_HOME": "C:\\groovy\\apache-groovy-binary-2.6.0-alpha-3\\groovy-2.6.0-alpha-3"
}
}
},
"paths":
{
"linux":
[
],
"osx":
[
],
"windows":
[
"C:\\groovy\\apache-groovy-binary-2.6.0-alpha-3\\groovy-2.6.0-alpha-3\\bin"
]
}
}
```

## Project settings

```
"SublimeLinter": {
"linters": {
"groovy": {
"classpath": "C:\\code\\project1\\src"
}
}
}
```
71 changes: 65 additions & 6 deletions linter.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,69 @@
from SublimeLinter.lint import Linter # or NodeLinter, PythonLinter, ComposerLinter, RubyLinter
import os
import platform
import tempfile

from SublimeLinter.lint import Linter

if platform.system() == "Windows":
GROOVY_BINARY = 'groovyc.bat'
CLASSPATH_DIVIDER = ';'
else:
GROOVY_BINARY = "groovyc"
CLASSPATH_DIVIDER = ':'


class Groovy(Linter):

tempfile_suffix = "-"

regex = r'''(?sx)(.*?:\ # Filepath part
\d+:\ # Line part, we ignore it as we have it later
(?P<message>.*?)\s* # Error message till @
@\ line\ (?P<line>\d+),\ column\ (?P<col>\d+)\. # line and column, ends with dot
''' \
'{}'.format(os.linesep) +\
r'''\s*(?P<code>.*?)\n # 2line - code snippet of error, it has to end with unix newline
''' \
r'|.*) # The last resort match - if we do not match error, match anything to silence info from SL'

multiline = True

class __class__(Linter):
cmd = '__cmd__'
regex = r''
multiline = False
defaults = {
'selector': 'source.python'
'classpath': None,
'sourcepath': None,
'selector': 'source.groovy',
}

on_stderr = None

def cmd(self):
cmd = (GROOVY_BINARY,)
settings = self.get_view_settings()
# pylint: disable=attribute-defined-outside-init
self._tempdir = tempfile.TemporaryDirectory(prefix="sublimelinter-contrib-groovyc-target-")

classpaths = []
classpaths.append(settings.get('classpath') or '')
classpaths.append(self._tempdir.name)

classpath_str = '"{}'.format(CLASSPATH_DIVIDER) + '{}"'.format(CLASSPATH_DIVIDER.join(classpaths))
cmd += ('-classpath', classpath_str)

for opt in ('sourcepath',):
value = settings.get(opt)
if value is not None:
cmd += ('--{}'.format(opt), '"{}"'.format(value),)

cmd += ('-d', '"{}"'.format(self._tempdir.name))
return cmd

def run(self, cmd, code=None):
with self._tempdir:
return super().run(cmd, code)

def split_match(self, match):
match, line, col, error, warning, message, near = super().split_match(match)

if line is None:
return match, 0, 0, None, None, None, None
return match, line, col, error, warning, message, near
9 changes: 6 additions & 3 deletions messages/install.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
SublimeLinter-contrib-__linter__
SublimeLinter-contrib-groovyc
-------------------------------
This linter plugin for SublimeLinter provides an interface to __linter__.
This linter plugin for SublimeLinter provides an interface to groovyc.

You have to add groovyc to system PATH, or add it to paths in SublimeLinter settings. GROOVY_HOME
has to be properly set in environment or SublimeLinter settings.

For more information, please see:
https://github.com/__user__/SublimeLinter-contrib-__linter__
https://github.com/alkuzad/SublimeLinter-contrib-groovyc