Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
grunt-contrib-jshint
Advanced tools
grunt-contrib-jshint is a Grunt plugin for running JSHint, a tool that helps to detect errors and potential problems in JavaScript code. It allows you to integrate JSHint into your Grunt build process, enabling automated code quality checks.
Basic JSHint Task
This feature allows you to define a basic JSHint task in your Gruntfile. It specifies the files to be linted and sets JSHint options, such as ECMAScript version.
{
"grunt.initConfig": {
"jshint": {
"files": ['Gruntfile.js', 'src/**/*.js', 'test/**/*.js'],
"options": {
"esversion": 6
}
}
},
"grunt.loadNpmTasks": "grunt-contrib-jshint",
"grunt.registerTask": ["default", ["jshint"]]
}
Custom JSHint Reporter
This feature allows you to use a custom reporter for JSHint, such as 'jshint-stylish', to format the output of linting results in a more readable manner.
{
"grunt.initConfig": {
"jshint": {
"files": ['Gruntfile.js', 'src/**/*.js', 'test/**/*.js'],
"options": {
"reporter": require('jshint-stylish')
}
}
},
"grunt.loadNpmTasks": "grunt-contrib-jshint",
"grunt.registerTask": ["default", ["jshint"]]
}
JSHint with Custom Configuration File
This feature allows you to specify a custom JSHint configuration file (.jshintrc) to define your linting rules and options.
{
"grunt.initConfig": {
"jshint": {
"files": ['Gruntfile.js', 'src/**/*.js', 'test/**/*.js'],
"options": {
"jshintrc": '.jshintrc'
}
}
},
"grunt.loadNpmTasks": "grunt-contrib-jshint",
"grunt.registerTask": ["default", ["jshint"]]
}
ESLint is a popular linting tool for JavaScript and TypeScript. It is highly configurable and supports a wide range of plugins and rules. Compared to grunt-contrib-jshint, ESLint offers more flexibility and a larger ecosystem of plugins.
JSCS (JavaScript Code Style) is a code style linter for JavaScript. It focuses on enforcing coding conventions and style guidelines. While JSHint checks for potential errors and code quality, JSCS is more focused on code style.
TSLint is a linter for TypeScript code. It helps to enforce coding standards and catch potential errors in TypeScript projects. While grunt-contrib-jshint is for JavaScript, TSLint is specifically designed for TypeScript.
Validate files with JSHint
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-contrib-jshint --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-contrib-jshint');
Run this task with the grunt jshint
command.
Task targets, files and options may be specified according to the grunt Configuring tasks guide.
Any specified option will be passed through directly to JSHint, thus you can specify any option that JSHint supports. See the JSHint documentation for a list of supported options.
A few additional options are supported:
Type: Object
Default: null
A map of global variables, with keys as names and a boolean value to determine if they are assignable. This is not a standard JSHint option, but is passed into the JSHINT
function as its third argument. See the JSHint documentation for more information.
Type: String
or true
Default: null
If set to true
, no config will be sent to JSHint and JSHint will search for .jshintrc
files relative to the files being linted.
If a filename is specified, options and globals defined therein will be used. The jshintrc
file must be valid JSON and looks something like this:
{
"curly": true,
"eqnull": true,
"eqeqeq": true,
"undef": true,
"globals": {
"jQuery": true
}
}
Be aware that jshintrc
settings are not merged with your Grunt options.
Type: String
Default: ''
A list of non-dot-js extensions to check.
Type: Array
Default: null
A list of files and dirs to ignore. This will override your .jshintignore
file if set and does not merge.
Type: Boolean
Default: false
Set force
to true
to report JSHint errors but not fail the task.
Type: String
Default: null
Allows you to modify this plugins output. By default it will use a built-in Grunt reporter. Set the path to your own custom reporter or to one of the built-in JSHint reporters: jslint
or checkstyle
.
See also: Writing your own JSHint reporter.
You can also use an external reporter. For example jshint-stylish:
$ npm install --save-dev jshint-stylish
options: {
reporter: require('jshint-stylish')
}
Type: String
Default: null
Specify a filepath to output the results of a reporter. If reporterOutput
is specified then all output will be written to the given filepath instead of printed to stdout.
Type: Boolean
Default: true
Results of a reporter will use a relative filepath to reporterOutput
. If set to false
then filepaths will appear relative to the current folder. Unless reporterOutput
is not set this option will not have any effect.
In this example, running grunt jshint:all
(or grunt jshint
because jshint
is a multi task) will lint the project's Gruntfile as well as all JavaScript files in the lib
and test
directories and their subdirectories, using the default JSHint options.
// Project configuration.
grunt.initConfig({
jshint: {
all: ['Gruntfile.js', 'lib/**/*.js', 'test/**/*.js']
}
});
In this example, running grunt jshint
will lint both the "beforeconcat" set and "afterconcat" sets of files. This is not ideal, because dist/output.js
may get linted before it gets created via the grunt-contrib-concat plugin concat
task.
In this case, you should lint the "beforeconcat" files first, then concat, then lint the "afterconcat" files, by running grunt jshint:beforeconcat concat jshint:afterconcat
.
// Project configuration.
grunt.initConfig({
concat: {
dist: {
src: ['src/foo.js', 'src/bar.js'],
dest: 'dist/output.js'
}
},
jshint: {
beforeconcat: ['src/foo.js', 'src/bar.js'],
afterconcat: ['dist/output.js']
}
});
In this example, custom JSHint options are specified. Note that when grunt jshint:uses_defaults
is run, those files are linted using the default options, but when grunt jshint:with_overrides
is run, those files are linted using merged task/target options.
// Project configuration.
grunt.initConfig({
jshint: {
options: {
curly: true,
eqeqeq: true,
eqnull: true,
browser: true,
globals: {
jQuery: true
},
},
uses_defaults: ['dir1/**/*.js', 'dir2/**/*.js'],
with_overrides: {
options: {
curly: false,
undef: true,
},
files: {
src: ['dir3/**/*.js', 'dir4/**/*.js']
},
}
},
});
If you would like to ignore a specific warning:
[L24:C9] W015: Expected '}' to have an indentation at 11 instead at 9.
You can toggle it by prepending -
to the warning id as an option:
grunt.initConfig({
jshint: {
ignore_warning: {
options: {
'-W015': true,
},
src: ['**/*.js'],
},
},
});
>=0.4.0
.reporter
option.reporterOutput
was still passed to JSHint.reporterOutput
option to JSHint.grunt.util._.clone
with Object.create()
. Replace deprecated grunt.util.hooker
with hooker lib. Enhancing the readability of the output. Reporter output is relative to the output file. Pass JSHint options to the external reporter.maxerr
is low.extensions
option. Add support for custom reporters and output report to a file.predef
option when it's an object.force
option when jshintrc is used.this.filesSrc
API.Task submitted by "Cowboy" Ben Alman
This file was generated on Tue Oct 20 2020 09:55:41.
FAQs
Validate files with JSHint
The npm package grunt-contrib-jshint receives a total of 101,050 weekly downloads. As such, grunt-contrib-jshint popularity was classified as popular.
We found that grunt-contrib-jshint demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.