class

Ameba::Rule::Style::CallParentheses

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

A rule that enforces usage of parentheses in method or macro calls.

For example, this (and all of its variants) is considered invalid:

user.update name: "John", age: 30

And should be replaced by the following:

user.update(name: "John", age: 30)

Options

  • ExcludeMultilineCalls — controls whether multiline calls should be checked.

  • ExcludeTypeDeclarations — controls whether calls with type declarations should be checked.

  • ExcludeHeredocs — controls whether calls with heredoc arguments should be checked.

  • ExcludedToplevelCallNames — contains a list of top-level method names that should not be checked.

  • ExcludedCallNames — contains a list of non-top-level method names that should not be checked.

  • ExcludedDslCallNames — contains a list of DSL method names that should not be checked.

    Each entry should contain a full call chain path, with method names separated by >, e.g. properties > where, or builder > properties > query.

    Only calls with a block and no receiver are taken into account, e.g.:

      class UserQuery
        builder do
          scope :default do
            where { deleted_at.nil? } # UserQuery > builder > scope > where
          end
    
          organizations.each do |org|
            scope "org_#{org.name.camelcase}" do
              where { id == org.id } # UserQuery > builder > scope > where
            end
          end
        end
      end

    You can use * as a wildcard to match any method name and ** to match any method name at any depth, e.g. ** > where, or ** > where > *.

YAML configuration example:

Style/CallParentheses:
  Enabled: true
  ExcludeMultilineCalls: true
  ExcludeTypeDeclarations: true
  ExcludeHeredocs: true
  ExcludedToplevelCallNames: [spawn, raise, super, previous_def, exit, abort, sleep, print, printf, puts, p, p!, pp, pp!, record, class_getter, class_getter?, class_getter!, class_property, class_property?, class_property!, class_setter, getter, getter?, getter!, property, property?, property!, setter, def_equals_and_hash, def_equals, def_hash, delegate, forward_missing_to, describe, context, it, pending, pending!, fail, eq, be, be_a, be_close, contain, start_with, end_with, match, use_json_discriminator]
  ExcludedCallNames: [should, should_not]
  ExcludedDslCallNames: []

Constants

CALL_NAMES_SEPARATOR = " > "
MSG = "Missing parentheses in method call"

Constructors

new(config = nil)

A rule that enforces usage of parentheses in method or macro calls.

For example, this (and all of its variants) is considered invalid:

user.update name: "John", age: 30

And should be replaced by the following:

user.update(name: "John", age: 30)

Options

  • ExcludeMultilineCalls — controls whether multiline calls should be checked.

  • ExcludeTypeDeclarations — controls whether calls with type declarations should be checked.

  • ExcludeHeredocs — controls whether calls with heredoc arguments should be checked.

  • ExcludedToplevelCallNames — contains a list of top-level method names that should not be checked.

  • ExcludedCallNames — contains a list of non-top-level method names that should not be checked.

  • ExcludedDslCallNames — contains a list of DSL method names that should not be checked.

    Each entry should contain a full call chain path, with method names separated by >, e.g. properties > where, or builder > properties > query.

    Only calls with a block and no receiver are taken into account, e.g.:

      class UserQuery
        builder do
          scope :default do
            where { deleted_at.nil? } # UserQuery > builder > scope > where
          end
    
          organizations.each do |org|
            scope "org_#{org.name.camelcase}" do
              where { id == org.id } # UserQuery > builder > scope > where
            end
          end
        end
      end

    You can use * as a wildcard to match any method name and ** to match any method name at any depth, e.g. ** > where, or ** > where > *.

YAML configuration example:

Style/CallParentheses:
  Enabled: true
  ExcludeMultilineCalls: true
  ExcludeTypeDeclarations: true
  ExcludeHeredocs: true
  ExcludedToplevelCallNames: [spawn, raise, super, previous_def, exit, abort, sleep, print, printf, puts, p, p!, pp, pp!, record, class_getter, class_getter?, class_getter!, class_property, class_property?, class_property!, class_setter, getter, getter?, getter!, property, property?, property!, setter, def_equals_and_hash, def_equals, def_hash, delegate, forward_missing_to, describe, context, it, pending, pending!, fail, eq, be, be_a, be_close, contain, start_with, end_with, match, use_json_discriminator]
  ExcludedCallNames: [should, should_not]
  ExcludedDslCallNames: []
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

description
description=(description : String)
enabled=(enabled : Bool)
enabled?
exclude_heredocs=(exclude_heredocs : Bool)
exclude_heredocs?
exclude_multiline_calls=(exclude_multiline_calls : Bool)
exclude_multiline_calls?
exclude_type_declarations=(exclude_type_declarations : Bool)
exclude_type_declarations?
excluded
excluded=(excluded : Set(String) | Nil)
excluded_call_names
excluded_call_names=(excluded_call_names : Array(String))
excluded_dsl_call_names
excluded_dsl_call_names=(excluded_dsl_call_names : Array(String))
excluded_toplevel_call_names
excluded_toplevel_call_names=(excluded_toplevel_call_names : Array(String))
severity
severity=(severity : Ameba::Severity)
since_version
Source
since_version=(since_version : String)
test(source)
Source