CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-jshint

Static analysis tool for JavaScript that detects errors and potential problems in code

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

cli.mddocs/

Command Line Interface

Complete CLI functionality for file processing, configuration management, and output formatting. The JSHint CLI provides a comprehensive command-line tool for linting JavaScript files with flexible options and reporting.

Capabilities

CLI Entry Point

Main command-line interface entry point that processes arguments and executes linting.

/**
 * Main CLI entry point that parses command line arguments and runs JSHint
 * @param args - Command line arguments array in process.argv format
 */
function interpret(args);

Usage Examples:

# Basic file linting
jshint file.js

# Multiple files
jshint file1.js file2.js folder/

# With configuration file
jshint --config .jshintrc src/

# Using custom reporter
jshint --reporter unix app.js

# Reading from stdin
echo "var x = 1;" | jshint --stdin

# With custom filename for stdin
echo "var x = 1;" | jshint --stdin --filename test.js

Core CLI Functions

Core functions that power the command-line interface.

/**
 * Runs linting with processed CLI options
 * @param options - Processed CLI options object
 * @param callback - Optional completion callback function
 * @returns boolean result or null for async operations
 */
function run(options, callback);

/**
 * Gathers files to be linted based on patterns and options
 * @param options - File gathering options object
 * @returns Array of file paths to be processed
 */
function gather(options);

/**
 * Retrieves configuration for a specific file path
 * @param filepath - File path for configuration lookup
 * @returns Configuration object merged from various sources
 */
function getConfig(filepath);

/**
 * Loads and parses a JSHint configuration file
 * @param filepath - Path to configuration file (.jshintrc, package.json, etc.)
 * @returns Parsed configuration object
 */
function loadConfig(filepath);

/**
 * Extracts JavaScript code from HTML script tags
 * @param code - Source code string (potentially HTML)
 * @param when - Extraction mode: 'always', 'auto', or 'never'
 * @returns Extracted JavaScript code string
 */
function extract(code, when);

/**
 * Exits the process with specified code
 * @param code - Exit code number (0 for success, non-zero for error)
 */
function exit(code);

Usage Examples:

const cli = require('jshint/src/cli');

// Programmatic CLI usage
const options = {
  args: ['file1.js', 'file2.js'],
  config: '.jshintrc',
  reporter: 'unix'
};

cli.run(options, (success) => {
  console.log(success ? 'All files passed!' : 'Errors found');
});

// Gather files for processing
const files = cli.gather({
  args: ['src/'],
  exclude: ['node_modules/', '*.min.js']
});
console.log('Files to lint:', files);

// Extract JavaScript from HTML
const html = `
<html>
  <script>
    function hello() {
      console.log("Hello World");
    }
  </script>
</html>
`;

const js = cli.extract(html, 'always');
console.log('Extracted JS:', js);

Command Line Options

Complete set of command-line flags and options supported by JSHint CLI.

interface CLIOptions {
  // Configuration
  "--config": string;           // -c, Custom configuration file path
  "--reporter": string;         // Custom reporter (path|jslint|checkstyle|unix)
  
  // File handling
  "--exclude": string;          // File exclusion patterns
  "--exclude-path": string;     // Custom .jshintignore file path
  "--extra-ext": string;        // -e, Additional file extensions (comma-separated)
  
  // Input/output
  "--filename": string;         // Filename to use for stdin input
  "--prereq": string;           // Comma-separated prerequisite files
  
  // Output control
  "--verbose": boolean;         // Show error codes in output
  "--show-non-errors": boolean; // Show additional JSHint data
  
  // HTML processing
  "--extract": string;          // HTML extraction mode (always|auto|never)
}

Usage Examples:

# Use custom config file
jshint --config custom.jshintrc app.js

# Use unix-style reporter
jshint --reporter unix src/

# Process additional file extensions
jshint --extra-ext .jsx,.ts src/

# Exclude files and directories
jshint --exclude node_modules/,*.min.js src/

# Use custom .jshintignore file
jshint --exclude-path .customignore src/

# Show error codes
jshint --verbose app.js

# Show additional analysis data
jshint --show-non-errors app.js

# Process HTML files and extract JavaScript
jshint --extract always *.html

# Lint stdin with custom filename
echo "var x = 1;" | jshint --stdin --filename test.js

# Include prerequisite files
jshint --prereq jquery.js,underscore.js app.js

File Processing

File and directory processing capabilities for handling various input scenarios.

/**
 * File gathering options for processing multiple files and directories
 */
interface GatherOptions {
  args: string[];              // File/directory arguments
  exclude: string[];           // Exclusion patterns
  excludePath?: string;        // Path to .jshintignore file
  extensions?: string[];       // Additional file extensions
}

/**
 * Configuration loading hierarchy (in order of precedence):
 * 1. --config specified file
 * 2. .jshintrc in file's directory (walking up)
 * 3. package.json "jshintConfig" property
 * 4. ~/.jshintrc (user home directory)
 * 5. Default options
 */

Usage Examples:

const cli = require('jshint/src/cli');

// Advanced file gathering
const options = {
  args: ['src/', 'test/'],
  exclude: ['node_modules/', '*.min.js', 'vendor/'],
  extensions: ['.jsx', '.ts']
};

const files = cli.gather(options);
files.forEach(file => {
  const config = cli.getConfig(file);
  console.log(`Config for ${file}:`, config);
});

HTML JavaScript Extraction

Functionality for extracting and linting JavaScript code embedded in HTML files.

/**
 * HTML extraction modes for processing JavaScript in HTML files
 */
type ExtractionMode = 'always' | 'auto' | 'never';

/**
 * Extracts JavaScript from HTML script tags
 * @param code - HTML source code string
 * @param when - Extraction mode
 *   - 'always': Always extract JS from HTML
 *   - 'auto': Extract only if file extension is .html
 *   - 'never': Never extract, treat as plain JavaScript
 * @returns Extracted JavaScript code with line number preservation
 */
function extract(code, when);

Usage Examples:

# Extract JavaScript from HTML files
jshint --extract always page.html

# Auto-detect based on file extension
jshint --extract auto page.html script.js

# Process HTML but treat as JavaScript (don't extract)
jshint --extract never page.html

Configuration File Formats

JSHint supports multiple configuration file formats and locations.

.jshintrc (JSON format):

{
  "esversion": 6,
  "strict": true,
  "undef": true,
  "unused": true,
  "predef": ["myGlobal", "anotherGlobal"]
}

package.json (jshintConfig property):

{
  "name": "my-package",
  "jshintConfig": {
    "node": true,
    "esversion": 8,
    "strict": "global"
  }
}

.jshintignore file format:

node_modules/
dist/
*.min.js
test/fixtures/

Exit Codes

JSHint CLI uses standard exit codes for integration with build systems:

  • 0: Success - no linting errors found
  • 1: Linting errors found
  • 2: Fatal error (invalid arguments, missing files, etc.)

Reporter Integration

const cli = require('jshint/src/cli');

// Run with custom reporter
const options = {
  args: ['app.js'],
  reporter: './custom-reporter.js'
};

cli.run(options);

Custom Reporter Example:

// custom-reporter.js
module.exports = {
  reporter: function(results, data, opts) {
    results.forEach(result => {
      if (result.error) {
        console.log(`${result.file}: ${result.error.reason}`);
      }
    });
  }
};

docs

cli.md

configuration.md

core-linting.md

index.md

reporting.md

tile.json