pre-commit-checkstyle 0.0.1

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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZTNhMDBkMGE2MDM1YTA0ZTYyYjY1ZjQ2ZGVjMmMwY2M1ZjkyODMyZQ==
5
+ data.tar.gz: !binary |-
6
+ NmRkMTEzNDY1NWYzODlmNGQ1Y2VkYzhjNDRlZWQ0M2Q3YTkzMTZjZA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OTQzN2I2NmQ3NzkxNGUzY2M4MmFjNzllYjNkODIxMjlkNTA3YjdkMmQ4ZTI4
10
+ YWFmZWMyNDgxNjk3MGE1ODc2ZTJiYTMxMGQyYWI5Y2IyNzM0MDRiYTJhMDMx
11
+ OWQ1MTMwY2ExZmQ0ZWRiZjc1NDk4MGYwMWI4ZTM4NGNmMTY5OTk=
12
+ data.tar.gz: !binary |-
13
+ Y2M3NDcwMDMxZmY4NTcwODY1NGM4YTE4YjUwYTVmYTFkMjBlMjZhN2RmZjQw
14
+ OTkxYzVhMDBiOWEwM2FkMGEyMGM0OWUwNjEwMDkwOWRkZDg2NDA4NGMzMDVi
15
+ YjU0ZjIwNzk4OTQ0YjU2MGI5NGZmNTE3NjAxODJiYTk0ODYzNTA=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
6
+ - jruby-19mode
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pre-commit-checkstyle.gemspec
4
+ gemspec
5
+
6
+ gem 'pry-debugger', platforms: :mri
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Allen Madsen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # PreCommit::Checkstyle
2
+
3
+ [![Build Status](https://travis-ci.org/secondrotation/pre-commit-checkstyle.svg?branch=master)](https://travis-ci.org/secondrotation/pre-commit-checkstyle)
4
+
5
+ [Checkstyle](http://checkstyle.sourceforge.net/) linter plugin for [pre-commit](https://github.com/jish/pre-commit). Useful for linting Java code.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'pre-commit-checkstyle'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install pre-commit-checkstyle
20
+
21
+ ## Usage
22
+
23
+ Make sure the gem is installed and setup the check in [pre-commit](https://github.com/jish/pre-commit) with:
24
+
25
+ ``` bash
26
+ pre-commit enable git checks checkstyle
27
+ ```
28
+
29
+ OR
30
+
31
+ ``` bash
32
+ pre-commit enable yaml checks checkstyle
33
+ ```
34
+
35
+ ## Contributing
36
+
37
+ 1. Fork it ( http://github.com/secondrotation/pre-commit-checkstyle/fork )
38
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
39
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
40
+ 4. Push to the branch (`git push origin my-new-feature`)
41
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,36 @@
1
+ require 'pre-commit/checks/shell'
2
+
3
+ module PreCommit
4
+ module Checks
5
+ class Checkstyle < Shell
6
+ def call(staged_files)
7
+ staged_files = staged_files.grep(/\.java$/)
8
+ return if staged_files.empty?
9
+
10
+ args = (jar_flag + config_file_flag + staged_files).join(' ')
11
+
12
+ execute("java #{args}")
13
+ end
14
+
15
+ def jar_flag
16
+ ['-jar', support_path('checkstyle-5.7-all.jar')]
17
+ end
18
+
19
+ def support_path(file)
20
+ File.expand_path("../../../../pre-commit/support/checkstyle/#{file}", __FILE__)
21
+ end
22
+
23
+ def config_file_flag
24
+ config_file ? ['-c', config_file] : []
25
+ end
26
+
27
+ def alternate_config_file
28
+ support_path('sun_checks.xml')
29
+ end
30
+
31
+ def self.description
32
+ 'Runs coffeelint to detect errors'
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ module PreCommit
2
+ module Checkstyle
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,177 @@
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
+
6
+ <!--
7
+
8
+ Checkstyle configuration that checks the sun coding conventions from:
9
+
10
+ - the Java Language Specification at
11
+ http://java.sun.com/docs/books/jls/second_edition/html/index.html
12
+
13
+ - the Sun Code Conventions at http://java.sun.com/docs/codeconv/
14
+
15
+ - the Javadoc guidelines at
16
+ http://java.sun.com/j2se/javadoc/writingdoccomments/index.html
17
+
18
+ - the JDK Api documentation http://java.sun.com/j2se/docs/api/index.html
19
+
20
+ - some best practices
21
+
22
+ Checkstyle is very configurable. Be sure to read the documentation at
23
+ http://checkstyle.sf.net (or in your downloaded distribution).
24
+
25
+ Most Checks are configurable, be sure to consult the documentation.
26
+
27
+ To completely disable a check, just comment it out or delete it from the file.
28
+
29
+ Finally, it is worth reading the documentation.
30
+
31
+ -->
32
+
33
+ <module name="Checker">
34
+ <!--
35
+ If you set the basedir property below, then all reported file
36
+ names will be relative to the specified directory. See
37
+ http://checkstyle.sourceforge.net/5.x/config.html#Checker
38
+
39
+ <property name="basedir" value="${basedir}"/>
40
+ -->
41
+
42
+ <!-- Checks that a package-info.java file exists for each package. -->
43
+ <!-- See http://checkstyle.sf.net/config_javadoc.html#JavadocPackage -->
44
+ <!-- <module name="JavadocPackage"/> -->
45
+
46
+ <!-- Checks whether files end with a new line. -->
47
+ <!-- See http://checkstyle.sf.net/config_misc.html#NewlineAtEndOfFile -->
48
+ <module name="NewlineAtEndOfFile"/>
49
+
50
+ <!-- Checks that property files contain the same keys. -->
51
+ <!-- See http://checkstyle.sf.net/config_misc.html#Translation -->
52
+ <module name="Translation"/>
53
+
54
+ <!-- Checks for Size Violations. -->
55
+ <!-- See http://checkstyle.sf.net/config_sizes.html -->
56
+ <module name="FileLength"/>
57
+
58
+ <!-- Checks for whitespace -->
59
+ <!-- See http://checkstyle.sf.net/config_whitespace.html -->
60
+ <module name="FileTabCharacter"/>
61
+
62
+ <!-- Miscellaneous other checks. -->
63
+ <!-- See http://checkstyle.sf.net/config_misc.html -->
64
+ <module name="RegexpSingleline">
65
+ <property name="format" value="\s+$"/>
66
+ <property name="minimum" value="0"/>
67
+ <property name="maximum" value="0"/>
68
+ <property name="message" value="Line has trailing spaces."/>
69
+ </module>
70
+
71
+ <!-- Checks for Headers -->
72
+ <!-- See http://checkstyle.sf.net/config_header.html -->
73
+ <!-- <module name="Header"> -->
74
+ <!-- <property name="headerFile" value="${checkstyle.header.file}"/> -->
75
+ <!-- <property name="fileExtensions" value="java"/> -->
76
+ <!-- </module> -->
77
+
78
+ <module name="TreeWalker">
79
+
80
+ <!-- Checks for Javadoc comments. -->
81
+ <!-- See http://checkstyle.sf.net/config_javadoc.html -->
82
+ <module name="JavadocMethod"/>
83
+ <module name="JavadocType"/>
84
+ <module name="JavadocVariable"/>
85
+ <module name="JavadocStyle"/>
86
+
87
+
88
+ <!-- Checks for Naming Conventions. -->
89
+ <!-- See http://checkstyle.sf.net/config_naming.html -->
90
+ <module name="ConstantName"/>
91
+ <module name="LocalFinalVariableName"/>
92
+ <module name="LocalVariableName"/>
93
+ <module name="MemberName"/>
94
+ <module name="MethodName"/>
95
+ <module name="PackageName"/>
96
+ <module name="ParameterName"/>
97
+ <module name="StaticVariableName"/>
98
+ <module name="TypeName"/>
99
+
100
+
101
+ <!-- Checks for imports -->
102
+ <!-- See http://checkstyle.sf.net/config_import.html -->
103
+ <module name="AvoidStarImport"/>
104
+ <module name="IllegalImport"/> <!-- defaults to sun.* packages -->
105
+ <module name="RedundantImport"/>
106
+ <module name="UnusedImports"/>
107
+
108
+
109
+ <!-- Checks for Size Violations. -->
110
+ <!-- See http://checkstyle.sf.net/config_sizes.html -->
111
+ <module name="LineLength"/>
112
+ <module name="MethodLength"/>
113
+ <module name="ParameterNumber"/>
114
+
115
+
116
+ <!-- Checks for whitespace -->
117
+ <!-- See http://checkstyle.sf.net/config_whitespace.html -->
118
+ <module name="EmptyForIteratorPad"/>
119
+ <module name="GenericWhitespace"/>
120
+ <module name="MethodParamPad"/>
121
+ <module name="NoWhitespaceAfter"/>
122
+ <module name="NoWhitespaceBefore"/>
123
+ <module name="OperatorWrap"/>
124
+ <module name="ParenPad"/>
125
+ <module name="TypecastParenPad"/>
126
+ <module name="WhitespaceAfter"/>
127
+ <module name="WhitespaceAround"/>
128
+
129
+
130
+ <!-- Modifier Checks -->
131
+ <!-- See http://checkstyle.sf.net/config_modifiers.html -->
132
+ <module name="ModifierOrder"/>
133
+ <module name="RedundantModifier"/>
134
+
135
+
136
+ <!-- Checks for blocks. You know, those {}'s -->
137
+ <!-- See http://checkstyle.sf.net/config_blocks.html -->
138
+ <module name="AvoidNestedBlocks"/>
139
+ <module name="EmptyBlock"/>
140
+ <module name="LeftCurly"/>
141
+ <module name="NeedBraces"/>
142
+ <module name="RightCurly"/>
143
+
144
+
145
+ <!-- Checks for common coding problems -->
146
+ <!-- See http://checkstyle.sf.net/config_coding.html -->
147
+ <module name="AvoidInlineConditionals"/>
148
+ <module name="EmptyStatement"/>
149
+ <module name="EqualsHashCode"/>
150
+ <module name="HiddenField"/>
151
+ <module name="IllegalInstantiation"/>
152
+ <module name="InnerAssignment"/>
153
+ <module name="MagicNumber"/>
154
+ <module name="MissingSwitchDefault"/>
155
+ <module name="RedundantThrows"/>
156
+ <module name="SimplifyBooleanExpression"/>
157
+ <module name="SimplifyBooleanReturn"/>
158
+
159
+ <!-- Checks for class design -->
160
+ <!-- See http://checkstyle.sf.net/config_design.html -->
161
+ <module name="DesignForExtension"/>
162
+ <module name="FinalClass"/>
163
+ <module name="HideUtilityClassConstructor"/>
164
+ <module name="InterfaceIsType"/>
165
+ <module name="VisibilityModifier"/>
166
+
167
+
168
+ <!-- Miscellaneous other checks. -->
169
+ <!-- See http://checkstyle.sf.net/config_misc.html -->
170
+ <module name="ArrayTypeStyle"/>
171
+ <module name="FinalParameters"/>
172
+ <module name="TodoComment"/>
173
+ <module name="UpperEll"/>
174
+
175
+ </module>
176
+
177
+ </module>
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pre-commit/checkstyle/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pre-commit-checkstyle"
8
+ spec.version = PreCommit::Checkstyle::VERSION
9
+ spec.authors = ["Allen Madsen"]
10
+ spec.email = ["blatyo@gmail.com"]
11
+ spec.summary = %q{Checkstyle linter plugin for pre-commit}
12
+ spec.description = %q{Checkstyle linter plugin for pre-commit. Useful for linting Java code.}
13
+ spec.homepage = "https://github.com/secondrotation/pre-commit-checkstyle"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency('pre-commit', '~> 0.16')
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ end
@@ -0,0 +1,5 @@
1
+ class HelloWorld {
2
+ public static void main(String[] args) {
3
+ System.out.println("Hello World!");
4
+ }
5
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Typical hello world example.
3
+ */
4
+ final class HelloWorld {
5
+ /**
6
+ * Prevent class from being instantiated.
7
+ *
8
+ * @throws AssertionError
9
+ */
10
+ private HelloWorld() {
11
+ throw new AssertionError("Instantiating utility class...");
12
+ }
13
+
14
+ /**
15
+ * Prints Hello World!
16
+ *
17
+ * @param args Command line arguments
18
+ */
19
+ public static void main(final String[] args) {
20
+ System.out.println("Hello World!");
21
+ }
22
+ }
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+ require 'plugins/pre_commit/checks/checkstyle'
3
+
4
+ describe PreCommit::Checks::Checkstyle do
5
+ let(:config) {double(PreCommit::Configuration, get: '')}
6
+ let(:check) {PreCommit::Checks::Checkstyle.new(nil, config, [])}
7
+
8
+ it "succeds if nothing changed" do
9
+ expect(check.call([])).to be_nil
10
+ end
11
+
12
+ it "succeeds for good code" do
13
+ files = [fixture_file('good.java')]
14
+ expect(check.call(files)).to be_nil
15
+ end
16
+
17
+ it "fails for bad formatted code" do
18
+ file = fixture_file("bad.java")
19
+ expect(check.call([file])).to eq <<-ERROR
20
+ Starting audit...
21
+ #{file}:1: Missing a Javadoc comment.
22
+ #{file}:1:1: Utility classes should not have a public or default constructor.
23
+ #{file}:2:3: Missing a Javadoc comment.
24
+ #{file}:2:27: Parameter args should be final.
25
+ Audit done.
26
+ ERROR
27
+ end
28
+ end
@@ -0,0 +1,19 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ require 'pre-commit'
4
+
5
+ RSpec.configure do |config|
6
+ config.treat_symbols_as_metadata_keys_with_true_values = true
7
+ config.run_all_when_everything_filtered = true
8
+ config.filter_run :focus
9
+
10
+ # Run specs in random order to surface order dependencies. If you find an
11
+ # order dependency and want to debug it, you can fix the order by providing
12
+ # the seed, which is printed after each run.
13
+ # --seed 1234
14
+ config.order = 'random'
15
+ end
16
+
17
+ def fixture_file(file)
18
+ File.expand_path("../fixtures/#{file}", __FILE__)
19
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pre-commit-checkstyle
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Allen Madsen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pre-commit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.16'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Checkstyle linter plugin for pre-commit. Useful for linting Java code.
70
+ email:
71
+ - blatyo@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .rspec
78
+ - .travis.yml
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - lib/plugins/pre_commit/checks/checkstyle.rb
84
+ - lib/pre-commit/checkstyle/version.rb
85
+ - lib/pre-commit/support/checkstyle/checkstyle-5.7-all.jar
86
+ - lib/pre-commit/support/checkstyle/sun_checks.xml
87
+ - pre-commit-checkstyle.gemspec
88
+ - spec/fixtures/bad.java
89
+ - spec/fixtures/good.java
90
+ - spec/plugins/pre_commit/checks/checkstyle_spec.rb
91
+ - spec/spec_helper.rb
92
+ homepage: https://github.com/secondrotation/pre-commit-checkstyle
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.2.2
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Checkstyle linter plugin for pre-commit
116
+ test_files:
117
+ - spec/fixtures/bad.java
118
+ - spec/fixtures/good.java
119
+ - spec/plugins/pre_commit/checks/checkstyle_spec.rb
120
+ - spec/spec_helper.rb