CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rubocop/cop/lint/module_disclosure_date_present.rb
Views: 11784
1
# frozen_string_literal: true
2
3
module RuboCop
4
module Cop
5
module Lint
6
class ModuleDisclosureDatePresent < Base
7
extend AutoCorrector
8
include Alignment
9
10
MSG = 'Module is missing the required DisclosureDate information'
11
12
def_node_matcher :find_update_info_node, <<~PATTERN
13
(def :initialize _args (begin (super $(send nil? {:update_info :merge_info} (lvar :info) (hash ...))) ...))
14
PATTERN
15
16
def_node_matcher :find_nested_update_info_node, <<~PATTERN
17
(def :initialize _args (super $(send nil? {:update_info :merge_info} (lvar :info) (hash ...)) ...))
18
PATTERN
19
20
def on_def(node)
21
return if node.source =~ /Generic Payload Handler/
22
23
update_info_node = find_update_info_node(node) || find_nested_update_info_node(node)
24
return if update_info_node.nil?
25
26
hash = update_info_node.arguments.find { |argument| hash_arg?(argument) }
27
disclosure_date_present = false
28
last_key = nil
29
hash.each_pair do |key, _value|
30
if key.value == 'DisclosureDate'
31
disclosure_date_present = true
32
end
33
last_key = key
34
end
35
36
unless disclosure_date_present
37
add_offense(last_key || hash)
38
end
39
end
40
41
private
42
43
def hash_arg?(node)
44
node.type == :hash
45
end
46
end
47
end
48
end
49
end
50
51