This package has been deprecated

Author message:

No efforts are placed on updating grunt-jsinspect any longer. Please use jsinspect directly

grunt-jsinspect

3.0.0 • Public • Published

Build Status NPM version Built with Grunt Dependency Status

image

grunt-jsinspect

Grunt task for running jsinspect in order to detect copy-pasted and structurally similar JavaScript code.

Getting Started

This plugin requires Grunt version >=0.4.0, verbally the minimum of 0.4.0. The minimum Node.js version supported is 6.9.0 (the second LTS version).

If you haven’t used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you’re familiar with that process, you may install this plugin with this command:

npm install grunt-jsinspect --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile.js file with this line of JavaScript:

grunt.loadNpmTasks('grunt-jsinspect');

Configuration and available options

A simple configuration example with the default options.

grunt.initConfig({
  jsinspect: {
    examples: {
      options: {
        // jsinspect specific options
        identifiers:  false,
        literals:     true,
        minInstances: 2,
        reporter:     'default',
        threshold:    30,
        truncate:     100,
 
        // options used for grunt-jsinspect
        configFile:   '.jsinspectrc',
        failOnMatch:  true,
        outputPath:   undefined
      },
      src: [
        '**/*.js'
      ]
    }
  }
});

Execute with grunt jsinspect:examples.

Please note that in case the configuration file exists and its name matches the default value .jsinspectrc, it will be used to override any other configuration option that might be present in the file. In case you have the .jsinspectrc file in your project and do not want to use it for a particular configuration, set the options.configFile to point to a non existing file.

src

Type: string|array

Globbing pattern to get files to run grunt-jsinspect against.

Site note: In case you want to ignore files you can do this with prepending !.

grunt.initConfig({
  jsinspect: {
    examples: {
      src: [
        '**/*.js',
        '!**/node_modules/**'  // ignore node_modules folder
      ]
    }
  }
});

You can also inspect jsx files used in React.js, simply by using that suffix in the src list. The command line version of jsinspect uses a specific flag for this, namely --jsx.

options.configFile

Type: string

Default value: '.jsinspectrc'

In case the given JSON file exists, it will be used for setting and overriding any other options defined via Gruntfile.js configuration Please see the jsinspect for details.

The configuration file should be valid JSON, but can contain comments, which are stripped away via strip-json-comments internally:

{
  "threshold":     30,
  "identifiers":   true,
  "ignore":        "Test.js|Spec.js", // used as RegExp,
  "reporter":      "json",
  "truncate":      100
}

options.failOnMatch

Type: boolean|number

Default value: true

Use a number as a threshold (e.g. use 42 to pass for 41 matches but fail beyond 42 matches).

options.outputPath

Type: string

Default value: undefined

Specify the path of the output file. The destination directory must already exist. You’ll probably want to pick a file extension which corresponds with the chosen reporter.

options.reporter

Type: string

Default value: 'default'

Specify the reporter to use. Possible values: 'default', 'json', and 'pmd'.

Please see the lib/reporters/index.js file of the jsinspect project in order to find out about the existing reporters.

Other options passed directly to jsinspect

Code inspector specific options:

  • threshold, type number, defaults to 30
  • literals, type boolean, defaults to ``
  • minInstances, type number, defaults to 2
  • identifiers, type boolean, defaults to false

Options passed to the selected reporter:

  • truncate, type number, defaults to 100
  • identifiers, type boolean, defaults to false

For further details about each of these options, see the jsinspect documentation.

License

Copyright (c) Stefan Judis and Juga Paazmaya, licensed under the MIT license

Package Sidebar

Install

npm i grunt-jsinspect

Weekly Downloads

521

Version

3.0.0

License

MIT

Last publish

Collaborators

  • paazmaya
  • stefanjudis