eslint-plugin-crc
Analyze and refactor JavaScript codebases with auto-generated Class-Responsibility-Collaborator models.
Refactoring with Class-Responsibility-Collaborator (CRC) models
What are CRC models?
A CRC Model expresses how classes behave and interact using a simple and scannable template.
Note Since this product generates CRC models for the JavaScript language, I'm using the terms
class
andobject
synonymously to indicate objects with prototypal inheritance.
CRC model template
CRC models consist of three simple sections for:
- Name: what the class (or object) is called in source code.
- Responsibilities: the work that the class/object is supposed to perform, and the data it's supposed to maintain.
- Collaborators: other objects this class directly invokes in order to do its work.
CRC models were originally written index cards. eslint-plugin-crc
generates tables.
Class/Object name |
|
---|---|
Responsibilities | Collaborators |
The
|
Objects that this
|
CRC Models make design analysis easier
CRC models are meant to be scannable, readable, and comprehensible. They're useful for "Agile" teams and workflows, since they don't require a lot of time to create or understand.
CRC models focus on the purpose of classes instead of their mechanics, and (ideally) describe them in non-technical terms. CRC models can provide another perspective on software product improvement, since "experience pollution" and technical tunnel-vision often obscure simpler design possibilities.
CRCs and UML
I'm a big fan of the UML, and I use it often for formal design proposals and documentation. But when I don't need a first-order logical transformation of a product, CRC models work well.
CRC models are great for refactoring
CRC models are simple to read, write, and update. Because of their simplicity, CRC models are useful for determining why software might be difficult to extend or change.
CRC Models can help you pinpoint where problems might be, and reveal potential improvements to your design.
An example of a bloated controller
BlogController |
|
---|---|
Responsibilities | Collaborators |
|
|
This is an obvious case of code bloat, and a closer inspection of the source code would likely reveal that BlogController
has many source-lines of code; methods that are larger than 10 lines; and data primitives scattered all over the place. Regardless, the CRC model reveals that we're in the presence of a tyrannical God object that could benefit from class extraction.
eslint-plugin-crc
roadmap
MVP 1: report generation
Create actionable reports with CRC model that are easy generate and consume.
eslint
integration
MVP 2: Add or remove additional information generated by eslint
rules and plugins.
MVP 3..n: semantic analysis
Research and develop techniques that express possible semantic intent based on the semantic patterns mined from identifiers, method names, associations, and their true actions.
Please read about the goals of eslint-plugin-crc
for more details.
Installation
You'll first need to install ESLint:
$ npm i eslint --save-dev
Next, install eslint-plugin-crc
:
$ npm install eslint-plugin-crc --save-dev
Note: If you installed ESLint globally (using the -g
flag) then you must also install eslint-plugin-crc
globally.
Usage
Add crc
to the plugins section of your .eslintrc
configuration file. You can omit the eslint-plugin-
prefix:
{
"plugins": [
"crc"
]
}
Then configure the rules you want to use under the rules section.
{
"rules": {
"crc/rule-name": 2
}
}
Supported Rules
As of now, there are no rules. I plan on iterative releases, however, in hopes of parsing not only the syntactic structure of code, but also its semantic intent. I'd love to generate excellent explanations and recommendations like these, but that's a hefty task.
How to Contribute
Read to contribute CONTRIBUTING.md.
How to Make Pull Request
Read to contribute PULL_REQUEST_TEMPLATE.md.
License
Copyright (c) Greg Swindle. This source code is licensed under the MIT license.