Skip to content

Commit 9e02ec5

Browse files
author
Jafar Shadiq
committed
initial commit
1 parent 2a06970 commit 9e02ec5

6 files changed

Lines changed: 191 additions & 1 deletion

File tree

.sublimelinterrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"@python": 3,
3+
"linters": {
4+
"flake8": {
5+
"max-line-length": 120
6+
},
7+
"pep8": {
8+
"max-line-length": 120
9+
}
10+
}
11+
}

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2013 Jafar Shadiq
3+
Copyright (c) 2013 Ganesha <reekoheek@gmail.com>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of
66
this software and associated documentation files (the "Software"), to deal in

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,55 @@
11
SublimeLinter-java
22
==================
3+
4+
This linter plugin for [SublimeLinter](https://github.com/SublimeLinter/SublimeLinter3) provides an interface to [java](__linter_homepage__). It will be used with files that have the “__syntax__” syntax.
5+
6+
## Installation
7+
SublimeLinter 3 must be installed in order to use this plugin. If SublimeLinter 3 is not installed, please follow the instructions [here](https://github.com/SublimeLinter/SublimeLinter.github.io/wiki/Installation).
8+
9+
### Linter installation
10+
Before using this plugin, you must ensure that `java` is installed on your system. To install `java`, do the following:
11+
12+
1. Install Other.
13+
14+
1. Install `java` by typing the following in a terminal:
15+
```
16+
<package manager> install java
17+
```
18+
19+
Once java is installed, you can proceed to install the SublimeLinter-java plugin if it is not yet installed.
20+
21+
### Plugin installation
22+
Please use [Package Control](https://sublime.wbond.net/installation) to install the linter plugin. This will ensure that the plugin will be updated when new versions are available. If you want to install from source so you can modify the source code, you probably know what you are doing so we won’t cover that here.
23+
24+
To install via Package Control, do the following:
25+
26+
1. Within Sublime Text, bring up the [Command Palette](http://docs.sublimetext.info/en/sublime-text-3/extensibility/command_palette.html) and type `install`. Among the commands you should see `Package Control: Install Package`. If that command is not highlighted, use the keyboard or mouse to select it. There will be a pause of a few seconds while Package Control fetches the list of available plugins.
27+
28+
1. When the plugin list appears, type `java`. Among the entries you should see `SublimeLinter-java`. If that entry is not highlighted, use the keyboard or mouse to select it.
29+
30+
## Settings
31+
For general information on how SublimeLinter works with settings, please see [Settings](https://github.com/SublimeLinter/SublimeLinter.github.io/wiki/Settings). For information on generic linter settings, please see [Linter Settings](https://github.com/SublimeLinter/SublimeLinter.github.io/wiki/Linter-Settings).
32+
33+
In addition to the standard SublimeLinter settings, SublimeLinter-java provides its own settings. Those marked as “Inline Setting” or “Inline Override” may also be [used inline](https://github.com/SublimeLinter/SublimeLinter.github.io/wiki/Settings#inline-settings).
34+
35+
|Setting|Description|Inline Setting|Inline Override|
36+
|:------|:----------|:------------:|:-------------:|
37+
|foo|Something.|&#10003;| |
38+
|bar|Something else.| |&#10003;|
39+
40+
## Contributing
41+
If you would like to contribute enhancements or fixes, please do the following:
42+
43+
1. Fork the plugin repository.
44+
1. Hack on a separate topic branch created from the latest `master`.
45+
1. Commit and push the topic branch.
46+
1. Make a pull request.
47+
1. Be patient. ;-)
48+
49+
Please note that modications should follow these coding guidelines:
50+
51+
- Indent is 4 spaces.
52+
- Code should pass flake8 and pep257 linters.
53+
- Vertical whitespace helps readability, don’t be afraid to use it.
54+
55+
Thank you for helping out!

linter.py

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#
2+
# linter.py
3+
# Linter for SublimeLinter3, a code checking framework for Sublime Text 3
4+
#
5+
# Written by Jafar Shadiq,,,
6+
# Copyright (c) 2013 Jafar Shadiq,,,
7+
#
8+
# License: MIT
9+
#
10+
11+
"""This module exports the Java plugin class."""
12+
13+
import os
14+
import glob
15+
import shutil
16+
import tempfile
17+
from SublimeLinter.lint import Linter, util, persist
18+
19+
20+
class Java(Linter):
21+
22+
"""Provides an interface to java."""
23+
24+
syntax = ('java')
25+
# change to None to use fn
26+
cmd = None
27+
executable = 'javac'
28+
# regex = r'^.+?:(?P<line>\d+):\s*(?:(?P<warning>warning)|(?P<error>error)):\s*(?P<message>.+)'
29+
# multiline = False
30+
regex = r'''(?xi)
31+
# First line is (lineno): type: error message
32+
^.+?:(?P<line>\d+):\s*(?:(?P<warning>warning)|(?P<error>error)):\s*(?P<message>.+)$\r?\n
33+
34+
# Second line is the line of code
35+
^.*$\r?\n
36+
37+
# Third line is a caret pointing to the position of the error
38+
^(?P<col>[^\^]*)\^$
39+
'''
40+
multiline = True
41+
line_col_base = (1, 1)
42+
tempfile_suffix = 'java'
43+
error_stream = util.STREAM_STDERR
44+
selectors = {}
45+
word_re = None
46+
defaults = {}
47+
inline_settings = None
48+
inline_overrides = None
49+
comment_re = None
50+
51+
def cmd(self):
52+
"""
53+
Return a string with the command line to execute.
54+
55+
We define this method because we want to use the .jshintrc files,
56+
and we can't rely on jshint to find them, because we are using stdin.
57+
58+
"""
59+
60+
d = tempfile.mkdtemp('', 'sublimelinter-java-')
61+
listing = glob.glob(tempfile.tempdir + '/sublimelinter-java-*')
62+
for filename in listing:
63+
shutil.rmtree(filename, True)
64+
65+
d = tempfile.mkdtemp('', 'sublimelinter-java-')
66+
67+
command = [self.executable_path, '-d', d]
68+
69+
settings = self.get_view_settings()
70+
classpath = settings.get("classpath")
71+
if isinstance(classpath, str):
72+
classpath = classpath
73+
elif all(isinstance(item, str) for item in classpath): # check iterable for stringness of all items. Will raise TypeError if some_object is not iterable
74+
classpath = ":".join(classpath)
75+
else:
76+
classpath = ""
77+
78+
if classpath != "":
79+
command += ['-cp', classpath]
80+
81+
command += ['@']
82+
# print(command)
83+
return command
84+
85+
def tmpfile(self, cmd, code, suffix=''):
86+
"""Run an external executable using a temp file to pass code and return its output."""
87+
filename = os.path.basename(self.filename)
88+
89+
try:
90+
d = tempfile.mkdtemp('', 'sublimelinter-javasource-')
91+
92+
f = open(d + '/' + filename,'w')
93+
f.write(code)
94+
f.close()
95+
96+
cmd = list(cmd)
97+
98+
if '@' in cmd:
99+
cmd[cmd.index('@')] = f.name
100+
else:
101+
cmd.append(f.name)
102+
103+
# print(cmd)
104+
105+
out = util.popen(cmd, output_stream=self.error_stream)
106+
if out:
107+
out = out.communicate()
108+
return util.combine_output(out)
109+
else:
110+
return ''
111+
112+
finally:
113+
shutil.rmtree(d, True)

messages.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"install": "messages/install.txt"
3+
}

messages/install.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
SublimeLinter-java
2+
-------------------------------
3+
This linter plugin for SublimeLinter provides an interface to java.
4+
5+
** IMPORTANT! **
6+
7+
Before this plugin will activate, you *must*
8+
follow the installation instructions here:
9+
10+
https://github.com/Jafar Shadiq,,,/SublimeLinter-java

0 commit comments

Comments
 (0)