Skip to content

Commit 03bf4a7

Browse files
committed
(PUP-11993) Style/RedundantSort
This commit enables the Style/RedundantSort cop and fixes 7 (unsafe) autocorrectable offenses.
1 parent 29be5ae commit 03bf4a7

File tree

7 files changed

+7
-17
lines changed

7 files changed

+7
-17
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -679,16 +679,6 @@ Style/RedundantSelfAssignment:
679679
Exclude:
680680
- 'lib/puppet/context.rb'
681681

682-
# This cop supports unsafe auto-correction (--auto-correct-all).
683-
Style/RedundantSort:
684-
Exclude:
685-
- 'lib/puppet/interface/face_collection.rb'
686-
- 'lib/puppet/module/plan.rb'
687-
- 'lib/puppet/module_tool/applications/unpacker.rb'
688-
- 'lib/puppet/provider/package/apt.rb'
689-
- 'lib/puppet/provider/package/yum.rb'
690-
- 'lib/puppet/provider/package/zypper.rb'
691-
692682
# This cop supports safe auto-correction (--auto-correct).
693683
# Configuration parameters: EnforcedStyle, AllowInnerSlashes.
694684
# SupportedStyles: slashes, percent_r, mixed

lib/puppet/interface/face_collection.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def self.get_face(name, pattern)
5555
end
5656

5757
def self.find_matching(range, versions)
58-
versions.select { |v| range === v }.sort.last
58+
versions.select { |v| range === v }.max
5959
end
6060

6161
# try to load the face, and return it.
@@ -95,7 +95,7 @@ def self.load_face(name, version)
9595
# versions here and return the last item in that set.
9696
#
9797
# --daniel 2011-04-06
98-
latest_ver = @faces[name].keys.sort.last
98+
latest_ver = @faces[name].keys.max
9999
@faces[name][:current] = @faces[name][latest_ver]
100100
end
101101
end

lib/puppet/module/plan.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def self.find_implementations(name, plan_files)
8989
implementations = plan_files.select { |impl| File.basename(impl, '.*') == basename }
9090

9191
# Select .pp before .yaml, since .pp comes before .yaml alphabetically.
92-
chosen = implementations.sort.first
92+
chosen = implementations.min
9393

9494
[{ "name" => File.basename(chosen), "path" => chosen }]
9595
end

lib/puppet/module_tool/applications/unpacker.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def root_dir
6464
return @root_dir if @root_dir
6565

6666
# Grab the first directory containing a metadata.json file
67-
metadata_file = Dir["#{tmpdir}/**/metadata.json"].sort_by(&:length)[0]
67+
metadata_file = Dir["#{tmpdir}/**/metadata.json"].min_by(&:length)
6868

6969
if metadata_file
7070
@root_dir = Pathname.new(metadata_file).dirname

lib/puppet/provider/package/apt.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def best_version(should_range)
108108
end
109109
end
110110

111-
return versions.sort.last if versions.any?
111+
return versions.max if versions.any?
112112

113113
Puppet.debug("No available version for package #{@resource[:name]} is included in range #{should_range}")
114114
should_range

lib/puppet/provider/package/yum.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def best_version(should)
217217
Puppet.debug("Cannot parse #{version} as a RPM version")
218218
end
219219

220-
version = versions.sort.last if versions.any?
220+
version = versions.max if versions.any?
221221

222222
if version
223223
version = version.to_s.sub(/^\d+:/, '')

lib/puppet/provider/package/zypper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def best_version(should)
8282
end
8383
end
8484

85-
return versions.sort.last if versions.any?
85+
return versions.max if versions.any?
8686

8787
Puppet.debug("No available version for package #{@resource[:name]} is included in range #{should_range}")
8888
should

0 commit comments

Comments
 (0)