Skip to content

Commit ed730fc

Browse files
authored
Merge pull request #269 from 0x1eef/lint/standardrb
Add the standardrb linter
2 parents b6214d8 + 48125b1 commit ed730fc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+1744
-1470
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
fail-fast: false
1111
matrix:
12-
ruby_version: ["2.3", "2.4", "2.5", "2.6", "2.7", "3.0", "3.1", "3.2"]
12+
ruby_version: ["2.6", "2.7", "3.0", "3.1", "3.2"]
1313
experimental: [false]
1414
include:
1515
- ruby_version: "ruby-head"
@@ -21,4 +21,5 @@ jobs:
2121
with:
2222
ruby-version: ${{ matrix.ruby_version }}
2323
bundler-cache: true
24+
- run: "bundle exec rubocop lib/ spec/"
2425
- run: "bundle exec rspec spec/ -b"

.rubocop.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
##
2+
# Plugins
3+
require:
4+
- standard
5+
6+
##
7+
# Defaults: standardrb
8+
inherit_gem:
9+
standard: config/base.yml
10+
11+
##
12+
# Rules that break from standardrb defaults
13+
Style/StringLiterals:
14+
EnforcedStyle: single_quotes
15+
16+
##
17+
# Disabled rules
18+
Lint/AssignmentInCondition:
19+
Enabled: false
20+
Lint/FloatComparison:
21+
Enabled: false
22+
Lint/ConstantDefinitionInBlock:
23+
Enabled: false
24+
Lint/EmptyWhen:
25+
Exclude:
26+
- "lib/webmachine/dispatcher/route.rb"
27+
Lint/DuplicateMethods:
28+
Exclude:
29+
- "lib/webmachine/application.rb"
30+
Lint/UnderscorePrefixedVariableName:
31+
Exclude:
32+
- "lib/webmachine/trace/resource_proxy.rb"
33+
- "spec/webmachine/dispatcher_spec.rb"
34+
Lint/NestedMethodDefinition:
35+
Exclude:
36+
- "spec/webmachine/decision/flow_spec.rb"
37+
Lint/RescueException:
38+
Exclude:
39+
- "spec/webmachine/decision/fsm_spec.rb"
40+
Lint/RaiseException:
41+
Exclude:
42+
- "spec/webmachine/decision/fsm_spec.rb"
43+
Style/MissingRespondToMissing:
44+
Exclude:
45+
- "lib/webmachine/request.rb"
46+
Style/NilComparison:
47+
Exclude:
48+
- "spec/webmachine/decision/falsey_spec.rb"
49+
Style/GlobalVars:
50+
Exclude:
51+
- "lib/webmachine/decision/conneg.rb"
52+
53+
AllCops:
54+
SuggestExtensions: false

Gemfile

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,16 @@ source 'https://rubygems.org'
33
gemspec
44

55
group :development do
6-
gem "yard", "~> 0.9"
7-
gem "rake", "~> 12.0"
6+
gem 'yard', '~> 0.9'
7+
gem 'rake', '~> 12.0'
88
end
99

1010
group :test do
11-
gem "rspec", "~> 3.0", ">= 3.6.0"
12-
gem "rspec-its", "~> 1.2"
13-
gem "rack", "~> 2.0"
14-
gem "rack-test", "~> 0.7"
15-
gem "websocket_parser", "~>1.0"
16-
end
17-
18-
group :guard do
19-
gem 'guard-rspec', '~> 4.7'
20-
case RbConfig::CONFIG['host_os']
21-
when /darwin/
22-
gem 'rb-fsevent', '~> 0.10'
23-
# gem 'growl_notify'
24-
gem 'growl', '~> 1.0'
25-
when /linux/
26-
gem 'rb-inotify'
27-
gem 'libnotify'
28-
end
11+
gem 'rspec', '~> 3.0', '>= 3.6.0'
12+
gem 'rspec-its', '~> 1.2'
13+
gem 'rack', '~> 2.0'
14+
gem 'rack-test', '~> 0.7'
15+
gem 'websocket_parser', '~>1.0'
2916
end
3017

3118
group :docs do

Guardfile

Lines changed: 0 additions & 11 deletions
This file was deleted.

Rakefile

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
1-
require "bundler/gem_tasks"
1+
require 'bundler/gem_tasks'
22

33
begin
44
require 'yard'
55
require 'yard/rake/yardoc_task'
66
YARD::Rake::YardocTask.new do |doc|
7-
doc.files = Dir["lib/**/*.rb"] + ['README.md']
8-
doc.options = ["-m", "markdown"]
7+
doc.files = Dir['lib/**/*.rb'] + ['README.md']
8+
doc.options = ['-m', 'markdown']
99
end
1010
rescue LoadError
1111
end
1212

13-
desc "Validate the gemspec file."
13+
desc 'Validate the gemspec file.'
1414
task :validate_gemspec do
15-
Gem::Specification.load("webmachine.gemspec").validate
15+
Gem::Specification.load('webmachine.gemspec').validate
1616
end
1717

18-
task :build => :validate_gemspec
18+
task build: :validate_gemspec
1919

20-
desc "Cleans up white space in source files"
20+
desc 'Cleans up white space in source files'
2121
task :clean_whitespace do
2222
no_file_cleaned = true
2323

24-
Dir["**/*.rb"].each do |file|
24+
Dir['**/*.rb'].each do |file|
2525
contents = File.read(file)
2626
cleaned_contents = contents.gsub(/([ \t]+)$/, '')
2727
unless cleaned_contents == contents
2828
no_file_cleaned = false
2929
puts " - Cleaned #{file}"
30-
File.open(file, 'w') { |f| f.write(cleaned_contents) }
30+
File.write(file, cleaned_contents)
3131
end
3232
end
3333

3434
if no_file_cleaned
35-
puts "No files with trailing whitespace found"
35+
puts 'No files with trailing whitespace found'
3636
end
3737
end
3838

3939
require 'rspec/core/rake_task'
4040

41-
desc "Run specs"
41+
desc 'Run specs'
4242
RSpec::Core::RakeTask.new(:spec)
4343

44-
task :default => :spec
44+
task default: :spec

examples/debugger.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,23 @@
22
require 'webmachine/trace'
33

44
class MyTracedResource < Webmachine::Resource
5-
def trace?; true; end
5+
def trace?
6+
true
7+
end
68

79
def resource_exists?
810
case request.query['e']
911
when 'true'
1012
true
1113
when 'fail'
12-
raise "BOOM"
14+
raise 'BOOM'
1315
else
1416
false
1517
end
1618
end
1719

1820
def to_html
19-
"<html>You found me.</html>"
21+
'<html>You found me.</html>'
2022
end
2123
end
2224

examples/logging.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def handle_event(event)
1818
resource = event.payload[:resource]
1919
code = event.payload[:code]
2020

21-
puts "[%s] method=%s uri=%s code=%d resource=%s time=%.4f" % [
21+
puts '[%s] method=%s uri=%s code=%d resource=%s time=%.4f' % [
2222
Time.now.iso8601, request.method, request.uri.to_s, code, resource,
2323
event.duration
2424
]
@@ -34,7 +34,7 @@ def handle_event(event)
3434

3535
app.configure do |config|
3636
config.adapter = :WEBrick
37-
config.adapter_options = {:AccessLog => [], :Logger => Logger.new('/dev/null')}
37+
config.adapter_options = {AccessLog: [], Logger: Logger.new('/dev/null')}
3838
end
3939
end
4040

examples/webrick.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ def last_modified
66
end
77

88
def encodings_provided
9-
{ "gzip" => :encode_gzip, "identity" => :encode_identity }
9+
{'gzip' => :encode_gzip, 'identity' => :encode_identity}
1010
end
1111

1212
def to_html
13-
"<html><head><title>Hello from Webmachine</title></head><body>Hello, world!</body></html>"
13+
'<html><head><title>Hello from Webmachine</title></head><body>Hello, world!</body></html>'
1414
end
1515
end
1616

lib/webmachine/adapter.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
module Webmachine
2-
32
# The abstract class for definining a Webmachine adapter.
43
#
54
# @abstract Subclass and override {#run} to implement a custom adapter.
65
class Adapter
7-
86
# @return [Webmachine::Application] returns the application
97
attr_reader :application
108

@@ -25,6 +23,5 @@ def self.run(application)
2523
def run
2624
raise NotImplementedError
2725
end
28-
2926
end
3027
end

lib/webmachine/adapters/lazy_request_body.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def empty?
2424
# @yield [chunk]
2525
# @yieldparam [String] chunk a chunk of the request body
2626
def each
27-
@request.body {|chunk| yield chunk }
27+
@request.body { |chunk| yield chunk }
2828
end
2929
end # class RequestBody
3030
end # module Adapters

0 commit comments

Comments
 (0)