Skip to content

Commit

Permalink
Fix rubocop errors (#1016)
Browse files Browse the repository at this point in the history
* Minimum Ruby version advanced to 2.1.0
* docker-compose.yml checked into git
  • Loading branch information
reconstructions authored and justin808 committed Jan 23, 2018
1 parent c2abcde commit 8c8077b
Show file tree
Hide file tree
Showing 29 changed files with 82 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

AllCops:
DisplayCopNames: true
TargetRubyVersion: 2.3
TargetRubyVersion: 2.1

Include:
- '**/Rakefile'
Expand Down
12 changes: 12 additions & 0 deletions Dockerfile_tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM dylangrafmyre/docker-ci

WORKDIR /app/

COPY ["/lib/react_on_rails/version.rb", "/app/lib/react_on_rails/"]
COPY ["Gemfile", "Gemfile.lock", "react_on_rails.gemspec", "rakelib/", "/app/"]
COPY ["/spec/dummy/Gemfile", "/spec/dummy/Gemfile.lock", "/app/spec/dummy/"]
RUN bundle install --gemfile=spec/dummy/Gemfile

ENV DISPLAY :99
ENTRYPOINT service xvfd start \
&& rake
11 changes: 4 additions & 7 deletions app/helpers/react_on_rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
module ReactOnRailsHelper
include ReactOnRails::Utils::Required

COMPONENT_HTML_KEY = "componentHtml"
COMPONENT_HTML_KEY = "componentHtml".freeze

# The env_javascript_include_tag and env_stylesheet_link_tag support the usage of a webpack
# dev server for providing the JS and CSS assets during development mode. See
Expand Down Expand Up @@ -178,9 +178,7 @@ def redux_store(store_name, props: {}, defer: false)
# that contains a data props.
def redux_store_hydration_data
return if @registered_stores_defer_render.blank?
# rubocop:disable Performance/UnfreezeString
@registered_stores_defer_render.reduce("".dup) do |accum, redux_store_data|
# rubocop:enable Performance/UnfreezeString
accum << render_redux_store_data(redux_store_data)
end.html_safe
end
Expand Down Expand Up @@ -447,15 +445,12 @@ def server_rendered_react_component_html(

def initialize_redux_stores
return "" unless @registered_stores.present? || @registered_stores_defer_render.present?
declarations = "var reduxProps, store, storeGenerator;\n".dup # rubocop:disable Performance/UnfreezeString

declarations = "var reduxProps, store, storeGenerator;\n".dup
all_stores = (@registered_stores || []) + (@registered_stores_defer_render || [])

# rubocop:disable Performance/UnfreezeString
result = <<-JS.dup
ReactOnRails.clearHydratedStores();
JS
# rubocop:enable Performance/UnfreezeString

result << all_stores.each_with_object(declarations) do |redux_store_data, memo|
store_name = redux_store_data[:store_name]
Expand Down Expand Up @@ -516,6 +511,7 @@ def rails_context(server_side: required("server_side"))

@rails_context.merge(serverSide: server_side)
end
# rubocop:enable Metrics/AbcSize

def replay_console_option(val)
val.nil? ? ReactOnRails.configuration.replay_console : val
Expand All @@ -539,3 +535,4 @@ def in_mailer?
controller.is_a?(ActionMailer::Base)
end
end
# rubocop:enable Metrics/ModuleLength
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
lint:
image: dylangrafmyre/docker-lint:latest
working_dir: /app/
volumes:
- '.:/app/'
tests:
build: .
dockerfile: Dockerfile_tests
working_dir: /app/
volumes:
- '.:/app/'
4 changes: 4 additions & 0 deletions lib/generators/react_on_rails/base_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def append_to_spec_rails_helper
if File.exist?(spec_helper)
add_configure_rspec_to_compile_assets(spec_helper)
else
# rubocop:disable Lint/UnneededDisable
# rubocop:disable Layout/EmptyLinesAroundArguments
GeneratorMessages.add_info(
<<-MSG.strip_heredoc
Expand All @@ -67,6 +69,8 @@ def append_to_spec_rails_helper
ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
MSG
)
# rubocop:enable Layout/EmptyLinesAroundArguments
# rubocop:enable Lint/UnneededDisable
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/react_on_rails/assets_precompile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ def delete_broken_symlinks
next unless File.lstat(filename).symlink?
begin
target = File.readlink(filename)
rescue # rubocop:disable Lint/RescueWithoutErrorClass
puts "React on Rails: Warning: your platform doesn't support File::readlink method." /
rescue StandardError
puts "React on Rails: Warning: your platform doesn't support File::readlink method." \
"Skipping broken link check."
break
end
Expand Down Expand Up @@ -139,7 +139,7 @@ def file_or_symlink_exists_at_path?(path)
# pointing to. We can't use File.exist?, as that would check the file pointed at by the symlink.
File.lstat(path)
true
rescue # rubocop:disable Lint/RescueWithoutErrorClass
rescue StandardError
false
end
end
Expand Down
7 changes: 2 additions & 5 deletions lib/react_on_rails/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ def self.ensure_webpack_generated_files_exists
return unless @configuration.webpack_generated_files.empty?

files = ["hello-world-bundle.js"]
if @configuration.server_bundle_js_file.present?
files << @configuration.server_bundle_js_file
end
files << @configuration.server_bundle_js_file if @configuration.server_bundle_js_file.present?

@configuration.webpack_generated_files = files
end

Expand All @@ -85,7 +84,6 @@ def self.configuration
@configuration ||= Configuration.new(
node_modules_location: nil,
generated_assets_dirs: nil,

# generated_assets_dirs is deprecated
generated_assets_dir: "",
server_bundle_js_file: "",
Expand All @@ -98,7 +96,6 @@ def self.configuration
server_renderer_pool_size: 1,
server_renderer_timeout: 20,
skip_display_none: nil,

# skip_display_none is deprecated
webpack_generated_files: %w[manifest.json],
rendering_extension: nil,
Expand Down
2 changes: 1 addition & 1 deletion lib/react_on_rails/prerender_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class PrerenderError < RuntimeError
# err might be nil if JS caught the error
def initialize(component_name: nil, err: nil, props: nil,
js_code: nil, console_messages: nil)
message = "ERROR in SERVER PRERENDERING\n".dup # rubocop:disable Performance/UnfreezeString
message = "ERROR in SERVER PRERENDERING\n".dup
if err
# rubocop:disable Layout/IndentHeredoc
message << <<-MSG
Expand Down
1 change: 1 addition & 0 deletions lib/react_on_rails/server_rendering_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def pool
def method_missing(sym, *args, &block)
pool.send sym, *args, &block
end
# rubocop:enable Style/MethodMissing
end
end
end
4 changes: 2 additions & 2 deletions lib/react_on_rails/server_rendering_pool/exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def create_js_context
# bundle_js_code = File.read(server_js_file)
begin
bundle_js_code = open(server_js_file, &:read)
rescue => e # rubocop:disable Lint/RescueWithoutErrorClass
rescue StandardError
msg = "You specified server rendering JS file: #{server_js_file}, but it cannot be "\
"read. You may set the server_bundle_js_file in your configuration to be \"\" to "\
"avoid this warning.\nError is: #{e}"
Expand All @@ -115,7 +115,7 @@ def create_js_context
begin
trace_messsage(base_js_code, file_name)
ExecJS.compile(base_js_code)
rescue => e # rubocop:disable Lint/RescueWithoutErrorClass
rescue StandardError
msg = "ERROR when compiling base_js_code! "\
"See file #{file_name} to "\
"correlate line numbers of error. Error is\n\n#{e.message}"\
Expand Down
4 changes: 1 addition & 3 deletions lib/react_on_rails/server_rendering_pool/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ def eval_js(js_code)
@js_context_pool.with do |js_context|
js_context.send(js_code + eof_symbol, 0)
result = ""
while result[-eof_symbol.length..-1] != eof_symbol
result += js_context.recv(max_int)
end
result[-eof_symbol.length..-1] != eof_symbol while result += js_context.recv(max_int)
result[0..-eof_symbol.length]
end
end
Expand Down
4 changes: 1 addition & 3 deletions lib/react_on_rails/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ def self.running_on_windows?
def self.rails_version_less_than(version)
@rails_version_less_than ||= {}

if @rails_version_less_than.key?(version)
return @rails_version_less_than[version]
end
return @rails_version_less_than[version] if @rails_version_less_than.key?(version)

@rails_version_less_than[version] = begin
Gem::Version.new(Rails.version) < Gem::Version.new(version)
Expand Down
2 changes: 1 addition & 1 deletion lib/react_on_rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module ReactOnRails
VERSION = "10.0.2"
VERSION = "10.0.2".freeze
end
3 changes: 2 additions & 1 deletion rakelib/dummy_apps.rake
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# frozen_string_literal: true

require_relative "task_helpers"
include ReactOnRails::TaskHelpers

namespace :dummy_apps do
include ReactOnRails::TaskHelpers

task :yarn_install do
yarn_install_cmd = "yarn install --mutex network"
sh_in_dir(dummy_app_dir, yarn_install_cmd)
Expand Down
3 changes: 2 additions & 1 deletion rakelib/examples.rake
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
require "yaml"
require_relative "example_type"
require_relative "task_helpers"
include ReactOnRails::TaskHelpers

namespace :examples do # rubocop:disable Metrics/BlockLength
include ReactOnRails::TaskHelpers
# Loads data from examples_config.yml and instantiates corresponding ExampleType objects
examples_config_file = File.expand_path("../examples_config.yml", __FILE__)
examples_config = symbolize_keys(YAML.safe_load(File.read(examples_config_file)))
Expand Down
5 changes: 3 additions & 2 deletions rakelib/lint.rake
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# frozen_string_literal: true

require_relative "task_helpers"
include ReactOnRails::TaskHelpers

namespace :lint do
namespace :lint do # rubocop:disable Metrics/BlockLength
include ReactOnRails::TaskHelpers

desc "Run Rubocop as shell"
task :rubocop do
sh_in_dir(gem_root, "bundle exec rubocop .")
Expand Down
3 changes: 2 additions & 1 deletion rakelib/node_package.rake
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# frozen_string_literal: true

require_relative "task_helpers"
include ReactOnRails::TaskHelpers

namespace :node_package do
include ReactOnRails::TaskHelpers

task :build do
puts "Building Node Package and running 'yarn link'"
sh "yarn run build && yarn link"
Expand Down
10 changes: 7 additions & 3 deletions rakelib/release.rake
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# frozen_string_literal: true

require_relative "task_helpers"
include ReactOnRails::TaskHelpers
require_relative File.join(gem_root, "lib", "react_on_rails", "version_syntax_converter")
require_relative File.join(gem_root, "lib", "react_on_rails", "git_utils")
require_relative File.join(gem_root, "lib", "react_on_rails", "utils")

# rubocop:disable Lint/UnneededDisable
# rubocop:disable Layout/EmptyLinesAroundArguments
desc("Releases both the gem and node package using the given version.
IMPORTANT: the gem version must be in valid rubygem format (no dashes).
Expand All @@ -21,9 +22,13 @@ which are installed via `bundle install` and `yarn`
2nd argument: Perform a dry run by passing 'true' as a second argument.
Example: `rake release[2.1.0,false]`")
# rubocop:enable Layout/EmptyLinesAroundArguments
# rubocop:enable Lint/UnneededDisable

# rubocop:disable Metrics/BlockLength
task :release, %i[gem_version dry_run tools_install] do |_t, args|
include ReactOnRails::TaskHelpers

class MessageHandler
def add_error(error)
raise error
Expand Down Expand Up @@ -60,9 +65,7 @@ task :release, %i[gem_version dry_run tools_install] do |_t, args|
sh_in_dir(gem_root, "git add .")

# Will bump the yarn version, commit, tag the commit, push to repo, and release on yarn
# rubocop:disable Performance/UnfreezeString
release_it_command = "$(yarn bin)/release-it --non-interactive --npm.publish".dup
# rubocop:enable Performance/UnfreezeString
release_it_command << " --dry-run --verbose" if is_dry_run
release_it_command << " #{npm_version}" unless npm_version.strip.empty?
sh_in_dir(gem_root, release_it_command)
Expand All @@ -77,3 +80,4 @@ task :release, %i[gem_version dry_run tools_install] do |_t, args|
sh_in_dir(gem_root, "git push")
end
end
# rubocop:enable Metrics/BlockLength
7 changes: 3 additions & 4 deletions rakelib/run_rspec.rake
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ require "pathname"
require_relative "task_helpers"
require_relative "example_type"

include ReactOnRails::TaskHelpers

# rubocop:disable Metrics/BlockLength
namespace :run_rspec do
include ReactOnRails::TaskHelpers

spec_dummy_dir = File.join("spec", "dummy")

desc "Run RSpec for top level only"
Expand Down Expand Up @@ -82,6 +82,7 @@ namespace :run_rspec do
puts "Completed all RSpec tests"
end
end
# rubocop:enable Metrics/BlockLength

desc "js tests (same as 'yarn run test')"
task :js_tests do
Expand Down Expand Up @@ -119,9 +120,7 @@ def run_tests_in(dir, options = {})

command_name = options.fetch(:command_name, path.basename)
rspec_args = options.fetch(:rspec_args, "")
# rubocop:disable Performance/UnfreezeString
env_vars = "#{options.fetch(:env_vars, '')} TEST_ENV_COMMAND_NAME=\"#{command_name}\"".dup
# rubocop:enable Performance/UnfreezeString
env_vars << "COVERAGE=true" if ENV["USE_COVERALLS"]
sh_in_dir(path.realpath, "#{env_vars} bundle exec rspec #{rspec_args}")
end
Expand Down
3 changes: 2 additions & 1 deletion react_on_rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Gem::Specification.new do |s|
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
s.require_paths = ["lib"]

s.required_ruby_version = ">= 2.0.0"
s.required_ruby_version = ">= 2.1.0"

s.add_dependency "addressable"
s.add_dependency "connection_pool"
Expand All @@ -48,3 +48,4 @@ Gem::Specification.new do |s|
s.add_development_dependency "rake", "~> 10.0"
s.add_development_dependency "rspec"
end
# rubocop:enable Metrics/BlockLength
4 changes: 1 addition & 3 deletions spec/dummy/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ gem "jquery-rails"
gem "puma"

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
if ENV["DISABLE_TURBOLINKS"].nil? || ENV["DISABLE_TURBOLINKS"].strip.empty?
gem "turbolinks", "~> 5.0"
end
gem "turbolinks", "~> 5.0" if ENV["DISABLE_TURBOLINKS"].nil? || ENV["DISABLE_TURBOLINKS"].strip.empty?

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem "jbuilder"
Expand Down
Loading

0 comments on commit 8c8077b

Please sign in to comment.