52 lines
1.3 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2019-10-04 09:47:54 +02:00
require "json"
require "style"
2019-10-04 09:47:54 +02:00
2018-09-06 08:29:14 +02:00
module Cask
2018-09-04 08:45:48 +01:00
class Cmd
2020-08-19 10:34:07 +02:00
# Implementation of the `brew cask style` command.
#
# @api private
2017-05-20 19:08:03 +02:00
class Style < AbstractCommand
2020-08-01 02:30:46 +02:00
def self.description
"Checks style of the given <cask> using RuboCop."
end
def self.parser
super do
switch "--fix",
description: "Fix style violations automatically using RuboCop's auto-correct feature."
end
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
2019-10-04 09:47:54 +02:00
def run
success = Homebrew::Style.check_style_and_print(
cask_paths,
fix: args.fix?,
debug: args.debug?,
verbose: args.verbose?,
)
raise CaskError, "Style check failed." unless success
2016-08-18 22:11:42 +03:00
end
2016-09-24 13:52:43 +02:00
def cask_paths
2020-08-01 02:30:46 +02:00
@cask_paths ||= if args.named.empty?
Tap.map(&:cask_dir).select(&:directory?).concat(test_cask_paths)
2020-08-01 02:30:46 +02:00
elsif args.named.any? { |file| File.exist?(file) }
args.named.map { |path| Pathname(path).expand_path }
else
casks.map(&:sourcefile_path)
end
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
def test_cask_paths
[
Pathname.new("#{HOMEBREW_LIBRARY}/Homebrew/test/support/fixtures/cask/Casks"),
Pathname.new("#{HOMEBREW_LIBRARY}/Homebrew/test/support/fixtures/third-party/Casks"),
]
end
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
end
end