From 2e45e5ba3f8ea5d409fb56712186021115b89cbf Mon Sep 17 00:00:00 2001 From: Jeff Widman Date: Mon, 24 Oct 2022 17:32:53 -0700 Subject: [PATCH] Freeze mutable constants Rubocop is warning about mutable constants that should be frozen. These warnings started showing up as part of the Ruby 3.1 upgrade, and were excluded from that PR in order to minimize noise. So this PR fixes those warnings. I resolved them using `rubocop -A` and then visually inspecting them to confirm they looked reasonable. --- cargo/lib/dependabot/cargo/requirement.rb | 2 +- common/lib/dependabot/shared_helpers.rb | 2 +- common/lib/dependabot/workspace/git.rb | 2 +- elm/lib/dependabot/elm/requirement.rb | 2 +- go_modules/lib/dependabot/go_modules/requirement.rb | 2 +- gradle/lib/dependabot/gradle/requirement.rb | 2 +- hex/lib/dependabot/hex/requirement.rb | 2 +- maven/lib/dependabot/maven/requirement.rb | 2 +- npm_and_yarn/lib/dependabot/npm_and_yarn/requirement.rb | 2 +- omnibus/.rubocop.yml | 2 -- pub/lib/dependabot/pub/requirement.rb | 2 +- python/lib/dependabot/python/file_fetcher.rb | 2 +- python/lib/dependabot/python/requirement.rb | 2 +- terraform/lib/dependabot/terraform/requirement.rb | 2 +- updater/lib/dependabot/job.rb | 2 +- updater/lib/dependabot/updater/operations.rb | 2 +- 16 files changed, 15 insertions(+), 17 deletions(-) diff --git a/cargo/lib/dependabot/cargo/requirement.rb b/cargo/lib/dependabot/cargo/requirement.rb index 84cec9a8316..007896ffcd3 100644 --- a/cargo/lib/dependabot/cargo/requirement.rb +++ b/cargo/lib/dependabot/cargo/requirement.rb @@ -15,7 +15,7 @@ class Requirement < Gem::Requirement quoted = OPS.keys.map { |k| Regexp.quote(k) }.join("|") version_pattern = Cargo::Version::VERSION_PATTERN - PATTERN_RAW = "\\s*(#{quoted})?\\s*(#{version_pattern})\\s*" + PATTERN_RAW = "\\s*(#{quoted})?\\s*(#{version_pattern})\\s*".freeze PATTERN = /\A#{PATTERN_RAW}\z/ # Use Cargo::Version rather than Gem::Version to ensure that diff --git a/common/lib/dependabot/shared_helpers.rb b/common/lib/dependabot/shared_helpers.rb index ba0f7f33fc6..7d87238930a 100644 --- a/common/lib/dependabot/shared_helpers.rb +++ b/common/lib/dependabot/shared_helpers.rb @@ -21,7 +21,7 @@ module SharedHelpers USER_AGENT = "dependabot-core/#{Dependabot::VERSION} " \ "#{Excon::USER_AGENT} ruby/#{RUBY_VERSION} " \ "(#{RUBY_PLATFORM}) " \ - "(+https://github.com/dependabot/dependabot-core)" + "(+https://github.com/dependabot/dependabot-core)".freeze SIGKILL = 9 def self.in_a_temporary_repo_directory(directory = "/", repo_contents_path = nil, &block) diff --git a/common/lib/dependabot/workspace/git.rb b/common/lib/dependabot/workspace/git.rb index 8fb79b84244..3303baf0c32 100644 --- a/common/lib/dependabot/workspace/git.rb +++ b/common/lib/dependabot/workspace/git.rb @@ -7,7 +7,7 @@ module Dependabot module Workspace class Git < Base USER = "dependabot[bot]" - EMAIL = "#{USER}@users.noreply.github.com" + EMAIL = "#{USER}@users.noreply.github.com".freeze attr_reader :initial_head_sha diff --git a/elm/lib/dependabot/elm/requirement.rb b/elm/lib/dependabot/elm/requirement.rb index 8b2d21fe8d9..9769522b65b 100644 --- a/elm/lib/dependabot/elm/requirement.rb +++ b/elm/lib/dependabot/elm/requirement.rb @@ -8,7 +8,7 @@ module Elm class Requirement < Gem::Requirement ELM_PATTERN_RAW = "(#{Elm::Version::VERSION_PATTERN}) (<=?) v (<=?) " \ - "(#{Elm::Version::VERSION_PATTERN})" + "(#{Elm::Version::VERSION_PATTERN})".freeze ELM_PATTERN = /\A#{ELM_PATTERN_RAW}\z/ ELM_EXACT_PATTERN = /\A#{Elm::Version::VERSION_PATTERN}\z/ diff --git a/go_modules/lib/dependabot/go_modules/requirement.rb b/go_modules/lib/dependabot/go_modules/requirement.rb index c7dfa6be5f1..54139658dfe 100644 --- a/go_modules/lib/dependabot/go_modules/requirement.rb +++ b/go_modules/lib/dependabot/go_modules/requirement.rb @@ -19,7 +19,7 @@ class Requirement < Gem::Requirement quoted = OPS.keys.map { |k| Regexp.quote(k) }.join("|") version_pattern = "v?#{Version::VERSION_PATTERN}" - PATTERN_RAW = "\\s*(#{quoted})?\\s*(#{version_pattern})\\s*" + PATTERN_RAW = "\\s*(#{quoted})?\\s*(#{version_pattern})\\s*".freeze PATTERN = /\A#{PATTERN_RAW}\z/ # Use GoModules::Version rather than Gem::Version to ensure that diff --git a/gradle/lib/dependabot/gradle/requirement.rb b/gradle/lib/dependabot/gradle/requirement.rb index 956fbd85b93..7f62d296933 100644 --- a/gradle/lib/dependabot/gradle/requirement.rb +++ b/gradle/lib/dependabot/gradle/requirement.rb @@ -8,7 +8,7 @@ module Dependabot module Gradle class Requirement < Gem::Requirement quoted = OPS.keys.map { |k| Regexp.quote k }.join("|") - PATTERN_RAW = "\\s*(#{quoted})?\\s*(#{Gradle::Version::VERSION_PATTERN})\\s*" + PATTERN_RAW = "\\s*(#{quoted})?\\s*(#{Gradle::Version::VERSION_PATTERN})\\s*".freeze PATTERN = /\A#{PATTERN_RAW}\z/ def self.parse(obj) diff --git a/hex/lib/dependabot/hex/requirement.rb b/hex/lib/dependabot/hex/requirement.rb index c6d60272414..7e7bcae4584 100644 --- a/hex/lib/dependabot/hex/requirement.rb +++ b/hex/lib/dependabot/hex/requirement.rb @@ -14,7 +14,7 @@ class Requirement < Gem::Requirement # Override the version pattern to allow local versions quoted = OPS.keys.map { |k| Regexp.quote k }.join "|" - PATTERN_RAW = "\\s*(#{quoted})?\\s*(#{Hex::Version::VERSION_PATTERN})\\s*" + PATTERN_RAW = "\\s*(#{quoted})?\\s*(#{Hex::Version::VERSION_PATTERN})\\s*".freeze PATTERN = /\A#{PATTERN_RAW}\z/ # Returns an array of requirements. At least one requirement from the diff --git a/maven/lib/dependabot/maven/requirement.rb b/maven/lib/dependabot/maven/requirement.rb index 89b9faf0e0c..74f8b9fe25b 100644 --- a/maven/lib/dependabot/maven/requirement.rb +++ b/maven/lib/dependabot/maven/requirement.rb @@ -8,7 +8,7 @@ module Maven class Requirement < Gem::Requirement quoted = OPS.keys.map { |k| Regexp.quote k }.join("|") OR_SYNTAX = /(?<=\]|\)),/ - PATTERN_RAW = "\\s*(#{quoted})?\\s*(#{Maven::Version::VERSION_PATTERN})\\s*" + PATTERN_RAW = "\\s*(#{quoted})?\\s*(#{Maven::Version::VERSION_PATTERN})\\s*".freeze PATTERN = /\A#{PATTERN_RAW}\z/ def self.parse(obj) diff --git a/npm_and_yarn/lib/dependabot/npm_and_yarn/requirement.rb b/npm_and_yarn/lib/dependabot/npm_and_yarn/requirement.rb index c6c4f1977bc..fc3647be8ba 100644 --- a/npm_and_yarn/lib/dependabot/npm_and_yarn/requirement.rb +++ b/npm_and_yarn/lib/dependabot/npm_and_yarn/requirement.rb @@ -14,7 +14,7 @@ class Requirement < Gem::Requirement quoted = OPS.keys.map { |k| Regexp.quote(k) }.join("|") version_pattern = "v?#{NpmAndYarn::Version::VERSION_PATTERN}" - PATTERN_RAW = "\\s*(#{quoted})?\\s*(#{version_pattern})\\s*" + PATTERN_RAW = "\\s*(#{quoted})?\\s*(#{version_pattern})\\s*".freeze PATTERN = /\A#{PATTERN_RAW}\z/ def self.parse(obj) diff --git a/omnibus/.rubocop.yml b/omnibus/.rubocop.yml index 76e637764f0..429e5397290 100644 --- a/omnibus/.rubocop.yml +++ b/omnibus/.rubocop.yml @@ -335,5 +335,3 @@ Style/SelectByRegexp: # a follow-on PR. Naming/BlockForwarding: Enabled: false -Style/MutableConstant: - Enabled: false diff --git a/pub/lib/dependabot/pub/requirement.rb b/pub/lib/dependabot/pub/requirement.rb index 0c6c3d7cabf..7da062ab1e3 100644 --- a/pub/lib/dependabot/pub/requirement.rb +++ b/pub/lib/dependabot/pub/requirement.rb @@ -14,7 +14,7 @@ class Requirement < Gem::Requirement quoted = OPS.keys.map { |k| Regexp.quote(k) }.join("|") version_pattern = Pub::Version::VERSION_PATTERN - PATTERN_RAW = "\\s*(#{quoted})?\\s*(#{version_pattern})\\s*" + PATTERN_RAW = "\\s*(#{quoted})?\\s*(#{version_pattern})\\s*".freeze PATTERN = /\A#{PATTERN_RAW}\z/ # Use Pub::Version rather than Gem::Version to ensure that diff --git a/python/lib/dependabot/python/file_fetcher.rb b/python/lib/dependabot/python/file_fetcher.rb index a5de350fc91..aed830021fb 100644 --- a/python/lib/dependabot/python/file_fetcher.rb +++ b/python/lib/dependabot/python/file_fetcher.rb @@ -13,7 +13,7 @@ module Python class FileFetcher < Dependabot::FileFetchers::Base CHILD_REQUIREMENT_REGEX = /^-r\s?(?.*\.(?:txt|in))/ CONSTRAINT_REGEX = /^-c\s?(?.*\.(?:txt|in))/ - DEPENDENCY_TYPES = %w(packages dev-packages) + DEPENDENCY_TYPES = %w(packages dev-packages).freeze def self.required_files_in?(filenames) return true if filenames.any? { |name| name.end_with?(".txt", ".in") } diff --git a/python/lib/dependabot/python/requirement.rb b/python/lib/dependabot/python/requirement.rb index 965c992d782..e29af315db1 100644 --- a/python/lib/dependabot/python/requirement.rb +++ b/python/lib/dependabot/python/requirement.rb @@ -18,7 +18,7 @@ class Requirement < Gem::Requirement map { |k| Regexp.quote(k) }.join("|") version_pattern = Python::Version::VERSION_PATTERN - PATTERN_RAW = "\\s*(#{quoted})?\\s*(#{version_pattern})\\s*" + PATTERN_RAW = "\\s*(#{quoted})?\\s*(#{version_pattern})\\s*".freeze PATTERN = /\A#{PATTERN_RAW}\z/ PARENS_PATTERN = /\A\(([^)]+)\)\z/ diff --git a/terraform/lib/dependabot/terraform/requirement.rb b/terraform/lib/dependabot/terraform/requirement.rb index b92c980a266..7963c597d4e 100644 --- a/terraform/lib/dependabot/terraform/requirement.rb +++ b/terraform/lib/dependabot/terraform/requirement.rb @@ -11,7 +11,7 @@ class Requirement < Gem::Requirement # optional 'v' prefix to release tag names, which Terraform supports. # https://www.terraform.io/docs/registry/modules/publish.html#requirements OPERATORS = OPS.keys.map { |key| Regexp.quote(key) }.join("|").freeze - PATTERN_RAW = "\\s*(#{OPERATORS})?\\s*v?(#{Gem::Version::VERSION_PATTERN})\\s*" + PATTERN_RAW = "\\s*(#{OPERATORS})?\\s*v?(#{Gem::Version::VERSION_PATTERN})\\s*".freeze PATTERN = /\A#{PATTERN_RAW}\z/ def self.parse(obj) diff --git a/updater/lib/dependabot/job.rb b/updater/lib/dependabot/job.rb index 4e8e0df899f..da87e6798dd 100644 --- a/updater/lib/dependabot/job.rb +++ b/updater/lib/dependabot/job.rb @@ -42,7 +42,7 @@ class Job dependency_groups dependency_group_to_refresh repo_private - ) + ).freeze attr_reader :allowed_updates, :credentials, diff --git a/updater/lib/dependabot/updater/operations.rb b/updater/lib/dependabot/updater/operations.rb index 2d365ef0e69..a8759a4339e 100644 --- a/updater/lib/dependabot/updater/operations.rb +++ b/updater/lib/dependabot/updater/operations.rb @@ -35,7 +35,7 @@ module Operations RefreshVersionUpdatePullRequest, GroupUpdateAllVersions, UpdateAllVersions - ] + ].freeze def self.class_for(job:) # Let's not bother generating the string if debug is disabled