diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-13 18:06:03 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-13 18:06:03 +0000 |
commit | 40d3d574132d2849646c20eb9d8742b159d9bfc8 (patch) | |
tree | 431dee6675639da4421dbb1d6f50b7734a3190c3 /rubocop/cop/qa | |
parent | 5939b09fd3db37ec98dfce0345162617d9d1d313 (diff) | |
download | gitlab-ce-40d3d574132d2849646c20eb9d8742b159d9bfc8.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'rubocop/cop/qa')
-rw-r--r-- | rubocop/cop/qa/ambiguous_page_object_name.rb | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/rubocop/cop/qa/ambiguous_page_object_name.rb b/rubocop/cop/qa/ambiguous_page_object_name.rb new file mode 100644 index 00000000000..5cd8ea25c87 --- /dev/null +++ b/rubocop/cop/qa/ambiguous_page_object_name.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +require_relative '../../qa_helpers' + +module RuboCop + module Cop + module QA + # This cop checks for the usage of the ambiguous name "page" + # + # @example + # + # # bad + # Page::Object.perform do |page| do ... + # Page::Another.perform { |page| ... } + # + # # good + # Page::Object.perform do |object| do ... + # Page::Another.perform { |another| ... } + class AmbiguousPageObjectName < RuboCop::Cop::Cop + include QAHelpers + + MESSAGE = "Don't use 'page' as a name for a Page Object. Use `%s` instead.".freeze + + def_node_matcher :ambiguous_page?, <<~PATTERN + (block + (send + (const ...) :perform) + (args + (arg :page)) ...) + PATTERN + + def on_block(node) + return unless in_qa_file?(node) + return unless ambiguous_page?(node) + + add_offense(node.arguments.each_node(:arg).first, + message: MESSAGE % page_object_name(node)) + end + + private + + def page_object_name(node) + node.send_node.children[-2].const_name.downcase.split('::').last + end + end + end + end +end |