Sam Ford 17b0493e18
Use struct for #audit_formula args
Adding type signatures to `#audit_formula` methods in formula cops
would lead to verbose, repetitive signatures across the existing ~63
instances. This reworks `#audit_formula` to use a `T::Struct` for its
arguments, which allows us to use a one-line signature for these
methods.
2024-07-08 12:22:25 -04:00

30 lines
883 B
Ruby

# typed: true
# frozen_string_literal: true
require "rubocops/extend/formula_cop"
module RuboCop
module Cop
module FormulaAudit
# This cop makes sure that a `version` is in the correct format.
class Version < FormulaCop
sig { override.params(formula_nodes: FormulaNodes).void }
def audit_formula(formula_nodes)
version_node = find_node_method_by_name(formula_nodes.body_node, :version)
return unless version_node
version = string_content(parameters(version_node).first)
problem "version is set to an empty string" if version.empty?
problem "version #{version} should not have a leading 'v'" if version.start_with?("v")
return unless version.match?(/_\d+$/)
problem "version #{version} should not end with an underline and a number"
end
end
end
end
end