This repository contains code and documentation for a RubyConf 2021 workshop called "All Comments Must Be Haiku! Custom linting with RuboCop". In this workshop, we will:
- Discuss RuboCop, what it does, its benefits and drawbacks.
- Experiment a little with parser and learn about the underlying data structure RuboCop uses to parse code.
- Write a custom cop (linting rule) that will enforce a rule that comments must be in haiku format.
- Extend that cop in order to get more practice with RuboCop's Node Pattern DSL
If time permits we will:
- Add auto-correction to our cop
- Add configuration options to our cop
This workshop assumes that you have some experience writing Ruby. This workshop does not assume that you have any experience with RuboCop.
You'll need Ruby installed. This code has been tested with Ruby 2.5, 2.6, and 3.0.
- Clone the repo
- Run
bundle install
This workshop will hopefully teach you:
- What abstract syntax trees are and what they are useful for
- How RuboCop uses ASTs to understand Ruby code
- How to use RuboCop to enforce custom linting rules
- Drawbacks to RuboCop
- What is possible with RuboCop, and what isn't
These are some links to useful reading about some of the topics we've touched on.