class RuboCop::Cop::Katello::CveAbbreviation
Flags variable, parameter, and method names that abbreviate “content view environment” as “cve”, which collides with the security meaning of CVE (Common Vulnerabilities and Exposures). Use “cvenv” instead.
This only inspects identifiers (locals, ivars, method/block params, method names) – not string or symbol literals – so it leaves legitimate CVE-security code alone as long as that code lives outside this cop’s configured ‘Exclude` paths.
@example
# bad cve = content_facet.content_view_environments.first cve1, cve2 = ak.content_view_environments # good cvenv = content_facet.content_view_environments.first cvenv1, cvenv2 = ak.content_view_environments
Constants
- CVE_WORD
- MSG
Public Instance Methods
on_block(node)
click to toggle source
# File lib/rubocop/cop/katello/cve_abbreviation.rb, line 46 def on_block(node) check_args(node.arguments) end
on_def(node)
click to toggle source
# File lib/rubocop/cop/katello/cve_abbreviation.rb, line 37 def on_def(node) check_name(node, node.method_name) check_args(node.arguments) end
on_defs(node)
click to toggle source
# File lib/rubocop/cop/katello/cve_abbreviation.rb, line 42 def on_defs(node) on_def(node) end
on_ivasgn(node)
click to toggle source
# File lib/rubocop/cop/katello/cve_abbreviation.rb, line 33 def on_ivasgn(node) check_name(node, node.children.first.to_s.delete('@').to_sym) end
on_lvasgn(node)
click to toggle source
# File lib/rubocop/cop/katello/cve_abbreviation.rb, line 29 def on_lvasgn(node) check_name(node, node.children.first) end
on_numblock(node)
click to toggle source
# File lib/rubocop/cop/katello/cve_abbreviation.rb, line 50 def on_numblock(node) on_block(node) end
Private Instance Methods
banned?(name)
click to toggle source
# File lib/rubocop/cop/katello/cve_abbreviation.rb, line 66 def banned?(name) name.to_s.split('_').any? { |word| CVE_WORD.match?(word) } end
check_args(args)
click to toggle source
# File lib/rubocop/cop/katello/cve_abbreviation.rb, line 56 def check_args(args) args.each { |arg| check_name(arg, arg.children.first) } end
check_name(node, name)
click to toggle source
# File lib/rubocop/cop/katello/cve_abbreviation.rb, line 60 def check_name(node, name) return unless name && banned?(name) add_offense(node, message: format(MSG, name: name, suggestion: suggest(name))) end
rename_word(word)
click to toggle source
# File lib/rubocop/cop/katello/cve_abbreviation.rb, line 75 def rename_word(word) match = CVE_WORD.match(word) match ? "cvenv#{match[1]}#{match[2]}#{match[3]}" : word end
suggest(name)
click to toggle source
# File lib/rubocop/cop/katello/cve_abbreviation.rb, line 70 def suggest(name) words = name.to_s.split('_').map { |word| rename_word(word) } words.join('_') end