rubocop-gemfile 0.1.0.beta1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ed344acd76ba9e93b93397e7e4f9871e97dd32ba
4
+ data.tar.gz: df19136e1b5e6af09269089f6ab71648f9f69bf0
5
+ SHA512:
6
+ metadata.gz: e70539e5cb5bc38f46ef40014de5592623dbba972e837dc80a70de4308344ae00488d57e2d818cc3aa7f6f9b15c8967cdeca4fa4008f5635f95b9fd9746bc545
7
+ data.tar.gz: 9c77b8c820ad81e3d13a268192686a0d9ff1ac28b5a2410fc3c84475e778015d5dcd2bdb594d469b2fb63147b1b363a0543f67e4968d6881d8aff5eaf98b2a21
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format progress
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rubocop-gemfile.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 sue445
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # RuboCop::Gemfile
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/gemfile`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rubocop-gemfile'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rubocop-gemfile
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rubocop-gemfile.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -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,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rubocop/gemfile"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,17 @@
1
+ AllCops:
2
+ Gemfile:
3
+ Patterns:
4
+ - "Gemfile"
5
+
6
+ Gemfile/SingleGroup:
7
+ Description: "Check that `group` method has single group name"
8
+ Enabled: true
9
+
10
+ Gemfile/GroupType:
11
+ Description: "Use enforced type group"
12
+ EnforcedStyle: symbol
13
+ SupportedStyles:
14
+ - symbol
15
+ - double_quotes
16
+ - single_quotes
17
+ Enabled: true
@@ -0,0 +1 @@
1
+ require "rubocop/gemfile"
@@ -0,0 +1,142 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Gemfile
6
+ # This cop makes sure that `group` has symbol group name
7
+ #
8
+ # @example
9
+ #
10
+ # EnforcedStyle: symbol
11
+ #
12
+ # # bad
13
+ # group "test" do
14
+ # gem "rspec-rails"
15
+ # end
16
+ #
17
+ # group 'test' do
18
+ # gem "rspec-rails"
19
+ # end
20
+ #
21
+ # # good
22
+ # group :test do
23
+ # gem "rspec-rails"
24
+ # end
25
+ #
26
+ # EnforcedStyle: single_quotes
27
+ #
28
+ # # bad
29
+ # group :test do
30
+ # gem "rspec-rails"
31
+ # end
32
+ #
33
+ # group "test" do
34
+ # gem "rspec-rails"
35
+ # end
36
+ #
37
+ # # good
38
+ # group 'test' do
39
+ # gem "rspec-rails"
40
+ # end
41
+ #
42
+ # EnforcedStyle: double_quotes
43
+ #
44
+ # # bad
45
+ # group :test do
46
+ # gem "rspec-rails"
47
+ # end
48
+ #
49
+ # group 'test' do
50
+ # gem "rspec-rails"
51
+ # end
52
+ #
53
+ # # good
54
+ # group "test" do
55
+ # gem "rspec-rails"
56
+ # end
57
+ class GroupType < Cop
58
+ MSG = 'Use %s group'.freeze
59
+
60
+ def on_send(node)
61
+ _, method_name, *args = *node
62
+
63
+ return unless method_name == :group
64
+
65
+ enforced_style = cop_config["EnforcedStyle"]
66
+ unless cop_config["SupportedStyles"].include?(enforced_style)
67
+ raise ValidationError, "EnforcedStyle(#{enforced_style}) is not neither double_quotes, single_quotes or symbol"
68
+ end
69
+
70
+ message = MSG % enforced_style
71
+
72
+ args.each do |arg|
73
+ case enforced_style
74
+ when "symbol"
75
+ add_offense(node, arg.loc.expression, message) if arg.str_type?
76
+ when "double_quotes"
77
+ add_offense(node, arg.loc.expression, message) if arg.sym_type? || single_quotes?(arg)
78
+ when "single_quotes"
79
+ add_offense(node, arg.loc.expression, message) if arg.sym_type? || double_quotes?(arg)
80
+ end
81
+ end
82
+ end
83
+
84
+ def autocorrect(node)
85
+ _receiver, _method_name, *args = *node
86
+
87
+ case cop_config["EnforcedStyle"]
88
+ when "symbol"
89
+ lambda do |corrector|
90
+ args.each do |arg|
91
+ content = arg_content(arg)
92
+ corrector.replace(arg_location(arg), to_symbol_literal(content)) if content
93
+ end
94
+ end
95
+ when "double_quotes"
96
+ lambda do |corrector|
97
+ args.each do |arg|
98
+ content = arg_content(arg)
99
+ corrector.replace(arg_location(arg), content.inspect) if content
100
+ end
101
+ end
102
+ when "single_quotes"
103
+ lambda do |corrector|
104
+ args.each do |arg|
105
+ content = arg_content(arg)
106
+ corrector.replace(arg_location(arg), to_string_literal(content)) if content
107
+ end
108
+ end
109
+ end
110
+ end
111
+
112
+ private
113
+
114
+ def single_quotes?(arg)
115
+ quotes?(arg, "'")
116
+ end
117
+
118
+ def double_quotes?(arg)
119
+ quotes?(arg, '"')
120
+ end
121
+
122
+ def quotes?(arg, quote)
123
+ arg.str_type? && arg.loc.expression.source_buffer.source[arg.loc.begin.begin_pos] == quote
124
+ end
125
+
126
+ def arg_location(arg)
127
+ begin_pos = arg.loc.begin.begin_pos
128
+ end_pos = arg.loc.expression.end_pos
129
+ Parser::Source::Range.new(arg.loc.expression.source_buffer, begin_pos, end_pos)
130
+ end
131
+
132
+ def arg_content(arg)
133
+ if arg.sym_type?
134
+ arg.to_a.first.to_s
135
+ elsif arg.str_type?
136
+ arg.str_content
137
+ end
138
+ end
139
+ end
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Gemfile
6
+ # This cop makes sure that `group` method has single group name
7
+ #
8
+ # @example
9
+ # # bad
10
+ # group :test, :development do
11
+ # gem "rspec-rails"
12
+ # end
13
+ #
14
+ # # good
15
+ # group :test do
16
+ # gem "rspec-rails", group: :development
17
+ # end
18
+ class SingleGroup < Cop
19
+ MSG = '`group` should not have multiple groups'.freeze
20
+
21
+ def on_send(node)
22
+ _, method_name, *args = *node
23
+
24
+ return unless method_name == :group
25
+
26
+ add_offense(node, arg_location(args)) if args.length >= 2
27
+ end
28
+
29
+ private
30
+
31
+ def arg_location(args)
32
+ begin_pos = args.first.loc.begin.begin_pos
33
+ end_pos = args.last.loc.expression.end_pos
34
+ Parser::Source::Range.new(args.first.loc.expression.source_buffer, begin_pos, end_pos)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,9 @@
1
+ require "rubocop"
2
+ require "rubocop/gemfile/version"
3
+ require "rubocop/gemfile/inject"
4
+
5
+ RuboCop::Gemfile::Inject.defaults!
6
+
7
+ # cops
8
+ require "rubocop/cop/gemfile/single_group"
9
+ require "rubocop/cop/gemfile/group_type"
@@ -0,0 +1,20 @@
1
+ module RuboCop
2
+ module Gemfile
3
+ # Because RuboCop doesn't yet support plugins, we have to monkey patch in a
4
+ # bit of our configuration.
5
+ module Inject
6
+ DEFAULT_FILE = File.expand_path(
7
+ '../../../../config/default.yml', __FILE__
8
+ )
9
+
10
+ def self.defaults!
11
+ path = File.absolute_path(DEFAULT_FILE)
12
+ hash = ConfigLoader.send(:load_yaml_configuration, path)
13
+ config = Config.new(hash, path)
14
+ puts "configuration from #{DEFAULT_FILE}" if ConfigLoader.debug?
15
+ config = ConfigLoader.merge_with_default(config, path)
16
+ ConfigLoader.instance_variable_set(:@default_configuration, config)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ module RuboCop
2
+ module Gemfile
3
+ VERSION = "0.1.0.beta1"
4
+ end
5
+ end
@@ -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 'rubocop/gemfile/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rubocop-gemfile"
8
+ spec.version = RuboCop::Gemfile::VERSION
9
+ spec.authors = ["sue445"]
10
+ spec.email = ["sue445@sue445.net"]
11
+
12
+ spec.summary = %q{Code style checking for Gemfile}
13
+ spec.description = %q{Code style checking for Gemfile}
14
+ # TODO make public
15
+ # spec.homepage = "https://github.com/sue445/rubocop-gemfile"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "rubocop", ">= 0.35.0"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.12"
26
+ spec.add_development_dependency "pry-byebug"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.5.0"
29
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-gemfile
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.beta1
5
+ platform: ruby
6
+ authors:
7
+ - sue445
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-10-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubocop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.35.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.35.0
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.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry-byebug
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: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.5.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.5.0
83
+ description: Code style checking for Gemfile
84
+ email:
85
+ - sue445@sue445.net
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - config/default.yml
100
+ - lib/rubocop-gemfile.rb
101
+ - lib/rubocop/cop/gemfile/group_type.rb
102
+ - lib/rubocop/cop/gemfile/single_group.rb
103
+ - lib/rubocop/gemfile.rb
104
+ - lib/rubocop/gemfile/inject.rb
105
+ - lib/rubocop/gemfile/version.rb
106
+ - rubocop-gemfile.gemspec
107
+ homepage:
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">"
123
+ - !ruby/object:Gem::Version
124
+ version: 1.3.1
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.5.1
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Code style checking for Gemfile
131
+ test_files: []