class

Ameba::Rule::Style::HeredocIndent

Inherits Ameba::AST::Util < YAML::Serializable < Ameba::Rule::Base < Ameba::Config::RuleConfig < Reference < Object

A rule that enforces heredoc bodies be indented one level above the indentation of the line they're used on.

For example, this is considered invalid:

<<-HEREDOC
  hello world
HEREDOC

  <<-HEREDOC
hello world
HEREDOC

And should be written as:

<<-HEREDOC
    hello world
  HEREDOC

<<-HEREDOC
  hello world
  HEREDOC

The IndentBy configuration option changes the enforced indentation level of the heredoc.

If BodyAutoDedent is enabled (default), the body of the heredoc will be automatically dedented to the minimum indentation level of the body lines.

For example:

<<-HEREDOC
  <article>
    ...
  </article>
HEREDOC

Will be automatically dedented to:

<<-HEREDOC
  <article>
    ...
  </article>
  HEREDOC

YAML configuration example:

Style/HeredocIndent:
  Enabled: true
  IndentBy: 2
  BodyAutoDedent: true

Constants

MSG = "Heredoc body should be indented by %d spaces"

Constructors

new(config = nil)

A rule that enforces heredoc bodies be indented one level above the indentation of the line they're used on.

For example, this is considered invalid:

<<-HEREDOC
  hello world
HEREDOC

  <<-HEREDOC
hello world
HEREDOC

And should be written as:

<<-HEREDOC
    hello world
  HEREDOC

<<-HEREDOC
  hello world
  HEREDOC

The IndentBy configuration option changes the enforced indentation level of the heredoc.

If BodyAutoDedent is enabled (default), the body of the heredoc will be automatically dedented to the minimum indentation level of the body lines.

For example:

<<-HEREDOC
  <article>
    ...
  </article>
HEREDOC

Will be automatically dedented to:

<<-HEREDOC
  <article>
    ...
  </article>
  HEREDOC

YAML configuration example:

Style/HeredocIndent:
  Enabled: true
  IndentBy: 2
  BodyAutoDedent: true
Source
new(*, __context_for_yaml_serializable ctx : YAML::ParseContext, __node_for_yaml_serializable node : YAML::Nodes::Node)

Class methods

deprecated?

Returns true if this rule is deprecated, false otherwise.

deprecation_reason

Returns the deprecation reason for this rule, if there is any.

documentation_url

Returns the documentation URL for this rule.

Ameba::Rule::Lint::Syntax.documentation_url
# => "https://crystal-ameba.org/api/master/Ameba/Rule/Lint/Syntax.html"
parsed_doc

Returns the documentation for this rule, if there is any.

module Ameba
  # This is a test rule.
  # Does nothing.
  class Rule::MyRule < Rule::Base
    def test(source)
    end
  end
end

Ameba::Rule::MyRule.parsed_doc # => "This is a test rule.\nDoes nothing."
to_json_schema(builder : JSON::Builder) : Nil
Source

Instance methods

body_auto_dedent=(body_auto_dedent : Bool)
body_auto_dedent?
description
description=(description : String)
enabled=(enabled : Bool)
enabled?
excluded
excluded=(excluded : Set(String) | Nil)
indent_by
indent_by=(indent_by : Int32)
severity
severity=(severity : Ameba::Severity)
since_version
Source
since_version=(since_version : String)
test(source, node : Crystal::StringInterpolation)
Source