Class: RuboCop::Cop::Katello::CveAbbreviation

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/katello/cve_abbreviation.rb

Overview

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.

Examples:

# 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

Constant Summary collapse

MSG =
'`%<name>s` abbreviates "content view environment" as "cve", which collides with the security ' \
'meaning of CVE (Common Vulnerabilities and Exposures). Use "cvenv" instead, e.g. `%<suggestion>s`.'
CVE_WORD =
/\Acve(\d*)(s?)([?!]?)\z/i

Instance Method Summary collapse

Instance Method Details

#on_block(node) ⇒ Object



46
47
48
# File 'lib/rubocop/cop/katello/cve_abbreviation.rb', line 46

def on_block(node)
  check_args(node.arguments)
end

#on_def(node) ⇒ Object



37
38
39
40
# 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) ⇒ Object



42
43
44
# File 'lib/rubocop/cop/katello/cve_abbreviation.rb', line 42

def on_defs(node)
  on_def(node)
end

#on_ivasgn(node) ⇒ Object



33
34
35
# 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) ⇒ Object



29
30
31
# File 'lib/rubocop/cop/katello/cve_abbreviation.rb', line 29

def on_lvasgn(node)
  check_name(node, node.children.first)
end

#on_numblock(node) ⇒ Object



50
51
52
# File 'lib/rubocop/cop/katello/cve_abbreviation.rb', line 50

def on_numblock(node)
  on_block(node)
end