or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-semistandard

JavaScript linting tool that enforces Standard Style rules with mandatory semicolons

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/semistandard@17.0.x

To install, run

npx @tessl/cli install tessl/npm-semistandard@17.0.0

index.mddocs/

Semistandard

Semistandard is a JavaScript linting tool that enforces JavaScript Standard Style rules with the addition of mandatory semicolons. Built on top of ESLint and the standard-engine, it provides both a command-line interface and a programmatic API for checking code style compliance in JavaScript projects.

Package Information

  • Package Name: semistandard
  • Package Type: npm
  • Language: JavaScript (ES modules)
  • Installation: npm install semistandard

Core Imports

import semistandard from "semistandard";

For CommonJS (legacy support):

const semistandard = require("semistandard");

Basic Usage

import semistandard from "semistandard";

// Lint files
const results = await semistandard.lintFiles(["src/**/*.js"]);

// Lint source code text
const results = await semistandard.lintText('console.log("hello")\n');

// Check results
results.forEach(result => {
  if (result.errorCount > 0) {
    console.log(`Errors in ${result.filePath}:`);
    result.messages.forEach(msg => {
      console.log(`  ${msg.message}`);
    });
  }
});

Capabilities

File Linting

Lints JavaScript files matching the provided file paths or glob patterns.

/**
 * Asynchronously lints files matching the provided file paths/globs
 * @param files - Array of file paths or glob patterns to lint
 * @param opts - Optional linting configuration options
 * @returns Promise resolving to array of lint results
 */
async function lintFiles(files: string[], opts?: LintOptions): Promise<LintResult[]>;

Usage Examples:

import semistandard from "semistandard";

// Lint specific files
const results = await semistandard.lintFiles(["index.js", "lib/utils.js"]);

// Lint with glob patterns
const results = await semistandard.lintFiles(["src/**/*.js", "test/*.js"]);

// With options
const results = await semistandard.lintFiles(["src/**/*.js"], {
  cwd: "/path/to/project",
  fix: true
});

Text Linting

Lints provided source code text directly without file system access.

/**
 * Asynchronously lints provided source code text
 * @param text - Source code text to lint
 * @param opts - Optional linting configuration options  
 * @returns Promise resolving to array of lint results
 */
async function lintText(text: string, opts?: LintOptions): Promise<LintResult[]>;

Usage Examples:

import semistandard from "semistandard";

// Lint source code string
const code = 'console.log("hello world")\n';
const results = await semistandard.lintText(code);

// With filename for better error reporting
const results = await semistandard.lintText(code, {
  filename: "example.js"
});

Command Line Interface

Global installation provides the semistandard command for terminal usage.

# Install globally
npm install -g semistandard

# Lint files
semistandard src/**/*.js

# Auto-fix issues
semistandard --fix src/**/*.js

# Verbose output
semistandard --verbose src/**/*.js

Types

interface LintResult {
  /** Number of errors found in the file/text */
  errorCount: number;
  /** Number of warnings found in the file/text */
  warningCount: number;
  /** File path (only present for lintFiles results) */
  filePath?: string;
  /** Array of lint messages */
  messages: LintMessage[];
  /** Fixed source code (only present when fix: true option is used) */
  output?: string;
}

interface LintMessage {
  /** Description of the lint issue */
  message: string;
  /** Line number where issue occurs */
  line: number;
  /** Column number where issue occurs */
  column: number;
  /** Rule that triggered the message */
  ruleId: string;
  /** Severity level (1 = warning, 2 = error) */
  severity: number;
}

interface LintOptions {
  /** Current working directory for resolving files */
  cwd?: string;
  /** Automatically fix fixable issues */
  fix?: boolean;
  /** File extensions to lint (default: ['.js']) */
  extensions?: string[];
  /** Filename to use for error reporting (lintText only) */
  filename?: string;
  /** Global variables to define */
  globals?: string[];
  /** Files/patterns to ignore */
  ignore?: string[];
  /** Custom parser to use (e.g., 'babel-eslint') */
  parser?: string;
  /** Plugins to enable */
  plugins?: string[];
}

Configuration

Package.json Integration

{
  "scripts": {
    "lint": "semistandard",
    "lint:fix": "semistandard --fix",
    "test": "semistandard && node test.js"
  },
  "semistandard": {
    "ignore": [
      "build/**",
      "dist/**", 
      "tmp.js"
    ],
    "parser": "babel-eslint",
    "globals": ["describe", "it", "before", "after"]
  }
}

Custom Parser Support

For projects using advanced JavaScript features or TypeScript:

{
  "semistandard": {
    "parser": "babel-eslint"
  }
}

Ignore Patterns

Files automatically ignored:

  • node_modules/**
  • *.min.js
  • bundle.js
  • coverage/**
  • Hidden files/folders (starting with .)
  • All patterns in .gitignore

Additional patterns can be specified:

{
  "semistandard": {
    "ignore": [
      "**/build/",
      "/lib/vendor/",
      "generated.js"
    ]
  }
}

Editor Integration

Visual Studio Code

Install the vscode-standardjs extension.

Sublime Text

Use SublimeLinter-contrib-semistandard.

Vim

Install Syntastic and configure:

let g:syntastic_javascript_checkers=['standard']
let g:syntastic_javascript_standard_exec = 'semistandard'

For auto-fix on save:

autocmd bufwritepost *.js silent !semistandard % --fix
set autoread

Rules

Semistandard enforces all JavaScript Standard Style rules with one key difference:

  • Mandatory semicolons - All statements must end with semicolons
  • All other Standard Style rules apply (2-space indentation, single quotes, etc.)

Common violations detected:

  • Missing semicolons: console.log('hello')console.log('hello');
  • Double quotes: "hello"'hello'
  • Wrong indentation: 4 spaces → 2 spaces
  • Trailing whitespace
  • Mixed operators without parentheses

Error Handling

Both lintFiles and lintText return arrays of results rather than throwing errors. Check the errorCount property and messages array to handle lint violations:

const results = await semistandard.lintFiles(['src/app.js']);

results.forEach(result => {
  if (result.errorCount > 0) {
    console.error(`Found ${result.errorCount} errors in ${result.filePath}:`);
    result.messages.forEach(msg => {
      console.error(`  Line ${msg.line}: ${msg.message}`);
    });
    process.exit(1);
  }
});