Skip to content

Commit 32d9bf1

Browse files
committed
Disable Rubocop Layout cops in package providers
This commit targets portions of package providers to disable Rubocop's Layout cops. These portions of the code mix confine statements, control expressions, and exception handling, which cause Rubocop to act unexpectedly and flag false positives.
1 parent db74925 commit 32d9bf1

File tree

7 files changed

+25
-13
lines changed

7 files changed

+25
-13
lines changed

.rubocop.yml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,9 @@ Layout:
2323
Exclude:
2424
- 'lib/puppet/defaults.rb'
2525

26-
# The confine statements in package providers unexpectedly affect this cop.
27-
Layout/BeginEndAlignment:
28-
Enabled: true
29-
Exclude:
30-
- 'lib/puppet/provider/package/*.rb'
31-
32-
Layout/ElseAlignment:
33-
Enabled: true
34-
Exclude:
35-
- 'lib/puppet/provider/package/*.rb'
36-
3726
# We don't mind when module and class keywords are aligned.
3827
Layout/IndentationWidth:
3928
AllowedPatterns: ['^\s*module']
40-
Exclude:
41-
- 'lib/puppet/provider/package/*.rb'
4229

4330
Layout/LineEndStringConcatenationIndentation:
4431
Enabled: true

lib/puppet/provider/package/apt.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,16 @@ def flush
7878
# Debian boxes, and the only thing that differs is that it can
7979
# install packages from remote sites.
8080

81+
# Double negation confuses Rubocop's Layout cops
82+
# rubocop:disable Layout
8183
def checkforcdrom
8284
have_cdrom = begin
8385
!!(File.read("/etc/apt/sources.list") =~ /^[^#]*cdrom:/)
8486
rescue
8587
# This is basically pathological...
8688
false
8789
end
90+
# rubocop:enable Layout
8891

8992
if have_cdrom and @resource[:allowcdrom] != :true
9093
raise Puppet::Error,

lib/puppet/provider/package/aptrpm.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
commands :aptcache => "apt-cache"
1313
commands :rpm => "rpm"
1414

15+
# Mixing confine statements, control expressions, and exception handling
16+
# confuses Rubocop's Layout cops, so we disable them entirely.
17+
# rubocop:disable Layout
1518
if command('rpm')
1619
confine :true => begin
1720
rpm('-ql', 'rpm')
@@ -21,6 +24,7 @@
2124
true
2225
end
2326
end
27+
# rubocop:enable Layout
2428

2529
# Install a package using 'apt-get'. This function needs to support
2630
# installing a specific version.

lib/puppet/provider/package/dnf.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
# never try to use RPM on a machine without it. We think this
2121
# has probably become obsolete with the way `commands` work, so
2222
# we should investigate removing it at some point.
23+
#
24+
# Mixing confine statements, control expressions, and exception handling
25+
# confuses Rubocop's Layout cops, so we disable them entirely.
26+
# rubocop:disable Layout
2327
if command('rpm')
2428
confine :true => begin
2529
rpm('--version')
@@ -29,6 +33,7 @@
2933
true
3034
end
3135
end
36+
# rubocop:enable Layout
3237

3338
defaultfor 'os.name' => :fedora
3439
notdefaultfor 'os.name' => :fedora, 'os.release.major' => (19..21).to_a

lib/puppet/provider/package/rpm.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131

3232
commands :rpm => "rpm"
3333

34+
# Mixing confine statements, control expressions, and exception handling
35+
# confuses Rubocop's Layout cops, so we disable them entirely.
36+
# rubocop:disable Layout
3437
if command('rpm')
3538
confine :true => begin
3639
rpm('--version')
@@ -40,6 +43,7 @@
4043
true
4144
end
4245
end
46+
# rubocop:enable Layout
4347

4448
def self.current_version
4549
return @current_version unless @current_version.nil?

lib/puppet/provider/package/tdnf.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
# never try to use RPM on a machine without it. We think this
1717
# has probably become obsolete with the way `commands` work, so
1818
# we should investigate removing it at some point.
19+
#
20+
# Mixing confine statements, control expressions, and exception handling
21+
# confuses Rubocop's Layout cops, so we disable them entirely.
22+
# rubocop:disable Layout
1923
if command('rpm')
2024
confine :true => begin
2125
rpm('--version')
@@ -25,6 +29,7 @@
2529
true
2630
end
2731
end
32+
# rubocop:enable Layout
2833

2934
defaultfor 'os.name' => "PhotonOS"
3035
end

lib/puppet/provider/package/yum.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424

2525
commands :cmd => "yum", :rpm => "rpm"
2626

27+
# Mixing confine statements, control expressions, and exception handling
28+
# confuses Rubocop's Layout cops, so we disable them entirely.
29+
# rubocop:disable Layout
2730
if command('rpm')
2831
confine :true => begin
2932
rpm('--version')
@@ -33,6 +36,7 @@
3336
true
3437
end
3538
end
39+
# rubocop:enable Layout
3640

3741
defaultfor 'os.name' => :amazon
3842
defaultfor 'os.family' => :redhat, 'os.release.major' => (4..7).to_a

0 commit comments

Comments
 (0)