Skip to content

Commit

Permalink
Add RuboCop
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Dec 11, 2013
1 parent 15c14d6 commit a1e2424
Show file tree
Hide file tree
Showing 31 changed files with 2,860 additions and 2,878 deletions.
69 changes: 69 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
AllCops:
Includes:
- 'Gemfile'

# Avoid long parameter lists
ParameterLists:
Max: 3
CountKeywordArgs: true

# Avoid more than `Max` levels of nesting.
BlockNesting:
Max: 3

# Align with the style guide.
CollectionMethods:
PreferredMethods:
collect: 'map'
inject: 'reduce'
find: 'detect'
find_all: 'select'

# Do not force public/protected/private keyword to be indented at the same
# level as the def keyword. My personal preference is to outdent these keywords
# because I think when scanning code it makes it easier to identify the
# sections of code and visually separate them. When the keyword is at the same
# level I think it sort of blends in with the def keywords and makes it harder
# to scan the code and see where the sections are.
AccessModifierIndentation:
Enabled: false

# Limit line length
LineLength:
Enabled: false

# Disable documentation checking until a class needs to be documented once
Documentation:
Enabled: false

# Enforce Ruby 1.8-compatible hash syntax
HashSyntax:
EnforcedStyle: hash_rockets

# No spaces inside hash literals
SpaceInsideHashLiteralBraces:
EnforcedStyle: no_space

# Allow dots at the end of lines
DotPosition:
Enabled: false

# Don't require magic comment at the top of every file
Encoding:
Enabled: false

# Don't prefer sprintf to String#%
FavorSprintf:
Enabled: false

# Trailing whitespace is required to test output
TrailingWhitespace:
Enabled: false

# Thor makes it hard to write short classes
ClassLength:
Enabled: false

# Thor makes it hard to write short methods
MethodLength:
Enabled: false
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Ideally, a bug report should include a pull request with failing specs.
3. Add specs for your unimplemented feature or bug fix.
4. Run `bundle exec rake spec`. If your specs pass, return to step 3.
5. Implement your feature or bug fix.
6. Run `bundle exec rake spec`. If your specs fail, return to step 5.
6. Run `bundle exec rake default`. If your specs fail, return to step 5.
7. Run `open coverage/index.html`. If your changes are not completely covered
by your tests, return to step 3.
8. Add, commit, and push your changes.
Expand Down
7 changes: 6 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ gem 'jruby-openssl', :platforms => :jruby
group :development do
gem 'guard-rspec'
gem 'pry'
gem 'pry-debugger', :platforms => :mri_19
gem 'pry-rescue'
platforms :ruby_19, :ruby_20 do
gem 'pry-debugger'
gem 'pry-stack_explorer'
end
end

group :test do
gem 'coveralls', :require => false
gem 'rspec', '>= 2.14'
gem 'rubocop', '>= 0.15', :platforms => [:ruby_19, :ruby_20]
gem 'simplecov', :require => false
gem 'timecop'
gem 'webmock', '>= 1.10.1'
Expand Down
12 changes: 11 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,18 @@ Bundler::GemHelper.install_tasks
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)

begin
require 'rubocop/rake_task'
Rubocop::RakeTask.new
rescue LoadError
desc 'Run RuboCop'
task :rubocop do
$stderr.puts 'Rubocop is disabled'
end
end

Dir.glob('tasks/*.rake').each { |r| import r }

task :release => 'completion:zsh'
task :test => :spec
task :default => :spec
task :default => [:spec, :rubocop]
22 changes: 11 additions & 11 deletions bin/t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Trap interrupts to quit cleanly. See
# https://twitter.com/mitchellh/status/283014103189053442
Signal.trap("INT") { exit 1 }
Signal.trap('INT') { exit 1 }

require 'oauth'
require 't'
Expand All @@ -11,37 +11,37 @@ require 'twitter'
# Output message to $stderr, prefixed with the program name
def pute(*args)
first = args.shift.dup
first.insert(0, "#{$0}: ")
first.insert(0, "#{$PROGRAM_NAME}: ")
args.unshift(first)
$stderr.puts(*args)
end

begin
T::CLI.start(ARGV)
rescue Interrupt
pute "Quitting..."
pute 'Quitting...'
exit 1
rescue OAuth::Unauthorized
pute "Authorization failed"
pute 'Authorization failed'
exit 1
rescue Twitter::Error::TooManyRequests => error
pute error.message,
"The rate limit for this request will reset in #{error.rate_limit.reset_in} seconds.",
"While you wait, consider making a polite request for Twitter to increase the API rate limit at https://dev.twitter.com/discussions/10644"
"The rate limit for this request will reset in #{error.rate_limit.reset_in} seconds.",
'While you wait, consider making a polite request for Twitter to increase the API rate limit at https://dev.twitter.com/discussions/10644'
exit 1
rescue Twitter::Error::BadRequest => error
pute error.message,
"Run `t authorize` to authorize."
'Run `t authorize` to authorize.'
exit 1
rescue Twitter::Error::Forbidden, Twitter::Error::Unauthorized => error
pute error.message
if error.message == "Error processing your OAuth request: Read-only application cannot POST" ||
error.message == "This application is not allowed to access or delete your direct messages"
if error.message == 'Error processing your OAuth request: Read-only application cannot POST' ||
error.message == 'This application is not allowed to access or delete your direct messages'
$stderr.puts(%q(Make sure to set your Twitter application's Access Level to "Read, Write and Access direct messages".))
require 'thor'
Thor::Shell::Basic.new.ask "Press [Enter] to open the Twitter Developer site."
Thor::Shell::Basic.new.ask 'Press [Enter] to open the Twitter Developer site.'
require 'launchy'
Launchy.open("https://dev.twitter.com/apps") { |u,o,e| $stderr.puts "Manually open #{u}" }
Launchy.open('https://dev.twitter.com/apps') { |u, o, e| $stderr.puts "Manually open #{u}" }
end
exit 1
rescue Twitter::Error => error
Expand Down
16 changes: 7 additions & 9 deletions lib/t.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

module T
class << self

# Convert time to local time by applying the `utc_offset` setting.
def local_time(time)
utc_offset ? (time.dup.utc + utc_offset) : time.localtime
Expand All @@ -15,14 +14,13 @@ def local_time(time)

def utc_offset=(offset)
@utc_offset = case offset
when String
Time.zone_offset(offset)
when NilClass
nil
else
offset.to_i
end
when String
Time.zone_offset(offset)
when NilClass
nil
else
offset.to_i
end
end

end
end

0 comments on commit a1e2424

Please sign in to comment.