jlint 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +8 -1
- data/lib/jlint.rb +63 -6
- data/lib/jlint/version.rb +2 -2
- data/test/jlint/test_jlint.rb +22 -2
- data/test/support/custom.xml +6 -0
- metadata +4 -3
- data/lib/jlint/base.rb +0 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6813c93f52c5132c0563f58f28b5765881688eb
|
4
|
+
data.tar.gz: 9e33d6836d5419f85f930b838944b25512ac193e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27c3d746cf4e26ec606298506de467807589cf2460159cd10d5f013fa3c55ea832b093f7b04fa7865233a700f62fa72150a5d11d1bb5a47c41251ce82bb1c11f
|
7
|
+
data.tar.gz: 8158c782278d8a1460a7c7b2dc0241d4e808a85f9c53c9c948355cd3fe97a1ab206ddb572a3682d47c62851a74c22cb3964958494d2f873a058ea5eea2326cf6
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -25,7 +25,14 @@ Or install it yourself as:
|
|
25
25
|
## Usage
|
26
26
|
|
27
27
|
```ruby
|
28
|
-
Jlint.lint(content
|
28
|
+
Jlint.lint(content) #=> [[message, line], ...]
|
29
|
+
Jlint.file_lint(file_path) #=> [[message, line], ...]
|
30
|
+
|
31
|
+
# Default it use [sun checks]()
|
32
|
+
# If Want to custom config
|
33
|
+
|
34
|
+
lint = Jlint.new(config_content)
|
35
|
+
lint.lint(content) #=> [[message, line], ...]
|
29
36
|
```
|
30
37
|
|
31
38
|
## Contributing
|
data/lib/jlint.rb
CHANGED
@@ -1,10 +1,67 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
def self.lint content
|
4
|
-
|
1
|
+
require 'tempfile'
|
2
|
+
class Jlint
|
3
|
+
def self.lint content
|
4
|
+
new.lint content
|
5
5
|
end
|
6
6
|
|
7
|
-
def self.file_lint file_path
|
8
|
-
|
7
|
+
def self.file_lint file_path
|
8
|
+
new.file_lint file_path
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
def initialize custom_config = nil
|
13
|
+
@custom_config = custom_config
|
14
|
+
end
|
15
|
+
|
16
|
+
def lint content
|
17
|
+
as_file content do |file|
|
18
|
+
file_lint file.path
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def file_lint file_path
|
23
|
+
if @custom_config
|
24
|
+
as_file @custom_config, ".xml" do |file|
|
25
|
+
parse_lint checkstyle_command, file.path, file_path
|
26
|
+
end
|
27
|
+
else
|
28
|
+
parse_lint checkstyle_command, checkstyle_config, file_path
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def parse_lint command, config_path, file_path
|
35
|
+
parse `java -jar #{checkstyle_command} -c #{config_path} #{file_path}`
|
36
|
+
end
|
37
|
+
|
38
|
+
def as_file content, format = ".java"
|
39
|
+
file = Tempfile.new(["temp", format])
|
40
|
+
begin
|
41
|
+
file.puts content
|
42
|
+
file.rewind
|
43
|
+
file.close
|
44
|
+
|
45
|
+
yield file
|
46
|
+
ensure
|
47
|
+
file.unlink
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def checkstyle_command
|
52
|
+
File.join(File.dirname(__FILE__), '..', 'bin', 'checkstyle.jar')
|
53
|
+
end
|
54
|
+
|
55
|
+
def checkstyle_config
|
56
|
+
File.join(File.dirname(__FILE__), '..', 'doc', 'sun_checks.xml')
|
57
|
+
end
|
58
|
+
|
59
|
+
def parse results
|
60
|
+
array = results.split("\n")
|
61
|
+
array.reject! { |s| s == 'Starting audit...' || s == 'Audit done.' }
|
62
|
+
array.map! do |msg|
|
63
|
+
msgs = msg.split(":")
|
64
|
+
[msgs.last.strip, msgs[1].to_i]
|
65
|
+
end
|
9
66
|
end
|
10
67
|
end
|
data/lib/jlint/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = '0.1.
|
1
|
+
class Jlint
|
2
|
+
VERSION = '0.1.2'
|
3
3
|
end
|
data/test/jlint/test_jlint.rb
CHANGED
@@ -4,7 +4,7 @@ describe Jlint do
|
|
4
4
|
|
5
5
|
it "should lint for file_path" do
|
6
6
|
file_path = File.join(File.dirname(__FILE__), "..", "support", "sample.java")
|
7
|
-
result = Jlint.file_lint(file_path
|
7
|
+
result = Jlint.file_lint(file_path)
|
8
8
|
assert result.is_a?(Array)
|
9
9
|
assert result.include?(["Missing package-info.java file.", 0])
|
10
10
|
end
|
@@ -18,10 +18,30 @@ describe Jlint do
|
|
18
18
|
system.out.printf("Hi, " + name);
|
19
19
|
}
|
20
20
|
}]
|
21
|
-
result = Jlint.lint(content
|
21
|
+
result = Jlint.lint(content)
|
22
22
|
assert result.is_a?(Array)
|
23
23
|
assert !result.include?(["File does not end with a newline.", 0])
|
24
24
|
assert result.include?(["Missing package-info.java file.", 0])
|
25
25
|
end
|
26
26
|
|
27
|
+
it "should lint with custom config content" do
|
28
|
+
content = %Q[public class Sample {
|
29
|
+
public static void Sample() {
|
30
|
+
}
|
31
|
+
|
32
|
+
public void hi(long name) {
|
33
|
+
system.out.printf("Hi, " + name);
|
34
|
+
}
|
35
|
+
}]
|
36
|
+
config_content = %Q[<?xml version="1.0"?>
|
37
|
+
<!DOCTYPE module PUBLIC
|
38
|
+
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
|
39
|
+
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
|
40
|
+
<module name="Checker">
|
41
|
+
</module>]
|
42
|
+
result = Jlint.new(config_content).lint(content)
|
43
|
+
assert result.is_a?(Array)
|
44
|
+
assert !result.include?(["Missing package-info.java file.", 0])
|
45
|
+
end
|
46
|
+
|
27
47
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jlint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- soffolk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -71,9 +71,9 @@ files:
|
|
71
71
|
- doc/sun_checks.xml
|
72
72
|
- jlint.gemspec
|
73
73
|
- lib/jlint.rb
|
74
|
-
- lib/jlint/base.rb
|
75
74
|
- lib/jlint/version.rb
|
76
75
|
- test/jlint/test_jlint.rb
|
76
|
+
- test/support/custom.xml
|
77
77
|
- test/support/sample.java
|
78
78
|
- test/test_helper.rb
|
79
79
|
homepage: ''
|
@@ -102,6 +102,7 @@ specification_version: 4
|
|
102
102
|
summary: 'Ruby Warp for CheckStyle: https://github.com/checkstyle/checkstyle'
|
103
103
|
test_files:
|
104
104
|
- test/jlint/test_jlint.rb
|
105
|
+
- test/support/custom.xml
|
105
106
|
- test/support/sample.java
|
106
107
|
- test/test_helper.rb
|
107
108
|
has_rdoc:
|
data/lib/jlint/base.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'tempfile'
|
2
|
-
|
3
|
-
module Jlint
|
4
|
-
class Base
|
5
|
-
def initialize
|
6
|
-
end
|
7
|
-
|
8
|
-
def lint content, config
|
9
|
-
file = Tempfile.new(["temp", ".java"])
|
10
|
-
begin
|
11
|
-
file.puts content
|
12
|
-
file.rewind
|
13
|
-
file.close
|
14
|
-
|
15
|
-
file_lint file.path, config
|
16
|
-
ensure
|
17
|
-
file.unlink
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def file_lint file_path, config
|
22
|
-
parse `java -jar #{checkstyle_command} -c #{checkstyle_config} #{file_path}`
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def checkstyle_command
|
28
|
-
File.join(File.dirname(__FILE__), '..', '..', 'bin', 'checkstyle.jar')
|
29
|
-
end
|
30
|
-
|
31
|
-
def checkstyle_config
|
32
|
-
File.join(File.dirname(__FILE__), '..', '..', 'doc', 'sun_checks.xml')
|
33
|
-
end
|
34
|
-
|
35
|
-
def parse results
|
36
|
-
array = results.split("\n")
|
37
|
-
array.reject! { |s| s == 'Starting audit...' || s == 'Audit done.' }
|
38
|
-
array.map! do |msg|
|
39
|
-
msgs = msg.split(":")
|
40
|
-
[msgs.last.strip, msgs[1].to_i]
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|