rubocop-decko 0.1 → 0.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: 91fe3230eb2beec60d685171f8ed8c74038e4cad
4
- data.tar.gz: 304dc90817b0786fcb33874afc6eec54a459983d
3
+ metadata.gz: 2317e1d406d4d99fed71a1ccf1d846ce5fa6713d
4
+ data.tar.gz: 4d75085a5ce222c614b5bb9027f0fe94bb3cd0dc
5
5
  SHA512:
6
- metadata.gz: 735556d6247f244f691a68e57e8b08acd8a2dea0fde5697d5805464b01cbb80048b324cdaf58bea6b2164c2d4e8318ab9b855d126b76f0245b7e5b7c84247497
7
- data.tar.gz: 989342f968dad91e3351f7626adc30128d5e8909baf978b68e64c9d58a6a83b021f05a77436e73d0e8b56b0b7e2ebfc9b75067de10e1b95161b566cc019fb0d2
6
+ metadata.gz: f2b1133694ebea9df07acef4af6e8eae668a6851cf3e5501538d5b00a9c9eb2038b63fceeab69efc1a12c0b3c824c9fa1f54f877178d31c4bcc76e0c1831f466
7
+ data.tar.gz: 72c09f7badbbe7f50b8fbd665946507e3f4875fb45f93141a01976e7e9bd6e1bf3b1ad54c3ad21cd246b818187f11aac59a9887d0e3e7da4d7e431f8498c8060
data/README.md CHANGED
@@ -1,2 +1,80 @@
1
- # rubocop-decko
2
- Code style checking for Wagn/Decko files
1
+ # RuboCop Decko
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/rubocop-decko.svg)](http://badge.fury.io/rb/rubocop-decko)
4
+
5
+ Wagn-specific analysis for your Wagn deck, as an extension to
6
+ [RuboCop](https://github.com/bbatsov/rubocop). Heavily inspired by [`rubocop-rspec`](https://github.com/nevir/rubocop-rspec) and [`rubocop-cask`](https://github.com/nevir/rubocop-rspec).
7
+
8
+
9
+ ## Installation
10
+
11
+ Just install the `rubocop-decko` gem
12
+
13
+ ```bash
14
+ gem install rubocop-decko
15
+ ```
16
+
17
+ or if you use bundler put this in your `Gemfile`
18
+
19
+ ```
20
+ gem 'rubocop-decko'
21
+ ```
22
+
23
+
24
+ ## Usage
25
+
26
+ You need to tell RuboCop to load the Decko extension. There are three ways to do this:
27
+
28
+ ### RuboCop configuration file
29
+
30
+ Put this into your `.rubocop.yml`:
31
+
32
+ ```
33
+ require: rubocop-decko
34
+ ```
35
+
36
+ Now you can run `rubocop` and it will automatically load the RuboCop Decko cops together with the standard cops.
37
+
38
+ ### Command line
39
+
40
+ ```bash
41
+ rubocop --require rubocop-decko
42
+ ```
43
+
44
+ ### Rake task
45
+
46
+ ```ruby
47
+ RuboCop::RakeTask.new do |task|
48
+ task.requires << 'rubocop-decko'
49
+ end
50
+ ```
51
+
52
+
53
+ ## The Cops
54
+
55
+ All cops are located under [`lib/rubocop/cop/decko`](lib/rubocop/cop/decko), and contain examples/documentation.
56
+
57
+ In your `.rubocop.yml`, you may treat the Decko cops just like any other cop. For example:
58
+
59
+ ```yaml
60
+ Decko/ViewLength:
61
+ Description: Avoid views longer than 15 lines of code.
62
+ Enabled: true
63
+ CountComments: false
64
+ Max: 15
65
+ ```
66
+
67
+
68
+ ## Contributing
69
+
70
+ 1. Fork it
71
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
72
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
73
+ 4. Push to the branch (`git push origin my-new-feature`)
74
+ 5. Create new Pull Request
75
+
76
+ ## License
77
+
78
+ `rubocop-cask` is MIT licensed. [See the accompanying file](MIT-LICENSE.md) for
79
+ the full text.
80
+
@@ -1,14 +1,19 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require 'pathname'
4
+ require 'yaml'
5
+
3
6
  require 'rubocop'
4
7
 
8
+ require 'rubocop/decko'
5
9
  require 'rubocop/decko/version'
6
10
  require 'rubocop/decko/inject'
7
11
 
8
12
  RuboCop::Decko::Inject.defaults!
9
13
 
10
- require 'rubocop/cop/mixin/block_length'
14
+ require 'rubocop/cop/mixin/block_lines'
11
15
 
12
16
  # cops
13
17
  require 'rubocop/cop/decko/view_length'
14
18
  require 'rubocop/cop/decko/event_length'
19
+ require 'rubocop/cop/decko/block_length'
@@ -0,0 +1,18 @@
1
+
2
+ module RuboCop
3
+ module Cop
4
+ module Metrics
5
+ # monkeypatch rubocop's block length cop so that it ignores format
6
+ # blocks.
7
+ # It doesn't work if I use the same path ("cop/metrics/block_length")
8
+ # for this.
9
+ class BlockLength < Cop
10
+ include BlockLines
11
+
12
+ def on_block(node)
13
+ check_block_length node, except: [:format, :view, :event]
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -5,20 +5,18 @@ module RuboCop
5
5
  module Decko
6
6
  # Checks that the lines of a view block don't exceed the allowed maximum
7
7
  # @example
8
- # view :editor do |args|
8
+ # event :some_event, :store do
9
9
  # ...
10
10
  # end
11
11
  class EventLength < Cop
12
- include BlockLength
12
+ include BlockLines
13
13
 
14
14
  def on_block(node)
15
- method, args, body = *node
16
- _receiver, method_name, _args = *method
17
- return unless method_name == :event
18
- check_code_length(node, body)
15
+ check_block_length node, only: :event
19
16
  end
20
17
 
21
18
  private
19
+
22
20
  def message(length, max_length)
23
21
  format('Event has too many lines. [%d/%d]', length, max_length)
24
22
  end
@@ -9,13 +9,10 @@ module RuboCop
9
9
  # ...
10
10
  # end
11
11
  class ViewLength < Cop
12
- include BlockLength
12
+ include BlockLines
13
13
 
14
14
  def on_block(node)
15
- method, args, body = *node
16
- _receiver, method_name, _args = *method
17
- return unless method_name == :view
18
- check_code_length(node, body)
15
+ check_block_length node, only: :view
19
16
  end
20
17
 
21
18
  private
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module BlockLines
6
+ # Common functionality for checking length of a block.
7
+
8
+ include TooManyLines
9
+
10
+ def check_block_length(node, opts={})
11
+ method, args, body = *node
12
+ require 'pry'
13
+ _receiver, method_name, _args = *method
14
+ return if opts[:only] && !Array(opts[:only]).include?(method_name)
15
+ return if opts[:except] && Array(opts[:except]).include?(method_name)
16
+ check_code_length node
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,10 @@
1
+ module RuboCop
2
+ # RuboCop Decko project namespace
3
+ module Decko
4
+ PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
5
+ CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
6
+ CONFIG = YAML.load(CONFIG_DEFAULT.read).freeze
7
+
8
+ private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
9
+ end
10
+ end
@@ -7,17 +7,29 @@ module RuboCop
7
7
  # Because RuboCop doesn't yet support plugins, we have to monkey patch in a
8
8
  # bit of our configuration.
9
9
  module Inject
10
- DEFAULT_FILE = File.expand_path(
11
- '../../../../config/default.yml', __FILE__
12
- )
13
-
14
10
  def self.defaults!
15
- hash = YAML.load_file(DEFAULT_FILE)
16
- puts "configuration from #{DEFAULT_FILE}" if ConfigLoader.debug?
17
- config = ConfigLoader.merge_with_default(hash, DEFAULT_FILE)
18
-
11
+ path = CONFIG_DEFAULT.to_s
12
+ hash = ConfigLoader.send(:load_yaml_configuration, path)
13
+ config = Config.new(hash, path)
14
+ puts "configuration from #{path}" if ConfigLoader.debug?
15
+ config = ConfigLoader.merge_with_default(config, path)
19
16
  ConfigLoader.instance_variable_set(:@default_configuration, config)
20
17
  end
21
18
  end
19
+
20
+ # module Inject
21
+ #
22
+ # DEFAULT_FILE = File.expand_path(
23
+ # '../../../../config/default.yml', __FILE__
24
+ # )
25
+ #
26
+ # def self.defaults!
27
+ # hash = YAML.load_file(DEFAULT_FILE)
28
+ # puts "configuration from #{DEFAULT_FILE}" if ConfigLoader.debug?
29
+ # config = ConfigLoader.merge_with_default(hash, DEFAULT_FILE)
30
+ #
31
+ # ConfigLoader.instance_variable_set(:@default_configuration, config)
32
+ # end
33
+ # end
22
34
  end
23
35
  end
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Decko
5
5
  # Version information for the Decko RuboCop plugin.
6
6
  module Version
7
- STRING = '0.1'
7
+ STRING = '0.2'
8
8
  end
9
9
  end
10
10
  end
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.test_files = spec.files.grep(%r{^spec/})
30
30
  spec.extra_rdoc_files = ['README.md']
31
31
 
32
- spec.add_development_dependency('rubocop', '~> 0.31')
32
+ spec.add_development_dependency('rubocop', '~> 0.45')
33
33
  # spec.add_development_dependency('rake', '~> 10.1')
34
34
  # spec.add_development_dependency('rspec', '~> 3.0')
35
35
  # spec.add_development_dependency('simplecov', '~> 0.8')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-decko
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philipp Kuehl
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.31'
19
+ version: '0.45'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.31'
26
+ version: '0.45'
27
27
  description: |2
28
28
  Code style checking for Wagn/Decko files.
29
29
  A plugin for the RuboCop code style enforcing & linting tool.
@@ -38,9 +38,11 @@ files:
38
38
  - Rakefile
39
39
  - config/default.yml
40
40
  - lib/rubocop-decko.rb
41
+ - lib/rubocop/cop/decko/block_length.rb
41
42
  - lib/rubocop/cop/decko/event_length.rb
42
43
  - lib/rubocop/cop/decko/view_length.rb
43
- - lib/rubocop/cop/mixin/block_length.rb
44
+ - lib/rubocop/cop/mixin/block_lines.rb
45
+ - lib/rubocop/decko.rb
44
46
  - lib/rubocop/decko/inject.rb
45
47
  - lib/rubocop/decko/version.rb
46
48
  - rubocop-decko.gemspec
@@ -1,27 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module RuboCop
4
- module Cop
5
- module BlockLength
6
- # Common functionality for checking length of a block.
7
- include CodeLength
8
-
9
- def check_code_length(node, body)
10
- length = code_length(body.loc.expression)
11
- return unless length > max_length
12
-
13
- add_offense(node, :expression, message(length, max_length)) do
14
- self.max = length
15
- end
16
- end
17
-
18
- private
19
-
20
- def code_length(node)
21
- lines = node.source.lines.to_a[1..-2] || []
22
-
23
- lines.count { |line| !irrelevant_line(line) }
24
- end
25
- end
26
- end
27
- end