Class: RuboCop::Cop::Sorbet::ValidGemVersionAnnotations
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Sorbet::ValidGemVersionAnnotations
- Includes:
- GemVersionAnnotationHelper
- Defined in:
- lib/rubocop/cop/sorbet/rbi_versioning/valid_gem_version_annotations.rb
Overview
Checks that gem versions in RBI annotations are properly formatted per the Bundler gem specification.
Constant Summary collapse
- MSG =
"Invalid gem version(s) detected: %<versions>s"
- VALID_OPERATORS =
["=", "!=", ">", ">=", "<", "<=", "~>"]
Constants included from GemVersionAnnotationHelper
GemVersionAnnotationHelper::VERSION_PREFIX
Instance Method Summary collapse
Methods included from GemVersionAnnotationHelper
Instance Method Details
#on_new_investigation ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rubocop/cop/sorbet/rbi_versioning/valid_gem_version_annotations.rb', line 27 def on_new_investigation gem_version_annotations.each do |comment| gem_versions = gem_versions(comment) if gem_versions.empty? = format(MSG, versions: "empty version") add_offense(comment, message: ) break end invalid_versions = gem_versions.reject do |version| valid_version?(version) end unless invalid_versions.empty? = format(MSG, versions: invalid_versions.map(&:strip).join(", ")) add_offense(comment, message: ) end end end |