jlint 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ac58a70f61ad72118a655e61ce7344dbe4aeb162
4
- data.tar.gz: c62d20259cef8cf7f5aecc578d3c54a16111fc0a
3
+ metadata.gz: b6813c93f52c5132c0563f58f28b5765881688eb
4
+ data.tar.gz: 9e33d6836d5419f85f930b838944b25512ac193e
5
5
  SHA512:
6
- metadata.gz: 4b3719d2be30d246557136348841b52f1d30b9781fe1a70e5011164beb09c7b4f531e33f1c68ea82b83af17acf3ffc9ffd105954b26ab435c9f3121fac6931bc
7
- data.tar.gz: e28edb10669f82f1afb4018ec3f1981247c0c03869b015d6d101281eff71f95e781fb8fd1cf2f0c88b2b505f494e6c3ca9eda8212ac78e000efc48b274944440
6
+ metadata.gz: 27c3d746cf4e26ec606298506de467807589cf2460159cd10d5f013fa3c55ea832b093f7b04fa7865233a700f62fa72150a5d11d1bb5a47c41251ce82bb1c11f
7
+ data.tar.gz: 8158c782278d8a1460a7c7b2dc0241d4e808a85f9c53c9c948355cd3fe97a1ab206ddb572a3682d47c62851a74c22cb3964958494d2f873a058ea5eea2326cf6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jlint (0.0.1)
4
+ jlint (0.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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, config) # [message, line]
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 'jlint/base'
2
- module Jlint
3
- def self.lint content, config
4
- Base.new.lint content, config
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, config
8
- Base.new.file_lint file_path, config
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
- module Jlint
2
- VERSION = '0.1.0'
1
+ class Jlint
2
+ VERSION = '0.1.2'
3
3
  end
@@ -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
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0"?>
2
+ <!DOCTYPE module PUBLIC
3
+ "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
4
+ "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
5
+ <module name="Checker">
6
+ </module>
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.0
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-21 00:00:00.000000000 Z
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