Skip to content

Commit

Permalink
Disable max-code-lines* at cmd line, refs turboladen#117.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Crump committed Aug 12, 2013
1 parent 1434435 commit 0465e42
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
4 changes: 2 additions & 2 deletions lib/tailor/cli/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ def self.parse!(args)
opt.separator ""
opt.separator " * Vertical Spacing"

opt.on('--max-code-lines-in-class NUMBER', Integer,
opt.on('--max-code-lines-in-class NUMBER', IntegerOrDisabled,
'Max number lines of code in a class.', '(default: 300)') do |c|
options.style[:max_code_lines_in_class] = c
end

opt.on('--max-code-lines-in-method NUMBER', Integer,
opt.on('--max-code-lines-in-method NUMBER', IntegerOrDisabled,
'Max number lines of code in a method.', '(default: 30)') do |c|
options.style[:max_code_lines_in_method] = c
end
Expand Down
2 changes: 1 addition & 1 deletion lib/tailor/rulers/max_code_lines_in_class_ruler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def nl_update(lexed_line, lineno, column)
# @param [Fixnum] lineno The line the potential problem is on.
# @param [Fixnum] column The column the potential problem is on.
def measure(actual_count, lineno, column)
if actual_count > @config
if @config and actual_count > @config
msg = "Class/module has #{actual_count} code lines, but "
msg << "should have no more than #{@config}."

Expand Down
2 changes: 1 addition & 1 deletion lib/tailor/rulers/max_code_lines_in_method_ruler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def nl_update(lexed_line, lineno, column)
# @param [Fixnum] lineno The line the potential problem is on.
# @param [Fixnum] column The column the potential problem is on.
def measure(actual_count, lineno, column)
if actual_count > @config
if @config and actual_count > @config
msg = "Method has #{actual_count} code lines, but "
msg << "should have no more than #{@config}."

Expand Down
36 changes: 21 additions & 15 deletions spec/unit/tailor/cli/options_spec.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
require 'spec_helper'
require 'tailor/cli/options'

class Tailor::CLI
describe Options do
describe "#parse!" do
it "allows trailing newlines to be set to a number of lines" do
options = Options.parse!(['--trailing-newlines', '1'])
expect(options.style[:trailing_newlines]).to eql 1
end
it "allows trailing newlines to be disabled with false" do
options = Options.parse!(['--trailing-newlines', 'false'])
expect(options.style[:trailing_newlines]).to eql false
end
it "allows trailing newlines to be disabled with off" do
options = Options.parse!(['--trailing-newlines', 'off'])
expect(options.style[:trailing_newlines]).to eql false
module OptionHelpers
def cli_option(name)
"--#{name.to_s.gsub('_', '-')}"
end
def option_value(name, value)
options = Tailor::CLI::Options.parse!([cli_option(name), value])
options.style[name]
end
end

describe Tailor::CLI::Options do
include OptionHelpers
describe "#parse!" do
[
:max_code_lines_in_class,
:max_code_lines_in_method,
:trailing_newlines
].each do |o|
it { expect(option_value(o, '1')).to eq 1 }
it { expect(option_value(o, 'false')).to eq false }
it { expect(option_value(o, 'off')).to eq false }
end
end
end
end

0 comments on commit 0465e42

Please sign in to comment.