With Squawk, we frequently add new linter rules. A quick way to do this is to duplicate an existing rule and modify it. This works, but we also want to add documentation, update imports for the new rule, and update our homepage. That’s tedious work.

A code generator makes adding a new rule easy.

With a code generator, we can:

I’ve found Plop is a decent generator. I originally searched GitHub for plopfile.js files for inspiration and used Next.js’s plopfile.js as a starting point.

Squawk’s s/new-rule script makes it easy to start adding new rules to Squawk:

s/new-rule 'my new rule'
✔  ++ /linter/src/rules/my_new_rule.rs
✔  ++ /docs/docs/my-new-rule.md
✔  +- /linter/src/rules/mod.rs
✔  +- /linter/src/violations.rs
✔  +- /linter/src/lib.rs
✔  +- /linter/src/lib.rs
✔  +- /docs/sidebars.js
✔  +- /docs/src/pages/index.js

I think using a code generator like Plop can be useful for adding HTTP endpoints, queue workers, database models, UI components and more to a project.