gazelle_styleguide 0.0.1 → 0.0.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.
data/config/rubocop.yml CHANGED
@@ -1,21 +1,13 @@
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
1
  # Common configuration.
9
2
  AllCops:
10
3
  # Include gemspec and Rakefile
11
- Includes:
4
+ Include:
12
5
  - '**/*.gemspec'
13
6
  - '**/Rakefile'
14
7
  - '**/*.rake'
15
8
  - '**/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.
9
+ Exclude:
10
+ - 'vendor/**'
19
11
  RunRailsCops: true
20
12
 
21
13
  # Indent private/protected/public as deep as method definitions
@@ -25,6 +17,81 @@ AccessModifierIndentation:
25
17
  - outdent
26
18
  - indent
27
19
 
20
+ # Indentation of `when`.
21
+ CaseIndentation:
22
+ IndentWhenRelativeTo: end
23
+ SupportedStyles:
24
+ - case
25
+ - end
26
+ IndentOneStep: false
27
+
28
+ ClassLength:
29
+ CountComments: false # count full line comments?
30
+ Max: 200
31
+
32
+ # Align ends correctly.
33
+ EndAlignment:
34
+ # The value `keyword` means that `end` should be aligned with the matching
35
+ # keyword (if, while, etc.).
36
+ # The value `variable` means that in assignments, `end` should be aligned
37
+ # with the start of the variable on the left hand side of `=`. In all other
38
+ # situations, `end` should still be aligned with the keyword.
39
+ AlignWith: variable
40
+ SupportedStyles:
41
+ - keyword
42
+ - variable
43
+
44
+ # Built-in global variables are allowed by default.
45
+ GlobalVars:
46
+ AllowedVariables: ['$1', '$2', '$3', '$4', '$5', '$6']
47
+
48
+ LineLength:
49
+ Max: 120
50
+
51
+ MethodLength:
52
+ CountComments: false # count full line comments?
53
+ Max: 20
54
+
55
+ NumericLiterals:
56
+ MinDigits: 10
57
+
58
+ SignalException:
59
+ EnforcedStyle: only_raise
60
+ SupportedStyles:
61
+ - only_raise
62
+ - only_fail
63
+ - semantic
64
+
65
+ SpaceBeforeBlockBraces:
66
+ EnforcedStyle: no_space
67
+ SupportedStyles:
68
+ - space
69
+ - no_space
70
+
71
+ SpaceInsideBlockBraces:
72
+ EnforcedStyle: no_space
73
+ SupportedStyles:
74
+ - space
75
+ - no_space
76
+ # Valid values are: space, no_space
77
+ EnforcedStyleForEmptyBraces: no_space
78
+ # Space between { and |. Overrides EnforcedStyle if there is a conflict.
79
+ SpaceBeforeBlockParameters: false
80
+
81
+ SpaceInsideHashLiteralBraces:
82
+ EnforcedStyle: no_space
83
+ EnforcedStyleForEmptyBraces: no_space
84
+ SupportedStyles:
85
+ - space
86
+ - no_space
87
+
88
+ WordArray:
89
+ MinSize: 0
90
+
91
+ ##########################################################################
92
+ ####################### DEFAULTS FROM RUBOCOP ############################
93
+ ##########################################################################
94
+
28
95
  # Align the elements of a hash literal if they span more than one line.
29
96
  AlignHash:
30
97
  # Alignment of entries using hash rocket as separator. Valid values are:
@@ -51,6 +118,62 @@ AlignHash:
51
118
  # a: 0
52
119
  # bb: 1
53
120
  EnforcedColonStyle: key
121
+ # Select whether hashes that are the last argument in a method call should be
122
+ # inspected? Valid values are:
123
+ #
124
+ # always_inspect - Inspect both implicit and explicit hashes.
125
+ # Registers and offence for:
126
+ # function(a: 1,
127
+ # b: 2)
128
+ # Registers an offence for:
129
+ # function({a: 1,
130
+ # b: 2})
131
+ # always_ignore - Ignore both implicit and explicit hashes.
132
+ # Accepts:
133
+ # function(a: 1,
134
+ # b: 2)
135
+ # Accepts:
136
+ # function({a: 1,
137
+ # b: 2})
138
+ # ignore_implicit - Ingore only implicit hashes.
139
+ # Accepts:
140
+ # function(a: 1,
141
+ # b: 2)
142
+ # Registers an offence for:
143
+ # function({a: 1,
144
+ # b: 2})
145
+ # ignore_explicit - Ingore only explicit hashes.
146
+ # Accepts:
147
+ # function({a: 1,
148
+ # b: 2})
149
+ # Registers an offence for:
150
+ # function(a: 1,
151
+ # b: 2)
152
+ EnforcedLastArgumentHashStyle: always_inspect
153
+ SupportedLastArgumentHashStyles:
154
+ - always_inspect
155
+ - always_ignore
156
+ - ignore_implicit
157
+ - ignore_explicit
158
+
159
+ AlignParameters:
160
+ # Alignment of parameters in multi-line method calls.
161
+ #
162
+ # The `with_first_parameter` style aligns the following lines along the same column
163
+ # as the first parameter.
164
+ #
165
+ # method_call(a,
166
+ # b)
167
+ #
168
+ # The `with_fixed_indentation` style alignes the following lines with one
169
+ # level of indenation relative to the start of the line with the method call.
170
+ #
171
+ # method_call(a,
172
+ # b)
173
+ EnforcedStyle: with_first_parameter
174
+ SupportedStyles:
175
+ - with_first_parameter
176
+ - with_fixed_indentation
54
177
 
55
178
  # Allow safe assignment in conditions.
56
179
  AssignmentInCondition:
@@ -65,20 +188,35 @@ BracesAroundHashParameters:
65
188
  - braces
66
189
  - no_braces
67
190
 
68
- # Indentation of `when`.
69
- CaseIndentation:
70
- IndentWhenRelativeTo: case
191
+ ClassAndModuleChildren:
192
+ # Checks the style of children definitions at classes and modules.
193
+ #
194
+ # Basically there are two different styles:
195
+ #
196
+ # `nested` - have each child on a separat line
197
+ # class Foo
198
+ # class Bar
199
+ # end
200
+ # end
201
+ #
202
+ # `compact` - combine definitions as much as possible
203
+ # class Foo::Bar
204
+ # end
205
+ #
206
+ # The compact style is only forced, for classes / modules with one child.
207
+ EnforcedStyle: nested
71
208
  SupportedStyles:
72
- - case
73
- - end
74
- IndentOneStep: false
75
-
76
- ClassLength:
77
- CountComments: false # count full line comments?
78
- Max: 200
209
+ - nested
210
+ - compact
79
211
 
80
212
  # Align with the style guide.
81
213
  CollectionMethods:
214
+ # Mapping from undesired method to desired_method
215
+ # e.g. to use `detect` over `find`:
216
+ #
217
+ # CollectionMethods:
218
+ # PreferredMethods:
219
+ # find: detect
82
220
  PreferredMethods:
83
221
  collect: 'map'
84
222
  collect!: 'map!'
@@ -99,12 +237,9 @@ CommentAnnotation:
99
237
  CyclomaticComplexity:
100
238
  Max: 6
101
239
 
102
- Documentation:
103
- Enabled: true
104
-
105
240
  # Multi-line method chaining should be done with leading dots.
106
241
  DotPosition:
107
- Style: leading
242
+ EnforcedStyle: leading
108
243
  SupportedStyles:
109
244
  - leading
110
245
  - trailing
@@ -115,20 +250,11 @@ EmptyLineBetweenDefs:
115
250
  # need an empty line between them.
116
251
  AllowAdjacentOneLineDefs: false
117
252
 
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
253
+ FileName:
254
+ Exclude:
255
+ - Rakefile
256
+ - Gemfile
257
+ - Capfile
132
258
 
133
259
  # Checks use of for or each in multiline loops.
134
260
  For:
@@ -137,9 +263,13 @@ For:
137
263
  - for
138
264
  - each
139
265
 
140
- # Built-in global variables are allowed by default.
141
- GlobalVars:
142
- AllowedVariables: ['$1', '$2', '$3', '$4', '$5', '$6']
266
+ # Enforce the method used for string formatting.
267
+ FormatString:
268
+ EnforcedStyle: format
269
+ SupportedStyles:
270
+ - format
271
+ - sprintf
272
+ - percent
143
273
 
144
274
  HashSyntax:
145
275
  EnforcedStyle: ruby19
@@ -147,15 +277,29 @@ HashSyntax:
147
277
  - ruby19
148
278
  - hash_rockets
149
279
 
280
+ IfUnlessModifier:
281
+ MaxLineLength: 79
282
+
283
+ # Checks the indentation of the first key in a hash literal.
284
+ IndentHash:
285
+ # The value `special_inside_parentheses` means that hash literals with braces
286
+ # that have their opening brace on the same line as a surrounding opening
287
+ # round parenthesis, shall have their first key indented relative to the
288
+ # first position inside the parenthesis.
289
+ # The value `consistent` means that the indentation of the first key shall
290
+ # always be relative to the first position of the line where the opening
291
+ # brace is.
292
+ EnforcedStyle: special_inside_parentheses
293
+ SupportedStyles:
294
+ - special_inside_parentheses
295
+ - consistent
296
+
150
297
  LambdaCall:
151
298
  EnforcedStyle: call
152
299
  SupportedStyles:
153
300
  - call
154
301
  - braces
155
302
 
156
- LineLength:
157
- Max: 120
158
-
159
303
  MethodDefParentheses:
160
304
  EnforcedStyle: require_parentheses
161
305
  SupportedStyles:
@@ -164,7 +308,7 @@ MethodDefParentheses:
164
308
 
165
309
  MethodLength:
166
310
  CountComments: false # count full line comments?
167
- Max: 20
311
+ Max: 10
168
312
 
169
313
  MethodName:
170
314
  EnforcedStyle: snake_case
@@ -172,16 +316,6 @@ MethodName:
172
316
  - snake_case
173
317
  - camelCase
174
318
 
175
- NumericLiterals:
176
- MinDigits: 10
177
-
178
- Output:
179
- Ignore:
180
- - '^.*\.rake$'
181
- - '^.*/script/.*$'
182
- - '^.*/tasks/.*$'
183
- - 'Rakefile$'
184
-
185
319
  ParameterLists:
186
320
  Max: 5
187
321
  CountKeywordArgs: true
@@ -190,6 +324,18 @@ ParameterLists:
190
324
  ParenthesesAroundCondition:
191
325
  AllowSafeAssignment: true
192
326
 
327
+ PercentLiteralDelimiters:
328
+ PreferredDelimiters:
329
+ '%': ()
330
+ '%i': ()
331
+ '%q': ()
332
+ '%Q': ()
333
+ '%r': '{}'
334
+ '%s': ()
335
+ '%w': ()
336
+ '%W': ()
337
+ '%x': ()
338
+
193
339
  PredicateName:
194
340
  NamePrefixBlacklist:
195
341
  - is_
@@ -208,20 +354,14 @@ RedundantReturn:
208
354
  AllowMultipleReturnValues: false
209
355
 
210
356
  RegexpLiteral:
357
+ # The maximum number of (escaped) slashes that a slash-delimited regexp is
358
+ # allowed to have. If there are more slashes, a %r regexp shall be used.
211
359
  MaxSlashes: 1
212
360
 
213
361
  Semicolon:
214
362
  # Allow ; to separate several expressions on the same line.
215
363
  AllowAsExpressionSeparator: false
216
364
 
217
- SignalException:
218
- EnforcedStyle: only_raise
219
- SupportedStyles:
220
- - only_raise
221
- - only_fail
222
- - semantic
223
-
224
-
225
365
  SingleLineBlockParams:
226
366
  Methods:
227
367
  - reduce:
@@ -240,23 +380,18 @@ StringLiterals:
240
380
  - single_quotes
241
381
  - double_quotes
242
382
 
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
383
+ SpaceAroundEqualsInParameterDefault:
384
+ EnforcedStyle: space
256
385
  SupportedStyles:
257
386
  - space
258
387
  - no_space
259
388
 
389
+ TrailingBlankLines:
390
+ EnforcedStyle: final_newline
391
+ SupportedStyles:
392
+ - final_newline
393
+ - final_blank_line
394
+
260
395
  TrailingComma:
261
396
  EnforcedStyleForMultiline: no_comma
262
397
  SupportedStyles:
@@ -268,6 +403,15 @@ TrailingComma:
268
403
  TrivialAccessors:
269
404
  ExactNameMatch: false
270
405
  AllowPredicates: false
406
+ # Allows trivial writers that don't end in an equal sign. e.g.
407
+ #
408
+ # def on_exception(action)
409
+ # @on_exception=action
410
+ # end
411
+ # on_exception :restart
412
+ #
413
+ # Commonly used in DSLs
414
+ AllowDSLWriters: false
271
415
  Whitelist:
272
416
  - to_ary
273
417
  - to_a
@@ -293,23 +437,35 @@ VariableName:
293
437
  - snake_case
294
438
  - camelCase
295
439
 
296
- WordArray:
297
- MinSize: 0
440
+ WhileUntilModifier:
441
+ MaxLineLength: 79
298
442
 
299
443
  ##################### Rails ##################################
300
444
 
445
+ ActionFilter:
446
+ EnforcedStyle: action
447
+ SupportedStyles:
448
+ - action
449
+ - filter
450
+ Include:
451
+ - app/controllers/*.rb
452
+
301
453
  DefaultScope:
302
- IncludePaths:
303
- - app/models
454
+ Include:
455
+ - app/models/*.rb
304
456
 
305
457
  HasAndBelongsToMany:
306
- IncludePaths:
307
- - app/models
458
+ Include:
459
+ - app/models/*.rb
460
+
461
+ ReadWriteAttribute:
462
+ Include:
463
+ - app/models/*.rb
308
464
 
309
- ReadAttribute:
310
- IncludePaths:
311
- - app/models
465
+ ScopeArgs:
466
+ Include:
467
+ - app/models/*.rb
312
468
 
313
469
  Validation:
314
- IncludePaths:
315
- - app/models
470
+ Include:
471
+ - app/models/*.rb
File without changes
@@ -19,9 +19,11 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_runtime_dependency 'pre-commit'
22
+ spec.add_runtime_dependency 'pre-commit-checkstyle'
22
23
  spec.add_runtime_dependency 'rubocop'
23
24
  spec.add_runtime_dependency 'execjs'
24
25
  spec.add_runtime_dependency 'grit'
26
+ spec.add_runtime_dependency 'thor'
25
27
 
26
28
  spec.add_development_dependency "bundler", "~> 1.5"
27
29
  spec.add_development_dependency "rake"
@@ -1,28 +1,31 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  require 'grit'
3
3
  require 'thor'
4
+ require 'fileutils'
4
5
 
5
6
  module GazelleStyleguide
6
7
  # Command line tool for managing linter running and pre-commits
7
8
  class CLI < Thor
8
- CHECKS = 'env, jshint, rspec_focus, merge_conflict, rubocop, coffee_lint, json, yaml, scss_lint, checkstyle'
9
+ CHECKS = 'rubocop, jshint, rspec_focus, merge_conflict, coffeelint, json, yaml, scss_lint, checkstyle'
9
10
 
10
11
  desc 'init', 'Sets up pre-commit hooks to check style.'
11
12
  def init
12
- install_pre_commit
13
13
  setup_git_config
14
+ install_pre_commit
15
+ setup_houndci
14
16
  end
15
17
 
16
18
  desc 'lint [flags|FILES]', 'Runs linters'
17
19
  option :all, aliases: :a
18
20
  option :changed, aliases: :c
19
21
  def lint(*files)
22
+ require 'pre-commit'
20
23
  files = lint_files(files, options)
21
24
 
22
25
  PreCommit::Runner.new($stderr, files).run
23
26
  end
24
27
 
25
- private
28
+ private
26
29
 
27
30
  def install_pre_commit
28
31
  require 'pre-commit/installer'
@@ -32,21 +35,40 @@ module GazelleStyleguide
32
35
 
33
36
  def setup_git_config
34
37
  repo.config['pre-commit.checks'] = CHECKS
38
+ repo.config['pre-commit.jshint.config'] = GazelleStyleguide.config_for('jshintrc.json')
35
39
  repo.config['pre-commit.rubocop.config'] = GazelleStyleguide.config_for('rubocop.yml')
40
+ repo.config['pre-commit.coffeelint.config'] = GazelleStyleguide.config_for('coffeelint.json')
41
+ repo.config['pre-commit.checkstyle.config'] = GazelleStyleguide.config_for('sun_checks.xml')
42
+ end
43
+
44
+ def setup_houndci
45
+ return unless ruby?
46
+
47
+ FileUtils.cp(GazelleStyleguide.config_for('rubocop.yml'), project_root.join('.hound.yml'))
48
+ end
49
+
50
+ def project_root
51
+ @project_root ||= Pathname.new('.').ascend do |path|
52
+ return path if path.join('.git').exist?
53
+ end
54
+ end
55
+
56
+ def ruby?
57
+ project_root.join('Gemfile').exist?
36
58
  end
37
59
 
38
60
  def lint_files(files, options)
39
61
  if files.any?
40
62
  files
41
63
  elsif options[:all]
42
- Dir['./**/*'].select {|f| File.file?(f)}
64
+ Dir['./**/*'].select { |f| File.file?(f) }
43
65
  else
44
66
  changed_files
45
67
  end
46
68
  end
47
69
 
48
70
  def changed_files
49
- repo.status.files.select {|file, status| status.type == 'M' || status.untracked}.keys
71
+ repo.status.files.select { |file, status| status.type == 'M' || status.untracked }.keys
50
72
  end
51
73
 
52
74
  def repo
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Styleguide version
4
4
  module GazelleStyleguide
5
- VERSION = '0.0.1'
5
+ VERSION = '0.0.2'
6
6
  end
@@ -1,15 +1,7 @@
1
1
  # -*- encoding : utf-8 -*-
2
- require 'pre-commit'
3
2
  require 'rubocop'
4
3
  require 'execjs'
5
4
 
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
5
  require 'gazelle_styleguide/version'
14
6
  require 'gazelle_styleguide/cli'
15
7
 
@@ -6,7 +6,4 @@ describe GazelleStyleguide do
6
6
  expect(GazelleStyleguide::VERSION).not_to be nil
7
7
  end
8
8
 
9
- it 'should do something useful' do
10
- expect(false).to be true
11
- end
12
9
  end