Skip to content

Commit a1e2424

Browse files
committed
Add RuboCop
1 parent 15c14d6 commit a1e2424

31 files changed

+2860
-2878
lines changed

.rubocop.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
AllCops:
2+
Includes:
3+
- 'Gemfile'
4+
5+
# Avoid long parameter lists
6+
ParameterLists:
7+
Max: 3
8+
CountKeywordArgs: true
9+
10+
# Avoid more than `Max` levels of nesting.
11+
BlockNesting:
12+
Max: 3
13+
14+
# Align with the style guide.
15+
CollectionMethods:
16+
PreferredMethods:
17+
collect: 'map'
18+
inject: 'reduce'
19+
find: 'detect'
20+
find_all: 'select'
21+
22+
# Do not force public/protected/private keyword to be indented at the same
23+
# level as the def keyword. My personal preference is to outdent these keywords
24+
# because I think when scanning code it makes it easier to identify the
25+
# sections of code and visually separate them. When the keyword is at the same
26+
# level I think it sort of blends in with the def keywords and makes it harder
27+
# to scan the code and see where the sections are.
28+
AccessModifierIndentation:
29+
Enabled: false
30+
31+
# Limit line length
32+
LineLength:
33+
Enabled: false
34+
35+
# Disable documentation checking until a class needs to be documented once
36+
Documentation:
37+
Enabled: false
38+
39+
# Enforce Ruby 1.8-compatible hash syntax
40+
HashSyntax:
41+
EnforcedStyle: hash_rockets
42+
43+
# No spaces inside hash literals
44+
SpaceInsideHashLiteralBraces:
45+
EnforcedStyle: no_space
46+
47+
# Allow dots at the end of lines
48+
DotPosition:
49+
Enabled: false
50+
51+
# Don't require magic comment at the top of every file
52+
Encoding:
53+
Enabled: false
54+
55+
# Don't prefer sprintf to String#%
56+
FavorSprintf:
57+
Enabled: false
58+
59+
# Trailing whitespace is required to test output
60+
TrailingWhitespace:
61+
Enabled: false
62+
63+
# Thor makes it hard to write short classes
64+
ClassLength:
65+
Enabled: false
66+
67+
# Thor makes it hard to write short methods
68+
MethodLength:
69+
Enabled: false

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Ideally, a bug report should include a pull request with failing specs.
3737
3. Add specs for your unimplemented feature or bug fix.
3838
4. Run `bundle exec rake spec`. If your specs pass, return to step 3.
3939
5. Implement your feature or bug fix.
40-
6. Run `bundle exec rake spec`. If your specs fail, return to step 5.
40+
6. Run `bundle exec rake default`. If your specs fail, return to step 5.
4141
7. Run `open coverage/index.html`. If your changes are not completely covered
4242
by your tests, return to step 3.
4343
8. Add, commit, and push your changes.

Gemfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@ gem 'jruby-openssl', :platforms => :jruby
66
group :development do
77
gem 'guard-rspec'
88
gem 'pry'
9-
gem 'pry-debugger', :platforms => :mri_19
9+
gem 'pry-rescue'
10+
platforms :ruby_19, :ruby_20 do
11+
gem 'pry-debugger'
12+
gem 'pry-stack_explorer'
13+
end
1014
end
1115

1216
group :test do
1317
gem 'coveralls', :require => false
1418
gem 'rspec', '>= 2.14'
19+
gem 'rubocop', '>= 0.15', :platforms => [:ruby_19, :ruby_20]
1520
gem 'simplecov', :require => false
1621
gem 'timecop'
1722
gem 'webmock', '>= 1.10.1'

Rakefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,18 @@ Bundler::GemHelper.install_tasks
44
require 'rspec/core/rake_task'
55
RSpec::Core::RakeTask.new(:spec)
66

7+
begin
8+
require 'rubocop/rake_task'
9+
Rubocop::RakeTask.new
10+
rescue LoadError
11+
desc 'Run RuboCop'
12+
task :rubocop do
13+
$stderr.puts 'Rubocop is disabled'
14+
end
15+
end
16+
717
Dir.glob('tasks/*.rake').each { |r| import r }
818

919
task :release => 'completion:zsh'
1020
task :test => :spec
11-
task :default => :spec
21+
task :default => [:spec, :rubocop]

bin/t

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

77
require 'oauth'
88
require 't'
@@ -11,37 +11,37 @@ require 'twitter'
1111
# Output message to $stderr, prefixed with the program name
1212
def pute(*args)
1313
first = args.shift.dup
14-
first.insert(0, "#{$0}: ")
14+
first.insert(0, "#{$PROGRAM_NAME}: ")
1515
args.unshift(first)
1616
$stderr.puts(*args)
1717
end
1818

1919
begin
2020
T::CLI.start(ARGV)
2121
rescue Interrupt
22-
pute "Quitting..."
22+
pute 'Quitting...'
2323
exit 1
2424
rescue OAuth::Unauthorized
25-
pute "Authorization failed"
25+
pute 'Authorization failed'
2626
exit 1
2727
rescue Twitter::Error::TooManyRequests => error
2828
pute error.message,
29-
"The rate limit for this request will reset in #{error.rate_limit.reset_in} seconds.",
30-
"While you wait, consider making a polite request for Twitter to increase the API rate limit at https://dev.twitter.com/discussions/10644"
29+
"The rate limit for this request will reset in #{error.rate_limit.reset_in} seconds.",
30+
'While you wait, consider making a polite request for Twitter to increase the API rate limit at https://dev.twitter.com/discussions/10644'
3131
exit 1
3232
rescue Twitter::Error::BadRequest => error
3333
pute error.message,
34-
"Run `t authorize` to authorize."
34+
'Run `t authorize` to authorize.'
3535
exit 1
3636
rescue Twitter::Error::Forbidden, Twitter::Error::Unauthorized => error
3737
pute error.message
38-
if error.message == "Error processing your OAuth request: Read-only application cannot POST" ||
39-
error.message == "This application is not allowed to access or delete your direct messages"
38+
if error.message == 'Error processing your OAuth request: Read-only application cannot POST' ||
39+
error.message == 'This application is not allowed to access or delete your direct messages'
4040
$stderr.puts(%q(Make sure to set your Twitter application's Access Level to "Read, Write and Access direct messages".))
4141
require 'thor'
42-
Thor::Shell::Basic.new.ask "Press [Enter] to open the Twitter Developer site."
42+
Thor::Shell::Basic.new.ask 'Press [Enter] to open the Twitter Developer site.'
4343
require 'launchy'
44-
Launchy.open("https://dev.twitter.com/apps") { |u,o,e| $stderr.puts "Manually open #{u}" }
44+
Launchy.open('https://dev.twitter.com/apps') { |u, o, e| $stderr.puts "Manually open #{u}" }
4545
end
4646
exit 1
4747
rescue Twitter::Error => error

lib/t.rb

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
module T
55
class << self
6-
76
# Convert time to local time by applying the `utc_offset` setting.
87
def local_time(time)
98
utc_offset ? (time.dup.utc + utc_offset) : time.localtime
@@ -15,14 +14,13 @@ def local_time(time)
1514

1615
def utc_offset=(offset)
1716
@utc_offset = case offset
18-
when String
19-
Time.zone_offset(offset)
20-
when NilClass
21-
nil
22-
else
23-
offset.to_i
24-
end
17+
when String
18+
Time.zone_offset(offset)
19+
when NilClass
20+
nil
21+
else
22+
offset.to_i
23+
end
2524
end
26-
2725
end
2826
end

0 commit comments

Comments
 (0)