rubocop-itamae 0.1.0.alpha1 → 0.1.0.alpha2

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
  SHA256:
3
- metadata.gz: 43b0711e43b2fe39e6b0b5115686d402e602801b3df7be1cdf397d4007ba4ad8
4
- data.tar.gz: de4843a38e16ab19b2f4867d866a0a97ac1e23ace11742cada1d55b287bf7e4b
3
+ metadata.gz: 8a6dcc9ca91e8578aacc2f1392c3c6980248910bf23ef70344444f08bf0c8845
4
+ data.tar.gz: 74b0f1f90551217e6e3f28f85cf903e90d2beedb9472a91a7b5fc3c11890ebf9
5
5
  SHA512:
6
- metadata.gz: a684ebe47004196a3e0e203478207171f20deb418e7d0ca3afdbd503c77fa3a0bccd8bcb265cff9109efb4dc2d944aae2e30cd9d92f83e2b8c348b18092595eb
7
- data.tar.gz: fe327d5b6f73761648e04f54510aef76332887f3eda1470880e473f614e49af26483f857244cf37834952433b3f891ad9e2c3224eae08c73a69d780a6f070c04
6
+ metadata.gz: 741d394a7a7c555c7098ee4e99438cfcf742b1ecc61d20098c823b0ac888bba8f71d3f88d4a978274d885125fee3f985f29fa57f793ebbcab532b3b2bcfd789e
7
+ data.tar.gz: 0e362de43e270348505adf76d17e42cac8b22e6022f1a5299e5f96880064ab317362ab00d4bee54346d47e1ce19f11f7e96a5c4ffb0a80c4112486adccf9406b
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ repo_token: vkR421tHTHWp8ptygFoT5Uc3mV1qR3Rxb
data/.rubocop.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  AllCops:
2
- # rubocop requires ruby 2.1+ since v0.51.0
3
- # https://github.com/rubocop-hq/rubocop/commit/753227914c1ad311e6116311fc1ef76d9b0904dc
4
- TargetRubyVersion: 2.1
2
+ # rubocop requires ruby 2.2+
3
+ # https://github.com/rubocop-hq/rubocop/pull/5990
4
+ TargetRubyVersion: 2.2
5
5
 
6
6
  Metrics/BlockLength:
7
7
  Exclude:
data/.travis.yml CHANGED
@@ -1,5 +1,30 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.5.1
5
- before_install: gem install bundler -v 1.16.1
4
+ - 2.2
5
+ - 2.3
6
+ - 2.4
7
+ - 2.5
8
+ - ruby-head
9
+ bundler_args: "--jobs=4"
10
+ cache: bundler
11
+ before_install:
12
+ - gem update --system --no-document
13
+ - gem install bundler --no-document
14
+ before_script:
15
+ - export CODECLIMATE_REPO_TOKEN=7e9993b9f657bb33552e76a7b9c8292541cf9a5d8d6811f585f6cfbc0785c820
16
+ before_script:
17
+ script:
18
+ - bundle exec rspec
19
+ - bundle exec codeclimate-test-reporter
20
+ - bundle exec rubocop
21
+ branches:
22
+ only:
23
+ - master
24
+ notifications:
25
+ email: false
26
+ slack:
27
+ secure: eKV6s6mQEb3T9qeatHvUMvAQPVOn+hjvdPl+v+1RYQaC/kgTMpLkCwRPokrDYiK51/HgMSH1cPGVl6QfoqaJvdHKdZtuAmikVeqhygablFPdLYuseMTHTr9zT9MOoEzSbyzO9tUTL3jIHeLIrXdBhVJ/YCw/9uWIlA10iFDE0KZ8WiPIIAJ34GORnzIqIASHY5zGKhiIqer1xeNecXXhTBcnUYzOhN7qBYCRl0yYL11NIy7xh50DLcKSYYAIUr6oBYOI6QeSe/0cZGOGst0JfHE5jQvT/3O6wMK2lGnrXovXuL4JIbFT6bODo9XyzSSkyy/P1wqPe8hpY7Thh4qyt1r+tRdO8oBdkxdzQTopRgemyc3wOa/5mE7keEXJh8V1TPCi4yfa/rfXxLSXmXYGXa3q8TBwDkxmWFd1Ej2KV3e3c1AVVqp7cqflq12HH6v2XHPXHyX6zZszOKpDjELCc2SZ49jx+D1tg15YHJ+Q8FIyUVAvyjD1bW7z+v8fsXqViyhwrue11jVsdpfSy0ZaXwtiSC7RyUwX7u/TdnHbMKRaGNQ9GHyqfirT+f7tcnHxGqBIpR5oqnnFnNEfVTxm+k1YmX4VY5q2kVn0jT8GDyRygUHAhFMOxGg2g85/sFxSx1bJD9pRUDTX3cHgxMhmEj7z0aI7gfEZW+NrqJO5AX8=
28
+ matrix:
29
+ allow_failures:
30
+ - rvm: ruby-head
data/.yardopts ADDED
@@ -0,0 +1,2 @@
1
+ --markup markdown
2
+ --no-private
data/README.md CHANGED
@@ -1,8 +1,11 @@
1
1
  # RuboCop::Itamae
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rubocop/itamae`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Code style checking for [itamae](https://github.com/itamae-kitchen/itamae) recipes
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ [![Gem Version](https://badge.fury.io/rb/rubocop-itamae.svg)](https://badge.fury.io/rb/rubocop-itamae)
6
+ [![Build Status](https://travis-ci.org/sue445/rubocop-itamae.svg?branch=master)](https://travis-ci.org/sue445/rubocop-itamae)
7
+ [![Coverage Status](https://coveralls.io/repos/github/sue445/rubocop-itamae/badge.svg?branch=master)](https://coveralls.io/github/sue445/rubocop-itamae?branch=master)
8
+ [![Maintainability](https://api.codeclimate.com/v1/badges/bf2f4b2cbf9c2cfc0e92/maintainability)](https://codeclimate.com/github/sue445/rubocop-itamae/maintainability)
6
9
 
7
10
  ## Installation
8
11
 
@@ -21,8 +24,13 @@ Or install it yourself as:
21
24
  $ gem install rubocop-itamae
22
25
 
23
26
  ## Usage
27
+ Add this line to your application's `.rubocop.yml`
24
28
 
25
- TODO: Write usage instructions here
29
+ ```yml
30
+ inherit_gem:
31
+ rubocop-itamae:
32
+ - config/default.yml
33
+ ```
26
34
 
27
35
  ## Development
28
36
 
@@ -32,7 +40,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
40
 
33
41
  ## Contributing
34
42
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rubocop-itamae.
43
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sue445/rubocop-itamae.
36
44
 
37
45
  ## License
38
46
 
data/config/default.yml CHANGED
@@ -7,3 +7,13 @@ Itamae/CommandEqualsToName:
7
7
  Description: Check that `command` doesn't equals to name of `execute`.
8
8
  Enabled: true
9
9
  StyleGuide: http://www.rubydoc.info/gems/rubocop-itamae/RuboCop/Cop/Itamae/CommandEqualsToName
10
+
11
+ Itamae/NeedlessDefaultAction:
12
+ Description: Checks whether default action is written for resource.
13
+ Enabled: true
14
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-itamae/RuboCop/Cop/Itamae/NeedlessDefaultAction
15
+
16
+ Itamae/RecipePath:
17
+ Description: Checks whether the recipe is placed under `cookbooks` dir or `roles` dir.
18
+ Enabled: true
19
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-itamae/RuboCop/Cop/Itamae/RecipePath
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Itamae
6
+ # Checks whether default action is written for resource.
7
+ #
8
+ # @example
9
+ # # bad
10
+ # package 'git' do
11
+ # action :install
12
+ # end
13
+ #
14
+ # # good
15
+ # package 'git' do
16
+ # end
17
+ #
18
+ # package 'git'
19
+ #
20
+ class NeedlessDefaultAction < Cop
21
+ include RangeHelp
22
+
23
+ MSG = 'Prefer to omit the default action.'.freeze
24
+
25
+ RESOURCE_DEFAULT_ACTIONS = {
26
+ directory: :create,
27
+ execute: :run,
28
+ file: :create,
29
+ gem_package: :install,
30
+ git: :sync,
31
+ group: :create,
32
+ http_request: :create,
33
+ link: :create,
34
+ local_ruby_block: :run,
35
+ package: :install,
36
+ remote_directory: :create,
37
+ remote_file: :create,
38
+ service: :nothing,
39
+ template: :create,
40
+ user: :create
41
+ }.freeze
42
+
43
+ def_node_search :find_resource, <<-PATTERN
44
+ (block
45
+ (send nil? ${:directory :execute :file :gem_package :git :group :http_request :link :local_ruby_block :package :remote_directory :remote_file :service :template :user}
46
+ (...)
47
+ )
48
+ args
49
+ $...
50
+ )
51
+ PATTERN
52
+
53
+ def_node_search :find_action, <<-PATTERN
54
+ (send nil? :action
55
+ (sym $_)
56
+ )
57
+ PATTERN
58
+
59
+ def on_block(node)
60
+ find_resource(node) do |resource, param_nodes|
61
+ param_nodes.compact.each do |param_node|
62
+ find_action(param_node) do |action|
63
+ next unless action == RESOURCE_DEFAULT_ACTIONS[resource]
64
+
65
+ add_offense(param_node, location: :expression)
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ def autocorrect(node)
72
+ lambda do |corrector|
73
+ remove_action_param(corrector, node.parent, node) if node.send_type?
74
+ end
75
+ end
76
+
77
+ private
78
+
79
+ def remove_action_param(corrector, parent_node, param_node)
80
+ find_resource(parent_node) do |resource|
81
+ find_action(param_node) do |action|
82
+ next unless action == RESOURCE_DEFAULT_ACTIONS[resource]
83
+
84
+ corrector.remove(node_range(param_node))
85
+ end
86
+ end
87
+ end
88
+
89
+ def node_range(node)
90
+ range_by_whole_lines(node.source_range, include_final_newline: true)
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Itamae
6
+ # Checks whether the recipe is placed under `cookbooks` dir
7
+ # or `roles` dir.
8
+ #
9
+ # @example
10
+ # # bad
11
+ # default.rb
12
+ # hoge/web.rb
13
+ #
14
+ # # good
15
+ # cookbooks/nginx/default.rb
16
+ # roles/web.rb
17
+ #
18
+ class RecipePath < Cop
19
+ include RangeHelp
20
+
21
+ MSG = 'Prefer recipe to placed under `cookbooks` dir' \
22
+ ' or `roles` dir.'.freeze
23
+
24
+ def investigate(processed_source)
25
+ file_path = processed_source.file_path
26
+ return if config.file_to_include?(file_path)
27
+
28
+ for_bad_filename(file_path) do |range, msg|
29
+ add_offense(nil, location: range, message: msg)
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def for_bad_filename(file_path)
36
+ return unless File.extname(file_path) == '.rb'
37
+ return if file_path =~ %r{/(cookbooks|roles)/}
38
+
39
+ yield source_range(processed_source.buffer, 1, 0), MSG
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -2,3 +2,5 @@
2
2
 
3
3
  require_relative 'itamae/cd_in_execute'
4
4
  require_relative 'itamae/command_equals_to_name'
5
+ require_relative 'itamae/needless_default_action'
6
+ require_relative 'itamae/recipe_path'
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Itamae
5
- VERSION = '0.1.0.alpha1'.freeze
5
+ VERSION = '0.1.0.alpha2'.freeze
6
6
  end
7
7
  end
@@ -25,7 +25,11 @@ Gem::Specification.new do |spec|
25
25
  spec.add_dependency 'rubocop'
26
26
 
27
27
  spec.add_development_dependency 'bundler', '~> 1.16'
28
+ spec.add_development_dependency 'codeclimate-test-reporter', '~> 1.0.0'
29
+ spec.add_development_dependency 'coveralls'
28
30
  spec.add_development_dependency 'pry-byebug'
29
31
  spec.add_development_dependency 'rake', '>= 11.0'
30
32
  spec.add_development_dependency 'rspec', '~> 3.0'
33
+ spec.add_development_dependency 'simplecov'
34
+ spec.add_development_dependency 'yard'
31
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-itamae
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.alpha1
4
+ version: 0.1.0.alpha2
5
5
  platform: ruby
6
6
  authors:
7
7
  - sue445
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-19 00:00:00.000000000 Z
11
+ date: 2018-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: codeclimate-test-reporter
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.0.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: coveralls
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'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: pry-byebug
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +108,34 @@ dependencies:
80
108
  - - "~>"
81
109
  - !ruby/object:Gem::Version
82
110
  version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
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
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: yard
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
83
139
  description: Code style checking for itamae recipes
84
140
  email:
85
141
  - sue445@sue445.net
@@ -87,10 +143,12 @@ executables: []
87
143
  extensions: []
88
144
  extra_rdoc_files: []
89
145
  files:
146
+ - ".coveralls.yml"
90
147
  - ".gitignore"
91
148
  - ".rspec"
92
149
  - ".rubocop.yml"
93
150
  - ".travis.yml"
151
+ - ".yardopts"
94
152
  - CHANGELOG.md
95
153
  - Gemfile
96
154
  - LICENSE.txt
@@ -102,6 +160,8 @@ files:
102
160
  - lib/rubocop-itamae.rb
103
161
  - lib/rubocop/cop/itamae/cd_in_execute.rb
104
162
  - lib/rubocop/cop/itamae/command_equals_to_name.rb
163
+ - lib/rubocop/cop/itamae/needless_default_action.rb
164
+ - lib/rubocop/cop/itamae/recipe_path.rb
105
165
  - lib/rubocop/cop/itamae_cops.rb
106
166
  - lib/rubocop/itamae.rb
107
167
  - lib/rubocop/itamae/version.rb