Class: HamlLint::RakeTask

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/haml_lint/rake_task.rb

Overview

Rake task interface for haml-lint command line interface.

You can also specify the list of files as explicit task arguments:

Examples:

# Add the following to your Rakefile...
require 'haml_lint/rake_task'

HamlLint::RakeTask.new do |t|
  t.config = 'path/to/custom/haml-lint.yml'
  t.files = %w[app/views/**/*.haml custom/*.haml]
  t.quiet = true # Don't display output from haml-lint
end

# ...and then execute from the command line:
rake haml_lint
# Add the following to your Rakefile...
require 'haml_lint/rake_task'

HamlLint::RakeTask.new

# ...and then execute from the command line (single quotes prevent shell
# glob expansion and allow us to have a space after commas):
rake 'haml_lint[app/views/**/*.haml, other_files/**/*.haml]'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = :haml_lint) {|_self| ... } ⇒ RakeTask

Create the task so it exists in the current namespace.

Parameters:

  • name (Symbol) (defaults to: :haml_lint)

    task name

Yields:

  • (_self)

Yield Parameters:


78
79
80
81
82
83
84
85
86
# File 'lib/haml_lint/rake_task.rb', line 78

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

Instance Attribute Details

#fail_levelString

The severity level above which we should fail the Rake task.

Examples:

HamlLint::RakeTask.new do |task|
  task.fail_level = 'error'
end

Returns:

  • (String)

73
74
75
# File 'lib/haml_lint/rake_task.rb', line 73

def fail_level
  @fail_level
end

#filesArray<String>

List of files to lint (can contain shell globs).

Note that this will be ignored if you explicitly pass a list of files as task arguments via the command line or a task definition.

Returns:

  • (Array<String>)

58
59
60
# File 'lib/haml_lint/rake_task.rb', line 58

def files
  @files
end

#nameString

Name of the task.

Returns:

  • (String)

38
39
40
# File 'lib/haml_lint/rake_task.rb', line 38

def name
  @name
end

#quiettrue, false

Whether output from haml-lint should not be displayed to the standard out stream.

Returns:

  • (true, false)

63
64
65
# File 'lib/haml_lint/rake_task.rb', line 63

def quiet
  @quiet
end

Instance Method Details

#configString

Return the configuration file path.

Returns:

  • (String)

49
50
51
# File 'lib/haml_lint/rake_task.rb', line 49

def config
  @config&.path
end

#config=(config) ⇒ Object

Set the configuration file or path.

Parameters:

  • config (String, File)

43
44
45
# File 'lib/haml_lint/rake_task.rb', line 43

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