During my early days implementing new cops, I created rubocopular search to allow me to understand if my node patterns are clear and matching with the nodes that I expected.
I'm curious how other developers are dealing with it and validating their node patterns.
The feature would be we have some rubocop-search or something that we can just enter with a node pattern and grep in all the code for it.
I'd like to know if the team has the interest to put it in the core. I can provide the PR for the feature.
ps: I'm actively working on fast that is a tool only with this purpose but my node pattern implementation is not complete and fully functional as the RuboCop one.
I think a good first step would be to extra the pattern matching library into its own gem, perhaps our note extensions as well. We discussed this back in the day, but we never made any progress.
I'm not strongly opposed to the idea of adding more scripts in the main gem, but it seems to me that something that searching for node patterns in somewhat orthogonal to the main purpose of RuboCop.
It could be useful if there is a tool that searches for a given pattern, extract the line that matches, run a given cop on that line and aggregates report with:
I often find myself in a TDD loop setting a breakpoint in a wrapping method, e.g.
def matcher(node)
binding.pry
_matcher(node)
end
def_node_matcher :_matcher, <<~PATTERN
(send _ $...)
end
and running RSpec.
You can define a matcher on the fly from the console on that breakpoint to improve the matcher pattern iteratively:
self.class.def_node_matcher :_matcher, '(send nil _ $...)'
Extraction of the node pattern library will allow for an alternative CSS-selector-like to become a reality. The idea is in the air.
I think a good first step would be to extra the pattern matching library into its own gem, perhaps our note extensions as well. We discussed this back in the day, but we never made any progress.
I was thinking about this as well, while working on the node extensions. Something like parser-tools.
Great! I started working on it 鈽濓笍
Let me know if the name is good or we can run a poll to find the proper name. I personally like NodePattern but I also thought about the following names:
Let me know if the name is good or we can run a poll to find the proper name.
The gem contains more than one part (node patterns and node extensions), so I'm hesitant to name it after only one of those parts.
Humm, I'm not sure if it is good to do Gemify. I think that it is API depending on the use of RuboCop. Extracting from RuboCop makes code tracking inconvenient. I don't have confidence that the gain is larger than pain.
BTW, If node patterns gemify, I think that it is necessary to keep the commit log why the change was made. I made it possible to keep the commit log by extracted RuboCop Rails and RuboCop Performance (These are WIP) .
I extracted ast/node part as a consequence of the node pattern dependencies. As they're in the same scope I thought it was good to be extracted because that part can be also useful for other AST researches.
@koic not sure if I got the Gemify meaning. If we use add_runtime_dependency probably we're not going to expand the Gemfile definition, only the new library as a runtime dependency as we do with parser and powerpack gems.
As the code under the ast/node domain is less updated than cops, I can't see a big issue. You mean, will it potentially become a problem if we need to change the code in both places and keep bumping versions to make it easy to release?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!
This issues been automatically closed due to lack of activity. Feel free to re-open it if you ever come back to it.
Most helpful comment
I think a good first step would be to extra the pattern matching library into its own gem, perhaps our note extensions as well. We discussed this back in the day, but we never made any progress.
I'm not strongly opposed to the idea of adding more scripts in the main gem, but it seems to me that something that searching for node patterns in somewhat orthogonal to the main purpose of RuboCop.