Skip to content

Commit

Permalink
Improve offense messages
Browse files Browse the repository at this point in the history
Make it a bit more clearer as to what's
problematic and what to do intead of those
lines of code.

Signed-off-by: Utkarsh Gupta <utkarsh@debian.org>
  • Loading branch information
utkarsh2102 committed Sep 19, 2020
1 parent 8f9f396 commit ce31001
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
19 changes: 15 additions & 4 deletions config/default.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
# This is the default configuration file.

Packaging/BundlerSetupInTests:
Description: 'Avoid using `bundler/setup` in your tests.'
Description: >-
Using `bundler/setup` in tests is redundant. Consider
removing it.
Enabled: true
VersionAdded: '0.4'
VersionChanged: '0.5'

Packaging/GemspecGit:
Description: 'Use pure Ruby alternative instead of `git ls-files`.'
Description: >-
Using `bundler/setup` in tests is redundant. Consider
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`.
Enabled: true
VersionAdded: '0.1'
VersionChanged: '0.1'

Packaging/RequireHardcodingLib:
Description: 'Avoid using `require` with relative path to lib.'
Description: >-
Avoid using `require` with relative path to lib. Use
`require` with absolute path instead.
Enabled: true
VersionAdded: '0.4'
VersionChanged: '0.5'

Packaging/RequireRelativeHardcodingLib:
Description: 'Avoid using `require_relative` with relative path to lib.'
Description: >-
Avoid using `require_relative` with relative path to
lib. Use `require` with absolute path instead.
Enabled: true
VersionAdded: '0.2'
VersionChanged: '0.5'
2 changes: 1 addition & 1 deletion lib/rubocop/cop/packaging/bundler_setup_in_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class BundlerSetupInTests < Base

# This is the message that will be displayed when RuboCop::Packaging finds
# an offense of using `require "bundler/setup"` in the tests directory.
MSG = "Avoid using `bundler/setup` in your tests."
MSG = "Using `bundler/setup` in tests is redundant. Consider removing it."

def_node_matcher :bundler_setup?, <<~PATTERN
(send nil? :require
Expand Down
6 changes: 3 additions & 3 deletions lib/rubocop/cop/packaging/gemspec_git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ class GemspecGit < Base
# This is the message that will be displayed when RuboCop finds an
# offense of using `git ls-files`.
MSG = "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`."
"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`."

def_node_search :xstr, <<~PATTERN
(block
Expand Down
3 changes: 2 additions & 1 deletion lib/rubocop/cop/packaging/require_hardcoding_lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class RequireHardcodingLib < Base

# This is the message that will be displayed when RuboCop::Packaging
# finds an offense of using `require` with relative path to lib.
MSG = "Avoid using `require` with relative path to `lib/`."
MSG = "Avoid using `require` with relative path to `lib/`. " \
"Use `require` with absolute path instead."

def_node_matcher :require?, <<~PATTERN
{(send nil? :require (str #falls_in_lib?))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class RequireRelativeHardcodingLib < Base
# This is the message that will be displayed when RuboCop finds an
# offense of using `require_relative` with relative path to lib.
MSG = "Avoid using `require_relative` with relative path to lib. " \
"Use `require` instead."
"Use `require` with absolute path instead."

def_node_matcher :require_relative, <<~PATTERN
(send nil? :require_relative
Expand Down

0 comments on commit ce31001

Please sign in to comment.