Skip to content

Commit 30c1553

Browse files
committed
Adds a check to skip modules with execellent ranking and sentinel values
1 parent a454217 commit 30c1553

File tree

3 files changed

+4
-57
lines changed

3 files changed

+4
-57
lines changed

lib/rubocop/cop/lint/module_enforce_notes.rb

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ module RuboCop
44
module Cop
55
module Lint
66
class ModuleEnforceNotes < Base
7-
extend AutoCorrector
87

98
NO_NOTES_MSG = 'Module is missing the Notes section which must include Stability, Reliability and SideEffects] - https://docs.metasploit.com/docs/development/developing-modules/module-metadata/definition-of-module-reliability-side-effects-and-stability.html'
109
MISSING_KEY_MSG = 'Module is missing %s from the Notes section - https://docs.metasploit.com/docs/development/developing-modules/module-metadata/definition-of-module-reliability-side-effects-and-stability.html'
@@ -37,62 +36,12 @@ def on_def(node)
3736
if notes_present
3837
check_for_required_keys(notes)
3938
else
40-
add_offense(last_key || hash, message: NO_NOTES_MSG) do |corrector|
41-
insert_notes_autocorrect(corrector, hash)
42-
end
39+
add_offense(last_key || hash, message: NO_NOTES_MSG)
4340
end
4441
end
4542

4643
private
4744

48-
def insert_notes_autocorrect(corrector, hash)
49-
indent, last_pair = calculate_indent(hash)
50-
corrector.insert_after(last_pair.loc.expression, notes_formatted(indent))
51-
end
52-
53-
# def insert_notes_keys_autocorrect(corrector, hash)
54-
# indent, last_pair = calculate_indent(hash)
55-
# corrector.insert_after(last_pair.loc.expression, notes_formatted(indent))
56-
# end
57-
58-
# def insert_missing_notes_keys(corrector, missing_keys, notes)
59-
# indent, last_pair = calculate_indent(notes)
60-
# corrector.insert_after(last_pair.loc.expression, keys_formatted(indent, missing_keys))
61-
# end
62-
63-
def calculate_indent(hash)
64-
last_pair = hash.pairs.last
65-
indent_width = last_pair.loc.expression.column
66-
[' ' * indent_width, last_pair]
67-
end
68-
69-
# def keys_formatted(indent, missing_keys)
70-
# keys_to_insert = []
71-
# missing_keys.each do |key|
72-
# case key
73-
# when 'Reliability'
74-
# keys_to_insert << "#{indent}'Reliability' => UNKNOWN_RELIABILITY"
75-
# when 'Stability'
76-
# keys_to_insert << "#{indent}'Stability' => UNKNOWN_STABILITY"
77-
# when 'SideEffects'
78-
# keys_to_insert << "#{indent}'SideEffects' => UNKNOWN_SIDE_EFFECTS"
79-
# end
80-
# end
81-
#
82-
# ",\n#{keys_to_insert.join(",\n")}"
83-
# end
84-
85-
def notes_formatted(indent)
86-
<<~EOF.strip
87-
,
88-
#{indent}'Notes' => {
89-
#{indent} 'Reliability' => UNKNOWN_RELIABILITY,
90-
#{indent} 'Stability' => UNKNOWN_STABILITY,
91-
#{indent} 'SideEffects' => UNKNOWN_SIDE_EFFECTS
92-
#{indent}}
93-
EOF
94-
end
95-
9645
def check_for_required_keys(notes)
9746
last_key = nil
9847
keys_present = []
@@ -111,10 +60,6 @@ def check_for_required_keys(notes)
11160
msg = missing_keys[0...-1].join(', ') + ' and ' + missing_keys[-1]
11261
end
11362
add_offense(last_key || notes, message: MISSING_KEY_MSG % msg)
114-
115-
# add_offense(last_key || notes, message: MISSING_KEY_MSG % msg) do |corrector|
116-
# insert_missing_notes_keys(corrector, missing_keys, notes)
117-
# end
11863
end
11964
end
12065

spec/module_validation_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@
236236
side_effects: Msf::UNKNOWN_SIDE_EFFECTS,
237237
reliability: Msf::UNKNOWN_RELIABILITY,
238238
}
239-
super().merge(new_module_options, rank: Msf::GreatRanking, rank_to_s: 'great')
239+
super().merge(new_module_options)
240240
end
241241

242242
it 'has no errors' do

spec/support/lib/module_validation.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ def validate_notes_values_are_arrays
104104

105105
def validate_crash_safe_not_present_in_stability_notes
106106
if rank == Msf::ExcellentRanking && !stability.include?(Msf::CRASH_SAFE)
107+
return if stability == Msf::UNKNOWN_STABILITY
108+
107109
errors.add :stability, "must have CRASH_SAFE value if module has an ExcellentRanking, instead found #{stability.inspect}"
108110
end
109111
end

0 commit comments

Comments
 (0)