Skip to content

Commit

Permalink
Rubocop and gem specification cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
justin808 committed Nov 14, 2020
1 parent c5980c6 commit 5d8c130
Show file tree
Hide file tree
Showing 22 changed files with 199 additions and 388 deletions.
134 changes: 16 additions & 118 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Check out: https://github.com/bbatsov/rubocop

AllCops:
NewCops: enable
DisplayCopNames: true
TargetRubyVersion: 2.5

Expand All @@ -13,35 +14,32 @@ AllCops:
- '**/*.rake'

Exclude:
- 'vendor/**/*'
- 'spec/fixtures/**/*'
- 'node_modules/**/.*'
- 'node_modules/**/*'
<% `git status --ignored --porcelain`.lines.grep(/^!! /).each do |path| %>
- <%= path.sub(/^!! /, '') %>
<% end %>
- '**/*.js'
- '**/log/**/*'
- '**/node_modules/**/*'
- '**/public/**/*'
- '**/tmp/**/*'
- '.git/**/*'
- 'bin/**/*'
- 'coverage/**/*'
- 'db/**/*'
- 'db/schema.rb'
- 'db/seeds.rb'
- 'client/node_modules/**/*.*'
- 'client/node_modules/**/.*'
- 'bin/**/*'
- !ruby/regexp /old_and_unused\.rb$/
- 'spec/react_on_rails/dummy-for-generators/**/*'
- 'spec/dummy/Procfile.*'
- 'spec/dummy/bin/**/*'
- 'spec/dummy/node_modules/**/*'
- 'spec/dummy/node_modules/**/.*'
- 'gen-examples/examples/**/.*'
- 'gen-examples/examples/**/*'
- 'node_modules/**/*'
- 'spec/fixtures/**/*'
- 'spec/react_on_rails/dummy-for-generators/**/*'
- 'tmp/**/*'
- 'vendor/**/*'

Naming/FileName:
Exclude:
- 'Gemfile'
- 'spec/dummy/Gemfile'

# Turn off until we require 2.3 ruby
Style/SafeNavigation:
Enabled: false

Layout/LineLength:
Max: 120

Expand Down Expand Up @@ -97,103 +95,3 @@ Naming/RescuedExceptionsVariableName:
Style/GlobalVars:
Exclude:
- 'spec/dummy/config/environments/development.rb'

Style/FrozenStringLiteralComment:
EnforcedStyle: always

Layout/EmptyLinesAroundAttributeAccessor:
Enabled: true

Layout/SpaceAroundMethodCallOperator:
Enabled: true

Lint/RaiseException:
Enabled: true

Lint/StructNewOverride:
Enabled: true

Style/ExponentialNotation:
Enabled: true

Style/SlicingWithRange:
Enabled: true

Layout/BeginEndAlignment: # (new in 0.91)
Enabled: true
Lint/BinaryOperatorWithIdenticalOperands: # (new in 0.89)
Enabled: true
Lint/ConstantDefinitionInBlock: # (new in 0.91)
Enabled: true
Lint/DeprecatedOpenSSLConstant: # (new in 0.84)
Enabled: true
Lint/DuplicateElsifCondition: # (new in 0.88)
Enabled: true
Lint/DuplicateRequire: # (new in 0.90)
Enabled: true
Lint/DuplicateRescueException: # (new in 0.89)
Enabled: true
Lint/EmptyConditionalBody: # (new in 0.89)
Enabled: true
Lint/EmptyFile: # (new in 0.90)
Enabled: true
Lint/FloatComparison: # (new in 0.89)
Enabled: true
Lint/IdentityComparison: # (new in 0.91)
Enabled: true
Lint/MissingSuper: # (new in 0.89)
Enabled: true
Lint/MixedRegexpCaptureTypes: # (new in 0.85)
Enabled: true
Lint/OutOfRangeRegexpRef: # (new in 0.89)
Enabled: true
Lint/SelfAssignment: # (new in 0.89)
Enabled: true
Lint/TopLevelReturnWithArgument: # (new in 0.89)
Enabled: true
Lint/TrailingCommaInAttributeDeclaration: # (new in 0.90)
Enabled: true
Lint/UnreachableLoop: # (new in 0.89)
Enabled: true
Lint/UselessMethodDefinition: # (new in 0.90)
Enabled: true
Lint/UselessTimes: # (new in 0.91)
Enabled: true
Style/AccessorGrouping: # (new in 0.87)
Enabled: true
Style/BisectedAttrAccessor: # (new in 0.87)
Enabled: true
Style/CaseLikeIf: # (new in 0.88)
Enabled: true
Style/CombinableLoops: # (new in 0.90)
Enabled: true
Style/ExplicitBlockArgument: # (new in 0.89)
Enabled: true
Style/GlobalStdStream: # (new in 0.89)
Enabled: true
Style/HashAsLastArrayItem: # (new in 0.88)
Enabled: true
Style/HashLikeCase: # (new in 0.88)
Enabled: true
Style/KeywordParametersOrder: # (new in 0.90)
Enabled: true
Style/OptionalBooleanParameter: # (new in 0.89)
Enabled: true
Style/RedundantAssignment: # (new in 0.87)
Enabled: true
Style/RedundantFetchBlock: # (new in 0.86)
Enabled: true
Style/RedundantFileExtensionInRequire: # (new in 0.88)
Enabled: true
Style/RedundantRegexpCharacterClass: # (new in 0.85)
Enabled: true
Style/RedundantRegexpEscape: # (new in 0.85)
Enabled: true
Style/RedundantSelfAssignment: # (new in 0.90)
Enabled: true
Style/SingleArgumentDig: # (new in 0.89)
Enabled: true
Style/SoleNestedConditional: # (new in 0.89)
Enabled: true
Style/StringConcatenation: # (new in 0.89)
Enabled: true
34 changes: 1 addition & 33 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,4 @@ source "https://rubygems.org"
# Specify your gem"s dependencies in react_on_rails.gemspec
gemspec

# The following gems are dependencies of the gem's dummy/example apps, not the gem itself.
# They must be defined here because of the way Travis CI works, in that it will only
# bundle install from a single Gemfile. Therefore, all gems that we will need for any dummy/example
# app have to be manually added to this file.
gem "bootsnap", ">= 1.1.0", require: false
gem "bootstrap-sass"
gem "jbuilder"
gem "jquery-rails"
gem "mini_racer"
gem "puma"
gem "rails_12factor"
gem "ruby-lint", require: false
gem "sass-rails"
gem "scss_lint", require: false
gem "sdoc", group: :doc
gem "spring"
gem "sprockets", "~>3.0"
gem "sqlite3", "~> 1.4"
gem "turbolinks"
gem "uglifier"
gem "web-console", group: :development

# below are copied from spec/dummy/Gemfile
gem "capybara"
gem "capybara-screenshot"
gem "launchy"
gem "rspec-rails"
gem "rspec-retry"
gem "selenium-webdriver"
gem "webpacker", ">= 5.2.1"

gem "equivalent-xml", github: "mbklein/equivalent-xml"
gem "rainbow"
eval_gemfile File.expand_path("./Gemfile.development_dependencies", __dir__)
54 changes: 54 additions & 0 deletions Gemfile.development_dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# frozen_string_literal: true


# We'll revert this before the final merge.
# gem "webpacker", git: 'https://github.com/rails/webpacker.git'
gem "webpacker"
gem "bootsnap", ">= 1.1.0", require: false
gem "rails"
gem "sqlite3"
gem "sass-rails"
gem "uglifier"
gem "jquery-rails"
gem "puma"

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

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem "jbuilder"
# bundle exec rake doc:rails generates the API under doc/api.
gem "sdoc", group: :doc

gem "sprockets"

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
gem "awesome_print"
gem "mini_racer"

group :development, :test do
gem "listen"
gem "pry"
gem "pry-byebug"
gem "pry-doc"
gem "pry-rails"
gem "pry-rescue"
gem "rubocop", "1.2.0", require: false
gem "scss_lint", require: false
gem "spring"
end

group :test do
gem "capybara"
gem "capybara-screenshot"
gem "coveralls", require: false
gem "equivalent-xml"
gem "generator_spec"
gem "launchy"
gem "rspec_junit_formatter"
gem "rspec-rails"
gem "rspec-retry"
gem "selenium-webdriver"
gem "webdrivers", "~> 3.0"
end
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*These are the docs for React on Rails 12. To see the version 11 docs, [click here](https://github.com/shakacode/react_on_rails/tree/11.3.0).*

#### News

**October 14, 2020**: [RUBY ROGUES
RR 474: React on Rails V12 – Don’t Shave That Yak! with Justin Gordon](https://devchat.tv/ruby-rogues/rr-474-react-on-rails-v12-dont-shave-that-yak-with-justin-gordon/).

Expand Down
6 changes: 3 additions & 3 deletions lib/react_on_rails/git_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ def self.uncommitted_changes?(message_handler)
status = `git status --porcelain`
return false if $CHILD_STATUS.success? && status.empty?

error = if !$CHILD_STATUS.success?
"You do not have Git installed. Please install Git, and commit your changes before continuing"
else
error = if $CHILD_STATUS.success?
"You have uncommitted code. Please commit or stash your changes before continuing"
else
"You do not have Git installed. Please install Git, and commit your changes before continuing"
end
message_handler.add_error(error)
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,9 @@ def exec_server_render_js(js_code, render_options, js_evaluator = nil)
console_script_lines = console_script.split("\n")
console_script_lines = console_script_lines[2..-2]
re = /console\.(?:log|error)\.apply\(console, \["\[SERVER\] (?<msg>.*)"\]\);/
if console_script_lines
console_script_lines.each do |line|
match = re.match(line)
Rails.logger.info { "[react_on_rails] #{match[:msg]}" } if match
end
console_script_lines&.each do |line|
match = re.match(line)
Rails.logger.info { "[react_on_rails] #{match[:msg]}" } if match
end
end
result
Expand Down
2 changes: 1 addition & 1 deletion lib/react_on_rails/test_helper/webpack_assets_compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class WebpackAssetsCompiler
def compile_assets
if ReactOnRails.configuration.build_test_command.blank?
msg = <<~MSG
You are using the React on Rails test helper.
You are using the React on Rails test helper.
Either you used:
ReactOnRails::TestHelper.configure_rspec_to_compile_assets or
ReactOnRails::TestHelper.ensure_assets_compiled
Expand Down
4 changes: 3 additions & 1 deletion lib/react_on_rails/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def self.wrap_message(msg, color = :red)
end

def self.object_to_boolean(value)
[true, "true", "yes", 1, "1", "t"].include?(value.class == String ? value.downcase : value)
[true, "true", "yes", 1, "1", "t"].include?(value.instance_of?(String) ? value.downcase : value)
end

def self.server_rendering_is_enabled?
Expand Down Expand Up @@ -118,9 +118,11 @@ def self.rails_version_less_than(version)
end
end

# rubocop:disable Naming/VariableNumber
def self.rails_version_less_than_4_1_1
rails_version_less_than("4.1.1")
end
# rubocop:enable Naming/VariableNumber

module Required
def required(arg_name)
Expand Down
8 changes: 4 additions & 4 deletions lib/tasks/assets.rake
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ end
namespace :react_on_rails do
namespace :assets do
desc <<-DESC.strip_heredoc
Compile assets with webpack
Uses command defined with ReactOnRails.configuration.build_production_command
sh "#{ReactOnRails::Utils.prepend_cd_node_modules_directory('<ReactOnRails.configuration.build_production_command>')}"
Note: This command is not automatically added to assets:precompile if the rails/webpacker
Compile assets with webpack
Uses command defined with ReactOnRails.configuration.build_production_command
sh "#{ReactOnRails::Utils.prepend_cd_node_modules_directory('<ReactOnRails.configuration.build_production_command>')}"
Note: This command is not automatically added to assets:precompile if the rails/webpacker
configuration file config/webpack/production.js exists.
DESC
task webpack: :locale do
Expand Down
5 changes: 0 additions & 5 deletions rakelib/docker.rake
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ namespace :docker do
sh "docker-compose run lint rake lint:rubocop"
end

desc "Run ruby-lint linter from docker"
task :ruby do
sh "docker-compose run lint rake lint:ruby"
end

desc "Run scss-lint linter from docker"
task :scss do
sh "docker-compose run lint rake lint:scss"
Expand Down
12 changes: 3 additions & 9 deletions rakelib/lint.rake
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@ namespace :lint do

desc "Run Rubocop as shell"
task :rubocop do
sh_in_dir(gem_root, "bundle exec rubocop .")
end

desc "Run ruby-lint as shell"
task :ruby do
puts "See /ruby-lint.yml for what directories are included."
sh_in_dir(gem_root, "bundle exec ruby-lint .")
sh_in_dir(gem_root, "bundle exec rubocop --version", "bundle exec rubocop .")
end

desc "Run scss-lint as shell"
Expand All @@ -23,10 +17,10 @@ namespace :lint do

desc "Run eslint as shell"
task :eslint do
sh_in_dir(gem_root, "yarn run eslint")
sh_in_dir(gem_root, "yarn run eslint --version", "yarn run eslint .")
end

desc "Run all eslint & rubocop linters. Skip ruby-lint and scss"
desc "Run all eslint & rubocop linters. Skip scss"
task lint: %i[eslint rubocop] do
puts "Completed all linting"
end
Expand Down
5 changes: 2 additions & 3 deletions rakelib/task_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ def dummy_app_dir
end

# Executes a string or an array of strings in a shell in the given directory
def sh_in_dir(dir, shell_commands)
shell_commands = [shell_commands] if shell_commands.is_a?(String)
shell_commands.each { |shell_command| sh %(cd #{dir} && #{shell_command.strip}) }
def sh_in_dir(dir, *shell_commands)
shell_commands.flatten.each { |shell_command| sh %(cd #{dir} && #{shell_command.strip}) }
end

def bundle_install_in(dir)
Expand Down
Loading

0 comments on commit 5d8c130

Please sign in to comment.