rubocop-packaging 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7763971e3ccedea64e6db97b4ec6351d489b99fe36110f4d01374a67bce0c0d1
4
+ data.tar.gz: 4e4e52ee808aba2ba256a757c225802cff30bafe9521ec33a259dbfe7f037e42
5
+ SHA512:
6
+ metadata.gz: c2cdd53a7671b724141244e0efec24e8a4eeffbe3a4e9830b3eb6b80fbf487f74649e552b465b6b17f537d985278d7da38bba14fc9a816d781adee54aefb55d3
7
+ data.tar.gz: 9f16cf74a99ab1d56e01ad056440d2329013a441a62618eccc4e1ee2a6052ed7df4fd5565f095468feb7739c863ca957f9199a8a4e3c8db1de92958e5bf802c6
data/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+ MIT License
2
+ ===========
3
+
4
+ Copyright (©) 2020 Utkarsh Gupta <utkarsh@debian.org>
5
+
6
+ Permission is hereby granted, free of charge, to any person
7
+ obtaining a copy of this software and associated documentation
8
+ files (the "Software"), to deal in the Software without
9
+ restriction, including without limitation the rights to use,
10
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the
12
+ Software is furnished to do so, subject to the following
13
+ conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,86 @@
1
+ # RuboCop::Packaging
2
+
3
+ `RuboCop::Packaging` is an extension of [RuboCop](https://rubocop.org/),
4
+ which is a Ruby static code analyzer (a.k.a. linter) and code formatter.
5
+
6
+ It helps enforcing some of the guidelines that are expected of upstream
7
+ maintainers so that the downstream can build their packages in a clean
8
+ environment without any problems.
9
+ Some of the other basic guidelines can be found
10
+ [here](https://wiki.debian.org/Teams/Ruby/RubyExtras/UpstreamDevelopers).
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'rubocop-packaging'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ ```bash
23
+ $ bundle install
24
+ ```
25
+
26
+ Or install it yourself as:
27
+
28
+ ```bash
29
+ $ gem install rubocop-packaging
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ You need to tell RuboCop to load the Packaging extension. There are three
35
+ ways to do this:
36
+
37
+ ### RuboCop configuration file
38
+
39
+ Put this into your `.rubocop.yml` file:
40
+
41
+ ```yaml
42
+ require: rubocop-packaging
43
+ ```
44
+
45
+ Alternatively, use the following array notation when specifying multiple
46
+ extensions:
47
+
48
+ ```yaml
49
+ require:
50
+ - rubocop-other-extension
51
+ - rubocop-packaging
52
+ ```
53
+
54
+ Now you can run `rubocop` and it will automatically load the RuboCop Packaging
55
+ cops together with the standard cops.
56
+
57
+ ### Command line
58
+
59
+ ```bash
60
+ rubocop --require rubocop-packaging
61
+ ```
62
+
63
+ ### Rake task
64
+
65
+ ```ruby
66
+ RuboCop::RakeTask.new do |task|
67
+ task.requires << 'rubocop-packaging'
68
+ end
69
+ ```
70
+
71
+ ## Development
72
+
73
+ After checking out the repo, run `bin/setup` to install dependencies. Then,
74
+ run `rake spec` to run the tests. You can also run `bin/console` for an
75
+ interactive prompt that will allow you to experiment.
76
+
77
+ To install this gem onto your local machine, run `bundle exec rake install`.
78
+
79
+ ## Contributing
80
+
81
+ As always, bug reports and pull requests are heartily welcomed! 💖
82
+ This project is intended to be a safe and welcoming space for collaboration.
83
+
84
+ ## License
85
+ `rubocop-packaging` is available as open-source under the
86
+ [MIT License](https://github.com/utkarsh2102/rubocop-packaging/blob/master/LICENSE).
@@ -0,0 +1,6 @@
1
+ # This is the default configuration file.
2
+
3
+ Packaging/GemspecGit:
4
+ Description: 'Use pure Ruby alternative instead of `git ls-files`.'
5
+ Enabled: true
6
+ VersionAdded: '0.86'
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop'
4
+
5
+ require_relative 'rubocop/packaging'
6
+ require_relative 'rubocop/packaging/version'
7
+ require_relative 'rubocop/packaging/inject'
8
+
9
+ RuboCop::Packaging::Inject.defaults!
10
+
11
+ require_relative 'rubocop/cop/packaging_cops'
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop # :nodoc:
4
+ module Cop # :nodoc:
5
+ module Packaging # :nodoc:
6
+ # This cop is used to identify the usage of `git ls-files`
7
+ # and suggests to use a plain Ruby alternative, like `Dir`,
8
+ # `Dir.glob` or `Rake::FileList` instead.
9
+ #
10
+ # @example
11
+ #
12
+ # # bad
13
+ # Gem::Specification.new do |spec|
14
+ # spec.files = `git ls-files`.split('\n')
15
+ # end
16
+ #
17
+ # # bad
18
+ # Gem::Specification.new do |spec|
19
+ # spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ # `git ls-files -z`.split('\\x0').reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ # end
22
+ # end
23
+ #
24
+ # # bad
25
+ # Gem::Specification.new do |spec|
26
+ # spec.files = `git ls-files`.split('\n')
27
+ # spec.test_files = `git ls-files -- test/{functional,unit}/*`.split('\n')
28
+ # spec.executables = `git ls-files -- bin/*`.split('\n').map{ |f| File.basename(f) }
29
+ # end
30
+ #
31
+ # # good
32
+ # Gem::Specification.new do |spec|
33
+ # spec.files = Dir['lib/**/*', 'LICENSE', 'README.md']
34
+ # spec.test_files = Dir['spec/**/*']
35
+ # end
36
+ #
37
+ # # good
38
+ # Gem::Specification.new do |spec|
39
+ # spec.files = Rake::FileList['**/*'].exclude(*File.read('.gitignore').split)
40
+ # end
41
+ #
42
+ # # good
43
+ # Gem::Specification.new do |spec|
44
+ # spec.files = Dir.glob('lib/**/*')
45
+ # spec.test_files = Dir.glob('test/{functional,test}/*')
46
+ # spec.executables = Dir.glob('bin/*').map{ |f| File.basename(f) }
47
+ # end
48
+ #
49
+ class GemspecGit < Cop
50
+ # This is the message that will be displayed when RuboCop finds an
51
+ # offense of using `git ls-files`.
52
+ MSG = 'Avoid using git to produce lists of files. ' \
53
+ 'Downstreams often need to build your package in an environment ' \
54
+ 'that does not have git (on purpose). ' \
55
+ 'Use some pure Ruby alternative, like `Dir` or `Dir.glob`.'
56
+
57
+ def_node_search :xstr, <<~PATTERN
58
+ (block
59
+ (send
60
+ (const
61
+ (const {cbase nil?} :Gem) :Specification) :new)
62
+ (args
63
+ (arg _)) `$(xstr (str #starts_with_git?)))
64
+ PATTERN
65
+
66
+ # Extended from the Cop class.
67
+ # More about the `#investigate` method can be found here:
68
+ # https://github.com/rubocop-hq/rubocop/blob/59543c8e2b66bff249de131fa9105f3eb11e9edb/lib/rubocop/cop/cop.rb#L13-L25
69
+ #
70
+ # Processing of the AST happens here.
71
+ def investigate(processed_source)
72
+ xstr(processed_source.ast).each do |node|
73
+ add_offense(
74
+ processed_source.ast,
75
+ location: node.loc.expression,
76
+ message: MSG
77
+ )
78
+ end
79
+ end
80
+
81
+ # This method is called from inside `#def_node_search`.
82
+ # It is used to find strings which start with 'git'.
83
+ def starts_with_git?(str)
84
+ str.start_with?('git')
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'packaging/gemspec_git'
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop/packaging/version'
4
+
5
+ module RuboCop
6
+ # RuboCop Packaging project namespace
7
+ module Packaging
8
+ PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
9
+ CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
10
+ CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze
11
+
12
+ private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Packaging
5
+ # Because RuboCop doesn't yet support plugins, we have to monkey patch in a
6
+ # bit of our configuration.
7
+ module Inject
8
+ def self.defaults!
9
+ path = CONFIG_DEFAULT.to_s
10
+ hash = ConfigLoader.send(:load_yaml_configuration, path)
11
+ config = Config.new(hash, path).tap(&:make_excludes_absolute)
12
+ puts "configuration from #{path}" if ConfigLoader.debug?
13
+ config = ConfigLoader.merge_with_default(config, path)
14
+ ConfigLoader.instance_variable_set(:@default_configuration, config)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Packaging
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-packaging
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Utkarsh Gupta
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-06-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bump
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.13.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.13.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '13.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: yard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.9'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 0.75.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 0.75.0
97
+ description: |
98
+ A collection of RuboCop cops to check for downstream compatability issues in the
99
+ Ruby code.
100
+ email:
101
+ - utkarsh@debian.org
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - LICENSE
107
+ - README.md
108
+ - config/default.yml
109
+ - lib/rubocop-packaging.rb
110
+ - lib/rubocop/cop/packaging/gemspec_git.rb
111
+ - lib/rubocop/cop/packaging_cops.rb
112
+ - lib/rubocop/packaging.rb
113
+ - lib/rubocop/packaging/inject.rb
114
+ - lib/rubocop/packaging/version.rb
115
+ homepage: https://github.com/utkarsh2102/rubocop-packaging
116
+ licenses:
117
+ - MIT
118
+ metadata:
119
+ homepage_uri: https://github.com/utkarsh2102/rubocop-packaging
120
+ source_code_uri: https://github.com/utkarsh2102/rubocop-packaging
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: 2.3.0
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubygems_version: 3.1.2
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Automatic downstream compatability checking tool for Ruby code
140
+ test_files: []