Coder Social home page Coder Social logo

glavin001 / eslint-plugin-crc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gregswindle/eslint-plugin-crc

0.0 3.0 0.0 871 KB

Analyze and refactor JavaScript codebases with auto-generated Class-Responsibility-Collaboration models.

License: MIT License

JavaScript 97.62% HTML 2.38%

eslint-plugin-crc's Introduction

eslint-plugin-crc

Analyze and refactor JavaScript codebases with auto-generated Class-Responsibility-Collaborator models.

Inline docs Travis CI Build Status NSP Status Codacy Badge Coverage Status Quality Gate bitHound Dependencies bitHound Dev Dependencies


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 and object synonymously to indicate objects with prototypal inheritance.

CRC model template

CRC models consist of three simple sections for:

  1. Name: what the class (or object) is called in source code.
  2. Responsibilities: the work that the class/object is supposed to perform, and the data it's supposed to maintain.
  3. 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 class/object's activities and purpose:

  1. What the class/object does.
  2. The information it maintains.

Objects that this class depends on to:

  1. Assist Class name with its work.
  2. Provide info/data that Class name needs.

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
  1. Fetches content with web services
  2. Determines the type of content (e.g., Article, Comment, Version History, each of which has different interfaces)
  3. Adapts each content-type so it can be displayed in a single template
  4. Sanitizes users' comments
  5. Saves users' comments
  6. Displays comment status messages
  7. Validates form field input
  8. Transforms hyperlinks based on personalization rules
  1. XMLHTTPRequest

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.

MVP 2: eslint integration

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.

Referred via generator-iojs.

How to Make Pull Request

Read to contribute PULL_REQUEST_TEMPLATE.md.

Referred via generator-iojs.

License

Copyright (c) Greg Swindle. This source code is licensed under the MIT license.

eslint-plugin-crc's People

Contributors

greenkeeper[bot] avatar gregswindle avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.