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/deprecated_gem_version.rb
Views: 11784
1
# frozen_string_literal: true
2
3
module RuboCop
4
module Cop
5
module Lint
6
class DeprecatedGemVersion < Base
7
include RangeHelp
8
extend AutoCorrector
9
10
MSG = 'Use `Rex::Version` instead of `Gem::Version`.'
11
12
# @!method gem_version_const(node)
13
def_node_matcher :gem_version_const, <<~PATTERN
14
(const
15
$(const {nil? cbase} :Gem) {:Version})
16
PATTERN
17
18
# @!method gem_version_const_cbase(node)
19
def_node_matcher :gem_version_const_cbase, <<~PATTERN
20
(const
21
$(const {cbase} :Gem) {:Version})
22
PATTERN
23
24
def on_const(node)
25
return unless gem_version_const(node)
26
27
add_offense(node, message: MSG) do |corrector|
28
autocorrect(corrector, node)
29
end
30
end
31
32
private
33
34
def autocorrect(corrector, node)
35
if gem_version_const_cbase(node)
36
corrector.replace(gem_version_const_cbase(node), '::Rex')
37
else
38
corrector.replace(gem_version_const(node), 'Rex')
39
end
40
end
41
42
end
43
end
44
end
45
end
46
47