Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.38.0 still throwing errors #2944

Closed
coding-bunny opened this issue Mar 11, 2016 · 14 comments
Closed

0.38.0 still throwing errors #2944

coding-bunny opened this issue Mar 11, 2016 · 14 comments

Comments

@coding-bunny
Copy link

Okay,

I reported before that the Style/StringLiterals cop was generating errors in the 0.37.2 error.
Today I upgraded Rubocop to version 0.38.0 on a separate branch and tried to run it again to see what has changed.

Expected behavior

No new errors should be generated
Existing code should not marked as violations

Actual behavior

The current code base suddenly get's marked as violations for specific cops

Steps to reproduce the problem

  • upgrade to 0.38.0 from 0.37.2
  • use the supplied config files

.rubocop.yml

inherit_from: .rubocop_todo.yml
AllCops:
  Include:
    - '**/Rakefile'
    - '**/config.ru'
  Exclude:
    - 'db/schema.rb'
    - 'vendor/**/*'
  TargetRubyVersion: 2.3

# This rule checks whether the *end* keyword is always properly aligned with the variable
# it belongs to.
Lint/EndAlignment:
  AlignWith: variable

# This rule checks whether the alignment of hashes is following the correct configuration:
# All entries are aligned on keys, and no exceptions are allowed.
Style/AlignHash:
  EnforcedHashRocketStyle: key
  EnforcedColonStyle: key
  EnforcedLastArgumentHashStyle: always_inspect

# This rule enforces spaces around equal signs in function parameters.
Style/SpaceAroundEqualsInParameterDefault:
  EnforcedStyle: space

# This rule enforces spaces around operators.
# Alignment spaces are allowed as exception to the rule.
Style/SpaceAroundOperators:
  AllowForAlignment: true

# This rule enforces a single space to be placed before the block braces.
# Increases readability of the code.
Style/SpaceBeforeBlockBraces:
  EnforcedStyle: space

# This rule prevents spaces before the first argument in function calls.
# The only exception to this rule is properly aligning the parameters.
Style/SpaceBeforeFirstArg:
  AllowForAlignment: true

# This rule checks whether proper spacing is used for block braces in method calls.
# With the current configuration we do not allow spaces before or after the braces,
# except for the block parameters.
Style/SpaceInsideBlockBraces:
  EnforcedStyle: space
  EnforcedStyleForEmptyBraces: no_space
  SpaceBeforeBlockParameters: space

# Configures the spacing for curly brackets to be one space.
# The exception is empty braces, where no space is enforced.
Style/SpaceInsideHashLiteralBraces:
  EnforcedStyle: space
  EnforcedStyleForEmptyBraces: no_space

# This enforces the usage of proper english names for special variables, increasing the
# readability of the source code and removing things like $1 $$ and $:.
Style/SpecialGlobalVars:
  EnforcedStyle: use_english_names

# This rule checks whether string literals used inside interpolated strings are following the
# configured rule, which for Riskmethods is single quotes.
Style/StringLiteralsInInterpolation:
  EnforcedStyle: single_quotes

# This rule checks whether procs are properly written as symbol procs, unless the method in question
# is inside the ignore whitelist.
Style/SymbolProc:
  IgnoredMethods:
    - respond_to

# This rule checks whether trailing comma's are removed from string literals.
Style/TrailingCommaInLiteral:
  EnforcedStyleForMultiline: no_comma

# This rule enforces the removal of trivial accessors in the code, keeping the code base clean.
Style/TrivialAccessors:
  ExactNameMatch: true
  AllowPredicates: false
  AllowDSLWriters: false
  IgnoreClassMethods: false
  Whitelist:
    - to_ary
    - to_a
    - to_c
    - to_enum
    - to_h
    - to_hash
    - to_i
    - to_int
    - to_io
    - to_open
    - to_path
    - to_proc
    - to_r
    - to_regexp
    - to_str
    - to_s
    - to_sym

Style/TrailingCommaInLiteral:
  EnforcedStyleForMultiline: no_comma

Style/TrailingCommaInArguments:
  EnforcedStyleForMultiline: no_comma

Style/SymbolProc:
  IgnoredMethods:
    - respond_to

# Use single quotes for string literals unless they are being interpolated by the code.
# Strings spanning multiple lines using \ need to follow the same quote convention
Style/StringLiterals:
  EnforcedStyle: single_quotes
  ConsistentQuotesInMultiline: true

# When using Strings inside Interpolated strings, respect the same quote convention.
Style/StringLiteralsInInterpolation:
  EnforcedStyle: single_quotes

# Use proper English names for special variables, and not the obsucre Perl ones.
Style/SpecialGlobalVars:
  EnforcedStyle: use_english_names

.rubocop_todo.yml

# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2016-03-11 11:00:49 +0100 using RuboCop version 0.38.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 11
Lint/IneffectiveAccessModifier:
  Exclude:
    -some_file.rb

# Offense count: 4
Lint/UselessAccessModifier:
  Exclude:
    - 'app/business_objects/sql_search/supplier.rb'
    - 'app/form_objects/indicator_message/supplier_form_object.rb'
    - 'app/models/indicator.rb'
    - 'spec/support/database_support.rb'

# Offense count: 397
Metrics/AbcSize:
  Max: 169

# Offense count: 39
# Configuration parameters: CountComments.
Metrics/ClassLength:
  Max: 756

# Offense count: 36
Metrics/CyclomaticComplexity:
  Max: 37

# Offense count: 7509
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
# URISchemes: http, https
Metrics/LineLength:
  Max: 414

# Offense count: 457
# Configuration parameters: CountComments.
Metrics/MethodLength:
  Max: 132

# Offense count: 6
# Configuration parameters: CountComments.
Metrics/ModuleLength:
  Max: 424

# Offense count: 3
# Configuration parameters: CountKeywordArgs.
Metrics/ParameterLists:
  Max: 6

# Offense count: 22
Metrics/PerceivedComplexity:
  Max: 37

# Offense count: 2
# Cop supports --auto-correct.
Performance/Casecmp:
  Exclude:
    - some_file.rb

# Offense count: 1
# Cop supports --auto-correct.
Performance/Count:
  Exclude:
    - some_file.rb

# Offense count: 2
# Cop supports --auto-correct.
Performance/Detect:
  Exclude:
    - some_file.rb

# Offense count: 2
# Cop supports --auto-correct.
Performance/RangeInclude:
  Exclude:
    - some_file.rb

# Offense count: 3
# Cop supports --auto-correct.
Performance/RedundantBlockCall:
  Exclude:
    - some_file.rb

# Offense count: 1
# Cop supports --auto-correct.
Performance/RedundantMatch:
  Exclude:
    - some_file.rb

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: MaxKeyValuePairs.
Performance/RedundantMerge:
  Exclude:
    - some_file.rb

# Offense count: 5
# Cop supports --auto-correct.
Performance/Size:
  Exclude:
    - some_file.rb

# Offense count: 19
# Cop supports --auto-correct.
Performance/StringReplacement:
  Exclude:
    - some_file.rb

# Offense count: 1
Performance/TimesMap:
  Exclude:
    - some_file.rb

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
# SupportedStyles: outdent, indent
Style/AccessModifierIndentation:
  Enabled: false

# Offense count: 34
Style/AccessorMethodName:
  Enabled: false

# Offense count: 7
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: prefer_alias, prefer_alias_method
Style/Alias:
  Exclude:
    - some_file.rb

# Offense count: 228
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: with_first_parameter, with_fixed_indentation
Style/AlignParameters:
  Enabled: false

# Offense count: 5
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: always, conditionals
Style/AndOr:
  Exclude:
    - some_file.rb

# Offense count: 32
Style/AsciiComments:
  Exclude:
    - some_file.rb

# Offense count: 194
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
# SupportedStyles: line_count_based, semantic, braces_for_chaining
# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
# FunctionalMethods: let, let!, subject, watch
# IgnoredMethods: lambda, proc, it
Style/BlockDelimiters:
  Enabled: false

# Offense count: 2
# Cop supports --auto-correct.
Style/BlockEndNewline:
  Exclude:
    - some_file.rb

# Offense count: 468
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: braces, no_braces, context_dependent
Style/BracesAroundHashParameters:
  Enabled: false

# Offense count: 18
# Cop supports --auto-correct.
# Configuration parameters: IndentWhenRelativeTo, SupportedStyles, IndentOneStep, IndentationWidth.
# SupportedStyles: case, end
Style/CaseIndentation:
  Enabled: false

# Offense count: 5
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: nested, compact
Style/ClassAndModuleChildren:
  Exclude:
    - some_file.rb

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: is_a?, kind_of?
Style/ClassCheck:
  Exclude:
    - some_file.rb

# Offense count: 2
Style/ClassVars:
  Exclude:
    - some_file.rb

# Offense count: 312
# Cop supports --auto-correct.
Style/ClosingParenthesisIndentation:
  Enabled: false

# Offense count: 14
# Cop supports --auto-correct.
# Configuration parameters: Keywords.
# Keywords: TODO, FIXME, OPTIMIZE, HACK, REVIEW
Style/CommentAnnotation:
  Exclude:
    - some_file.rb

# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: SingleLineConditionsOnly.
Style/ConditionalAssignment:
  Exclude:
    - some_file.rb

# Offense count: 16
# Cop supports --auto-correct.
Style/DeprecatedHashMethods:
  Exclude:
    - some_file.rb

# Offense count: 1483
Style/Documentation:
  Enabled: false

# Offense count: 143
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: leading, trailing
Style/DotPosition:
  Enabled: false

# Offense count: 1
Style/DoubleNegation:
  Exclude:
    - some_file.rb

# Offense count: 1
Style/EachWithObject:
  Exclude:
    - some_file.rb

# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: empty, nil, both
Style/EmptyElse:
  Exclude:
    - some_file.rb

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AllowAdjacentOneLineDefs.
Style/EmptyLineBetweenDefs:
  Exclude:
    - some_file.rb

# Offense count: 1209
# Cop supports --auto-correct.
Style/EmptyLines:
  Enabled: false

# Offense count: 3973
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: empty_lines, no_empty_lines
Style/EmptyLinesAroundBlockBody:
  Enabled: false

# Offense count: 1554
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: empty_lines, no_empty_lines
Style/EmptyLinesAroundClassBody:
  Enabled: false

# Offense count: 26
# Cop supports --auto-correct.
Style/EmptyLinesAroundMethodBody:
  Enabled: false

# Offense count: 1576
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: empty_lines, no_empty_lines
Style/EmptyLinesAroundModuleBody:
  Enabled: false

# Offense count: 26
# Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment.
Style/ExtraSpacing:
  Enabled: false

# Offense count: 123
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
# SupportedStyles: consistent, special_for_inner_method_call, special_for_inner_method_call_in_parentheses
Style/FirstParameterIndentation:
  Enabled: false

# Offense count: 2
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: format, sprintf, percent
Style/FormatString:
  Exclude:
    - some_file.rb

# Offense count: 2265
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: when_needed, always
Style/FrozenStringLiteralComment:
  Enabled: false

# Offense count: 4
# Configuration parameters: AllowedVariables.
Style/GlobalVars:
  Exclude:
    - some_file.rb

# Offense count: 14
# Configuration parameters: MinBodyLength.
Style/GuardClause:
  Exclude:
    - some_file.rb

# Offense count: 79
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues.
# SupportedStyles: ruby19, ruby19_no_mixed_keys, hash_rockets
Style/HashSyntax:
  Enabled: false

# Offense count: 2
Style/IfInsideElse:
  Exclude:
    - 'app/models/indicator_message/base.rb'
    - 'lib/extensions/whitelist.rb'

# Offense count: 27
# Cop supports --auto-correct.
# Configuration parameters: MaxLineLength.
Style/IfUnlessModifier:
  Enabled: false

# Offense count: 48
# Cop supports --auto-correct.
# Configuration parameters: SupportedStyles, IndentationWidth.
# SupportedStyles: special_inside_parentheses, consistent, align_brackets
Style/IndentArray:
  EnforcedStyle: consistent

# Offense count: 706
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
# SupportedStyles: special_inside_parentheses, consistent, align_braces
Style/IndentHash:
  Enabled: false

# Offense count: 32
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: normal, rails
Style/IndentationConsistency:
  Exclude:
    - some_file.rb

# Offense count: 6
# Cop supports --auto-correct.
# Configuration parameters: Width.
Style/IndentationWidth:
  Exclude:
    - some_file.rb

# Offense count: 9
# Cop supports --auto-correct.
Style/Lambda:
  Exclude:
    - some_file.rb

# Offense count: 90
# Cop supports --auto-correct.
Style/LeadingCommentSpace:
  Enabled: false

# Offense count: 9
# Cop supports --auto-correct.
Style/MethodCallParentheses:
  Exclude:
    - some_file.rb

# Offense count: 5
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: snake_case, camelCase
Style/MethodName:
  Enabled: false

# Offense count: 1
Style/MultilineBlockChain:
  Exclude:
    - some_file.rb

# Offense count: 2
# Cop supports --auto-correct.
Style/MultilineBlockLayout:
  Exclude:
    - some_file.rb

# Offense count: 102
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
# SupportedStyles: aligned, indented
Style/MultilineMethodCallIndentation:
  Enabled: false

# Offense count: 12
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
# SupportedStyles: aligned, indented
Style/MultilineOperationIndentation:
  Enabled: false

# Offense count: 35
# Cop supports --auto-correct.
Style/MutableConstant:
  Enabled: false

# Offense count: 3
# Cop supports --auto-correct.
Style/NegatedIf:
  Exclude:
    - some_file.rb

# Offense count: 3
# Cop supports --auto-correct.
Style/NegatedWhile:
  Exclude:
    - some_file.rb

# Offense count: 22
Style/NestedParenthesizedCalls:
  Exclude:
    - some_file.rb

# Offense count: 13
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles.
# SupportedStyles: skip_modifier_ifs, always
Style/Next:
  Exclude:
    - some_file.rb

# Offense count: 1
# Cop supports --auto-correct.
Style/Not:
  Exclude:
    - some_file.rb

# Offense count: 77
# Cop supports --auto-correct.
Style/NumericLiterals:
  MinDigits: 13

# Offense count: 1
# Cop supports --auto-correct.
Style/OneLineConditional:
  Exclude:
    - some_file.rb

# Offense count: 1
Style/OpMethod:
  Exclude:
    - some_file.rb

# Offense count: 1
Style/OptionalArguments:
  Exclude:
    - some_file.rb

# Offense count: 5
# Cop supports --auto-correct.
Style/ParallelAssignment:
  Exclude:
    - some_file.rb

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AllowSafeAssignment.
Style/ParenthesesAroundCondition:
  Exclude:
    - some_file.rb

# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: PreferredDelimiters.
Style/PercentLiteralDelimiters:
  Exclude:
    - some_file.rb

# Offense count: 10
# Cop supports --auto-correct.
Style/PerlBackrefs:
  Exclude:
    - some_file.rb

# Offense count: 26
# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist.
# NamePrefix: is_, has_, have_
# NamePrefixBlacklist: is_, has_, have_
# NameWhitelist: is_a?
Style/PredicateName:
  Enabled: false

# Offense count: 11
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: compact, exploded
Style/RaiseArgs:
  Enabled: false

# Offense count: 1
# Cop supports --auto-correct.
Style/RedundantBegin:
  Exclude:
    - some_file.rb

# Offense count: 1
# Cop supports --auto-correct.
Style/RedundantFreeze:
  Exclude:
    - some_file.rb

# Offense count: 2
# Cop supports --auto-correct.
Style/RedundantParentheses:
  Exclude:
    - some_file.rb

# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: AllowMultipleReturnValues.
Style/RedundantReturn:
  Exclude:
    - some_file.rb

# Offense count: 1079
# Cop supports --auto-correct.
Style/RedundantSelf:
  Enabled: false

# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
# SupportedStyles: slashes, percent_r, mixed
Style/RegexpLiteral:
  Exclude:
    - some_file.rb

# Offense count: 52
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiterals:
  Enabled: false

RuboCop version

Include the output of rubocop -V:

$ rubocop -V
0.38.0 (using Parser 2.3.0.6, running on ruby 2.2.3 x86_64-darwin15)

Additional information

An error occurred while Style/StringLiterals cop was inspecting /Users/olivar/RubymineProjects/riskmethods/spec/business_objects/sql_search/risk_object/base_spec.rb.

But when I try this:

➜  riskmethods git:(rubocop-upgrade) ✗ bundle exec rubocop -d  /Users/olivar/RubymineProjects/riskmethods/spec/business_objects/sql_search/risk_object/base_spec.rb 
For /Users/olivar/RubymineProjects/riskmethods: configuration from /Users/olivar/RubymineProjects/riskmethods/.rubocop.yml
Inheriting configuration from /Users/olivar/RubymineProjects/riskmethods/.rubocop_todo.yml
Default configuration from /Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/config/default.yml
Inheriting configuration from /Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/config/enabled.yml
Inheriting configuration from /Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/config/disabled.yml
Inspecting 1 file
Scanning /Users/olivar/RubymineProjects/riskmethods/spec/business_objects/sql_search/risk_object/base_spec.rb
.

1 file inspected, no offenses detected
Finished in 0.6144763129996136 seconds

So something is off when running RUbocop over all files.

@coding-bunny
Copy link
Author

Additional Information 2

I've reverted the changes to my rubocop_todo.yml file, so that it is back on the 0.37.2 version.
Then I simply rub rubocop with bundle exec rubocop and I receive 2265 new offenses:

snippet:

spec/uploaders/base_uploader_spec.rb:1:1: C: Missing frozen string literal comment.
require 'rails_helper'
^

2272 files inspected, 2265 offenses detected

This is the file in question:

require 'rails_helper'

describe ::BaseUploader do

  subject { ::BaseUploader.new }

  let(:cache_dir) { Rails.root.join('tmp/uploads') }

  describe '#cache_dir' do

    it 'it has the correct dir for the cache store' do
      expect(subject.cache_dir).to eq cache_dir
    end

  end

end

There's no way this should be reported as string literal offense.

@basex
Copy link

basex commented Mar 11, 2016

I think the problem is this one: #2802

TargetRubyVersion: 2.3 is forcing EnforcedStyle: always for FrozenStringLiteralComment

@coding-bunny
Copy link
Author

that would explain the frozen string literal at least.
Still needs to be looked at the errors being generated.

@alexdowad
Copy link
Contributor

The only error I can repro is caused by:

Lint/IneffectiveAccessModifier:
  Exclude:
    -some_file.rb

...in .rubocop_todo.yml. This is invalid YAML; it should be - some_file.rb.

@coding-bunny
Copy link
Author

that's just a copy paste error, didn't want our file structure in there.

@alexdowad
Copy link
Contributor

In that case I can't reproduce your problem at all.

@coding-bunny
Copy link
Author

I'll run a -d tommorow on the files throwing it on my side

@coding-bunny
Copy link
Author

going to close this. Reinstalled Rubocop again and now it wll worked fine.
Writing this off as a quirk in IOS

@coding-bunny
Copy link
Author

sigh,

Sorry reopening this.
I ran the command again on my system and on our Jenkins, and receive the following:

➜  riskmethods git:(rubocop-upgrade) bundle exec rubocop -d /Users/olivar/RubymineProjects/riskmethods/spec/business_objects/sql_search/risk_object/base_spec.rb
For /Users/olivar/RubymineProjects/riskmethods: configuration from /Users/olivar/RubymineProjects/riskmethods/.rubocop.yml
Inheriting configuration from /Users/olivar/RubymineProjects/riskmethods/.rubocop_todo.yml
Default configuration from /Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/config/default.yml
Inheriting configuration from /Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/config/enabled.yml
Inheriting configuration from /Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/config/disabled.yml
Inspecting 1 file
Scanning /Users/olivar/RubymineProjects/riskmethods/spec/business_objects/sql_search/risk_object/base_spec.rb
An error occurred while Style/StringLiterals cop was inspecting /Users/olivar/RubymineProjects/riskmethods/spec/business_objects/sql_search/risk_object/base_spec.rb.
undefined method `source' for nil:NilClass
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/cop/style/string_literals.rb:25:in `block in on_dstr'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/cop/style/string_literals.rb:25:in `map'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/cop/style/string_literals.rb:25:in `on_dstr'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/cop/commissioner.rb:42:in `block (2 levels) in on_dstr'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/cop/commissioner.rb:97:in `with_cop_error_handling'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/cop/commissioner.rb:41:in `block in on_dstr'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/cop/commissioner.rb:40:in `each'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/cop/commissioner.rb:40:in `on_dstr'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/ast_node/traversal.rb:102:in `block in on_send'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/ast_node/traversal.rb:100:in `each'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/ast_node/traversal.rb:100:in `each_with_index'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/ast_node/traversal.rb:100:in `on_send'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/cop/commissioner.rb:46:in `on_send'
(eval):3:in `on_lvasgn'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/cop/commissioner.rb:46:in `on_lvasgn'
(eval):2:in `block in on_begin'
(eval):2:in `each'
(eval):2:in `on_begin'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/cop/commissioner.rb:46:in `on_begin'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/ast_node/traversal.rb:155:in `on_block'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/cop/commissioner.rb:46:in `on_block'
(eval):2:in `block in on_begin'
(eval):2:in `each'
(eval):2:in `on_begin'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/cop/commissioner.rb:46:in `on_begin'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/ast_node/traversal.rb:155:in `on_block'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/cop/commissioner.rb:46:in `on_block'
(eval):2:in `block in on_begin'
(eval):2:in `each'
(eval):2:in `on_begin'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/cop/commissioner.rb:46:in `on_begin'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/ast_node/traversal.rb:155:in `on_block'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/cop/commissioner.rb:46:in `on_block'
(eval):2:in `block in on_begin'
(eval):2:in `each'
(eval):2:in `on_begin'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/cop/commissioner.rb:46:in `on_begin'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/ast_node/traversal.rb:155:in `on_block'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/cop/commissioner.rb:46:in `on_block'
(eval):2:in `block in on_begin'
(eval):2:in `each'
(eval):2:in `on_begin'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/cop/commissioner.rb:46:in `on_begin'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/ast_node/traversal.rb:13:in `walk'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/cop/commissioner.rb:59:in `investigate'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/cop/team.rb:70:in `inspect_file'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/runner.rb:203:in `inspect_file'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/runner.rb:173:in `block in do_inspection_loop'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/runner.rb:163:in `loop'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/runner.rb:163:in `do_inspection_loop'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/runner.rb:87:in `process_file'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/runner.rb:59:in `block in inspect_files'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/runner.rb:57:in `each'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/runner.rb:57:in `inspect_files'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/runner.rb:35:in `run'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/lib/rubocop/cli.rb:30:in `run'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/bin/rubocop:14:in `block in <top (required)>'
/Users/olivar/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/benchmark.rb:303:in `realtime'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/gems/rubocop-0.38.0/bin/rubocop:13:in `<top (required)>'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/bin/rubocop:23:in `load'
/Users/olivar/.rvm/gems/ruby-2.2.3@riskmethods/bin/rubocop:23:in `<main>'
.

1 file inspected, no offenses detected

1 error occurred:
An error occurred while Style/StringLiterals cop was inspecting /Users/olivar/RubymineProjects/riskmethods/spec/business_objects/sql_search/risk_object/base_spec.rb.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
Mention the following information in the issue report:
0.38.0 (using Parser 2.3.0.6, running on ruby 2.2.3 x86_64-darwin15)
Finished in 0.6169131550000202 seconds

The file in question is a standard spec file, but contains again a multiline string with a mix of single and double quotes.

@coding-bunny coding-bunny reopened this Mar 14, 2016
@coding-bunny
Copy link
Author

Here's a slightly modified file that is throwing the errors:

# frozen_string_literal: true
module TestModule
  module SecondTestModule

    class TestEntity < ::TestModule::SecondTestModule::Base
      # Virtus attributes
      attribute :some_id, Integer

      protected

      def affected_entities
        affected_cookies = reference[:cookie_ids]
        affected_boxes = reference[:box_ids]
        affected_cars = reference[:car_ids]
        affected_countries = reference[:country_ids]
        affected_factories = reference[:factory_ids]
        @affected_entities ||= ::Entity::Base.where(id: some_id).where(
          'indicator_entities.cookie_id IN (?) OR
          indicator_entities.box_id IN (?) OR
          indicator_entities.cars_id IN (?) OR
          indicator_entities.country_id IN (?) OR
          indicator_entities.factory_id IN (?)',
          affected_cookies,
          affected_boxes,
          affected_cars,
          affected_countries,
          affected_factories
          )
      end

      def affected_scores
        []
      end

    end

  end
end

@coding-bunny
Copy link
Author

and writing it like this fixes it:

# frozen_string_literal: true
module TestModule
  module SecondTestModule

    class TestEntity < ::TestModule::SecondTestModule::Base
      # Virtus attributes
      attribute :some_id, Integer

      protected

      def affected_entities
        affected_cookies = reference[:cookie_ids]
        affected_boxes = reference[:box_ids]
        affected_cars = reference[:car_ids]
        affected_countries = reference[:country_ids]
        affected_factories = reference[:factory_ids]
        @affected_entities ||= ::Entity::Base.where(id: some_id).where(
          sql_string,
          affected_cookies,
          affected_boxes,
          affected_cars,
          affected_countries,
          affected_factories
          )
      end

      def affected_scores
        []
      end

    end

    private

    def sql_string
      <<-SQL
         indicator_entities.cookie_id IN (?) OR
         indicator_entities.box_id IN (?) OR
         indicator_entities.cars_id IN (?) OR
         indicator_entities.country_id IN (?) OR
         indicator_entities.factory_id IN (?)
      SQL
    end
  end
end

@coding-bunny
Copy link
Author

I've rewritten all our offensive files using this structure:

some_function(
  "--\n"\
  "SELECT something\n"\
  "FROM SOMETHING"
end

and all the Rubocop errors dissapeared.
When the source code is written like this:

def joined_model
    self.relation(
      "--
      SELECT *
      LEFT JOIN X on Y
      FROM Models"
   )
end

Rubocop throws out the above mentioned errors.

@alexdowad
Copy link
Contributor

Thanks for the update. I will probably be able to find it with this extra
information.

On Mon, Mar 14, 2016 at 2:44 PM, Arne De Herdt [email protected]
wrote:

I've rewritten all our offensive files using this structure:

some_function(
"--\n"
"SELECT something\n"
"FROM SOMETHING"
end

and all the Rubocop errors dissapeared.
When the source code is written like this:

def joined_model
self.relation(
"--
SELECT *
LEFT JOIN X on Y
FROM Models"
)
end

Rubocop throws out the above mentioned errors.


Reply to this email directly or view it on GitHub
#2944 (comment).

@coding-bunny
Copy link
Author

If you need more input from my side, just let me know and I'll be happy to help out.
Really love this tool, and supporting it.

Also, writing the code in heredoc style seems to work as well:

def some_function
   ActiveRecord.execute(<<-SQL, param1, param2)
      SELECT *
      FROM Models
      WHERE X IN (?)
      AND Y IN (?)
   SQL
end

jonas054 added a commit to jonas054/rubocop that referenced this issue May 28, 2016
Neodelf pushed a commit to Neodelf/rubocop that referenced this issue Oct 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants