gazelle_styleguide 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gazelle_styleguide.gemspec
4
+ gemspec
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,51 @@
1
+ # GazelleStyleguide
2
+
3
+ This gem bundles up Gazelle's style guides for Ruby, JavaScript, CoffeeScript, SCSS, CSS, JSON, and YAML.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'gazelle_styleguide'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install gazelle_styleguide
18
+
19
+ ## Usage
20
+
21
+ To install the pre-commit hook, run:
22
+
23
+ ``` bash
24
+ gazelle_styleguide init
25
+ ```
26
+
27
+ To lint all new and changed files, run:
28
+
29
+ ``` bash
30
+ gazelle_styleguide lint
31
+ ```
32
+
33
+ To lint all files, run:
34
+
35
+ ``` bash
36
+ gazelle_styleguide lint -a
37
+ ```
38
+
39
+ To lint specific files, run:
40
+
41
+ ``` bash
42
+ gazelle_styleguide lint FILES
43
+ ```
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it ( http://github.com/secondrotation/gazelle_styleguide/fork )
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 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,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gazelle_styleguide'
3
+
4
+ GazelleStyleguide::CLI.start(ARGV)
File without changes
@@ -0,0 +1,114 @@
1
+ {
2
+ "coffeescript_error": {
3
+ "level": "error"
4
+ },
5
+ "arrow_spacing": {
6
+ "name": "arrow_spacing",
7
+ "level": "ignore"
8
+ },
9
+ "no_tabs": {
10
+ "name": "no_tabs",
11
+ "level": "error"
12
+ },
13
+ "no_trailing_whitespace": {
14
+ "name": "no_trailing_whitespace",
15
+ "level": "error",
16
+ "allowed_in_comments": false,
17
+ "allowed_in_empty_lines": false
18
+ },
19
+ "max_line_length": {
20
+ "name": "max_line_length",
21
+ "value": 120,
22
+ "level": "error",
23
+ "limitComments": true
24
+ },
25
+ "line_endings": {
26
+ "name": "line_endings",
27
+ "level": "error",
28
+ "value": "unix"
29
+ },
30
+ "no_trailing_semicolons": {
31
+ "name": "no_trailing_semicolons",
32
+ "level": "error"
33
+ },
34
+ "indentation": {
35
+ "name": "indentation",
36
+ "value": 2,
37
+ "level": "error"
38
+ },
39
+ "camel_case_classes": {
40
+ "name": "camel_case_classes",
41
+ "level": "error"
42
+ },
43
+ "colon_assignment_spacing": {
44
+ "name": "colon_assignment_spacing",
45
+ "level": "error",
46
+ "spacing": {
47
+ "left": 0,
48
+ "right": 1
49
+ }
50
+ },
51
+ "no_implicit_braces": {
52
+ "name": "no_implicit_braces",
53
+ "level": "ignore",
54
+ "strict": true
55
+ },
56
+ "no_plusplus": {
57
+ "name": "no_plusplus",
58
+ "level": "ignore"
59
+ },
60
+ "no_throwing_strings": {
61
+ "name": "no_throwing_strings",
62
+ "level": "error"
63
+ },
64
+ "no_backticks": {
65
+ "name": "no_backticks",
66
+ "level": "error"
67
+ },
68
+ "no_implicit_parens": {
69
+ "name": "no_implicit_parens",
70
+ "level": "error"
71
+ },
72
+ "no_empty_param_list": {
73
+ "name": "no_empty_param_list",
74
+ "level": "error"
75
+ },
76
+ "no_stand_alone_at": {
77
+ "name": "no_stand_alone_at",
78
+ "level": "ignore"
79
+ },
80
+ "space_operators": {
81
+ "name": "space_operators",
82
+ "level": "error"
83
+ },
84
+ "duplicate_key": {
85
+ "name": "duplicate_key",
86
+ "level": "error"
87
+ },
88
+ "empty_constructor_needs_parens": {
89
+ "name": "empty_constructor_needs_parens",
90
+ "level": "ignore"
91
+ },
92
+ "cyclomatic_complexity": {
93
+ "name": "cyclomatic_complexity",
94
+ "value": 6,
95
+ "level": "error"
96
+ },
97
+ "newlines_after_classes": {
98
+ "name": "newlines_after_classes",
99
+ "value": 2,
100
+ "level": "error"
101
+ },
102
+ "no_unnecessary_fat_arrows": {
103
+ "name": "no_unnecessary_fat_arrows",
104
+ "level": "warn"
105
+ },
106
+ "missing_fat_arrows": {
107
+ "name": "missing_fat_arrows",
108
+ "level": "ignore"
109
+ },
110
+ "non_empty_constructor_needs_parens": {
111
+ "name": "non_empty_constructor_needs_parens",
112
+ "level": "error"
113
+ }
114
+ }
@@ -0,0 +1,86 @@
1
+ {
2
+ // JSHint Default Configuration File (as on JSHint website)
3
+ // See http://jshint.com/docs/ for more details
4
+
5
+ "maxerr" : 50, // {int} Maximum error before stopping
6
+
7
+ // Enforcing
8
+ "bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.)
9
+ "camelcase" : true, // true: Identifiers must be in camelCase
10
+ "curly" : true, // true: Require {} for every new block or scope
11
+ "eqeqeq" : true, // true: Require triple equals (===) for comparison
12
+ "forin" : true, // true: Require filtering for..in loops with obj.hasOwnProperty()
13
+ "immed" : false, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());`
14
+ "indent" : 2, // {int} Number of spaces to use for indentation
15
+ "latedef" : true, // true: Require variables/functions to be defined before being used
16
+ "newcap" : true, // true: Require capitalization of all constructor functions e.g. `new F()`
17
+ "noarg" : true, // true: Prohibit use of `arguments.caller` and `arguments.callee`
18
+ "noempty" : true, // true: Prohibit use of empty blocks
19
+ "nonew" : false, // true: Prohibit use of constructors for side-effects (without assignment)
20
+ "plusplus" : false, // true: Prohibit use of `++` & `--`
21
+ "quotmark" : false, // Quotation mark consistency:
22
+ // false : do nothing (default)
23
+ // true : ensure whatever is used is consistent
24
+ // "single" : require single quotes
25
+ // "double" : require double quotes
26
+ "undef" : true, // true: Require all non-global variables to be declared (prevents global leaks)
27
+ "unused" : true, // true: Require all defined variables be used
28
+ "strict" : true, // true: Requires all functions run in ES5 Strict Mode
29
+ "trailing" : true, // true: Prohibit trailing whitespaces
30
+ "maxparams" : false, // {int} Max number of formal params allowed per function
31
+ "maxdepth" : 3, // {int} Max depth of nested blocks (within functions)
32
+ "maxstatements" : 20, // {int} Max number statements per function
33
+ "maxcomplexity" : 6, // {int} Max cyclomatic complexity per function
34
+ "maxlen" : 120, // {int} Max number of characters per line
35
+
36
+ // Relaxing
37
+ "asi" : false, // true: Tolerate Automatic Semicolon Insertion (no semicolons)
38
+ "boss" : false, // true: Tolerate assignments where comparisons would be expected
39
+ "debug" : false, // true: Allow debugger statements e.g. browser breakpoints.
40
+ "eqnull" : false, // true: Tolerate use of `== null`
41
+ "es5" : false, // true: Allow ES5 syntax (ex: getters and setters)
42
+ "esnext" : false, // true: Allow ES.next (ES6) syntax (ex: `const`)
43
+ "moz" : false, // true: Allow Mozilla specific syntax (extends and overrides esnext features)
44
+ // (ex: `for each`, multiple try/catch, function expression…)
45
+ "evil" : false, // true: Tolerate use of `eval` and `new Function()`
46
+ "expr" : false, // true: Tolerate `ExpressionStatement` as Programs
47
+ "funcscope" : false, // true: Tolerate defining variables inside control statements"
48
+ "globalstrict" : false, // true: Allow global "use strict" (also enables 'strict')
49
+ "iterator" : false, // true: Tolerate using the `__iterator__` property
50
+ "lastsemic" : false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block
51
+ "laxbreak" : false, // true: Tolerate possibly unsafe line breakings
52
+ "laxcomma" : false, // true: Tolerate comma-first style coding
53
+ "loopfunc" : false, // true: Tolerate functions being defined in loops
54
+ "multistr" : false, // true: Tolerate multi-line strings
55
+ "proto" : false, // true: Tolerate using the `__proto__` property
56
+ "scripturl" : false, // true: Tolerate script-targeted URLs
57
+ "smarttabs" : false, // true: Tolerate mixed tabs/spaces when used for alignment
58
+ "shadow" : false, // true: Allows re-define variables later in code e.g. `var x=1; x=2;`
59
+ "sub" : false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation
60
+ "supernew" : false, // true: Tolerate `new function () { ... };` and `new Object;`
61
+ "validthis" : false, // true: Tolerate using this in a non-constructor function
62
+
63
+ // Environments
64
+ "browser" : true, // Web Browser (window, document, etc)
65
+ "couch" : false, // CouchDB
66
+ "devel" : true, // Development/debugging (alert, confirm, etc)
67
+ "dojo" : false, // Dojo Toolkit
68
+ "jquery" : true, // jQuery
69
+ "mootools" : false, // MooTools
70
+ "node" : false, // Node.js
71
+ "nonstandard" : true, // Widely adopted globals (escape, unescape, etc)
72
+ "prototypejs" : false, // Prototype and Scriptaculous
73
+ "rhino" : false, // Rhino
74
+ "worker" : false, // Web Workers
75
+ "wsh" : false, // Windows Scripting Host
76
+ "yui" : false, // Yahoo User Interface
77
+
78
+ // Legacy
79
+ "nomen" : false, // true: Prohibit dangling `_` in variables
80
+ "onevar" : false, // true: Allow only one `var` statement per function
81
+ "passfail" : false, // true: Stop on first error
82
+ "white" : false, // true: Check against strict whitespace and indentation rules
83
+
84
+ // Custom Globals
85
+ "globals" : {} // additional predefined global variables
86
+ }
@@ -0,0 +1,315 @@
1
+ # This is the default configuration file. Enabling and disabling is configured
2
+ # in separate files. This file adds all other parameters apart from Enabled.
3
+
4
+ inherit_from:
5
+ # - enabled.yml
6
+ # - disabled.yml
7
+
8
+ # Common configuration.
9
+ AllCops:
10
+ # Include gemspec and Rakefile
11
+ Includes:
12
+ - '**/*.gemspec'
13
+ - '**/Rakefile'
14
+ - '**/*.rake'
15
+ - '**/Gemfile'
16
+ Excludes: []
17
+ # By default, the rails cops are not run. Override in project or home
18
+ # directory .rubocop.yml files, or by giving the -R/--rails option.
19
+ RunRailsCops: true
20
+
21
+ # Indent private/protected/public as deep as method definitions
22
+ AccessModifierIndentation:
23
+ EnforcedStyle: outdent
24
+ SupportedStyles:
25
+ - outdent
26
+ - indent
27
+
28
+ # Align the elements of a hash literal if they span more than one line.
29
+ AlignHash:
30
+ # Alignment of entries using hash rocket as separator. Valid values are:
31
+ #
32
+ # key - left alignment of keys
33
+ # 'a' => 2
34
+ # 'bb' => 3
35
+ # separator - alignment of hash rockets, keys are right aligned
36
+ # 'a' => 2
37
+ # 'bb' => 3
38
+ # table - left alignment of keys, hash rockets, and values
39
+ # 'a' => 2
40
+ # 'bb' => 3
41
+ EnforcedHashRocketStyle: key
42
+ # Alignment of entries using colon as separator. Valid values are:
43
+ #
44
+ # key - left alignment of keys
45
+ # a: 0
46
+ # bb: 1
47
+ # separator - alignment of colons, keys are right aligned
48
+ # a: 0
49
+ # bb: 1
50
+ # table - left alignment of keys and values
51
+ # a: 0
52
+ # bb: 1
53
+ EnforcedColonStyle: key
54
+
55
+ # Allow safe assignment in conditions.
56
+ AssignmentInCondition:
57
+ AllowSafeAssignment: true
58
+
59
+ BlockNesting:
60
+ Max: 3
61
+
62
+ BracesAroundHashParameters:
63
+ EnforcedStyle: no_braces
64
+ SupportedStyles:
65
+ - braces
66
+ - no_braces
67
+
68
+ # Indentation of `when`.
69
+ CaseIndentation:
70
+ IndentWhenRelativeTo: case
71
+ SupportedStyles:
72
+ - case
73
+ - end
74
+ IndentOneStep: false
75
+
76
+ ClassLength:
77
+ CountComments: false # count full line comments?
78
+ Max: 200
79
+
80
+ # Align with the style guide.
81
+ CollectionMethods:
82
+ PreferredMethods:
83
+ collect: 'map'
84
+ collect!: 'map!'
85
+ inject: 'reduce'
86
+ detect: 'find'
87
+ find_all: 'select'
88
+
89
+ # Checks formatting of special comments
90
+ CommentAnnotation:
91
+ Keywords:
92
+ - TODO
93
+ - FIXME
94
+ - OPTIMIZE
95
+ - HACK
96
+ - REVIEW
97
+
98
+ # Avoid complex methods.
99
+ CyclomaticComplexity:
100
+ Max: 6
101
+
102
+ Documentation:
103
+ Enabled: true
104
+
105
+ # Multi-line method chaining should be done with leading dots.
106
+ DotPosition:
107
+ Style: leading
108
+ SupportedStyles:
109
+ - leading
110
+ - trailing
111
+
112
+ # Use empty lines between defs.
113
+ EmptyLineBetweenDefs:
114
+ # If true, this parameter means that single line method definitions don't
115
+ # need an empty line between them.
116
+ AllowAdjacentOneLineDefs: false
117
+
118
+ Encoding:
119
+ Enabled: true
120
+
121
+ # Align ends correctly.
122
+ EndAlignment:
123
+ # The value `keyword` means that `end` should be aligned with the matching
124
+ # keyword (if, while, etc.).
125
+ # The value `variable` means that in assignments, `end` should be aligned
126
+ # with the start of the variable on the left hand side of `=`. In all other
127
+ # situations, `end` should still be aligned with the keyword.
128
+ AlignWith: variable
129
+ SupportedStyles:
130
+ - keyword
131
+ - variable
132
+
133
+ # Checks use of for or each in multiline loops.
134
+ For:
135
+ EnforcedStyle: each
136
+ SupportedStyles:
137
+ - for
138
+ - each
139
+
140
+ # Built-in global variables are allowed by default.
141
+ GlobalVars:
142
+ AllowedVariables: ['$1', '$2', '$3', '$4', '$5', '$6']
143
+
144
+ HashSyntax:
145
+ EnforcedStyle: ruby19
146
+ SupportedStyles:
147
+ - ruby19
148
+ - hash_rockets
149
+
150
+ LambdaCall:
151
+ EnforcedStyle: call
152
+ SupportedStyles:
153
+ - call
154
+ - braces
155
+
156
+ LineLength:
157
+ Max: 120
158
+
159
+ MethodDefParentheses:
160
+ EnforcedStyle: require_parentheses
161
+ SupportedStyles:
162
+ - require_parentheses
163
+ - require_no_parentheses
164
+
165
+ MethodLength:
166
+ CountComments: false # count full line comments?
167
+ Max: 20
168
+
169
+ MethodName:
170
+ EnforcedStyle: snake_case
171
+ SupportedStyles:
172
+ - snake_case
173
+ - camelCase
174
+
175
+ NumericLiterals:
176
+ MinDigits: 10
177
+
178
+ Output:
179
+ Ignore:
180
+ - '^.*\.rake$'
181
+ - '^.*/script/.*$'
182
+ - '^.*/tasks/.*$'
183
+ - 'Rakefile$'
184
+
185
+ ParameterLists:
186
+ Max: 5
187
+ CountKeywordArgs: true
188
+
189
+ # Allow safe assignment in conditions.
190
+ ParenthesesAroundCondition:
191
+ AllowSafeAssignment: true
192
+
193
+ PredicateName:
194
+ NamePrefixBlacklist:
195
+ - is_
196
+ - has_
197
+ - have_
198
+
199
+ RaiseArgs:
200
+ EnforcedStyle: exploded
201
+ SupportedStyles:
202
+ - compact # raise Exception.new(msg)
203
+ - exploded # raise Exception, msg
204
+
205
+
206
+ RedundantReturn:
207
+ # When true allows code like `return x, y`.
208
+ AllowMultipleReturnValues: false
209
+
210
+ RegexpLiteral:
211
+ MaxSlashes: 1
212
+
213
+ Semicolon:
214
+ # Allow ; to separate several expressions on the same line.
215
+ AllowAsExpressionSeparator: false
216
+
217
+ SignalException:
218
+ EnforcedStyle: only_raise
219
+ SupportedStyles:
220
+ - only_raise
221
+ - only_fail
222
+ - semantic
223
+
224
+
225
+ SingleLineBlockParams:
226
+ Methods:
227
+ - reduce:
228
+ - a
229
+ - e
230
+ - inject:
231
+ - a
232
+ - e
233
+
234
+ SingleLineMethods:
235
+ AllowIfMethodIsEmpty: true
236
+
237
+ StringLiterals:
238
+ EnforcedStyle: single_quotes
239
+ SupportedStyles:
240
+ - single_quotes
241
+ - double_quotes
242
+
243
+ SpaceAroundBlockBraces:
244
+ EnforcedStyle: no_space_inside_braces
245
+ SupportedStyles:
246
+ - space_inside_braces
247
+ - no_space_inside_braces
248
+ # Valid values are: space, no_space
249
+ EnforcedStyleForEmptyBraces: no_space
250
+ # Space between { and |. Overrides EnforcedStyle if there is a conflict.
251
+ SpaceBeforeBlockParameters: false
252
+
253
+ SpaceInsideHashLiteralBraces:
254
+ EnforcedStyle: no_space
255
+ EnforcedStyleForEmptyBraces: no_space
256
+ SupportedStyles:
257
+ - space
258
+ - no_space
259
+
260
+ TrailingComma:
261
+ EnforcedStyleForMultiline: no_comma
262
+ SupportedStyles:
263
+ - comma
264
+ - no_comma
265
+
266
+ # TrivialAccessors doesn't require exact name matches and doesn't allow
267
+ # predicated methods by default.
268
+ TrivialAccessors:
269
+ ExactNameMatch: false
270
+ AllowPredicates: false
271
+ Whitelist:
272
+ - to_ary
273
+ - to_a
274
+ - to_c
275
+ - to_enum
276
+ - to_h
277
+ - to_hash
278
+ - to_i
279
+ - to_int
280
+ - to_io
281
+ - to_open
282
+ - to_path
283
+ - to_proc
284
+ - to_r
285
+ - to_regexp
286
+ - to_str
287
+ - to_s
288
+ - to_sym
289
+
290
+ VariableName:
291
+ EnforcedStyle: snake_case
292
+ SupportedStyles:
293
+ - snake_case
294
+ - camelCase
295
+
296
+ WordArray:
297
+ MinSize: 0
298
+
299
+ ##################### Rails ##################################
300
+
301
+ DefaultScope:
302
+ IncludePaths:
303
+ - app/models
304
+
305
+ HasAndBelongsToMany:
306
+ IncludePaths:
307
+ - app/models
308
+
309
+ ReadAttribute:
310
+ IncludePaths:
311
+ - app/models
312
+
313
+ Validation:
314
+ IncludePaths:
315
+ - app/models
@@ -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,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gazelle_styleguide/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gazelle_styleguide"
8
+ spec.version = GazelleStyleguide::VERSION
9
+ spec.authors = ["Allen Madsen"]
10
+ spec.email = ["blatyo@gmail.com"]
11
+ spec.summary = %q{Gazelle's coding style guidelines and checks}
12
+ spec.description = %q{Gazelle's coding style guidelines and checks}
13
+ spec.homepage = "https://github.com/secondrotation/gazelle_styleguide"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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_runtime_dependency 'pre-commit'
22
+ spec.add_runtime_dependency 'rubocop'
23
+ spec.add_runtime_dependency 'execjs'
24
+ spec.add_runtime_dependency 'grit'
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.5"
27
+ spec.add_development_dependency "rake"
28
+ spec.add_development_dependency "rspec"
29
+ end
@@ -0,0 +1,56 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'grit'
3
+ require 'thor'
4
+
5
+ module GazelleStyleguide
6
+ # Command line tool for managing linter running and pre-commits
7
+ class CLI < Thor
8
+ CHECKS = 'env, jshint, rspec_focus, merge_conflict, rubocop, coffee_lint, json, yaml, scss_lint, checkstyle'
9
+
10
+ desc 'init', 'Sets up pre-commit hooks to check style.'
11
+ def init
12
+ install_pre_commit
13
+ setup_git_config
14
+ end
15
+
16
+ desc 'lint [flags|FILES]', 'Runs linters'
17
+ option :all, aliases: :a
18
+ option :changed, aliases: :c
19
+ def lint(*files)
20
+ files = lint_files(files, options)
21
+
22
+ PreCommit::Runner.new($stderr, files).run
23
+ end
24
+
25
+ private
26
+
27
+ def install_pre_commit
28
+ require 'pre-commit/installer'
29
+
30
+ PreCommit::Installer.new.install
31
+ end
32
+
33
+ def setup_git_config
34
+ repo.config['pre-commit.checks'] = CHECKS
35
+ repo.config['pre-commit.rubocop.config'] = GazelleStyleguide.config_for('rubocop.yml')
36
+ end
37
+
38
+ def lint_files(files, options)
39
+ if files.any?
40
+ files
41
+ elsif options[:all]
42
+ Dir['./**/*'].select {|f| File.file?(f)}
43
+ else
44
+ changed_files
45
+ end
46
+ end
47
+
48
+ def changed_files
49
+ repo.status.files.select {|file, status| status.type == 'M' || status.untracked}.keys
50
+ end
51
+
52
+ def repo
53
+ @repo ||= Grit::Repo.new('.')
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,6 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ # Styleguide version
4
+ module GazelleStyleguide
5
+ VERSION = '0.0.1'
6
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'pre-commit'
3
+ require 'rubocop'
4
+ require 'execjs'
5
+
6
+ require 'plugins/pre_commit/checks/checkstyle'
7
+ require 'plugins/pre_commit/checks/coffee_lint'
8
+ require 'plugins/pre_commit/checks/env'
9
+ require 'plugins/pre_commit/checks/json'
10
+ require 'plugins/pre_commit/checks/scss_lint'
11
+ require 'plugins/pre_commit/checks/yaml'
12
+
13
+ require 'gazelle_styleguide/version'
14
+ require 'gazelle_styleguide/cli'
15
+
16
+ # This module namespaces Gazelle's style guide. Manages configuration for various linters.
17
+ module GazelleStyleguide
18
+ class << self
19
+ def config_for(config_file)
20
+ File.expand_path("../../config/#{config_file}", __FILE__)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,36 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'open3'
3
+ require 'pre-commit/checks/plugin'
4
+
5
+ module PreCommit
6
+ module Checks
7
+ # Runs checkstyle against java files
8
+ class Checkstyle < Plugin
9
+ def call(staged_files)
10
+ staged_files = staged_files.grep(/\.java$/)
11
+ return if staged_files.empty?
12
+
13
+ args = (jar_flag + config_file_flag + checks_file_flag + staged_files).join(' ')
14
+ puts "java #{args}"
15
+ stdout, stderr, result = Open3.capture3("java #{args}")
16
+ stdout + stderr unless result.success?
17
+ end
18
+
19
+ def jar_flag
20
+ ['-jar', File.expand_path('../../../../gazelle_styleguide/support/checkstyle-5.7-all.jar', __FILE__)]
21
+ end
22
+
23
+ def config_file_flag
24
+ ENV['CHECKSTYLE_CONFIG'] ? ['-p', ENV['CHECKSTYLE_CONFIG']] : []
25
+ end
26
+
27
+ def checks_file_flag
28
+ ENV['CHECKSTYLE_CHECKS'] ? ['-c', ENV['CHECKSTYLE_CHECKS']] : []
29
+ end
30
+
31
+ def self.description
32
+ 'Runs coffeelint to detect errors'
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'open3'
3
+ require 'pre-commit/checks/plugin'
4
+
5
+ module PreCommit
6
+ module Checks
7
+ # Runs coffeelint against coffeescript files
8
+ class CoffeeLint < Plugin
9
+ def call(staged_files)
10
+ staged_files = staged_files.grep(/\.coffee$/)
11
+ return if staged_files.empty?
12
+
13
+ config_flag = ENV['COFFEELINT_CONFIG'] ? "-f #{ENV['COFFEELINT_CONFIG']}" : ''
14
+ args = staged_files.join(' ')
15
+
16
+ stdout, stderr, result = Open3.capture3("coffeelint #{config_flag} #{args}")
17
+ stdout + stderr unless result.success?
18
+ end
19
+
20
+ def self.description
21
+ 'Runs coffeelint to detect errors'
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'gazelle_styleguide'
3
+ require 'pre-commit/checks/plugin'
4
+
5
+ module PreCommit
6
+ module Checks
7
+ # Loads environment variables for configuration.
8
+ class Env < Plugin
9
+ def call(staged_files)
10
+ ENV['JSHINT_CONFIG'] = GazelleStyleguide.config_for('jshintrc.json')
11
+ ENV['COFFEELINT_CONFIG'] = GazelleStyleguide.config_for('coffeelint.json')
12
+ ENV['RUBOCOP_CONFIG'] = GazelleStyleguide.config_for('rubocop.yml')
13
+ ENV['CHECKSTYLE_CONFIG'] = GazelleStyleguide.config_for('checkstyle.properties')
14
+ ENV['CHECKSTYLE_CHECKS'] = GazelleStyleguide.config_for('sun_checks.xml')
15
+
16
+ nil
17
+ end
18
+
19
+ def self.description
20
+ 'Load environment variables for linter configuration.'
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,30 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'json'
3
+ require 'pre-commit/checks/plugin'
4
+
5
+ module PreCommit
6
+ module Checks
7
+ # Checks JSON to make sure it's parsable.
8
+ class Json < Plugin
9
+ def call(staged_files)
10
+ staged_files = staged_files.grep(/\.json$/)
11
+ return if staged_files.empty?
12
+
13
+ errors = staged_files.map {|file| load_file(file)}.compact
14
+
15
+ errors.join("\n") unless errors.empty?
16
+ end
17
+
18
+ def load_file(file)
19
+ File.open(file) {|io| JSON.load(io)}
20
+ nil
21
+ rescue StandardError => e
22
+ "#{e.message} parsing #{file}"
23
+ end
24
+
25
+ def self.description
26
+ 'Runs json to detect errors.'
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,33 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'open3'
3
+ require 'pre-commit/checks/plugin'
4
+
5
+ module PreCommit
6
+ module Checks
7
+ # Lints SCSS files with scss-lint
8
+ class ScssLint < Plugin
9
+ def call(staged_files)
10
+ staged_files = staged_files.grep(/\.coffee$/)
11
+ return if staged_files.empty?
12
+
13
+ args = staged_files.join(' ')
14
+ command = "scss-lint #{config_flag} #{args}"
15
+
16
+ stdout, stderr, result = Open3.capture3(command)
17
+ stdout + stderr unless result.success?
18
+ end
19
+
20
+ def config_flag
21
+ if ENV['SCSSLINT_CONFIG']
22
+ "-c #{ENV['SCSSLINT_CONFIG']}"
23
+ else
24
+ ''
25
+ end
26
+ end
27
+
28
+ def self.description
29
+ 'Runs scss-lint to detect errors'
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,30 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'yaml'
3
+ require 'pre-commit/checks/plugin'
4
+
5
+ module PreCommit
6
+ module Checks
7
+ # Checks YAML to make sure it's parsable.
8
+ class Yaml < Plugin
9
+ def call(staged_files)
10
+ staged_files = staged_files.grep(/\.(yml|yaml)$/)
11
+ return if staged_files.empty?
12
+
13
+ errors = staged_files.map {|file| load_file(file)}.compact
14
+
15
+ errors.join('\n') unless errors.empty?
16
+ end
17
+
18
+ def load_file(file)
19
+ YAML.load_file(file)
20
+ nil
21
+ rescue ArgumentError => e
22
+ "#{e.message} parsing #{file}"
23
+ end
24
+
25
+ def self.description
26
+ 'Runs yaml to detect errors.'
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,12 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe GazelleStyleguide do
5
+ it 'should have a version number' do
6
+ expect(GazelleStyleguide::VERSION).not_to be nil
7
+ end
8
+
9
+ it 'should do something useful' do
10
+ expect(false).to be true
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ # -*- encoding : utf-8 -*-
2
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3
+ require 'gazelle_styleguide'
metadata ADDED
@@ -0,0 +1,188 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gazelle_styleguide
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Allen Madsen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-03-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: pre-commit
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rubocop
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: execjs
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: grit
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: bundler
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: '1.5'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '1.5'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rake
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: rspec
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: Gazelle's coding style guidelines and checks
127
+ email:
128
+ - blatyo@gmail.com
129
+ executables:
130
+ - gazelle_styleguide
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - .gitignore
135
+ - .rspec
136
+ - .travis.yml
137
+ - Gemfile
138
+ - LICENSE.txt
139
+ - README.md
140
+ - Rakefile
141
+ - bin/gazelle_styleguide
142
+ - config/checkstyle.properties
143
+ - config/coffeelint.json
144
+ - config/jshintrc.json
145
+ - config/rubocop.yml
146
+ - config/sun_checks.xml
147
+ - gazelle_styleguide.gemspec
148
+ - lib/gazelle_styleguide.rb
149
+ - lib/gazelle_styleguide/cli.rb
150
+ - lib/gazelle_styleguide/support/checkstyle-5.7-all.jar
151
+ - lib/gazelle_styleguide/version.rb
152
+ - lib/plugins/pre_commit/checks/checkstyle.rb
153
+ - lib/plugins/pre_commit/checks/coffee_lint.rb
154
+ - lib/plugins/pre_commit/checks/env.rb
155
+ - lib/plugins/pre_commit/checks/json.rb
156
+ - lib/plugins/pre_commit/checks/scss_lint.rb
157
+ - lib/plugins/pre_commit/checks/yaml.rb
158
+ - spec/gazelle_styleguide_spec.rb
159
+ - spec/spec_helper.rb
160
+ homepage: https://github.com/secondrotation/gazelle_styleguide
161
+ licenses:
162
+ - MIT
163
+ post_install_message:
164
+ rdoc_options: []
165
+ require_paths:
166
+ - lib
167
+ required_ruby_version: !ruby/object:Gem::Requirement
168
+ none: false
169
+ requirements:
170
+ - - ! '>='
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ required_rubygems_version: !ruby/object:Gem::Requirement
174
+ none: false
175
+ requirements:
176
+ - - ! '>='
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
179
+ requirements: []
180
+ rubyforge_project:
181
+ rubygems_version: 1.8.23
182
+ signing_key:
183
+ specification_version: 3
184
+ summary: Gazelle's coding style guidelines and checks
185
+ test_files:
186
+ - spec/gazelle_styleguide_spec.rb
187
+ - spec/spec_helper.rb
188
+ has_rdoc: