Class: RuboCop::Cop::Packaging::GemspecGit
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Packaging::GemspecGit
- Defined in:
- lib/rubocop/cop/packaging/gemspec_git.rb
Overview
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.
Constant Summary collapse
- MSG =
This is the message that will be displayed when RuboCop finds an offense of using
git ls-files. "Avoid using git to produce lists of files. " \ "Downstreams often need to build your package in an environment " \ "that does not have git (on purpose). " \ "Use some pure Ruby alternative, like `Dir` or `Dir.glob`."
Instance Method Summary collapse
-
#on_new_investigation ⇒ Object
Extended from the Cop class.
-
#starts_with_git?(str) ⇒ Boolean
This method is called from inside
#def_node_search.
Instance Method Details
#on_new_investigation ⇒ Object
Extended from the Cop class.
More about the #investigate method can be found here:
https://github.com/rubocop-hq/rubocop/blob/59543c8e2b66bff249de131fa9105f3eb11e9edb/lib/rubocop/cop/cop.rb#L13-L25
Processing of the AST happens here.
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/rubocop/cop/packaging/gemspec_git.rb', line 70 def on_new_investigation return if processed_source.blank? xstr(processed_source.ast).each do |node| add_offense( node.loc.expression, message: MSG ) end end |
#starts_with_git?(str) ⇒ Boolean
This method is called from inside #def_node_search.
It is used to find strings which start with "git".
83 84 85 |
# File 'lib/rubocop/cop/packaging/gemspec_git.rb', line 83 def starts_with_git?(str) str.start_with?("git") end |