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/Copyright Bug #2068

Closed
philoserf opened this issue Jul 25, 2015 · 8 comments
Closed

Style/Copyright Bug #2068

philoserf opened this issue Jul 25, 2015 · 8 comments
Labels

Comments

@philoserf
Copy link

I decided to give the copyright style cop a try. No joy. I will dig in to the spec/code tomorrow.

An error occurred while Style/Copyright cop was inspecting [snip]/test_file.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.32.1 (using Parser 2.2.2.6, running on ruby 2.2.2 x86_64-darwin14)
@bbatsov
Copy link
Collaborator

bbatsov commented Jul 25, 2015

A minimal reproducible use-case would be much appreciated. The cop's not on by default and hasn't been tested much in the field so far.

@philoserf
Copy link
Author

Here was my use case. On OS X and Ruby 2.2.2 run bundle gem test, touch .robocop.yml, add the following to that file:

Style/Copyright:
  Enabled: true

Run rubocop -a

@bbatsov
Copy link
Collaborator

bbatsov commented Jul 25, 2015

I meant we need some Ruby file that will produce this offense.

@philoserf
Copy link
Author

The boiler plate created by bundle gem is enough. Even one of its .rb files is enough.

Bundler's gem command is a generator.

This gist holds one of the ruby files and the full output of rubocop -a.

https://gist.github.com/philoserf/5f309bee863151eb80ce
edit: I updated the gist with gistfile2.txt containing the rubocop -ad stacktrace of lib/test.rb.

@philoserf
Copy link
Author

I'll be able to look more closely at the code, the spec, and try some other ruby versions today.

@philoserf
Copy link
Author

I have tested with clean ruby installations of Ruby 2.0.0-p645, 2.1.6, and 2.2.2 on OS X 10.10 using rbenv.

The Style/Copyright cop works with rubocop on the boilerplate created by bundler gem test on all these versions.

It fails with autocorrect enabled, rubocop -a on all these versions.

I will look at the autocorrect code in that cop next.

@philoserf
Copy link
Author

I see the issue now.

When run as rubocop -a the error message is An error occurred while Style/Copyright cop was inspecting /[snip]/test/Gemfile.

But when rub as rubocop -ad we see the needed message An error occurred while Style/Copyright cop was inspecting /[snip]/test/Gemfile. An AutocorrectNotice must be defined in your RuboCop config.

I am missing a required config value in my .rubocop.yml BUT I only learn that with debug enabled.

@philoserf
Copy link
Author

More detail

With a .rubocop.yml with this content:

Style/Copyright:
  Enabled: true
  AutocorrectNotice: 'Copyright 2015 by name'

The autocorrect runs BUT injects the value as written Copyright 2015 by name which is invalid ruby. The correct output of the autocorrect must be # Copyright 2015 by name; however, if the .rubocop.yml is as follows:

Style/Copyright:
  Enabled: true
  AutocorrectNotice: '# Copyright 2015 by name'

then the cop fails with AutocorrectNotice '# Copyright 2015 by name' must match Notice /^Copyright (\(c\) )?2[0-9]{3} .+/

I have to break for the day. I hope to look at the code and the tests for correction/improvement tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants