Skip to content

Commit 48ef2a9

Browse files
committed
Make RuboCop pass again after upgrading
* Remove `TargetRubyVersion` This is an application, not a library. We specify an explicit Ruby version in `Gemfile`. RuboCop can read this Ruby version from `Gemfile.lock` since v0.54.0. * Fix some minor complaints This includes: * whitespace issues * `rescue` without specifying an error * `YAML.load` -> `YAML.safe_load` * variable naming Thank you `--auto-correct`! * Replace custom enum implementation with `ActiveRecord::Enum` Instead of just fixing the complaint about an uncommunicative parameter name. Ref: <https://api.rubyonrails.org/v4.2/classes/ActiveRecord/Enum.html> * Update `.rubocop_todo.yml` Postpone addressing some of the new-found issues in order to keep the diff size down.
1 parent fcc68cc commit 48ef2a9

26 files changed

+143
-92
lines changed

.rubocop.yml

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ AllCops:
44
Exclude:
55
- 'db/schema.rb'
66
- 'vendor/**/*'
7-
TargetRubyVersion: 2.3
87

98
Metrics/LineLength:
109
Max: 120

.rubocop_todo.yml

+57-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,67 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2016-03-22 20:52:58 +0100 using RuboCop version 0.38.0.
3+
# on 2019-11-16 20:15:02 +0100 using RuboCop version 0.76.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 163
9+
# Offense count: 41
10+
# Configuration parameters: CountComments, ExcludedMethods.
11+
# ExcludedMethods: refine
12+
Metrics/BlockLength:
13+
Exclude:
14+
- 'spec/**/*'
15+
16+
# Offense count: 9
17+
# Configuration parameters: Blacklist.
18+
# Blacklist: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$))
19+
Naming/HeredocDelimiterNaming:
20+
Exclude:
21+
- 'app/utils/sample_story.rb'
22+
- 'spec/helpers/url_helpers_spec.rb'
23+
- 'spec/utils/opml_parser_spec.rb'
24+
25+
# Offense count: 139
1026
# Cop supports --auto-correct.
11-
# Configuration parameters: EnforcedStyle, SupportedStyles.
12-
# SupportedStyles: when_needed, always
27+
# Configuration parameters: EnforcedStyle.
28+
# SupportedStyles: always, never
1329
Style/FrozenStringLiteralComment:
1430
Enabled: false
31+
32+
# Offense count: 1
33+
# Cop supports --auto-correct.
34+
# Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods.
35+
# SupportedStyles: predicate, comparison
36+
Style/NumericPredicate:
37+
Exclude:
38+
- 'app/commands/stories/mark_group_as_read.rb'
39+
40+
# Offense count: 12
41+
# Cop supports --auto-correct.
42+
# Configuration parameters: PreferredDelimiters.
43+
Style/PercentLiteralDelimiters:
44+
Exclude:
45+
- 'app/helpers/authentication_helpers.rb'
46+
- 'app/helpers/url_helpers.rb'
47+
- 'spec/controllers/stories_controller_spec.rb'
48+
- 'spec/fever_api/read_items_spec.rb'
49+
- 'spec/helpers/authentications_helper_spec.rb'
50+
- 'spec/helpers/url_helpers_spec.rb'
51+
- 'spec/javascript/test_controller.rb'
52+
53+
# Offense count: 3
54+
# Cop supports --auto-correct.
55+
# Configuration parameters: ConvertCodeThatCanStartToReturnNil, Whitelist.
56+
# Whitelist: present?, blank?, presence, try, try!
57+
Style/SafeNavigation:
58+
Exclude:
59+
- 'app/controllers/feeds_controller.rb'
60+
- 'app/tasks/fetch_feed.rb'
61+
62+
# Offense count: 7
63+
# Cop supports --auto-correct.
64+
# Configuration parameters: MinSize.
65+
# SupportedStyles: percent, brackets
66+
Style/SymbolArray:
67+
EnforcedStyle: brackets

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ruby_version_file = File.join(File.expand_path("..", __FILE__), ".ruby-version")
1+
ruby_version_file = File.expand_path(".ruby-version", __dir__)
22
ruby File.read(ruby_version_file).chomp if File.readable?(ruby_version_file)
33
source "https://rubygems.org"
44

app/commands/feeds/find_new_stories.rb

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def new_stories
1616
@raw_feed.entries.each do |story|
1717
break if @latest_entry_id && story.id == @latest_entry_id
1818
next if story_age_exceeds_threshold?(story) || StoryRepository.exists?(story.id, @feed_id)
19+
1920
stories << story
2021
end
2122

app/fever_api/read_items.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def call(params = {})
1010
if params.keys.include?("items")
1111
item_ids = begin
1212
params[:with_ids].split(",")
13-
rescue
13+
rescue StandardError
1414
nil
1515
end
1616

app/fever_api/response.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def initialize(params)
4040
@params = params
4141
end
4242

43-
def to_json
43+
def to_json(*_args)
4444
base_response = { api_version: API_VERSION }
4545
ACTIONS
4646
.inject(base_response) { |a, e| a.merge!(e.new.call(@params)) }

app/fever_api/write_mark_item.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def call(params = {})
2020

2121
private
2222

23-
def mark_item_as(id, as)
24-
case as
23+
def mark_item_as(id, mark_as)
24+
case mark_as
2525
when "read"
2626
@read_marker_class.new(id).mark_as_read
2727
when "unread"

app/helpers/authentication_helpers.rb

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def needs_authentication?(path)
1313
return false unless UserRepository.setup_complete?
1414
return false if %w(/login /logout /heroku).include?(path)
1515
return false if path =~ /css|js|img/
16+
1617
true
1718
end
1819

app/models/feed.rb

+2-9
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,11 @@ class Feed < ActiveRecord::Base
44

55
validates_uniqueness_of :url
66

7-
STATUS = { green: 0, yellow: 1, red: 2 }.freeze
8-
9-
def status
10-
STATUS.key(read_attribute(:status))
11-
end
12-
13-
def status=(s)
14-
write_attribute(:status, STATUS[s])
15-
end
7+
enum status: { green: 0, yellow: 1, red: 2 }
168

179
def status_bubble
1810
return :yellow if status == :red && stories.any?
11+
1912
status
2013
end
2114

app/repositories/feed_repository.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ def self.update_feed(feed, name, url, group_id = nil)
1919
end
2020

2121
def self.update_last_fetched(feed, timestamp)
22-
if valid_timestamp?(timestamp, feed.last_fetched)
23-
feed.last_fetched = timestamp
24-
feed.save
25-
end
22+
return unless valid_timestamp?(timestamp, feed.last_fetched)
23+
24+
feed.last_fetched = timestamp
25+
feed.save
2626
end
2727

2828
def self.delete(feed_id)

app/repositories/story_repository.rb

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ def self.extract_content(entry)
107107
def self.extract_title(entry)
108108
return ContentSanitizer.sanitize(entry.title) if entry.title.present?
109109
return ContentSanitizer.sanitize(entry.summary) if entry.summary.present?
110+
110111
"There isn't a title for this story"
111112
end
112113

app/tasks/fetch_feed.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ def fetch
2121
end
2222

2323
FeedRepository.set_status(:green, @feed)
24-
rescue => ex
24+
rescue StandardError => e
2525
FeedRepository.set_status(:red, @feed)
2626

27-
@logger.error "Something went wrong when parsing #{@feed.url}: #{ex}" if @logger
27+
@logger.error "Something went wrong when parsing #{@feed.url}: #{e}" if @logger
2828
end
2929

3030
private

app/utils/feed_discovery.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def get_feed_for_url(url, parser)
1717
feed = parser.fetch_and_parse(url)
1818
feed.feed_url ||= url
1919
feed
20-
rescue
20+
rescue StandardError
2121
yield if block_given?
2222
end
2323
end

app/utils/opml_parser.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def extract_name(attributes)
3838
def feed_to_hash(feed)
3939
{
4040
name: extract_name(feed.attributes).value,
41-
url: feed.attributes["xmlUrl"].value
41+
url: feed.attributes["xmlUrl"].value
4242
}
4343
end
4444
end

app/utils/sample_story.rb

+21-21
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
SampleStory = Struct.new(:source, :title, :lead, :is_read, :published) do
2-
BODY = <<-eos.freeze
3-
<p>Tofu shoreditch intelligentsia <a href="#">umami</a>, fashion axe photo booth
4-
try-hard terry richardson quinoa actually fingerstache meggings fixie. Aesthetic
5-
salvia vinyl raw denim, keffiyeh master cleanse tonx selfies mlkshk occupy twee
6-
street art gentrify. Quinoa PBR readymade 90's. <b>Chambray</b> Austin aesthetic
7-
meggings, carles vinyl intelligentsia tattooed. Keffiyeh mumblecore
8-
fingerstache, sartorial sriracha disrupt biodiesel cred. Skateboard yr cosby
9-
sweater, narwhal beard ethnic jean shorts aesthetic. Post-ironic flannel mlkshk,
10-
pickled VHS wolf banjo forage portland wayfarers.</p>
11-
<img src='https://placekitten.com/g/500/300' />
12-
<p>Selfies mumblecore odd future <a href="#">irony DIY messenger bag</a>.
13-
Authentic neutra next level selvage squid. Four loko freegan occupy, tousled
14-
vinyl leggings selvage messenger bag. Four loko wayfarers kale chips, next level
15-
banksy banh mi umami flannel hella. Street art odd future scenester,
16-
intelligentsia brunch fingerstache YOLO narwhal single-origin coffee tousled
17-
tumblr pop-up four loko you probably haven't heard of them dreamcatcher.
18-
Single-origin coffee direct trade retro biodiesel, truffaut fanny pack portland
19-
blue bottle scenester bushwick. Skateboard squid fanny pack bushwick, photo
20-
booth vice literally.</p>
21-
eos
1+
SampleStory = Struct.new(:source, :title, :lead, :is_read, :published) do # rubocop:disable Metrics/BlockLength
2+
BODY = <<~EOS.freeze
3+
<p>Tofu shoreditch intelligentsia <a href="#">umami</a>, fashion axe photo booth
4+
try-hard terry richardson quinoa actually fingerstache meggings fixie. Aesthetic
5+
salvia vinyl raw denim, keffiyeh master cleanse tonx selfies mlkshk occupy twee
6+
street art gentrify. Quinoa PBR readymade 90's. <b>Chambray</b> Austin aesthetic
7+
meggings, carles vinyl intelligentsia tattooed. Keffiyeh mumblecore
8+
fingerstache, sartorial sriracha disrupt biodiesel cred. Skateboard yr cosby
9+
sweater, narwhal beard ethnic jean shorts aesthetic. Post-ironic flannel mlkshk,
10+
pickled VHS wolf banjo forage portland wayfarers.</p>
11+
<img src='https://placekitten.com/g/500/300' />
12+
<p>Selfies mumblecore odd future <a href="#">irony DIY messenger bag</a>.
13+
Authentic neutra next level selvage squid. Four loko freegan occupy, tousled
14+
vinyl leggings selvage messenger bag. Four loko wayfarers kale chips, next level
15+
banksy banh mi umami flannel hella. Street art odd future scenester,
16+
intelligentsia brunch fingerstache YOLO narwhal single-origin coffee tousled
17+
tumblr pop-up four loko you probably haven't heard of them dreamcatcher.
18+
Single-origin coffee direct trade retro biodiesel, truffaut fanny pack portland
19+
blue bottle scenester bushwick. Skateboard squid fanny pack bushwick, photo
20+
booth vice literally.</p>
21+
EOS
2222

2323
def id
2424
-1 * rand(100)

config/unicorn.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
after_fork do |_server, _worker|
1818
if defined?(ActiveRecord::Base)
1919
env = ENV["RACK_ENV"] || "development"
20-
config = YAML.load(ERB.new(File.read("config/database.yml")).result)[env]
20+
config = YAML.safe_load(ERB.new(File.read("config/database.yml")).result)[env]
2121
ActiveRecord::Base.establish_connection(config)
2222
end
2323
end

fever_api.rb

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Endpoint < Sinatra::Base
2020

2121
def authenticated?(api_key)
2222
return unless api_key
23+
2324
user = User.first
2425
user.api_key && api_key.casecmp(user.api_key).zero?
2526
end

spec/commands/feeds/import_from_opml_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
app_require "commands/feeds/import_from_opml"
44

55
describe ImportFromOpml do
6-
let(:subscriptions) { File.open(File.expand_path("../../../support/files/subscriptions.xml", __FILE__)) }
6+
let(:subscriptions) { File.open(File.expand_path("../../support/files/subscriptions.xml", __dir__)) }
77

88
def import
99
described_class.import(subscriptions)

spec/commands/stories/mark_group_as_read_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
app_require "commands/stories/mark_group_as_read"
44

55
describe MarkGroupAsRead do
6-
describe '#mark_group_as_read' do
6+
describe "#mark_group_as_read" do
77
let(:stories) { double }
88
let(:repo) { double }
99
let(:timestamp) { Time.now.to_i }

spec/factories/group_factory.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def as_fever_json
1111
def self.build(params = {})
1212
FakeGroup.new(
1313
id: rand(100),
14-
name: params[:name] || Faker::Name.name + " group")
14+
name: params[:name] || Faker::Name.name + " group"
15+
)
1516
end
1617
end

spec/factories/user_factory.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class FakeUser < OpenStruct; end
66
def self.build
77
FakeUser.new(
88
id: rand(100),
9-
setup_complete: false)
9+
setup_complete: false
10+
)
1011
end
1112
end

spec/helpers/url_helers_spec.rb renamed to spec/helpers/url_helpers_spec.rb

+25-25
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@ class Helper
1717
end
1818

1919
it "replaces relative urls in a, img and video tags" do
20-
content = <<-EOS
21-
<div>
22-
<img src="https://foo">
23-
<a href="/bar/baz">tee</a><img src="bar/bar">
24-
<video src="/tee"></video>
25-
</div>
20+
content = <<~EOS
21+
<div>
22+
<img src="https://foo">
23+
<a href="/bar/baz">tee</a><img src="bar/bar">
24+
<video src="/tee"></video>
25+
</div>
2626
EOS
2727

2828
result = helper.expand_absolute_urls(content, "http://oodl.io/d/")
29-
expect(result.delete("\n")).to eq <<-EOS.delete("\n")
30-
<div>
31-
<img src="https://foo">
32-
<a href="http://oodl.io/bar/baz">tee</a>
33-
<img src="http://oodl.io/d/bar/bar">
34-
<video src="http://oodl.io/tee"></video>
35-
</div>
29+
expect(result.delete("\n")).to eq <<~EOS.delete("\n")
30+
<div>
31+
<img src="https://foo">
32+
<a href="http://oodl.io/bar/baz">tee</a>
33+
<img src="http://oodl.io/d/bar/bar">
34+
<video src="http://oodl.io/tee"></video>
35+
</div>
3636
EOS
3737
end
3838

@@ -41,21 +41,21 @@ class Helper
4141
end
4242

4343
it "doesn't modify tags that do not have url attributes" do
44-
content = <<-EOS
45-
<div>
46-
<img foo="bar">
47-
<a name="something"/></a>
48-
<video foo="bar"></video>
49-
</div>
44+
content = <<~EOS
45+
<div>
46+
<img foo="bar">
47+
<a name="something"/></a>
48+
<video foo="bar"></video>
49+
</div>
5050
EOS
5151

5252
result = helper.expand_absolute_urls(content, "http://oodl.io/d/")
53-
expect(result.delete("\n")).to eq <<-EOS.delete("\n")
54-
<div>
55-
<img foo="bar">
56-
<a name="something"></a>
57-
<video foo="bar"></video>
58-
</div>
53+
expect(result.delete("\n")).to eq <<~EOS.delete("\n")
54+
<div>
55+
<img foo="bar">
56+
<a name="something"></a>
57+
<video foo="bar"></video>
58+
</div>
5959
EOS
6060
end
6161

0 commit comments

Comments
 (0)