Skip to content

Commit

Permalink
Rubocop format with the Rails config
Browse files Browse the repository at this point in the history
  • Loading branch information
gsamokovarov committed Mar 30, 2018
1 parent 66891a0 commit 05c99ae
Show file tree
Hide file tree
Showing 51 changed files with 533 additions and 356 deletions.
162 changes: 162 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
AllCops:
TargetRubyVersion: 2.4
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
# to ignore them, so only the ones explicitly set in this file are enabled.
DisabledByDefault: true
Exclude:
- '**/templates/**/*'
- '**/vendor/**/*'
- 'actionpack/lib/action_dispatch/journey/parser.rb'

# Prefer &&/|| over and/or.
Style/AndOr:
Enabled: true

# Do not use braces for hash literals when they are the last argument of a
# method call.
Style/BracesAroundHashParameters:
Enabled: true
EnforcedStyle: context_dependent

# Align `when` with `case`.
Layout/CaseIndentation:
Enabled: true

# Align comments with method definitions.
Layout/CommentIndentation:
Enabled: true

Layout/ElseAlignment:
Enabled: true

Layout/EmptyLineAfterMagicComment:
Enabled: true

# In a regular class definition, no empty lines around the body.
Layout/EmptyLinesAroundClassBody:
Enabled: true

# In a regular method definition, no empty lines around the body.
Layout/EmptyLinesAroundMethodBody:
Enabled: true

# In a regular module definition, no empty lines around the body.
Layout/EmptyLinesAroundModuleBody:
Enabled: true

Layout/FirstParameterIndentation:
Enabled: true

# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
Style/HashSyntax:
Enabled: true

# Method definitions after `private` or `protected` isolated calls need one
# extra level of indentation.
Layout/IndentationConsistency:
Enabled: true
EnforcedStyle: rails

# Two spaces, no tabs (for indentation).
Layout/IndentationWidth:
Enabled: true

Layout/LeadingCommentSpace:
Enabled: true

Layout/SpaceAfterColon:
Enabled: true

Layout/SpaceAfterComma:
Enabled: true

Layout/SpaceAroundEqualsInParameterDefault:
Enabled: true

Layout/SpaceAroundKeyword:
Enabled: true

Layout/SpaceAroundOperators:
Enabled: true

Layout/SpaceBeforeComma:
Enabled: true

Layout/SpaceBeforeFirstArg:
Enabled: true

Style/DefWithParentheses:
Enabled: true

# Defining a method with parameters needs parentheses.
Style/MethodDefParentheses:
Enabled: true

Style/FrozenStringLiteralComment:
Enabled: true
EnforcedStyle: always
Exclude:
- 'actionview/test/**/*.builder'
- 'actionview/test/**/*.ruby'
- 'actionpack/test/**/*.builder'
- 'actionpack/test/**/*.ruby'
- 'activestorage/db/migrate/**/*.rb'

# Use `foo {}` not `foo{}`.
Layout/SpaceBeforeBlockBraces:
Enabled: true

# Use `foo { bar }` not `foo {bar}`.
Layout/SpaceInsideBlockBraces:
Enabled: true

# Use `{ a: 1 }` not `{a:1}`.
Layout/SpaceInsideHashLiteralBraces:
Enabled: true

Layout/SpaceInsideParens:
Enabled: true

# Check quotes usage according to lint rule below.
Style/StringLiterals:
Enabled: true
EnforcedStyle: double_quotes

# Detect hard tabs, no hard tabs.
Layout/Tab:
Enabled: true

# Blank lines should not have any spaces.
Layout/TrailingBlankLines:
Enabled: true

# No trailing whitespace.
Layout/TrailingWhitespace:
Enabled: true

# Use quotes for string literals when they are enough.
Style/UnneededPercentQ:
Enabled: true

# Align `end` with the matching keyword or starting expression except for
# assignments, where it should be aligned with the LHS.
Lint/EndAlignment:
Enabled: true
EnforcedStyleAlignWith: variable
AutoCorrect: true

# Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
Lint/RequireParentheses:
Enabled: true

Style/RedundantReturn:
Enabled: true
AllowMultipleReturnValues: true

Style/Semicolon:
Enabled: true
AllowAsExpressionSeparator: true

# Prefer Foo.method over Foo::method
Style/ColonMethodCall:
Enabled: true
20 changes: 11 additions & 9 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
source 'https://rubygems.org'
# frozen_string_literal: true

source "https://rubygems.org"

gemspec

gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
gem 'rack', github: 'rack/rack'
gem "rails", github: "rails/rails"
gem "arel", github: "rails/arel"
gem "rack", github: "rack/rack"

group :development do
platform :ruby do
gem 'byebug'
gem "byebug"
end
gem 'puma'
gem "puma"
end

group :test do
gem 'rake'
gem 'mocha', require: false
gem 'simplecov', require: false
gem "rake"
gem "mocha", require: false
gem "simplecov", require: false
end
26 changes: 14 additions & 12 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
# frozen_string_literal: true

begin
require 'bundler/setup'
require "bundler/setup"
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
end

require 'socket'
require 'rake/testtask'
require 'tmpdir'
require 'securerandom'
require 'json'
require 'web_console/testing/erb_precompiler'
require "socket"
require "rake/testtask"
require "tmpdir"
require "securerandom"
require "json"
require "web_console/testing/erb_precompiler"

EXPANDED_CWD = File.expand_path(File.dirname(__FILE__))

Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.libs << "lib"
t.libs << "test"
t.pattern = "test/**/*_test.rb"
t.verbose = false
end

Dir['lib/web_console/tasks/**/*.rake'].each { |task| load task }
Dir["lib/web_console/tasks/**/*.rake"].each { |task| load task }

Bundler::GemHelper.install_tasks

Expand Down
2 changes: 1 addition & 1 deletion lib/web-console.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# frozen_string_literal: true

require 'web_console'
require "web_console"
8 changes: 4 additions & 4 deletions lib/web_console.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require 'active_support/dependencies/autoload'
require 'active_support/logger'
require "active_support/dependencies/autoload"
require "active_support/logger"

module WebConsole
extend ActiveSupport::Autoload
Expand All @@ -18,7 +18,7 @@ module WebConsole
autoload :Middleware
autoload :Context

autoload_at 'web_console/errors' do
autoload_at "web_console/errors" do
autoload :Error
autoload :DoubleRenderError
end
Expand All @@ -28,4 +28,4 @@ def self.logger
end
end

require 'web_console/railtie'
require "web_console/railtie"
12 changes: 6 additions & 6 deletions lib/web_console/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ def extract(input = nil)
private

GLOBAL_OBJECTS = [
'instance_variables',
'local_variables',
'methods',
'class_variables',
'Object.constants',
'global_variables'
"instance_variables",
"local_variables",
"methods",
"class_variables",
"Object.constants",
"global_variables"
]

def global
Expand Down
2 changes: 1 addition & 1 deletion lib/web_console/evaluator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Evaluator
# Cleanses exceptions raised inside #eval.
cattr_reader :cleaner
@@cleaner = ActiveSupport::BacktraceCleaner.new
@@cleaner.add_silencer { |line| line.start_with?(File.expand_path('..', __FILE__)) }
@@cleaner.add_silencer { |line| line.start_with?(File.expand_path("..", __FILE__)) }

def initialize(binding = TOPLEVEL_BINDING)
@binding = binding
Expand Down
20 changes: 10 additions & 10 deletions lib/web_console/exception_mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ def [](index)

private

def guess_binding_for_index(index)
file, line = @backtrace[index].to_s.split(':')
line = line.to_i
def guess_binding_for_index(index)
file, line = @backtrace[index].to_s.split(":")
line = line.to_i

@bindings.find do |binding|
binding.eval('__FILE__') == file && binding.eval('__LINE__') == line
@bindings.find do |binding|
binding.eval("__FILE__") == file && binding.eval("__LINE__") == line
end
end
end

def guess_the_first_application_binding
@bindings.find do |binding|
binding.eval('__FILE__').to_s.start_with?(Rails.root.to_s)
def guess_the_first_application_binding
@bindings.find do |binding|
binding.eval("__FILE__").to_s.start_with?(Rails.root.to_s)
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/web_console/extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module ActionDispatch
class DebugExceptions
def render_exception_with_web_console(request, exception)
render_exception_without_web_console(request, exception).tap do
backtrace_cleaner = request.get_header('action_dispatch.backtrace_cleaner')
backtrace_cleaner = request.get_header("action_dispatch.backtrace_cleaner")
error = ExceptionWrapper.new(backtrace_cleaner, exception).exception

# Get the original exception if ExceptionWrapper decides to follow it.
Expand Down
18 changes: 9 additions & 9 deletions lib/web_console/middleware.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# frozen_string_literal: true

require 'active_support/core_ext/string/strip'
require "active_support/core_ext/string/strip"

module WebConsole
class Middleware
TEMPLATES_PATH = File.expand_path('../templates', __FILE__)
TEMPLATES_PATH = File.expand_path("../templates", __FILE__)

cattr_accessor :mount_point
@@mount_point = '/__web_console'
@@mount_point = "/__web_console"

cattr_accessor :whiny_requests
@@whiny_requests = true
Expand All @@ -29,13 +29,13 @@ def call(env)

status, headers, body = call_app(env)

if session = Session.from(Thread.current) and acceptable_content_type?(headers)
if (session = Session.from(Thread.current)) && acceptable_content_type?(headers)
response = Response.new(body, status, headers)
template = Template.new(env, session)

response.headers["X-Web-Console-Session-Id"] = session.id
response.headers["X-Web-Console-Mount-Point"] = mount_point
response.write(template.render('index'))
response.write(template.render("index"))
response.finish
else
[ status, headers, body ]
Expand All @@ -56,12 +56,12 @@ def call(env)
private

def acceptable_content_type?(headers)
Mime::Type.parse(headers['Content-Type'].to_s).first == Mime[:html]
Mime::Type.parse(headers["Content-Type"].to_s).first == Mime[:html]
end

def json_response(opts = {})
status = opts.fetch(:status, 200)
headers = { 'Content-Type' => 'application/json; charset = utf-8' }
headers = { "Content-Type" => "application/json; charset = utf-8" }
body = yield.to_json

Rack::Response.new(body, status, headers).finish
Expand Down Expand Up @@ -123,13 +123,13 @@ def change_stack_trace(id, request)

def respond_with_unavailable_session(id)
json_response(status: 404) do
{ output: format(I18n.t('errors.unavailable_session'), id: id)}
{ output: format(I18n.t("errors.unavailable_session"), id: id) }
end
end

def respond_with_unacceptable_request
json_response(status: 406) do
{ output: I18n.t('errors.unacceptable_request') }
{ output: I18n.t("errors.unacceptable_request") }
end
end

Expand Down
Loading

0 comments on commit 05c99ae

Please sign in to comment.