Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged |
---|---|---|---|---|
Enabled |
Yes |
No |
0.1 |
0.1 |
This cop flags the usage of git ls-files
in gemspec
and suggests to use a plain Ruby alternative, like Dir
,
Dir.glob
, or Rake::FileList
instead.
More information about the GemspecGit cop can be found here: https://packaging.rubystyle.guide/#gemspec-git
# bad
Gem::Specification.new do |spec|
spec.files = `git ls-files`.split("\n")
spec.test_files = `git ls-files -- spec`.split("\n")
end
# good
Gem::Specification.new do |spec|
spec.files = Dir["lib/**/*", "LICENSE", "README.md"]
spec.test_files = Dir["spec/**/*"]
end
# bad
Gem::Specification.new do |spec|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
`git ls-files -z`.split("\\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
end
end
# good
Gem::Specification.new do |spec|
spec.files = Rake::FileList["**/*"].exclude(*File.read(".gitignore").split)
end
# bad
Gem::Specification.new do |spec|
spec.files = `git ls-files -- lib/`.split("\n")
spec.test_files = `git ls-files -- test/{functional,unit}/*`.split("\n")
spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
end
# good
Gem::Specification.new do |spec|
spec.files = Dir.glob("lib/**/*")
spec.test_files = Dir.glob("test/{functional,test}/*")
spec.executables = Dir.glob("bin/*").map{ |f| File.basename(f) }
end
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged |
---|---|---|---|---|
Enabled |
Yes |
No |
0.2 |
0.3 |
This cop flags the require_relative
calls, from anywhere
mapping to the "lib" directory, except originating from lib/ or
the gemspec file, and suggests to use require
instead.
More information about the RequireRelativeHardcodingLib cop can be found here: https://packaging.rubystyle.guide/#require-relative-hardcoding-lib
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged |
---|---|---|---|---|
Enabled |
Yes |
No |
0.3 |
- |
This cop flags the require
calls, from anywhere mapping to
the "lib" directory, except originating from lib/.
# bad
require "../lib/foo/bar"
# good
require "foo/bar"
# bad
require File.expand_path("../../lib/foo", __FILE__)
# good
require "foo"
# bad
require File.expand_path("../../../lib/foo/bar/baz/qux", __dir__)
# good
require "foo/bar/baz/qux"
# bad
require File.dirname(__FILE__) + "/../../lib/baz/qux"
# good
require "baz/qux"