class HamlLint::RakeTask


rake ‘haml_lint[app/views/*/.haml, other_files/*/.haml]’
# glob expansion and allow us to have a space after commas):
# …and then execute from the command line (single quotes prevent shell
HamlLint::RakeTask.new
require ‘haml_lint/rake_task’
# Add the following to your Rakefile…
@example
You can also specify the list of files as explicit task arguments:
rake haml_lint
# …and then execute from the command line:
end
t.quiet = true # Don’t display output from haml-lint
t.files = %w[app/views/*/.haml custom/*.haml]
t.config = ‘path/to/custom/haml-lint.yml’
HamlLint::RakeTask.new do |t|
require ‘haml_lint/rake_task’
# Add the following to your Rakefile…
@example
Rake task interface for haml-lint command line interface.

def config

Returns:
  • (String) -
def config
  @config&.path
end

def config=(config)

Parameters:
  • config (String, File) --
def config=(config)
  @config = config.is_a?(String) ? File.open(config, 'r') : config
end

def default_description

Returns:
  • (String) -
def default_description
  description = "Run `#{HamlLint::APP_NAME}"
  description += " --config #{config}" if config
  description += " #{files.join(' ')}" if files.any?
  description += ' [files...]`'
  description
end

def define

Defines the Rake task.
def define
  desc default_description unless ::Rake.application.last_description
  task(name, [:files]) do |_task, task_args|
    # Lazy-load so task doesn't affect Rakefile load time
    require_relative 'cli'
    run_cli(task_args)
  end
end

def files_to_lint(task_args)

Parameters:
  • task_args (Rake::TaskArguments) --
def files_to_lint(task_args)
  # NOTE: we're abusing Rake's argument handling a bit here. We call the
  # first argument `files` but it's actually only the first file--we pull
  # the rest out of the `extras` from the task arguments. This is so we
  # can specify an arbitrary list of files separated by commas on the
  # command line or in a custom task definition.
  explicit_files = Array(task_args[:files]) + Array(task_args.extras)
  explicit_files.any? ? explicit_files : files
end

def initialize(name = :haml_lint)

Parameters:
  • name (Symbol) -- task name
def initialize(name = :haml_lint)
  @name = name
  @files = ['.'] # Search for everything under current directory by default
  @quiet = false
  yield self if block_given?
  define
end

def parse_args

def parse_args
  cli_args = config ? ['--config', config] : []
  cli_args.concat(['--fail-level', fail_level]) if fail_level
  cli_args
end

def run_cli(task_args)

Parameters:
  • task_args (Rake::TaskArguments) --
def run_cli(task_args)
  cli_args = parse_args
  logger = quiet ? HamlLint::Logger.silent : nil
  result = HamlLint::CLI.new(logger).run(Array(cli_args) + files_to_lint(task_args))
  fail "#{HamlLint::APP_NAME} failed with exit code #{result}" unless result == 0
end