1.0.76 • Published 5 years ago

js-code-metric v1.0.76

Weekly downloads
19
License
MIT
Repository
-
Last release
5 years ago

js-code-metric

Visualize JavaScript source complexity with js-code-metric. Based on the older es5 plato, this is a port to es6 and eslint

Start in 3 steps.

  1. Install. npm install --save-dev js-code-metric

  2. Add.

"scripts" : {
    "js-code-metric": "./node_modules/.bin/jschecker -r -d ./report src",
}
  1. Run. npm run js-code-metric

Installation

Install the module with: npm install --save-dev js-code-metric

Usage

From scripts

//be sure and set your src, output, and any options.
let src = "./scripts/**/*.js";
let outputDir = "./artifacts/jschecker";

let jscheckerArgs = {
  title: "example",
  eslint: {}
};

//you can use the reports in the callback.
function callback(reports) {
  let overview = jschecker.getOverviewReport(reports);

  let { total, average } = overview.summary;

  let output = `total
    ----------------------
    eslint: ${total.eslint}
    sloc: ${total.sloc}
    maintainability: ${total.maintainability}
    average
    ----------------------
    eslint: ${average.eslint}
    sloc: ${average.sloc}
    maintainability: ${average.maintainability}`;

  console.log(output);
}

//usage is jschecker.inspect
jschecker.inspect(src, outputDir, jscheckerArgs, callback);

Example Gulpfile

let gulp = require("gulp");
let jschecker = require("jschecker");

let src = "./scripts/**/*.js";
let outputDir = "./artifacts/jschecker";

let lintRules = {
  rules: {
    indent: [2, "tab"],
    quotes: [2, "single"],
    semi: [2, "always"],
    "no-console": [1],
    curly: ["error"],
    "no-dupe-keys": 2,
    "func-names": [1, "always"]
  },
  env: {
    es6: true
  },
  globals: ["require"],
  parserOptions: {
    sourceType: "module",
    ecmaFeatures: {
      jsx: true,
      modules: true
    }
  }
};

let complexityRules = {};

let jscheckerArgs = {
  title: "example",
  eslint: lintRules,
  complexity: complexityRules
};

function analysis() {
  return jschecker.inspect(src, outputDir, jscheckerArgs);
}

gulp.task("analysis", analysis);

From the commandline

Usage : js-code-metric [options] -d <output_dir> <input files>
  -h, --help
      Display this help text.
  -q, --quiet
      Reduce output to errors only
  -v, --version
      Print the version.
  -x, --exclude : String
      File exclusion regex
  -d, --dir : String *required*
      The output directory
  -r, --recurse
      Recursively search directories
  -l, --jshint : String
      Specify a jshintrc file for JSHint linting
  -t, --title : String
      Title of the report
  -D, --date : String
      Time to use as the report date (seconds, > 9999999999 assumed to be ms)
  -n, --noempty
      Skips empty lines from line count
  -e, --eslint : String
      Specify a eslintrc file for ESLint linting

Example

js-code-metric -r -d report src

Data sources

Contributors

Release History

versionupdate
1.0.0-alphaProject works with es6 and eslint

About

This is currently a reimplementation of the older plato, and started as a fork from https://github.com/deedubs/js-code-metric, but has since been heavily modified. After seeing it was unpublished on npm and also wanting to add more features, This project uses eslint, not jshint for default linting.

I have switched to the typhon-js module since it properly parses classes.

License

Copyright (c) 2019 Rajaprabhu Licensed under the MIT license.

1.0.76

5 years ago

1.0.75

5 years ago

1.0.74

5 years ago

1.0.73

5 years ago

1.0.72

5 years ago

1.0.71

5 years ago

1.0.70

5 years ago

1.0.69

5 years ago

1.0.68

5 years ago

1.0.67

5 years ago

1.0.66

5 years ago

1.0.64

5 years ago

1.0.63

5 years ago

1.0.62

5 years ago

1.0.61

5 years ago

1.0.60

5 years ago

1.0.59

5 years ago

1.0.58

5 years ago

1.0.57

5 years ago

1.0.56

5 years ago

1.0.55

5 years ago

1.0.54

5 years ago

1.0.53

5 years ago

1.0.52

5 years ago

1.0.51

5 years ago

1.0.50

5 years ago

1.0.49

5 years ago

1.0.48

5 years ago

1.0.47

5 years ago

1.0.46

5 years ago

1.0.45

5 years ago

1.0.44

5 years ago

1.0.43

5 years ago

1.0.42

5 years ago

1.0.41

5 years ago

1.0.40

5 years ago

1.0.39

5 years ago

1.0.38

5 years ago

1.0.37

5 years ago

1.0.36

5 years ago

1.0.35

5 years ago

1.0.34

5 years ago

1.0.33

5 years ago

1.0.32

5 years ago

1.0.31

5 years ago

1.0.30

5 years ago

1.0.29

5 years ago

1.0.28

5 years ago

1.0.27

5 years ago

1.0.26

5 years ago

1.0.25

5 years ago

1.0.24

5 years ago

1.0.23

5 years ago

1.0.22

5 years ago

1.0.21

5 years ago

1.0.20

5 years ago

1.0.19

5 years ago

1.0.18

5 years ago

1.0.17

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago