JSHint Deployment and Usage Guide
Prerequisites
- Node.js (version 10.0.0 or higher)
- npm (version 6.0.0 or higher)
- Git for cloning the repository
Installation
Using npm (Recommended)
npm install -g jshint
From Source
# Clone the repository
git clone https://github.com/jshint/jshint.git
cd jshint
# Install dependencies
npm install
# Build the project
npm run build
Using the Online Tool
You can also use JSHint directly at jshint.com without any installation.
Configuration
Configuration Files
JSHint looks for configuration in the following order:
.jshintrcfile in your project directorypackage.jsonwith a"jshintConfig"property- Command line options
Sample .jshintrc Configuration
{
"curly": true,
"eqeqeq": true,
"freeze": true,
"noempty": true,
"undef": true,
"unused": true,
"predef": [ "MyGlobal" ]
}
Environment Variables
JSHINT_CONFIG: Path to custom configuration fileJSHINT_EXCLUDE: Pattern for files to exclude
Build & Run
Running JSHint
On a Single File
jshint myfile.js
On Multiple Files
jshint file1.js file2.js directory/
Using STDIN
cat myfile.js | jshint
With Custom Configuration
jshint --config .jshintrc myfile.js
Development Mode
# Watch for changes and rebuild
npm run watch
# Run tests
npm test
# Run with coverage
npm run coverage
Production Mode
# Build for production
npm run build
# Run the CLI tool
node src/cli.js myfile.js
Deployment
As a CLI Tool
Since JSHint is primarily a CLI tool, deployment typically involves:
- Installing globally on your development machines
- Adding to your CI/CD pipeline
CI/CD Integration Examples
GitHub Actions
- name: Run JSHint
run: jshint .
Travis CI
script:
- jshint .
CircleCI
- run:
command: jshint .
As a Library
You can also use JSHint as a library in your Node.js applications:
npm install jshint --save-dev
const JSHINT = require("jshint").JSHINT;
const code = "function test() { return 'hello'; }";
const options = { undef: true };
const globals = { console: true };
JSHINT(code, options, globals);
console.log(JSHINT.errors);
Troubleshooting
Common Issues
1. "jshint: command not found"
Solution: Make sure JSHint is installed globally or add it to your PATH.
npm install -g jshint
2. Configuration Not Loading
Solution: Check the configuration file path and syntax.
# Verify configuration
jshint --verbose --config .jshintrc
3. False Positives
Solution: Use the /* jshint ignore:start */ and /* jshint ignore:end */ comments to exclude specific code blocks.
/* jshint ignore:start */
eval("alert('Hello World!');");
/* jshint ignore:end */
4. Missing Dependencies
Solution: Ensure all dependencies are installed.
npm install
5. ES6+ Features Not Working
Solution: Configure JSHint to support modern JavaScript features.
{
"esversion": 6
}
Getting Help
- Documentation: http://jshint.com/docs/
- FAQ: http://jshint.com/docs/faq
- GitHub Issues: https://github.com/jshint/jshint/issues
- Email: admin@jshint.org
Performance Tips
- Use
.jshintignoreto exclude large directories - Configure only necessary options for your project
- Use the
--extractoption for HTML files with inline scripts
jshint --extract=auto index.html