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

adjusting content of rubocop messages for educational purposes #2028

Closed
tansaku opened this issue Jul 10, 2015 · 11 comments
Closed

adjusting content of rubocop messages for educational purposes #2028

tansaku opened this issue Jul 10, 2015 · 11 comments

Comments

@tansaku
Copy link
Contributor

tansaku commented Jul 10, 2015

apologies for random question, but using reek in an educational context, is there a way to configure differences to the content of the rubocop mesages?

For example, say that for education purposes we wanted to be able to modify:

lib/coin.rb:19:13: C: Style/RedundantSelf: Redundant self detected. (https://github.com/bbatsov/ruby-style-guide#no-self-unless-required)
  QUARTER = self.new('25')
            ^^^^^^^^^^^^^^

to

lib/coin.rb:19:13: C: Style/RedundantSelf: This line of code has a "self." prefix when it is not necessary.  This is a violation called "Redundant self" which you can read more about here: https://github.com/bbatsov/ruby-style-guide#no-self-unless-required
  QUARTER = self.new('25')
            ^^^^^^^^^^^^^^

would there be a simple way to do this without modifying source code?

@bbatsov
Copy link
Collaborator

bbatsov commented Jul 10, 2015

Unfortunately, there's no such way. This was discussed in the past, but no progress was made. See #799

@bbatsov bbatsov closed this as completed Jul 28, 2015
@tansaku
Copy link
Contributor Author

tansaku commented Sep 10, 2015

thanks @bbatsov - when you say there is no such way, you mean the current code doesn't support it rather than impossible right?

I notice that if I modify the StyleGuide parameter in enabled.yml I can adjust which URL gets associated with the report:

Metrics/LineLength:
  Description: 'Limit lines to 80 characters.'
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#80-character-limits'
  Enabled: true

So I can point to an alternate article if I want to:

Metrics/LineLength:
  Description: 'Limit lines to 80 characters.'
  StyleGuide: 'http://programmers.stackexchange.com/questions/148677/why-is-80-characters-the-standard-limit-for-code-width'
  Enabled: true

Clearly the description can be modified in the config file as well - can that also be printed out somehow? I don't care so much about being able to change the error messages per se, just being able to add some "more details text", like so:

Metrics/LineLength:
  Description: 'Limit lines to 80 characters.'
  Details: "You can thank the IBM punch card for this limit - it had 80 columns" 
  StyleGuide: 'http://programmers.stackexchange.com/questions/148677/why-is-80-characters-the-standard-limit-for-code-width'
  Enabled: true

Might this be easier, more practical to support? We've got a very strong use case for this with students developers. I read the previous discussion and it seemed to fizzle out on not having a good reason to proceed rather than a technical challenge.

We have a great reason (novices often need slightly more verbose messages than experts), and the rubocop config seems set up to all this sort of parameter configuration.

Is there more documentation on what other parameters can be used in the cops? I've read https://github.com/bbatsov/rubocop#generic-configuration-parameters but it doesn't mention the StyleGuide or Description parameters and I can't find any other reference to those two in the README.

I'm trying to get something similar working with the reek project troessner/reek#589 where we are considering using internationalization features to support custom messages, but I'm guessing there's actually less work to support similar in rubocop, since it's already set up to make the contents of the config available to the cop ...

@bbatsov
Copy link
Collaborator

bbatsov commented Sep 10, 2015

thanks @bbatsov - when you say there is no such way, you mean the current code doesn't support it rather than impossible right?

It's possible, but all the messages for every cop have to be extracted in the config, which is a lot of work. And, of course, people should be careful when they edit them, as many of those messages are used as templates for the final messages that you'll see.

@tansaku
Copy link
Contributor Author

tansaku commented Sep 10, 2015

right, so adding an optional details parameter might be simpler then?

@bbatsov
Copy link
Collaborator

bbatsov commented Sep 10, 2015

right, so adding an optional details parameter might be simpler then?

Yeah, something like this would be simpler for sure.

@tansaku
Copy link
Contributor Author

tansaku commented Sep 21, 2015

thanks @bbatsov so what would the process be to get some kind of optional details parameter into rubocop?

@tansaku
Copy link
Contributor Author

tansaku commented Sep 24, 2015

would it be okay to re-open this issue for discussion @bbatsov ?

@bbatsov
Copy link
Collaborator

bbatsov commented Sep 24, 2015

Or you can cook some PR and we can discuss it.

@tansaku
Copy link
Contributor Author

tansaku commented Sep 24, 2015

sure - any tips on where to start in the code? Do you guys have anything other than the general pull request guidelines? https://github.com/bbatsov/rubocop/blob/master/CONTRIBUTING.md#pull-requests

anything about how the codebase is laid out? tips for starting on working on it?

@jonas054
Copy link
Collaborator

@tansaku I would recommend you start looking at Cop#annotate_message where URLs are added to messages under certain conditions. Do something similar for a new Details parameter. And look at the examples of --display-style-guide usage in cli_spec.rb for how to do the testing.

@tansaku
Copy link
Contributor Author

tansaku commented Sep 29, 2015

thanks @jonas054 that was really helpful - rough draft pull request submitted ...

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