Class: RuboCop::Cop::FormulaAudit::OptionDeclarations

Inherits:
RuboCop::Cop::FormulaCop show all
Defined in:
brew/Library/Homebrew/rubocops/lines.rb

Instance Attribute Summary

Attributes inherited from RuboCop::Cop::FormulaCop

#file_path

Instance Method Summary collapse

Methods inherited from RuboCop::Cop::FormulaCop

#audit_comments, #audit_urls, #block_size, #caveats_strings, #check_precedence, #class_name, #component_precedes?, #depends_on?, #depends_on_name_type?, #end_column, #expression_negated?, #find_all_blocks, #find_block, #find_blocks, #find_const, #find_every_func_call_by_name, #find_every_method_call_by_name, #find_instance_call, #find_instance_method_call, #find_method_calls_by_name, #find_method_def, #find_method_with_args, #find_node_method_by_name, #find_strings, #format_component, #formula_tap, #get_checksum_node, #line_number, #line_start_column, #method_called?, #method_called_ever?, #method_called_in_block?, #method_name, #node_equals?, #offending_node, #on_class, #parameters, #parameters_passed?, #problem, #regex_match_group, #size, #source_buffer, #start_column, #string_content, #versioned_formula?

Instance Method Details

#audit_formula(_node, _class_node, _parent_class_node, body_node) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'brew/Library/Homebrew/rubocops/lines.rb', line 93

def audit_formula(_node, _class_node, _parent_class_node, body_node)
  problem "Use new-style option definitions" if find_method_def(body_node, :options)

  find_instance_method_call(body_node, :build, :without?) do |method|
    next unless unless_modifier?(method.parent)

    correct = method.source.gsub("out?", "?")
    problem "Use if #{correct} instead of unless #{method.source}"
  end

  find_instance_method_call(body_node, :build, :with?) do |method|
    next unless unless_modifier?(method.parent)

    correct = method.source.gsub("?", "out?")
    problem "Use if #{correct} instead of unless #{method.source}"
  end

  find_instance_method_call(body_node, :build, :with?) do |method|
    next unless expression_negated?(method)

    problem "Don't negate 'build.with?': use 'build.without?'"
  end

  find_instance_method_call(body_node, :build, :without?) do |method|
    next unless expression_negated?(method)

    problem "Don't negate 'build.without?': use 'build.with?'"
  end

  find_instance_method_call(body_node, :build, :without?) do |method|
    arg = parameters(method).first
    next unless match = regex_match_group(arg, /^-?-?without-(.*)/)

    problem "Don't duplicate 'without': " \
            "Use `build.without? \"#{match[1]}\"` to check for \"--without-#{match[1]}\""
  end

  find_instance_method_call(body_node, :build, :with?) do |method|
    arg = parameters(method).first
    next unless match = regex_match_group(arg, /^-?-?with-(.*)/)

    problem "Don't duplicate 'with': Use `build.with? \"#{match[1]}\"` to check for \"--with-#{match[1]}\""
  end

  find_instance_method_call(body_node, :build, :include?) do |method|
    arg = parameters(method).first
    next unless match = regex_match_group(arg, /^with(out)?-(.*)/)

    problem "Use build.with#{match[1]}? \"#{match[2]}\" instead of " \
            "build.include? 'with#{match[1]}-#{match[2]}'"
  end

  find_instance_method_call(body_node, :build, :include?) do |method|
    arg = parameters(method).first
    next unless match = regex_match_group(arg, /^\-\-(.*)$/)

    problem "Reference '#{match[1]}' without dashes"
  end
end

#unless_modifier?(node) ⇒ Boolean

Returns:

  • (Boolean)


153
154
155
156
157
# File 'brew/Library/Homebrew/rubocops/lines.rb', line 153

def unless_modifier?(node)
  return false unless node.if_type?

  node.modifier_form? && node.unless?
end