rubocops (cask/url): add rubocop to use csv instead of before_comma and after_comma in cask
This commit is contained in:
parent
0b14b6d76d
commit
d5448ff54a
29
Library/Homebrew/rubocops/cask/mixin/on_url_stanza.rb
Normal file
29
Library/Homebrew/rubocops/cask/mixin/on_url_stanza.rb
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
# typed: false
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module RuboCop
|
||||||
|
module Cop
|
||||||
|
module Cask
|
||||||
|
# Common functionality for checking url stanzas.
|
||||||
|
module OnUrlStanza
|
||||||
|
extend Forwardable
|
||||||
|
include CaskHelp
|
||||||
|
|
||||||
|
def on_cask(cask_block)
|
||||||
|
@cask_block = cask_block
|
||||||
|
|
||||||
|
toplevel_stanzas.select(&:url?).each do |stanza|
|
||||||
|
on_url_stanza(stanza)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
attr_reader :cask_block
|
||||||
|
|
||||||
|
def_delegators :cask_block,
|
||||||
|
:toplevel_stanzas
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,35 @@
|
|||||||
|
# typed: true
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "forwardable"
|
||||||
|
require "uri"
|
||||||
|
|
||||||
|
module RuboCop
|
||||||
|
module Cop
|
||||||
|
module Cask
|
||||||
|
# This cop checks for version.before_comma and version.after_comma
|
||||||
|
class UrlLegacyCommaSeparators < Base
|
||||||
|
include OnUrlStanza
|
||||||
|
extend AutoCorrector
|
||||||
|
|
||||||
|
MSG_CSV = "Use 'version.csv.first' instead of 'version.before_comma' and 'version.csv.second' instead of 'version.after_comma'."
|
||||||
|
|
||||||
|
def on_url_stanza(stanza)
|
||||||
|
url_node = stanza.stanza_node.first_argument
|
||||||
|
|
||||||
|
legacy_comma_separator_pattern = /version.(before|after)_comma/
|
||||||
|
|
||||||
|
url = url_node.source
|
||||||
|
|
||||||
|
return unless url.match?(legacy_comma_separator_pattern)
|
||||||
|
|
||||||
|
corrected_url = url.sub("before_comma", "csv.first")&.sub("after_comma", "csv.second")
|
||||||
|
|
||||||
|
add_offense(url_node.loc.expression, message: format(MSG_CSV, url: url)) do |corrector|
|
||||||
|
corrector.replace(url_node.source_range, corrected_url)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -12,8 +12,10 @@ require_relative "cask/extend/string"
|
|||||||
require_relative "cask/extend/node"
|
require_relative "cask/extend/node"
|
||||||
require_relative "cask/mixin/cask_help"
|
require_relative "cask/mixin/cask_help"
|
||||||
require_relative "cask/mixin/on_homepage_stanza"
|
require_relative "cask/mixin/on_homepage_stanza"
|
||||||
|
require_relative "cask/mixin/on_url_stanza"
|
||||||
require_relative "cask/desc"
|
require_relative "cask/desc"
|
||||||
require_relative "cask/homepage_url_trailing_slash"
|
require_relative "cask/homepage_url_trailing_slash"
|
||||||
require_relative "cask/no_dsl_version"
|
require_relative "cask/no_dsl_version"
|
||||||
require_relative "cask/stanza_order"
|
require_relative "cask/stanza_order"
|
||||||
require_relative "cask/stanza_grouping"
|
require_relative "cask/stanza_grouping"
|
||||||
|
require_relative "cask/url_legacy_comma_separators"
|
||||||
|
@ -3,7 +3,7 @@ cask "hockeyapp-with-appcast" do
|
|||||||
sha256 "a69e7357bea014f4c14ac9699274f559086844ffa46563c4619bf1addfd72ad9"
|
sha256 "a69e7357bea014f4c14ac9699274f559086844ffa46563c4619bf1addfd72ad9"
|
||||||
|
|
||||||
# rink.hockeyapp.net/api/2/apps/67503a7926431872c4b6c1549f5bd6b1 was verified as official when first introduced to the cask
|
# rink.hockeyapp.net/api/2/apps/67503a7926431872c4b6c1549f5bd6b1 was verified as official when first introduced to the cask
|
||||||
url "https://rink.hockeyapp.net/api/2/apps/67503a7926431872c4b6c1549f5bd6b1/app_versions/#{version.after_comma}?format=zip"
|
url "https://rink.hockeyapp.net/api/2/apps/67503a7926431872c4b6c1549f5bd6b1/app_versions/#{version.csv.second}?format=zip"
|
||||||
appcast "https://rink.hockeyapp.net/api/2/apps/67503a7926431872c4b6c1549f5bd6b1"
|
appcast "https://rink.hockeyapp.net/api/2/apps/67503a7926431872c4b6c1549f5bd6b1"
|
||||||
name "HockeyApp"
|
name "HockeyApp"
|
||||||
homepage "https://www.brew.sh/"
|
homepage "https://www.brew.sh/"
|
||||||
|
@ -3,7 +3,7 @@ cask "hockeyapp-without-appcast" do
|
|||||||
sha256 "a69e7357bea014f4c14ac9699274f559086844ffa46563c4619bf1addfd72ad9"
|
sha256 "a69e7357bea014f4c14ac9699274f559086844ffa46563c4619bf1addfd72ad9"
|
||||||
|
|
||||||
# rink.hockeyapp.net/api/2/apps/67503a7926431872c4b6c1549f5bd6b1 was verified as official when first introduced to the cask
|
# rink.hockeyapp.net/api/2/apps/67503a7926431872c4b6c1549f5bd6b1 was verified as official when first introduced to the cask
|
||||||
url "https://rink.hockeyapp.net/api/2/apps/67503a7926431872c4b6c1549f5bd6b1/app_versions/#{version.after_comma}?format=zip"
|
url "https://rink.hockeyapp.net/api/2/apps/67503a7926431872c4b6c1549f5bd6b1/app_versions/#{version.csv.second}?format=zip"
|
||||||
name "HockeyApp"
|
name "HockeyApp"
|
||||||
homepage "https://www.brew.sh/"
|
homepage "https://www.brew.sh/"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user