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

Style/WordArray: type mismatch: String given #3345

Closed
lucadevitis-msm opened this issue Jul 26, 2016 · 2 comments · Fixed by #4022
Closed

Style/WordArray: type mismatch: String given #3345

lucadevitis-msm opened this issue Jul 26, 2016 · 2 comments · Fixed by #4022

Comments

@lucadevitis-msm
Copy link

lucadevitis-msm commented Jul 26, 2016

Expected behaviour

It is expected to behave in the same way either as a standalone command or as rake task. It is not expected to raise errors

Actual behaviour

Style/WordArray cop fails with type mismatch: String given when Rubocop is run as rake task.
It does not fail if Rubocop is run as a standalone command.
Following commands and output should give you all the information you need. Let me know if you need anything else. Rubocop version is included in the bundle list

Steps to reproduce the problem

cat /etc/redhat-release

CentOS release 6.8 (Final)

rvm --version

rvm 1.26.11 (master) by Wayne E. Seguin <[email protected]>, Michal Papis <[email protected]> [https://rvm.io/]

rvm list default rubies

Default Ruby (for new shells)

   ruby-2.1.5 [ x86_64 ]

bundle list

Gems included by the bundle:
  * CFPropertyList (2.2.8)
  * ast (2.3.0)
  * bundler (1.12.5)
  * diff-lcs (1.2.5)
  * docile (1.1.5)
  * facter (2.4.6)
  * hiera (1.3.4)
  * hiera-puppet-helper (1.0.1)
  * json (2.0.2)
  * json_pure (2.0.2)
  * metaclass (0.0.4)
  * metadata-json-lint (0.0.11)
  * mocha (1.1.0)
  * parser (2.3.1.2)
  * powerpack (0.1.1)
  * puppet (3.8.7)
  * puppet-lint (2.0.0)
  * puppet-strings (0.4.0)
  * puppet-syntax (2.1.0)
  * puppetlabs_spec_helper (1.1.1)
  * rainbow (2.1.0)
  * rake (11.2.2)
  * redcarpet (3.3.4)
  * rspec (3.5.0)
  * rspec-core (3.5.1)
  * rspec-expectations (3.5.0)
  * rspec-mocks (3.5.0)
  * rspec-puppet (2.4.0)
  * rspec-support (3.5.0)
  * rubocop (0.42.0)
  * ruby-augeas (0.5.0)
  * ruby-progressbar (1.8.1)
  * simplecov (0.12.0)
  * simplecov-html (0.10.0)
  * spdx-licenses (1.1.0)
  * unicode-display_width (1.1.0)
  * yard (0.9.5)

cat Rakefile

require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet_x/puppetlabs/strings/util'
require 'rake/clean'
require 'rubocop/rake_task'

# Tells which files to remove on clean task.
CLEAN.include(['.yardoc', 'doc', 'strings.json', 'coverage'])

# `:default` task require `:help`. Not necessary.
Rake.application['default'].prerequisites.delete('help')

# Create `:rubocop` task
RuboCop::RakeTask.new :rubocop do |config|
  config.options = %w(--debug)
  config.patterns = %w(Rakefile)
end

desc 'Generate Puppet documentation with YARD.'
task :strings do
  PuppetX::PuppetLabs::Strings::Util.generate
end

# Let's create a few requirements.
task default: [:strings, :spec]
task spec: [:spec_prep, :validate]
task validate: [:rubocop, :lint]
task clean: [:spec_clean]

bundle exec rake rubocop

/home/luca/.rvm/gems/ruby-2.1.5/gems/yard-0.9.5/lib/yard/code_objects/base.rb:51: warning: already initialized constant YARD::CodeObjects::CONSTANTMATCH
/home/luca/.rvm/gems/ruby-2.1.5/gems/puppet-strings-0.4.0/lib/puppet_x/puppetlabs/strings/yard/core_ext/yard.rb:10: warning: previous definition of CONSTANTMATCH was here
/home/luca/.rvm/gems/ruby-2.1.5/gems/yard-0.9.5/lib/yard/code_objects/base.rb:54: warning: already initialized constant YARD::CodeObjects::CONSTANTSTART
/home/luca/.rvm/gems/ruby-2.1.5/gems/puppet-strings-0.4.0/lib/puppet_x/puppetlabs/strings/yard/core_ext/yard.rb:21: warning: previous definition of CONSTANTSTART was here
Running RuboCop...
For /home/luca/github/lucadevitis-msm/puppet/talend: configuration from /home/luca/github/lucadevitis-msm/puppet/talend/.rubocop.yml
Default configuration from /home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/config/default.yml
Inheriting configuration from /home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/config/enabled.yml
Inheriting configuration from /home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/config/disabled.yml
Inspecting 1 file
Scanning /home/luca/github/lucadevitis-msm/puppet/talend/Rakefile
An error occurred while Style/WordArray cop was inspecting /home/luca/github/lucadevitis-msm/puppet/talend/Rakefile.
type mismatch: String given
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/cop/style/word_array.rb:81:in `=~'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/cop/style/word_array.rb:81:in `!~'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/cop/style/word_array.rb:81:in `block in complex_content?'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/cop/style/word_array.rb:79:in `each'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/cop/style/word_array.rb:79:in `any?'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/cop/style/word_array.rb:79:in `complex_content?'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/cop/style/word_array.rb:49:in `check_bracketed'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/cop/style/word_array.rb:21:in `on_array'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/cop/commissioner.rb:42:in `block (2 levels) in on_array'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/cop/commissioner.rb:97:in `with_cop_error_handling'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/cop/commissioner.rb:41:in `block in on_array'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/cop/commissioner.rb:40:in `each'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/cop/commissioner.rb:40:in `on_array'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/ast_node/traversal.rb:102:in `block in on_send'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/ast_node/traversal.rb:100:in `each'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/ast_node/traversal.rb:100:in `each_with_index'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/ast_node/traversal.rb:100:in `on_send'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/cop/commissioner.rb:46:in `on_send'
(eval):2:in `block in on_begin'
(eval):2:in `each'
(eval):2:in `on_begin'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/cop/commissioner.rb:46:in `on_begin'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/ast_node/traversal.rb:13:in `walk'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/cop/commissioner.rb:59:in `investigate'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/cop/team.rb:121:in `investigate'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/cop/team.rb:109:in `offenses'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/cop/team.rb:52:in `inspect_file'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/runner.rb:223:in `inspect_file'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/runner.rb:193:in `block in do_inspection_loop'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/runner.rb:183:in `loop'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/runner.rb:183:in `do_inspection_loop'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/runner.rb:93:in `block in file_offenses'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/runner.rb:103:in `file_offense_cache'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/runner.rb:91:in `file_offenses'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/runner.rb:82:in `process_file'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/runner.rb:59:in `block in inspect_files'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/runner.rb:57:in `each'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/runner.rb:57:in `inspect_files'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/runner.rb:35:in `run'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/cli.rb:72:in `execute_runner'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/cli.rb:28:in `run'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/rake_task.rb:49:in `run_cli'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/rake_task.rb:37:in `run_main_task'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/rake_task.rb:29:in `block (2 levels) in initialize'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rake-11.2.2/lib/rake/file_utils_ext.rb:58:in `verbose'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/lib/rubocop/rake_task.rb:27:in `block in initialize'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rake-11.2.2/lib/rake/task.rb:248:in `call'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rake-11.2.2/lib/rake/task.rb:248:in `block in execute'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rake-11.2.2/lib/rake/task.rb:243:in `each'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rake-11.2.2/lib/rake/task.rb:243:in `execute'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rake-11.2.2/lib/rake/task.rb:187:in `block in invoke_with_call_chain'
/home/luca/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rake-11.2.2/lib/rake/task.rb:180:in `invoke_with_call_chain'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rake-11.2.2/lib/rake/task.rb:173:in `invoke'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rake-11.2.2/lib/rake/application.rb:152:in `invoke_task'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rake-11.2.2/lib/rake/application.rb:108:in `block (2 levels) in top_level'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rake-11.2.2/lib/rake/application.rb:108:in `each'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rake-11.2.2/lib/rake/application.rb:108:in `block in top_level'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rake-11.2.2/lib/rake/application.rb:117:in `run_with_threads'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rake-11.2.2/lib/rake/application.rb:102:in `top_level'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rake-11.2.2/lib/rake/application.rb:80:in `block in run'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rake-11.2.2/lib/rake/application.rb:178:in `standard_exception_handling'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rake-11.2.2/lib/rake/application.rb:77:in `run'
/home/luca/.rvm/gems/ruby-2.1.5/gems/rake-11.2.2/exe/rake:27:in `<top (required)>'
/home/luca/.rvm/gems/ruby-2.1.5/bin/rake:23:in `load'
/home/luca/.rvm/gems/ruby-2.1.5/bin/rake:23:in `<top (required)>'
/home/luca/.rvm/gems/ruby-2.1.5/gems/bundler-1.12.5/lib/bundler/cli/exec.rb:63:in `load'
/home/luca/.rvm/gems/ruby-2.1.5/gems/bundler-1.12.5/lib/bundler/cli/exec.rb:63:in `kernel_load'
/home/luca/.rvm/gems/ruby-2.1.5/gems/bundler-1.12.5/lib/bundler/cli/exec.rb:24:in `run'
/home/luca/.rvm/gems/ruby-2.1.5/gems/bundler-1.12.5/lib/bundler/cli.rb:304:in `exec'
/home/luca/.rvm/gems/ruby-2.1.5/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/home/luca/.rvm/gems/ruby-2.1.5/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/home/luca/.rvm/gems/ruby-2.1.5/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor.rb:359:in `dispatch'
/home/luca/.rvm/gems/ruby-2.1.5/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor/base.rb:440:in `start'
/home/luca/.rvm/gems/ruby-2.1.5/gems/bundler-1.12.5/lib/bundler/cli.rb:11:in `start'
/home/luca/.rvm/gems/ruby-2.1.5/gems/bundler-1.12.5/exe/bundle:27:in `block in <top (required)>'
/home/luca/.rvm/gems/ruby-2.1.5/gems/bundler-1.12.5/lib/bundler/friendly_errors.rb:98:in `with_friendly_errors'
/home/luca/.rvm/gems/ruby-2.1.5/gems/bundler-1.12.5/exe/bundle:19:in `<top (required)>'
/home/luca/.rvm/gems/ruby-2.1.5/bin/bundle:23:in `load'
/home/luca/.rvm/gems/ruby-2.1.5/bin/bundle:23:in `<main>'
.

1 file inspected, no offenses detected

1 error occurred:
An error occurred while Style/WordArray cop was inspecting /home/luca/github/lucadevitis-msm/puppet/talend/Rakefile.
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.42.0 (using Parser 2.3.1.2, running on ruby 2.1.5 x86_64-linux)
RuboCop failed!

bundle exec rubocop -d Rakefile

For /home/luca/github/lucadevitis-msm/puppet/talend: configuration from /home/luca/github/lucadevitis-msm/puppet/talend/.rubocop.yml
Default configuration from /home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/config/default.yml
Inheriting configuration from /home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/config/enabled.yml
Inheriting configuration from /home/luca/.rvm/gems/ruby-2.1.5/gems/rubocop-0.42.0/config/disabled.yml
Inspecting 1 file
Scanning /home/luca/github/lucadevitis-msm/puppet/talend/Rakefile
.

1 file inspected, no offenses detected
Finished in 0.256752383 seconds
@nhinds
Copy link

nhinds commented Jul 27, 2016

I'm getting the same thing. Looks like something in the rake environment is making cop_config['WordRegex'] not return a Regexp object, because yours is failing on the expression string !~ word_regex, and mine is failing on line 48 in rubocop 0.33.0, which is return true unless str_content =~ word_regex

        def word_regex
          cop_config['WordRegex']
        end

I'm not sure what would cause cop_config['WordRegex'] to return a string rather than a regular expression.

@jonas054
Copy link
Collaborator

I don't know why it can be a String either, but just allowing the parameter to be a String would solve the problem, I think.

        def word_regex
          Regexp.new(cop_config['WordRegex'])
        end

mikegee added a commit to mikegee/rubocop that referenced this issue Feb 6, 2017
When configured with a `String` value, parse it as a regular
expression before assuming it is an instance of `Regexp`.
bbatsov pushed a commit that referenced this issue Feb 7, 2017
When configured with a `String` value, parse it as a regular
expression before assuming it is an instance of `Regexp`.
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

Successfully merging a pull request may close this issue.

3 participants