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

Call :expression on node instead of :keyword loc #2629

Merged
merged 4 commits into from
Feb 24, 2016

Conversation

rrosenblum
Copy link
Contributor

This is a continuation/replacement of #2414.

Two things have to be done:

  • there should be some indication in most formatters that the highlighted code spans beyond the line we've shown
  • offenses should keep track of both the start and the end of the highlighted code region, so tools like CodeClimate could query this information.

I have modified the formatters to include ellipses (...) at the end of the highlighted code if the highlighted code spans more than one line. This could open up the html formatter to have an expand button that could show the entire highlighted offense.

I will work on adding highlighted_area to the offense.

@@ -730,7 +730,7 @@ def full_description_of_cop(cop)
' ^',
'example2.rb:3:1: C: Inconsistent indentation ' \
'detected.',
'def a',
'def a...',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why we're highlighting more than def a here. A bug in the cop?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guess we should check this out.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's here that we highlight the whole node, in this case a def node. I wouldn't call it a bug. It's the easiest solution.

@bbatsov
Copy link
Collaborator

bbatsov commented Jan 17, 2016

I'm not sure ellipses are the way to go, as they don't see to imply strongly enough the omitted code is on a subsequent line, but I'm not sure what we can use instead.

@rrosenblum
Copy link
Contributor Author

I agree that ellipses do not imply that the code is on a different line. I am not sure that it necessarily matters though. Ellipses imply that there is more code included in the offense that is not shown. One alternative that we could do is add a line count to the end of the highlighted offense.

# source code
def some_method
  does_something
  does_something_else
end

An offense highlight could be

def some_method... + 3 lines
# or
def some_method + 3 lines

This may take me a little while to finish up. I have been in the process of moving and have not had too much free time recently.

@bbatsov
Copy link
Collaborator

bbatsov commented Jan 30, 2016

Well, everything beats nothing. There's one problem with ... - what if the line ends like this something.? At the very least we should colour them.

@rrosenblum
Copy link
Contributor Author

I could add a space between the end of the line and the ellipses. It could be something. .... I like the color idea. Do you have a color preference.

@bbatsov
Copy link
Collaborator

bbatsov commented Feb 1, 2016

I could add a space between the end of the line and the ellipses. It could be something. ....

Guess so. Or . (...). Some light colour would do.

@bbatsov
Copy link
Collaborator

bbatsov commented Feb 1, 2016

P.S. I like the html formatter idea as well.

@rrosenblum
Copy link
Contributor Author

I have a basic implementation for highlighted_coded in offense. I still need to change HTMLFormatter to use the new method. I have also been playing around with the idea of changing highlighted_code to a range or also including a highlighted_range method.

@bbatsov
Copy link
Collaborator

bbatsov commented Feb 10, 2016

OK, let me know when this is ready to be reviewed.

@rrosenblum
Copy link
Contributor Author

Will do. Sorry this has taken so long to get running. I should have this done shortly. Everything is functioning as expected. I still have a failing test. Also, as mentioned before, I think I am going to add a highlight_range method to offense. The main question with that is will it replace highlighted_code or go in as an addition.

@rrosenblum
Copy link
Contributor Author

This is finally functionally complete and ready for review.

@rrosenblum rrosenblum changed the title [WIP] - Call :expression on node instead of :keyword loc Call :expression on node instead of :keyword loc Feb 13, 2016
@rrosenblum rrosenblum force-pushed the expression_offense branch 3 times, most recently from 8a4a187 to 8ca7db9 Compare February 17, 2016 19:44
@@ -730,7 +730,7 @@ def full_description_of_cop(cop)
' ^',
'example2.rb:3:1: C: Inconsistent indentation ' \
'detected.',
'def a',
"def a \e[33m...\e[0m",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why coloring is enabled in this case can be found in spec_helper.rb. There we have the setting Rainbow.enabled = false, but it comes after require 'rubocop', which means that ELLIPSES = Rainbow('...').yellow.freeze has already been executed when we disable coloring.

@jonas054
Copy link
Collaborator

I made a comment about disabling Rainbow. Fix that if you want.
Otherwise it looks good!

@rrosenblum
Copy link
Contributor Author

@jonas054 thanks for the info on why the test was printing in color. In order to fix it, I had to require Rainbow in the spec_helper.rb and disable it before we require RuboCop.

@bbatsov
Copy link
Collaborator

bbatsov commented Feb 24, 2016

The changes look good. Just add some changelog entry.

@rrosenblum
Copy link
Contributor Author

I have added changelog entries. I also changed the name of the method from highlighted_range to highlighted_area. I thought this naming made more sense. If you prefer highlighted_range, I have no problem in changing it back.

bbatsov added a commit that referenced this pull request Feb 24, 2016
Call :expression on node instead of :keyword loc
@bbatsov bbatsov merged commit 515a6b4 into rubocop:master Feb 24, 2016
@rrosenblum
Copy link
Contributor Author

@BlakeWilliams, FYI, this has been merged.

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 this pull request may close these issues.

4 participants