-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Documentation request: some guidance on how to write a rubocop extension with custom cops #2040
Comments
Maybe taking a look here would help https://github.com/nevir/rubocop-rspec We never actually got to creating an extension API, but hooking in RuboCop proper is pretty easy. I plan to spin the Rails stuff in a separate gem some day, hopefully this will motivate me to work on an a proper extension API. :-) |
That sounds like a cool idea! rubocop rspec seems cool, and works for me, but I wasn't sure how confident to feel about it as a learning example because it's based on a not-super-recent version of rubocop. I ended up focusing more on looking at the rubocop source code and got one working. I wasn't really sure if I was doing it right along the way but got it working 😄 (that one is kind of a joke) |
@bbatsov just to follow-up on this one... I'm a bit more familiar with rubocop internals than I was when I wrote this, and I've made a few extensions for my use which didn't feel appropriate to submit to the main project. I've just bumped into a limitation that might require the extension API, but I'm not sure. Let's say I make a custom cop. By inheriting from Buuut what if I want to configure my custom cop to only be included for one file? I can try adding a line to my I'd be happy to submit a pull request adding some explanation to the README about how to create a custom cop without an extension API for the sake of addressing people who shared my confusion from a few months ago, btw. Or do you think the extension API is coming soon? Happy to try and help on that too 😄 |
One pitfall that could be mentioned in the Readme is that you should disable the cache when you're working on your custom cop ( Also, I'm still having an 'unrecognized cop' warning with my custom cop even though it's poperly loaded and executed. I'll tell you when I find the solution to this too but if you have suggestions I'm interested ! |
Here's how Also, I've started work on my own plugin for linting Homebrew-cask files: |
Whoa, that's intense |
I am commenting because I would also like documentation on how to create custom cops (for those unfamiliar with the codebase). I have been searching and unable to find it. |
+1 |
Well remembered @maxjacobson. I think we can create another section mentioning require:
- rubocop-rspec
- ./lib/custom-cop/rubocop/namespace/cop-name It works in the same way 🎉 |
This works, but there's a downside. You can't refer to it in the configuration file, so you can't make a custom cop and apply it to a single directory, for example. Fixing this is on my TODO list. |
Or maybe just some tips on which direction to start looking 😄
The text was updated successfully, but these errors were encountered: