diff options
author | Mike Greiling <mike@pixelcog.com> | 2017-10-09 23:00:00 +0300 |
---|---|---|
committer | Mike Greiling <mike@pixelcog.com> | 2017-10-09 23:00:00 +0300 |
commit | f7837988250bb93069b1e7473c40d155de75a111 (patch) | |
tree | 0a95264614e399b475cfeba3d0d158dd9705d0af /rubocop | |
parent | 02838d5be2f899793ce5e026f0bb20c509697061 (diff) | |
parent | d6170ce4d8a0cbfd8552531c29163e44549222cf (diff) |
Merge branch 'master' into sh-headless-chrome-support
* master: (113 commits)
Introduce new hook data builders for Issue and MergeRequest
Don't create todos for old issue assignees
Start adding Gitlab::HookData::IssuableBuilder
Include the changes in issuable webhook payloads
Rename the `codeclimate` job to `codequality`
Don't show an "Unsubscribe" link in snippet comment notifications
Add QA::Scenario::Gitlab::Group::Create
Removes CommitsList from global namespace
Fix wiki empty page translation namespace not being removed
Fixes mini graph in commit view
Fix link to new i18n index page
Update i18n docs
Move i18n/introduction to i18n/index
Resolve "Simple documentation update - backup to restore in restore section"
Remove AjaxLoadingSpinner and CreateLabelDropdown from global namespace
Move cycle analytics banner into a vue file
Updated Icons + Fix for Collapsed Groups Angle
Don't create fork networks for root projects that are deleted
Remove executable permissions on images to make docs lint happy
Sync up hard coded DN class in migration
...
Diffstat (limited to 'rubocop')
-rw-r--r-- | rubocop/cop/rspec/verbose_include_metadata.rb | 74 | ||||
-rw-r--r-- | rubocop/rubocop.rb | 1 |
2 files changed, 75 insertions, 0 deletions
diff --git a/rubocop/cop/rspec/verbose_include_metadata.rb b/rubocop/cop/rspec/verbose_include_metadata.rb new file mode 100644 index 00000000000..58390622d60 --- /dev/null +++ b/rubocop/cop/rspec/verbose_include_metadata.rb @@ -0,0 +1,74 @@ +# frozen_string_literal: true + +require 'rubocop-rspec' + +module RuboCop + module Cop + module RSpec + # Checks for verbose include metadata used in the specs. + # + # @example + # # bad + # describe MyClass, js: true do + # end + # + # # good + # describe MyClass, :js do + # end + class VerboseIncludeMetadata < Cop + MSG = 'Use `%s` instead of `%s`.' + + SELECTORS = %i[describe context feature example_group it specify example scenario its].freeze + + def_node_matcher :include_metadata, <<-PATTERN + (send {(const nil :RSpec) nil} {#{SELECTORS.map(&:inspect).join(' ')}} + !const + ... + (hash $...)) + PATTERN + + def_node_matcher :invalid_metadata?, <<-PATTERN + (pair + (sym $...) + (true)) + PATTERN + + def on_send(node) + invalid_metadata_matches(node) do |match| + add_offense(node, :expression, format(MSG, good(match), bad(match))) + end + end + + def autocorrect(node) + lambda do |corrector| + invalid_metadata_matches(node) do |match| + corrector.replace(match.loc.expression, good(match)) + end + end + end + + private + + def invalid_metadata_matches(node) + include_metadata(node) do |matches| + matches.select(&method(:invalid_metadata?)).each do |match| + yield match + end + end + end + + def bad(match) + "#{metadata_key(match)}: true" + end + + def good(match) + ":#{metadata_key(match)}" + end + + def metadata_key(match) + match.children[0].source + end + end + end + end +end diff --git a/rubocop/rubocop.rb b/rubocop/rubocop.rb index 1b6e8991a17..1df23899efb 100644 --- a/rubocop/rubocop.rb +++ b/rubocop/rubocop.rb @@ -21,3 +21,4 @@ require_relative 'cop/migration/reversible_add_column_with_default' require_relative 'cop/migration/timestamps' require_relative 'cop/migration/update_column_in_batches' require_relative 'cop/rspec/single_line_hook' +require_relative 'cop/rspec/verbose_include_metadata' |