class

Ameba::Rule::Style::PercentLiteralDelimiters

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

A rule that enforces the consistent usage of %-literal delimiters.

Specifying DefaultDelimiters option will set all preferred delimiters at once. You can continue to specify individual preferred delimiters via PreferredDelimiters setting to override the default. In both cases the delimiters should be specified as a string of two characters, or nil to ignore a particular %-literal / default.

Setting IgnoreLiteralsContainingDelimiters to true will ignore %-literals that contain one or both delimiters.

YAML configuration example:

Style/PercentLiteralDelimiters:
  Enabled: true
  DefaultDelimiters: '()'
  PreferredDelimiters:
    '%w': '[]'
    '%i': '[]'
    '%r': '{}'
  IgnoreLiteralsContainingDelimiters: false

Constants

MSG = "`%s`-literals should be delimited by `%s` and `%s`"

Constructors

new(config = nil)

A rule that enforces the consistent usage of %-literal delimiters.

Specifying DefaultDelimiters option will set all preferred delimiters at once. You can continue to specify individual preferred delimiters via PreferredDelimiters setting to override the default. In both cases the delimiters should be specified as a string of two characters, or nil to ignore a particular %-literal / default.

Setting IgnoreLiteralsContainingDelimiters to true will ignore %-literals that contain one or both delimiters.

YAML configuration example:

Style/PercentLiteralDelimiters:
  Enabled: true
  DefaultDelimiters: '()'
  PreferredDelimiters:
    '%w': '[]'
    '%i': '[]'
    '%r': '{}'
  IgnoreLiteralsContainingDelimiters: false
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

default_delimiters
default_delimiters=(default_delimiters : Union(String, Nil))
description
description=(description : String)
enabled=(enabled : Bool)
enabled?
excluded
excluded=(excluded : Set(String) | Nil)
ignore_literals_containing_delimiters=(ignore_literals_containing_delimiters : Bool)
ignore_literals_containing_delimiters?
preferred_delimiters
preferred_delimiters=(preferred_delimiters : Hash(String, Nil | String))
severity
severity=(severity : Ameba::Severity)
since_version
Source
since_version=(since_version : String)
test(source)
Source