From c9b5df8bbf6434a10ea3000248236142998fdf2c Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Fri, 13 Nov 2020 23:38:07 -1000 Subject: [PATCH] Rubocop refinements --- .rubocop.yml | 136 ++---------------- .../ruby_embedded_java_script.rb | 8 +- rakelib/lint.rake | 4 +- rakelib/task_helpers.rb | 5 +- spec/dummy/.rubocop.yml | 15 ++ spec/dummy/Gemfile | 1 - spec/{ => dummy/spec}/.rubocop.yml | 2 +- spec/react_on_rails/.rubocop.yml | 5 + 8 files changed, 43 insertions(+), 133 deletions(-) create mode 100644 spec/dummy/.rubocop.yml rename spec/{ => dummy/spec}/.rubocop.yml (83%) create mode 100644 spec/react_on_rails/.rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml index 306aeb917..5580ab6a0 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -14,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 @@ -98,106 +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/EmptyInterpolation: - Enabled: false - -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 diff --git a/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb b/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb index 7d29ce2c3..8910bf926 100644 --- a/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +++ b/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb @@ -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\] (?.*)"\]\);/ - 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 diff --git a/rakelib/lint.rake b/rakelib/lint.rake index 0ff9f738f..2e30fdd4e 100644 --- a/rakelib/lint.rake +++ b/rakelib/lint.rake @@ -7,7 +7,7 @@ namespace :lint do desc "Run Rubocop as shell" task :rubocop do - sh_in_dir(gem_root, "bundle exec rubocop .") + sh_in_dir(gem_root, "bundle exec rubocop --version", "bundle exec rubocop .") end desc "Run scss-lint as shell" @@ -17,7 +17,7 @@ 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 scss" diff --git a/rakelib/task_helpers.rb b/rakelib/task_helpers.rb index 0e773efc4..678d3ff24 100644 --- a/rakelib/task_helpers.rb +++ b/rakelib/task_helpers.rb @@ -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) diff --git a/spec/dummy/.rubocop.yml b/spec/dummy/.rubocop.yml new file mode 100644 index 000000000..8921f72c2 --- /dev/null +++ b/spec/dummy/.rubocop.yml @@ -0,0 +1,15 @@ +inherit_from: + - ../../.rubocop.yml + +AllCops: + Exclude: + - 'Procfile.*' + - 'bin/**/*' + - 'client/**/*' + - 'node_modules/react-on-rails' + - 'node_modules/**/*' + - 'public/webpack/**/*' + +Metrics/BlockLength: + Exclude: + - 'config/routes.rb' diff --git a/spec/dummy/Gemfile b/spec/dummy/Gemfile index aefa91992..a2bcc402b 100644 --- a/spec/dummy/Gemfile +++ b/spec/dummy/Gemfile @@ -5,4 +5,3 @@ source "https://rubygems.org" eval_gemfile File.expand_path("../../Gemfile.development_dependencies", __dir__) gem "react_on_rails", path: "../.." - diff --git a/spec/.rubocop.yml b/spec/dummy/spec/.rubocop.yml similarity index 83% rename from spec/.rubocop.yml rename to spec/dummy/spec/.rubocop.yml index 3ea5b1ae6..a56154490 100644 --- a/spec/.rubocop.yml +++ b/spec/dummy/spec/.rubocop.yml @@ -2,4 +2,4 @@ inherit_from: - ../.rubocop.yml Metrics/BlockLength: - Max: 180 + Max: 200 diff --git a/spec/react_on_rails/.rubocop.yml b/spec/react_on_rails/.rubocop.yml new file mode 100644 index 000000000..09336f757 --- /dev/null +++ b/spec/react_on_rails/.rubocop.yml @@ -0,0 +1,5 @@ +inherit_from: + - ../../.rubocop.yml + +Metrics/BlockLength: + Max: 145