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;
Configuration and available options
A simple configuration example with the default options.
grunt;
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;
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.
jsinspect
Other options passed directly to Code inspector specific options:
threshold
, typenumber
, defaults to30
literals
, typeboolean
, defaults to ``minInstances
, typenumber
, defaults to2
identifiers
, typeboolean
, defaults tofalse
Options passed to the selected reporter:
truncate
, typenumber
, defaults to100
identifiers
, typeboolean
, defaults tofalse
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