-
Notifications
You must be signed in to change notification settings - Fork 8
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
Add more file extensions #8
Conversation
- The plugin now also checks files with extensions .hpp, .hh, .cxx, .cc, .cpp - The error message is more informative. It first lists the offending files, then suggests appropriate actions and eventually prints the patches to apply.
Looks great! I believe it's a good start, a more generic approach (passing extensions as argument) can be implemented later. Adding/editing tests is easy, most of them are here. You might also want to run tests locally, to do that you need to install bundler gem and then do When in doubt, please use to .travis.yml file as a reference. Thank you for your contribution and feel free to ask anything. |
Thank for the pointers, @nikolaykasyanov. I have now fixed the existing tests and refactored the generation of the error message. I will try to add a tests for:
If you have suggestions on how to pass file extensions to be checked to the plugin, I can try to implement that too. |
@robertodr regarding file extension list as argument: we can do that by introducing a new key into plugin's configuration hash. At the time only A new key could be introduced and its value could be used instead of hardcoded list of extensions. Also, if this key is not specified in the config, current list of extensions must be used for backward compatibility reasons. Does it make sense? Plugin invocation could look like this: code_style_validation.check ignore_file_patterns: [/^Pods\//] file_extensions: ['.h', '.m', ...] |
How does it look now? 😄 I modified one line in the tests, so that the new parameter is tested: @my_plugin.check file_extensions: ['.h', '.m', '.mm', '.C', '.cpp'] Adding a new proper test for a |
README.md
Outdated
This plugin uses 'clang-format' to look for code style violations in added | ||
lines on the current MR / PR, and offers inline patches. | ||
By default only Objective-C files, with extensions `.h`, `.m`, `.mm` and | ||
`.C`, are checked. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does .C
have to be capitalized?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to Wikipedia Objective-C files usually have those extensions. I only kept Objective-C source file extensions as defaults for the file_extensions
input parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good find, I've never seen that extension in the wild, though. Also, it's effectively equal to .c
extension on case-insensitive filesystems (i.e. on most Macs).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, of course! I'll remove it and leave .m
, .mm
and .h
as defaults.
@robertodr 👍 looks great. It seems possible to make a test like existing "Reports code style violation as error", but such that does not specify Another crucial test I'd expect is to verify that |
I could assist you with mentioned tests tomorrow if needed. |
That would be great. I might not have time to look at it tomorrow, though. |
@robertodr could you please provide me a push access to this Pull Request so I can play with tests? |
@robertodr nevermind, it seems that checkbox was already enabled. |
lib/code_style_validation/plugin.rb
Outdated
message = '' | ||
unless offending_files.empty? | ||
message = 'Code style violations detected in the following files:' + "\n" | ||
offending_files.each do |file_name| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You seem to be using tabs here. Please use spaces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be helpful to configure Rubocop support in your editor. This repo doesn't have Rubocop's config yet, so it'll report some false positives, but it will also detect things like inconsistent indentation and trailing spaces.
lib/code_style_validation/plugin.rb
Outdated
|
||
message = '' | ||
unless offending_files.empty? | ||
message = 'Code style violations detected in the following files:' + "\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing space.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooops... Sorry. I haven't yet reconfigured my Neovim properly after reinstalling the OS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries!
My test fails on Travis, looking into it. |
My neovim configuration is back on track! I have fixed indentation inconsistencies and fixed #9
What do you think? |
@robertodr thanks! I'll try this out in our internal environment for a couple of days before merging. Don't you mind if I squash commits upon merging? |
Just test for as long as needed. No problem with squashing, as long as it preserves authorship assignment. What do you think about the crazy idea? Does it make sense? Is it doable? |
@robertodr sorry, I didn't notice your big comment. The idea about Gist sounds reasonable. The only concern is that it introduces a separate code path for open source projects (because posting diffs to Gist most certainly won't work for proprietary/closed source projects). I wonder if GitHub (GitLab) supports some kind of folding, that might solve the problem of big patches cluttering the review. Alternatively, patches could be attached as files (if GitHub API & Danger support that) and linked in comment text. |
Oh! Yes, of course. I had not thought about that. Well, this PR is complete. Anything else can be part of subsequent PRs. Would you agree to tag the code and mint a release when the PR is merged? |
@robertodr here you go: https://github.com/flix-tech/danger-code_style_validation/releases/tag/0.1.0 Thanks for your contribution! |
Thanks! It's been a pleasure collaborating with you on this. |
I am not a Ruby expert, but I've managed to make the following changes:
.hpp
,.hh
,.cxx
,.cc
,.cpp
, hence addressing Support more file extensions (hpp, cpp, etc.) #2.h
,.m
,.mm
)You can see the plugin in action for this example repository: PCMSolver/danger-cpp-example#3
### Questions/Ideas- [ ] I haven't added tests, because I don't know how to.- [ ]Generating the more informative error message requires iterating twice over thechanges
array.