CRC Model report sample - gregswindle/eslint-plugin-crc GitHub Wiki

CRC Model Report

Object count: 14. Generated on 2018-02-20T14:11:27.051Z.

Table of contents

CRC Models

ObjectastConfig

extends astConfig

eslint-plugin-crc's default Espree AST parsing options.

Responsibilities Collaborators
  1. eslint-plugin-crc's default Espree AST parsing options.

None found.
Select to toggle detailsastConfig details...

Source code

/**
 * `eslint-plugin-crc`'s default Espree AST parsing options.
 *
 * @static
 * @type {object}
 * @name astConfig
 * @property {boolean} attachComment - Attach comments to the closest relevant
 *  node as leadingComments and trailingComments.
 * @property {boolean} comment - Create a top-level comments array containing
 *  all comments.
 * @property {object} ecmaFeatures
 * @property {boolean} ecmaFeatures.experimentalObjectRestSpread - Allow
 *  experimental object rest/spread.
 * @property {boolean} ecmaFeatures.globalReturn - Enable return in global
 *  scope.
 * @property {boolean} ecmaFeatures.impliedStrict - Enable implied strict mode
 *  (if ecmaVersion >= 5).
 * @property {boolean} ecmaFeatures.jsx - Enable JSX parsing.
 * @property {number} ecmaVersion - Specify the version of ECMAScript syntax
 *  you want to use. Valid versions are:
 *
 * * 3
 * * 5 (default)
 * * 6 (2015)
 * * 7 (2016)
 * * 8 (2017)
 * * 9
 *
 * You can also set to 2015 (same as 6), 2016 (same as 7), or 2017
 * (same as 8) to use the year-based naming.
 * @property {boolean} loc - Attach line/column location information to each
 *  node.
 * @property {boolean} range - Attach range information to each node.
 * @property {enum} sourceType - Specify which type of script you're parsing
 *  (script or module, default is script).
 * @property {boolean} tokens - Create a top-level tokens array containing
 *  all tokens. `tokens` must be set to `true` in order for CRC models to
 *  maintain a list of "references", i.e., where they themselves are referenced.
 *
 */

const astConfig = {

  "attachComment": true,

  "comment": true,

  "ecmaFeatures": {

    "experimentalObjectRestSpread": true,

    "globalReturn": true,

    "impliedStrict": true,

    "jsx": true
  },

  "ecmaVersion": 6,

  "loc": true,

  "range": true,

  "sourceType": "module",

  "tokens": true
};

/**
 * @alias astConfig
 */

module.exports = Object.freeze(astConfig);

References

astConfig is referenced 4 times in n1 files.

  1. File name: astConfig [1570 : 1579]
  2. File name: module [1904 : 1910]
  3. File name: Object [1921 : 1927]
  4. File name: astConfig [1935 : 1944]

Path

/Users/swindle/Projects/github/gregswindle/eslint-plugin-crc/lib/crc/ast-config.js

classCommentsStrategy

eslint-disable-next-line no-unused-vars

Responsibilities Collaborators
  1. Provides an interface for various ways of retrieving source code comments.

  2. Provides tokenized JSDoc.

  3. Serializes comments as JSON.

None found.
Select to toggle detailsCommentsStrategy details...

Source code

const SourceCodeFactory = require("./source-code-factory");
// eslint-disable-next-line no-unused-vars
const {JsonString} = require("../typedef");
const {get} = require("lodash");

/**
 * Provides an interface for various ways of
 * retrieving source code comments.
 *
 * @class CommentsStrategy
 *
 * @prop {array.<String>} [files=[]] - An array of source code file paths.
 *
 * @param {array.<String>} [files=[]] - An array of source code file paths.
 */

class CommentsStrategy {
  constructor (files = []) {
    this.files = files;
  }

  /**
   * Provides tokenized JSDoc.
   *
   * @abstract
   * @method parse
   * @memberof CommentsStrategy
   * @instance
   *
   * @returns {array.<ESLint.SourceCode#ast#tokensAndComments>} The
   *  ESLint.SourceCode#ast#tokensAndComments.
   */

  parse () {
    return this.files
      .map((file) => new SourceCodeFactory(file))
      .map((source) => get(source, "code.tokensAndComments", []));
  }

  /**
   * Serializes comments as JSON.
   *
   * @abstract
   * @method toString
   * @memberof CommentsStrategy
   * @instance
   *
   * @returns {JsonString} A JSON string representation of the comments.
   */

  toString () {
    return JSON.stringify(this.parse());
  }
}

module.exports = CommentsStrategy;

References

CommentsStrategy is referenced 8 times in n1 files.

  1. File name: SourceCodeFactory [6 : 23]
  2. File name: require [26 : 33]
  3. File name: JsonString [110 : 120]
  4. File name: require [124 : 131]
  5. File name: get [154 : 157]
  6. File name: require [161 : 168]
  7. File name: module [1226 : 1232]
  8. File name: CommentsStrategy [1243 : 1259]

Path

/Users/swindle/Projects/github/gregswindle/eslint-plugin-crc/lib/crc/comments-strategy.js

classCrcClass

Default parameters for a CrcClass.

Responsibilities Collaborators
  1. Default parameters for a CrcClass.

  2. Create CrcClass.prototype.constructor parameters.

  3. Create a CrcClass from ESTree Nodes and ESLint Rule Contexts.

  4. A CrcClass NullObject.

    🔒 Note: NullCrcClass instances can only be created using the static getter CrcClass.nullObject.

  5. Creates a class representation for use in a CrcClass (Class-Responsibility-Collaboration model).

  6. A parameter object that sets all of the CrcClass's properties.

  7. The ESLint SourceCode object.

  8. The physcical path the source code file.

  9. Information about the SourceCode.

  10. The source code identifier of the class or object to be modeled.

  11. ESTree ASTNodes with locations.

  12. The prototype of the object being modeled. Defaults to null.

  13. const crcClass = new CrcClass({ code: sourceCode, meta: { context, description, filePath, references }, name: "Bravo", superClass: Alpha });

  14. The ESLint SourceCode object.

  15. A CrcMeta instance.

  16. The name of the "class", i.e., ECMAScript object that is a prototype of another constructor function.

  17. The function constructur that this CrcClass isPrototypeOf.

None found.
Select to toggle detailsCrcClass details...

Source code

const CrcMeta = require("./crc-meta");
const CrcResponsibility = require("./crc-responsibility");
const SourceCodeFactory = require("./source-code-factory");
const PrototypeInspector = require("./prototype-inspector");
const {
  get,
  invoke
} = require("lodash");

/**
 * Default parameters for a CrcClass.
 *
 * @type {CrcClass~NullCrcClass}
 * @private
 */

const defaultConstructorParams = {
  "code": SourceCodeFactory.nullObject,
  "meta": CrcMeta.nullObject,
  "name": null,
  "superClass": null
};

/**
 * Create CrcClass.prototype.constructor parameters.
 *
 * @param {CrcContext} context - A CrcContext object.
 *
 * @returns {type} Constructor parameters for a new CrcContext.
 * @ignore
 * @private
 */

const createParamsFromCrcContext = (context) => {
  const code = get(context, "code");
  const nodes = get(context, "nodes");
  const firstNode = get(invoke(nodes, "values().next()"), "value");
  const proto = PrototypeInspector.getPrototypeOf(context);
  const name = get(firstNode, "name") || proto.name;

  return {
    code,
    "meta": {
      context,
      "description": CrcResponsibility.descriptionFromContext(context),
      "filePath": get(context, "filePath"),
      "kind": proto.meta.kind,
      "references": PrototypeInspector.getScopeOf(context).references
    },
    name,
    "superClass": proto.superClass
  };
};

  /**
   * @namespace CrcClass
   * @kind class
   *
   * @classdesc
   * Creates a `class` representation for use in a CrcClass
   * (Class-Responsibility-Collaboration model).
   *
   * @param {Object} [params = defaultConstructorParams] - A parameter object that sets all of
   * the CrcClass's properties.
   * @param {SourceCode} [params.code] - The ESLint
   * [`SourceCode`](http://bit.ly/2kfR79f) object.
   * @param {string} [params.filePath] - The physcical path the source code
   *  file.
   * @param {CrcMeta} [params.meta] - Information about the SourceCode.
   * @param {string} [params.name] - The source code identifier of the class or
   * object to be modeled.
   * @param {array<ASTNode>} [params.references] - ESTree
   *  [`ASTNodes`](https://goo.gl/yTwW1m#node-objects) with locations.
   * @param {CrcClass} [params.superClass] - The `prototype` of the object being
   * modeled. Defaults to `null`.
   *
   * @example
   * const crcClass = new CrcClass({
   *   code: sourceCode,
   *   meta: {
   *     context,
   *     description,
   *     filePath,
   *     references
   *   },
   *   name: "Bravo",
   *   superClass: Alpha
   * });
   *
   * @property {SourceCode} code - The ESLint
   * [`SourceCode`](http://bit.ly/2kfR79f) object.
   * @property {CrcMeta} meta - A CrcMeta instance.
   * @property {String} name - The name of the "class", i.e.,
   *  ECMAScript object that is a `prototype` of another constructor function.
   * @property {CrcClass} superClass - The function constructur that this
   *  CrcClass isPrototypeOf.
   *
   * @this CrcClass
   */

class CrcClass {
  constructor (params = defaultConstructorParams) {
    this.code = params.code;
    this.meta = params.meta;
    this.name = params.name;
    this.superClass = params.superClass;
  }

  /**
   * Create a `CrcClass` from ESTree `Nodes` and ESLint Rule `Contexts`.
   *
   * @param {CrcContext} [context=null] - A summary object with information to derive
   * a CrcClass.
   * @example
   * const crcClass = CrcClass.create(context);
   * @returns {CrcClass|CrcClass~NullCrcClass} A summary representation of a PrototypeInspector object.
   */

  static create (context = null) {
    if (context) {
      const params = createParamsFromCrcContext(context);
      return new CrcClass(params);
    }
    return CrcClass.nullObject;
  }

  /**
   * @static
   * @property {NullCrcClass} nullObject - A CrcClass NullObject.
   *
   * 🔒 **Note:** `NullCrcClass` instances can **only** be created
   *  using the static getter `CrcClass.nullObject`.
   * @type CrcClass~NullCrcClass
   * @memberof CrcClass
   * @returns {CrcClass~NullCrcClass} A CrcClass NullObject.
   * @example
   * const nullCrcClass = CrcClass.nullObject;
   */

  static get nullObject () {
    /**
     * A CrcClass NullObject.
     *
     * 🔒 **Note:** `NullCrcClass` instances can **only** be created using the
     *  static getter `CrcClass.nullObject`.
     *
     * @extends CrcClass
     * @protected
     * @memberof CrcClass
     * @inner
     * @example
     * const nullCrcClass = CrcClass.nullObject;
     */

    class NullCrcClass extends CrcClass {}

    return new NullCrcClass(defaultConstructorParams);
  }
}

module.exports = CrcClass;

References

CrcClass is referenced 17 times in n1 files.

  1. File name: CrcMeta [6 : 13]
  2. File name: require [16 : 23]
  3. File name: CrcResponsibility [45 : 62]
  4. File name: require [65 : 72]
  5. File name: SourceCodeFactory [104 : 121]
  6. File name: require [124 : 131]
  7. File name: PrototypeInspector [164 : 182]
  8. File name: require [185 : 192]
  9. File name: get [229 : 232]
  10. File name: invoke [236 : 242]
  11. File name: require [247 : 254]
  12. File name: defaultConstructorParams [368 : 392]
  13. File name: SourceCodeFactory [407 : 424]
  14. File name: CrcMeta [447 : 454]
  15. File name: createParamsFromCrcContext [723 : 749]
  16. File name: module [4565 : 4571]
  17. File name: CrcClass [4582 : 4590]

Path

/Users/swindle/Projects/github/gregswindle/eslint-plugin-crc/lib/crc/crc-class.js

classCrcCodebase

Tracks contextual data for a collection of source code files.

Responsibilities Collaborators
  1. Tracks contextual data for a collection of source code files.

  2. Loads/initializes a CrcCodebase from ESLint result objects.

None found.
Select to toggle detailsCrcCodebase details...

Source code

const CrcContext = require("./crc-context");
const {sortedUniq} = require("lodash");

const defaultConstructorParams = {
  "code": new Map(),
  "contexts": [],
  "filePaths": [],
  "nodes": new Map()
};

/**
 * Tracks contextual data for a collection of source code files.
 *
 * @param {array.<Result>} results - All results from ESLint.
 * @class CrcCodebase
 *
 * @prop {Map.<SourceCode>} code - A Map of all SourceCode instances.
 * @prop {array.<CrcContext>} [contexts=[]] - An array of all CrcContexts.
 * @prop {array.<string>} [filePaths=[]] - An array of all source code file
 *  paths.
 * @prop {Map.<ASTNode>} nodes - A Map of all ASTNodes.
 */

class CrcCodebase {
  constructor (results) {
    Object.assign(this, defaultConstructorParams);
    this.load(results);
  }

  /**
   * Loads/initializes a `CrcCodebase` from ESLint result objects.
   *
   * @method load
   * @memberOf CrcCodebase
   * @instance
   *
   * @param {array.<Result>} results - All results from ESLint.
   *
   * @returns {void}
   */

  load (results) {
    results.forEach((result) => {
      const context = CrcContext.parse(result);
      this.contexts.push(context);
      this.filePaths.push(result.filePath);
      context.nodes.forEach((node, namespace) => {
        if (!this.nodes.has(namespace)) {
          this.nodes.set(namespace, node);
        }
      });
    });
    this.filePaths = sortedUniq(this.filePaths);
  }
}

module.exports = CrcCodebase;

References

CrcCodebase is referenced 9 times in n1 files.

  1. File name: CrcContext [6 : 16]
  2. File name: require [19 : 26]
  3. File name: sortedUniq [52 : 62]
  4. File name: require [66 : 73]
  5. File name: defaultConstructorParams [92 : 116]
  6. File name: Map [135 : 138]
  7. File name: Map [194 : 197]
  8. File name: module [1422 : 1428]
  9. File name: CrcCodebase [1439 : 1450]

Path

/Users/swindle/Projects/github/gregswindle/eslint-plugin-crc/lib/crc/crc-codebase.js

classCrcContext

A CrcContext NullObject. 🔒 Note: NullCrcContext instances can only be created using the static getter CrcContext.nullObject.

Responsibilities Collaborators
  1. A CrcContext NullObject.

    🔒 Note: NullCrcContext instances can only be created using the static getter CrcContext.nullObject.

  2. Factory method for generating a CrcContext object.

  3. Provides contextual information about source code.

  4. The ESLint.SourceCode for this CrcContext.

  5. The physical location of the source code.

  6. The ASTNodes associated with this CrcContext.

None found.
Select to toggle detailsCrcContext details...

Source code

const NodeManager = require("./node-manager");
const SourceCodeFactory = require("./source-code-factory");

const defaultConstructorParams = {
  "code": SourceCodeFactory.create(),
  "filePath": null,
  "nodes": new Map()
};

/**
 * @namespace CrcContext
 * @kind class
 *
 * @classdesc
 * Provides contextual information about source code.
 *
 * @property {SourceCode} code - The ESLint.SourceCode for this CrcContext.
 * @property {string} filePath - The physical location of the source code.
 * @property {array.<ASTNode>} nodes - The ASTNodes associated with this CrcContext.
 */

class CrcContext {
  constructor (params = defaultConstructorParams) {
    this.code = params.code;
    this.filePath = NodeManager.getNamespace(params.filePath);
    this.nodes = params.nodes;
  }

  /**
   * @static
   * @description A CrcContext NullObject.
   *
   * 🔒 **Note:** `NullCrcContext` instances can **only** be created
   *  using the static getter `CrcContext.nullObject`.
   * @type CrcContext~NullCrcContext
   * @returns {CrcContext~NullCrcContext} A CrcContext NullObject.
   * @example
   * const nullCrcContext = CrcContext.nullObject;
   */

  static get nullObject () {
    /**
     * A CrcContext NullObject.
     *
     * 🔒 **Note:** `NullCrcContext` instances can **only** be created using the
     *  static getter `CrcContext.nullObject`.
     *
     * @extends CrcContext
     * @protected
     * @memberOf CrcContext
     * @inner
     * @example
     * const nullCrcContext = CrcContext.nullObject;
     */

    class NullCrcContext extends CrcContext {}

    return new NullCrcContext();
  }

  /**
   * Factory method for generating a CrcContext object.
   *
   * @static
   * @param {Result} result - An ESLint Rule Result.
   * with ESQuery selectors.
   * @example
   * const context = CrcContext.parse(result);
   * @returns {CrcContext} A CrcContext object.
   */

  static parse (result) {
    const code = SourceCodeFactory.parse(result);
    const {filePath} = result;
    const nodes = NodeManager.getAllNodes(
      NodeManager.getNamespace(filePath),
      code
    );

    return new CrcContext({
      code,
      filePath,
      nodes
    });
  }
}

module.exports = CrcContext;

References

CrcContext is referenced 9 times in n1 files.

  1. File name: NodeManager [6 : 17]
  2. File name: require [20 : 27]
  3. File name: SourceCodeFactory [53 : 70]
  4. File name: require [73 : 80]
  5. File name: defaultConstructorParams [114 : 138]
  6. File name: SourceCodeFactory [153 : 170]
  7. File name: Map [216 : 219]
  8. File name: module [2185 : 2191]
  9. File name: CrcContext [2202 : 2212]

Path

/Users/swindle/Projects/github/gregswindle/eslint-plugin-crc/lib/crc/crc-context.js

classCrcMeta

A CrcMeta NullObject. 🔒 Note: NullCrcMeta instances can only be created using the static getter CrcMeta.nullObject.

Responsibilities Collaborators
  1. A CrcMeta NullObject.

    🔒 Note: NullCrcMeta instances can only be created using the static getter CrcMeta.nullObject.

  2. Collect metadata for CrcClasses, ESTree ASTNodes, and ESLint Contexts.

  3. The ESLint Context object.

  4. A summary of the object's purpose.

  5. The full path to the source code file.

  6. The ASTNodes type.

  7. A list of dependents.

  8. Table of content links for template rendering.

  9. All possible parameters.

  10. The ESLint Context object.

  11. A summary of the object's purpose.

  12. The full path to the source code file.

  13. The ASTNodes type.

  14. A list of dependents.

  15. Table of content links for template rendering.

  16. An HTMLLinkElement string.

  17. A slugified markdown link.

None found.
Select to toggle detailsCrcMeta details...

Source code

const defaultConstructorParams = {
  "context": null,
  "description": "",
  "filePath": null,
  "kind": "class",
  "references": [],
  "toc": {
    "anchor": null,
    "link": null
  }
};

/**
 * @class CrcMeta
 *
 * @classdesc
 * Collect metadata for CrcClasses, ESTree
 * [ASTNodes](https://goo.gl/yTwW1m#node-objects), and ESLint Contexts.
 *
 * @property {Context} context - The ESLint Context object.
 * @property {string} description - A summary of the object's purpose.
 * @property {string} filePath - The full path to the source code file.
 * @property {string} kind - The
 *  [`ASTNodes`](https://goo.gl/yTwW1m#node-objects) type.
 * @property {array.<Reference>} references - A list of dependents.
 * @property {object} toc - Table of content links for template
 *  rendering.
 *
 * @param {Object} [params] - All possible parameters.
 * @param {Context} [params.context] - The ESLint Context object.
 * @param {string} [params.description] - A summary of the object's purpose.
 * @param {string} [params.filePath] - The full path to the source code file.
 * @param {string} [params.kind] - The
 *  [`ASTNodes`](https://goo.gl/yTwW1m#node-objects) type.
 * @param {array.<ASTNode>} [params.references] - A list of dependents.
 * @param {object} [params.toc] - Table of content links for template
 *  rendering.
 * @param {string} [params.toc.anchor] - An HTMLLinkElement string.
 * @param {string} [params.toc.link] - A slugified markdown link.
 *
 * @this CrcMeta
 */

class CrcMeta {
  constructor (params = defaultConstructorParams) {
    this.context = params.context;
    this.description = params.description;
    this.filePath = params.filePath;
    this.kind = params.kind;
    this.references = params.references;
    this.toc = params.toc;
  }

  /**
   * @static
   * @description A CrcMeta NullObject.
   *
   * 🔒 **Note:** `NullCrcMeta` instances can **only** be created
   *  using the static getter `CrcMeta.nullObject`.
   * @type CrcMeta~NullCrcMeta
   * @example
   * const nullCrcMeta = CrcMeta.nullObject;
   *
   * @returns {CrcMeta~NullCrcMeta} A CrcMeta NullObject.
   */

  static get nullObject () {
    /**
     * A CrcMeta NullObject.
     *
     * 🔒 **Note:** `NullCrcMeta` instances can **only** be created using the
     *  static getter `CrcMeta.nullObject`.
     *
     * @extends CrcMeta
     * @protected
     * @inner
     * @memberOf CrcMeta
     * @example
     * const nullCrcMeta = CrcMeta.nullObject;
     */

    class NullCrcMeta extends CrcMeta {}
    return new NullCrcMeta();
  }
}

module.exports = CrcMeta;

References

CrcMeta is referenced 3 times in n1 files.

  1. File name: defaultConstructorParams [7 : 31]
  2. File name: module [2543 : 2549]
  3. File name: CrcMeta [2560 : 2567]

Path

/Users/swindle/Projects/github/gregswindle/eslint-plugin-crc/lib/crc/crc-meta.js

classCrcModel

Represents a Class-Responsibility-Collaboration model, which expresses the scope of an object's behaviors (responsibilities) and the objects it depends on to fulfill its responsibilities (collaborators).

Responsibilities Collaborators
  1. Represents a Class-Responsibility-Collaboration model, which expresses the scope of an object's behaviors (responsibilities) and the objects it depends on to fulfill its responsibilities (collaborators).

  2. A CrcModel NullObject.

    🔒 Note: NullCrcModel instances can only be created using the static getter CrcModel.nullObject.

  3. A CrcModel NullObject.

    🔒 Note: NullCrcModel instances can only be created using the static getter CrcModel.nullObject.

  4. CrcModel~NullCrcModel

  5. const nullCrcModel = CrcModel.nullObject;

  6. A CrcModel NullObject.

None found.
Select to toggle detailsCrcModel details...

Source code

const CrcClass = require("./crc-class");
const CrcMeta = require("./crc-meta");
const CrcResponsibility = require("./crc-responsibility");

/**
 * @private
 * @ignore
 */

const defaultConstructorParams = {
  "class": new CrcClass(),
  "collaborators": [],
  "meta": CrcMeta.nullObject,
  "responsibilities": []
};

/**
 * Represents a <strong>Class-Responsibility-Collaboration model</strong>,
 * which expresses the scope of an object's behaviors
 * (<strong><em>responsibilities</em></strong>) and the objects
 * it depends on to fulfill its responsibilities
 * (<strong><em>collaborators</em></strong>).
 *
 * @property {CrcClass} class - Provides a summary representation of PrototypeInspector
 *  objects.
 * @property {array.<CrcClass>} collaborators - Provides an array of zero or more objects
 *  required to fulfill the CrcModel#class's responsibilities.
 * @property {CrcMeta} meta - Provides additional information about the object.
 * @property {array.<CrcResponsibility>} responsibilities - Provides a list of
 * data this object must maintain and/or operations it must perform.
 *
 * @param {Object} [params] - A parameter object that optionally sets all of
 * the CrcModel's properties.
 * @param {CrcClass} [params.class] - A <code>class</code> representation.
 * @param {array.<CrcClass>} [params.collaborators] - A collection of zero or
 * more CrcClasses that this object depends on.
 * @param {CrcMeta} [params.meta] - An object with meta data necessary for
 *  visually rendering the CrcModel.
 * @param {array.<CrcResponsibility>} [params.responsibilities] - A list of
 * data this object must maintain and/or operations it must perform.
 *
 * @example
 * // Pass without parameters to create a NullCrcModel object
 * const crcModel = new CrcModel();
 *
 * // Provide a CrcClass instance to reveal its responsibilities and
 * // collaborators.
 * const crcModel = new CrcModel({
 *   class
 * });
 *
 * @this CrcModel
 */

class CrcModel {
  constructor (params = defaultConstructorParams) {
    this.class = params.class;
    this.collaborators = params.collaborators;
    this.meta = params.meta;
    this.responsibilities = CrcResponsibility.create(this.class);
  }

  /**
   * @static
   * @description A CrcModel NullObject.
   *
   * 🔒 **Note:** `NullCrcModel` instances can **only** be created
   *  using the static getter `CrcModel.nullObject`.
   * @type CrcModel~NullCrcModel
   * @example
   * const nullCrcModel = CrcModel.nullObject;
   * @returns {CrcModel~NullCrcModel} A CrcModel NullObject.
   */

  static get nullObject () {
    /**
     * A CrcModel NullObject.
     *
     * 🔒 **Note:** `NullCrcModel` instances can **only** be created using the
     *  static getter `CrcModel.nullObject`.
     *
     * @extends CrcModel
     * @protected
     * @inner
     * @memberOf CrcModel
     * @example
     * const nullCrcModel = CrcModel.nullObject;
     */

    class NullCrcModel extends CrcModel {}
    return new NullCrcModel();
  }
}

module.exports = CrcModel;

References

CrcModel is referenced 11 times in n1 files.

  1. File name: CrcClass [6 : 14]
  2. File name: require [17 : 24]
  3. File name: CrcMeta [47 : 54]
  4. File name: require [57 : 64]
  5. File name: CrcResponsibility [86 : 103]
  6. File name: require [106 : 113]
  7. File name: defaultConstructorParams [178 : 202]
  8. File name: CrcClass [222 : 230]
  9. File name: CrcMeta [267 : 274]
  10. File name: module [2983 : 2989]
  11. File name: CrcModel [3000 : 3008]

Path

/Users/swindle/Projects/github/gregswindle/eslint-plugin-crc/lib/crc/crc-model.js

classCrcReporter

Creates a report from all ECMAScript resources.

Responsibilities Collaborators
  1. Creates a report from all ECMAScript resources.

  2. Generates an array of CrcModels.

  3. Provides all CrcModels for a set of source code files.

  4. Provides the AST for a set of source code files.

None found.
Select to toggle detailsCrcReporter details...

Source code

const CrcClass = require("./crc-class");
const CrcCodebase = require("./crc-codebase");
const CrcModel = require("./crc-model");

/**
 * @class CrcReporter
 *
 * @classdesc Generates an array of CrcModels.
 *
 * @prop {array.<CrcModel>} crcModels - Provides all CrcModels for a set of source
 *  code files.
 * @prop {CrcCodebase} codebase - Provides the AST for a set of source code files.
 *
 * @this CrcReporter
 */

class CrcReporter {
  constructor () {
    this.crcModels = [];
    this.codebase = null;
  }

  /**
   * Creates a report from all ECMAScript resources.
   *
   * @param {array.<Result>} results - A list of result objects.
   *
   * @returns {array.<CrcModel>} A list of CrcModels.
   */

  report (results) {
    this.codebase = new CrcCodebase(results);

    const crcClasses = [];
    this.codebase.contexts.forEach((context) => {
      const crcClass = CrcClass.create(context);
      crcClasses.push(crcClass);
    });

    this.crcModels = crcClasses.map((crcClass) => new CrcModel({
      "class": crcClass,
      "collaborators": [],
      "responsibilities": []
    }));

    return this.crcModels;
  }
}

module.exports = CrcReporter;

References

CrcReporter is referenced 8 times in n1 files.

  1. File name: CrcClass [6 : 14]
  2. File name: require [17 : 24]
  3. File name: CrcCodebase [47 : 58]
  4. File name: require [61 : 68]
  5. File name: CrcModel [94 : 102]
  6. File name: require [105 : 112]
  7. File name: module [1136 : 1142]
  8. File name: CrcReporter [1153 : 1164]

Path

/Users/swindle/Projects/github/gregswindle/eslint-plugin-crc/lib/crc/crc-reporter.js

classCrcResponsibility

Get all responsibilities.

Responsibilities Collaborators
  1. Get all responsibilities.

  2. A factory method that generates a doctrine AST and responsibility string.

  3. Retrieve the purpose of an object based on its JSDoc description tag's value.

  4. Creates an instance of CrcResponsibility, which evaluates objects for declarations of intent, i.e., responsibility.

  5. A list of doctrine comments.

  6. A list of descriptions.

  7. The description for a given CrcClass.

  8. The ECMAScript object under analysis.

None found.
Select to toggle detailsCrcResponsibility details...

Source code

const doctrine = require("doctrine");
const doctrineOpts = require("./doctrine-opts");
const {
  first,
  get,
  isEmpty,
  pull,
  replace
} = require("lodash");

/**
 * @private
 * @ignore
 */

const cleanText = (text) => {
  const SINGLE_SPACE = " ";

  return replace(text, /\s+/gim, SINGLE_SPACE).trim();
};

/**
 * @private
 * @ignore
 */

const getComments = (crcClass) => get(crcClass, "code.ast.comments", [])
  .map((comment) => doctrine.parse(get(comment, "value"), doctrineOpts.parse));

/**
 * @private
 * @ignore
 */

const getPrimaryDescription =
  (comments) => get(comments
    .find((cmt) => !isEmpty(get(cmt, "description"))), "description", "");

/**
 * @private
 * @ignore
 */

const pullAllTags = (comments) => {
  const comment = comments.find((cmt) => {
    const tags = get(cmt, "tags", []);
    return tags.find((tag) => doctrineOpts.descriptions.includes(tag.title));
  });
  return get(comment, "tags", []);
};

/**
 * @private
 * @ignore
 */

const getDescriptionsFromTags = (comments) => {
  const tags = pullAllTags(comments);
  return pull(tags.map((tag) => get(tag, "description", null)), null);
};

/**
 * @private
 * @ignore
 */

const getDescriptionFromTags = (comments) => {
  const tags = pullAllTags(comments);
  return get(first(tags), "description");
};

/**
 * @private
 * @ignore
 */

const getDescriptionFromContext = (context) => {
  const cxtComments = context.code.ast.comments;
  const comments = cxtComments.map((comment) => doctrine.parse(comment.value, {
    "recoverable": true,
    "sloppy": true,
    "unwrap": true
  }));

  const description =
    getPrimaryDescription(comments) || getDescriptionFromTags(comments);

  return cleanText(description);
};

/**
 * @private
 * @ignore
 */

const getDescription =
  (crcClass) => cleanText(getDescriptionFromContext(crcClass.meta.context));

/**
 * @private
 * @ignore
 */

const getAllDescriptions = (comments) => {
  const descriptions =
    comments
      .filter((comment) => !isEmpty(get(comment, "description")))
      .map((comment) => get(comment, "description"))
      .filter((description) => !description.startsWith("eslint-disable"));
  const tagDescriptions = getDescriptionsFromTags(comments);
  return descriptions.concat(tagDescriptions);
};

/**
 * @class CrcResponsibility
 *
 * @classdesc
 * Creates an instance of CrcResponsibility, which evaluates objects
 * for declarations of intent, i.e., responsibility.
 *
 * @property {array.<Comment>} comments - A list of doctrine comments.
 * @property {array.<string>} descriptions - A list of descriptions.
 * @property {string} primary - The description for a given CrcClass.
 *
 * @param {CrcClass} crcClass - The ECMAScript object under analysis.
 *
 * @this CrcResponsibility
 */

class CrcResponsibility {
  constructor (crcClass) {
    this.comments = getComments(crcClass);
    this.descriptions = getAllDescriptions(this.comments);
    this.primary = getDescription(crcClass);
  }

  /**
   * Get all responsibilities.
   *
   * @memberof CrcResponsibility
   * @instance
   *
   * @returns {array.<string>} An arrary of resposibilities.
   */

  valueOf () {
    return this.descriptions;
  }

  /**
   * A factory method that generates a doctrine AST and
   * responsibility string.
   *
   * @static
   * @param {ASTNode} node - An ESLint representation of ECMAScript programming
   * elements.
   * @param {Context} context - A summary object with SourceCode and file info.
   * @returns {CrcResponsibility} An object with a doctrine AST and the
   * stated responsibility for the node.
   */

  static create (crcClass) {
    return new CrcResponsibility(crcClass);
  }

  /**
   * Retrieve the purpose of an object based on its JSDoc description tag's value.
   *
   * @static
   * @method descriptionFromContext
   * @param {CrcContext} context - The context of the object.
   * @returns {string} A declaration of purpose.
   */

  static descriptionFromContext (context) {
    return getDescriptionFromContext(context);
  }
}

module.exports = CrcResponsibility;

References

CrcResponsibility is referenced 21 times in n1 files.

  1. File name: doctrine [6 : 14]
  2. File name: require [17 : 24]
  3. File name: doctrineOpts [44 : 56]
  4. File name: require [59 : 66]
  5. File name: first [97 : 102]
  6. File name: get [106 : 109]
  7. File name: isEmpty [113 : 120]
  8. File name: pull [124 : 128]
  9. File name: replace [132 : 139]
  10. File name: require [144 : 151]
  11. File name: cleanText [202 : 211]
  12. File name: getComments [352 : 363]
  13. File name: getPrimaryDescription [538 : 559]
  14. File name: pullAllTags [705 : 716]
  15. File name: getDescriptionsFromTags [978 : 1001]
  16. File name: getDescriptionFromTags [1171 : 1193]
  17. File name: getDescriptionFromContext [1334 : 1359]
  18. File name: getDescription [1749 : 1763]
  19. File name: getAllDescriptions [1882 : 1900]
  20. File name: module [4011 : 4017]
  21. File name: CrcResponsibility [4028 : 4045]

Path

/Users/swindle/Projects/github/gregswindle/eslint-plugin-crc/lib/crc/crc-responsibility.js

Objectcrc

extends requireIndex

Create class-responsibilities-collaborators reporting model objects.

Responsibilities Collaborators
  1. Create class-responsibilities-collaborators reporting model objects.


  2. Requirements


  3. Plugin Definition

None found.
Select to toggle detailscrc details...

Source code

/**
 * Create class-responsibilities-collaborators
 * reporting model objects.
 *
 * @module crc
 */

/*
 *---------------------------------------------------------------------------
 * Requirements
 *---------------------------------------------------------------------------
 */

/**
 * @private
 * @ignore
 */

const requireIndex = require("requireindex");

/**
 * @private
 * @ignore
 */

const crc = requireIndex(__dirname);

/*
 *----------------------------------------------------------------------------
 * Plugin Definition
 *----------------------------------------------------------------------------
 */

module.exports = crc;

References

crc is referenced 7 times in n1 files.

  1. File name: requireIndex [320 : 332]
  2. File name: require [335 : 342]
  3. File name: crc [399 : 402]
  4. File name: requireIndex [405 : 417]
  5. File name: __dirname [418 : 427]
  6. File name: module [618 : 624]
  7. File name: crc [635 : 638]

Path

/Users/swindle/Projects/github/gregswindle/eslint-plugin-crc/lib/crc/index.js

classNodeManager

A utility object that manages ASTNode identity and parsing.

Responsibilities Collaborators
  1. A utility object that manages ASTNode identity and parsing.

  2. Provides all nodes within an eslint.SourceCode object.

  3. Gets a unique key for ASTNodes in source code files.

None found.
Select to toggle detailsNodeManager details...

Source code

const estraverse = require("estraverse");
const PrototypeInspector = require("./prototype-inspector");
const {get} = require("lodash");

/**
 * A utility object that manages [`ASTNode`](https://goo.gl/yTwW1m#node-objects) identity and parsing.
 *
 * @class
 */

class NodeManager {
  /**
   * Provides all nodes within an `eslint.SourceCode`
   *  object.
   *
   * @static
   * @param {string} namespace  The full path to a source file appended with
   *  a hash (#) to identify specific objects.
   * @param {SourceCode} sourceCode An `eslint.SourceCode` object.
   *
   * @returns {Map.<string, ASTNode>} A Map of all [`ASTNodes`](https://goo.gl/yTwW1m#node-objects), referencable by
   *  source file.
   */

  static getAllNodes (namespace, sourceCode) {
    const nodes = new Map();
    estraverse.traverse(sourceCode.ast, {
      enter (node) {
        const ns = NodeManager.getNamespace(namespace, node);
        nodes.set(ns, node);
      }
    });

    return nodes;
  }

  /**
   * Gets a unique key for [`ASTNodes`](https://goo.gl/yTwW1m#node-objects) in source code
   *  files.
   *
   * @static
   * @param {string} filePath - The path to the file with source code.
   * @param {ASTNode} node    - The [`ASTNode`](https://goo.gl/yTwW1m#node-objects) within a source code file.
   *
   * @returns {string|null} The source code file path followed by #Identifier.name
   *  (if applicable).
   */

  static getNamespace (filePath, node) {
    if (filePath) {
      return `${filePath}${NodeManager.getNodeName(node)}`;
    }
    return null;
  }

  /**
   * @static getNodeName - Provides the name of an [`ASTNode`](https://goo.gl/yTwW1m#node-objects).
   *
   * @param {ASTNode} node - The [`ASTNode`](https://goo.gl/yTwW1m#node-objects) within a source code file.
   *
   * @returns {string} The name of an [`ASTNode`](https://goo.gl/yTwW1m#node-objects), prepended by `/#`.
   */

  static getNodeName (node) {
    const nodeName = get(node, "id.name");
    if (nodeName) {
      return `/${nodeName}`;
    }
    return "";
  }
}

Object.assign(NodeManager, PrototypeInspector);

module.exports = NodeManager;

References

NodeManager is referenced 11 times in n1 files.

  1. File name: estraverse [6 : 16]
  2. File name: require [19 : 26]
  3. File name: PrototypeInspector [48 : 66]
  4. File name: require [69 : 76]
  5. File name: get [110 : 113]
  6. File name: require [117 : 124]
  7. File name: Object [2047 : 2053]
  8. File name: NodeManager [2061 : 2072]
  9. File name: PrototypeInspector [2074 : 2092]
  10. File name: module [2096 : 2102]
  11. File name: NodeManager [2113 : 2124]

Path

/Users/swindle/Projects/github/gregswindle/eslint-plugin-crc/lib/crc/node-manager.js

classPrototypeInspector

Detects the prototype of an object whenever possible.

Responsibilities Collaborators
  1. Detects the prototype of an object whenever possible.

  2. Returns a prototype ASTNode.

  3. Returns the Scope for a given Context.

None found.
Select to toggle detailsPrototypeInspector details...

Source code

const eslintScope = require("eslint-scope");
const esquery = require("esquery");
const {
  first,
  get,
  isString
} = require("lodash");

/**
 * @private
 * @ignore
 */

const nullResult = {
  "meta": {
    "kind": "Object"
  },
  "name": null,
  "superClass": {
  }
};

/**
 * @private
 * @ignore
 */

const queryContext = (context, descriptor) => first(esquery.match(
  context.code.ast,
  esquery.parse(descriptor)
));

/**
 * @private
 * @ignore
 */

const visitClass = (context) => {
  const descriptor = ":matches(ClassDeclaration, ClassExpression)";
  const node = queryContext(context, descriptor);
  return {
    "meta": {
      "kind": "class"
    },
    "name": get(node, "id.name"),
    "superClass": get(node, "superClass")
  };
};

/**
 * @private
 * @ignore
 */

const visitNewExpression = (context) => {
  const descriptor =
    "ExpressionStatement > [left.property.name=\"prototype\"]" +
    "[right.type=\"NewExpression\"]";
  const node = queryContext(context, descriptor);
  return {
    "meta": {
      "kind": "function"
    },
    "name": get(node, "left.object.name"),
    "superClass": get(node, "right.callee")
  };
};

/**
 * @private
 * @ignore
 */

const getSuperClass = (context, node) => {
  const superClassName = get(
    first(get(node, "declarations")),
    "id.name"
  );
  return first(esquery.match(
    context.code.ast,
    esquery.parse(`Identifier[name="${superClassName}"]`)
  ));
};

/**
 * @private
 * @ignore
 */

const visitObjectExpression = (context) => {
  const descriptor = ":matches(VariableDeclaration, AssignmentExpression" +
    "[left.property.name=\"prototype\"][right.type=\"CallExpression\"]," +
    "[right.callee.object.name=\"Object\"]" +
    "[callee.property.name=\"create\"][arguments]" +
    " [object][property.name=\"prototype\"])";
  const node = queryContext(context, descriptor);
  const superClass = getSuperClass(context, node);
  return {
    "meta": {
      "kind": "Object"
    },
    "name": get(context.nodes.get(context.filePath), "name"),
    superClass
  };
};

/**
 * @private
 * @ignore
 */

const visitPrototypeConstructor = (context) => {
  const descriptor = "AssignmentExpression" +
    "[left.property.name=\"constructor\"][right.type=\"Identifier\"]";
  const node = queryContext(context, descriptor);
  return {
    "meta": {
      "kind": "function"
    },
    "name": get(node, "left.object.object.name"),
    "superClass": get(node, "right")
  };
};

/**
 * Detects the prototype of an object whenever possible.
 *
 * @class
 * @throws {TypeError} ⛔️  **Note:** PrototypeInspector does not have a
 * working constructor. Invoking new PrototypeInspector will throw a TypeError.
 */

class PrototypeInspector {
  constructor () {
    const msg = "PrototypeInspector is static and does not " +
      "have a working constructor.";
    throw new TypeError(msg);
  }

  /**
   * Returns a prototype [`ASTNode`](https://goo.gl/yTwW1m#node-objects).
   *
   * @param {ASTNode} node - A node to check. This node type is one of
   *   `Program`, `FunctionDeclaratikon`, `FunctionExpression`, and
   *   `ArrowFunctionExpression`.
   * @memberOf PrototypeInspector
   * @returns {ASTNode} The node's prototype.
   * @static
   */

  static getPrototypeOf (node) {
    let index = 0;
    const ONE = 1;
    let proto = nullResult;
    const fns = [
      visitClass,
      visitNewExpression,
      visitPrototypeConstructor,
      visitObjectExpression
    ];

    for (; index < fns.length; index += ONE) {
      proto = get(fns, index)(node);
      if (isString(get(proto, "name"))) {
        break;
      }
    }

    return proto;
  }

  /**
   * Returns the [`Scope`](https://goo.gl/AXjJ84#scope-interface) for
   * a given Context.
   *
   * @param {CrcContext} context - A CrcContext instance.
   * @memberOf PrototypeInspector
   * @returns {Scope} The ESLint [`Scope`](https://goo.gl/AXjJ84#scope-interface).
   * @static
   */

  static getScopeOf (context) {
    const scopeManager = eslintScope.analyze(context.code.ast);
    return scopeManager.acquire(context.code.ast);
  }
}

module.exports = PrototypeInspector;

References

PrototypeInspector is referenced 17 times in n1 files.

  1. File name: eslintScope [6 : 17]
  2. File name: require [20 : 27]
  3. File name: esquery [51 : 58]
  4. File name: require [61 : 68]
  5. File name: first [91 : 96]
  6. File name: get [100 : 103]
  7. File name: isString [107 : 115]
  8. File name: require [120 : 127]
  9. File name: nullResult [178 : 188]
  10. File name: queryContext [311 : 323]
  11. File name: visitClass [463 : 473]
  12. File name: visitNewExpression [786 : 804]
  13. File name: getSuperClass [1187 : 1200]
  14. File name: visitObjectExpression [1469 : 1490]
  15. File name: visitPrototypeConstructor [2085 : 2110]
  16. File name: module [4079 : 4085]
  17. File name: PrototypeInspector [4096 : 4114]

Path

/Users/swindle/Projects/github/gregswindle/eslint-plugin-crc/lib/crc/prototype-inspector.js

classResponsibilities

Determines the responsibilities of an object.

Responsibilities Collaborators
  1. Determines the responsibilities of an object.

None found.
Select to toggle detailsResponsibilities details...

Source code

const DocumentationCommentsStrategy =
  require("./comment-strategies/documentation-comments-strategy");

/**
 * Determines the responsibilities of an object.
 *
 * @class Responsibilities
 */

class Responsibilities {
  constructor (crcClass) {
    this.comments = new DocumentationCommentsStrategy([crcClass.meta.filePath]);
    this.class = crcClass;
    this.descriptions = null;
    this.primary = null;
  }
}

module.exports = Responsibilities;

References

Responsibilities is referenced 4 times in n1 files.

  1. File name: DocumentationCommentsStrategy [6 : 35]
  2. File name: require [40 : 47]
  3. File name: module [416 : 422]
  4. File name: Responsibilities [433 : 449]

Path

/Users/swindle/Projects/github/gregswindle/eslint-plugin-crc/lib/crc/responsibilities.js

classSourceCodeFactory

A helper object that generates ESLint SourceCode objects.

Responsibilities Collaborators
  1. A helper object that generates ESLint SourceCode objects.

  2. Generates an AST from source code text.

  3. A SourceCode NullObject.

    🔒 Note: NullSourceCode instances can only be created using the static getter SourceCode.nullObject.

  4. An ESLint SourceCode NullObject.

    🔒 Note: NullSourceCode instances can only be created using the static getter SourceCode.nullObject.

None found.
Select to toggle detailsSourceCodeFactory details...

Source code

const astConfig = require("./ast-config");
const crcLogger = require("../crc-logger");
const espree = require("espree");
const fs = require("fs-extra");
const path = require("path");
const {SourceCode} = require("eslint");

/**
 * A helper object that generates ESLint
 * [`SourceCode`](https://goo.gl/Gp7Xjs#sourcecode) objects.
 *
 * @class
 */

class SourceCodeFactory {
  constructor (filePath) {
    // eslint-disable-next-line security/detect-non-literal-fs-filename
    const src = fs.readFileSync(path.resolve(filePath)).toString();
    const ast = SourceCodeFactory.getAst(src);
    this.code = SourceCodeFactory.create(src, ast);
  }

  /**
   * @static Factory method for creating an ESLint SourceCode object.
   *
   * @param {string} src - The raw source code.
   * @param {AST} ast - An Abstract Syntax Tree.
   *
   * @returns {SourceCode} An ESLint
   *  [SourceCode](https://goo.gl/Gp7Xjs#sourcecode) object.
   * @memberOf SourceCodeFactory
   */

  static create (src, ast) {
    try {
      return new SourceCode(src, ast);
    } catch (err) {
      crcLogger.error(err, "Returning a NullSourceCode object.");
    }
    return SourceCodeFactory.nullObject;
  }

  /**
   * Generates an AST from source code text.
   *
   * @static
   * @param {string} src - The source code text.
   * @returns {ASTNode} An ESTree spec-compliant ASTNode.
   * @memberof SourceCodeFactory
   */

  static getAst (src) {
    return espree.parse(src, astConfig);
  }

  /**
   * A [`SourceCode`](https://goo.gl/Gp7Xjs#sourcecode) NullObject.
   *
   * 🔒 **Note:** `NullSourceCode` instances can **only** be created
   *  using the static getter `SourceCode.nullObject`.
   *
   * @static
   * @type NullSourceCode
   * @example
   * const nullSourceCode = SourceCode.nullObject;
   * @returns {NullSourceCode} A
   * [`SourceCode`](https://goo.gl/Gp7Xjs#sourcecode) NullObject.
   */

  static get nullObject () {
    /**
     * An ESLint [`SourceCode`](https://goo.gl/Gp7Xjs#sourcecode) NullObject.
     *
     * 🔒 **Note:** `NullSourceCode` instances can **only** be created using the
     *  static getter `SourceCode.nullObject`.
     *
     * @extends SourceCode
     * @protected
     * @inner
     * @memberOf SourceCodeFactory
     * @example
     * const nullSourceCode = SourceCode.nullObject;
     * @see [`SourceCode`](https://goo.gl/Gp7Xjs#sourcecode)
     */

    class NullSourceCode extends SourceCode {}

    const emptyCode = "";
    const nullAst = espree.parse(emptyCode, astConfig);

    return new NullSourceCode(emptyCode, nullAst);
  }

  /**
   * @static parse - Generate an ESLint
   * [`SourceCode`](https://goo.gl/Gp7Xjs#sourcecode) object from an ESLint
   * {@link  https://goo.gl/XMjsa1#the-result-object Result}
   * object's `filePath`.
   *
   * @param {Result} result - An ESLint
   * {@link  https://goo.gl/XMjsa1#the-result-object Result} object.
   *
   * @returns {SourceCode} An ESLint
   * [`SourceCode`](https://goo.gl/Gp7Xjs#sourcecode) object.
   *
   * @see ESLint formatter
   * {@link  https://goo.gl/XMjsa1#the-result-object Result}
   */

  static parse (result) {
    return new SourceCodeFactory(result.filePath).code;
  }
}

module.exports = SourceCodeFactory;

References

SourceCodeFactory is referenced 14 times in n1 files.

  1. File name: astConfig [6 : 15]
  2. File name: require [18 : 25]
  3. File name: crcLogger [49 : 58]
  4. File name: require [61 : 68]
  5. File name: espree [93 : 99]
  6. File name: require [102 : 109]
  7. File name: fs [127 : 129]
  8. File name: require [132 : 139]
  9. File name: path [159 : 163]
  10. File name: require [166 : 173]
  11. File name: SourceCode [190 : 200]
  12. File name: require [204 : 211]
  13. File name: module [3179 : 3185]
  14. File name: SourceCodeFactory [3196 : 3213]

Path

/Users/swindle/Projects/github/gregswindle/eslint-plugin-crc/lib/crc/source-code-factory.js

Thanks for using eslint-plugin-crc!

PRs Welcome We welcome contributions with GitHub issues and pull requests.

⚠️ **GitHub.com Fallback** ⚠️