CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-ts-standard

TypeScript Standard Style linter based on StandardJS that enforces consistent code style and quality rules for TypeScript projects

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

ts-standard

ts-standard is a TypeScript linting tool that provides StandardJS-style linting for TypeScript projects. It combines ESLint with TypeScript-specific configurations to automatically check and fix TypeScript code according to the Standard Style guidelines, offering a zero-configuration alternative to manually setting up ESLint with TypeScript configurations.

Package Information

  • Package Name: ts-standard
  • Package Type: npm
  • Language: JavaScript (ES modules)
  • Installation: npm install --save-dev ts-standard

Core Imports

import tsStandard from "ts-standard";

For CommonJS:

const tsStandard = require("ts-standard");

Basic Usage

Programmatic API

import tsStandard from "ts-standard";

// Lint multiple files
const results = await tsStandard.lintFiles(['src/**/*.ts', 'src/**/*.js']);
console.log(results[0].errorCount); // Number of errors found

// Lint text directly
const [result] = await tsStandard.lintText('console.log("hello world")');
console.log(result.errorCount); // Will be 1 due to double quotes (should use single)

Command Line Interface

# Basic usage - lint all TypeScript/JavaScript files
ts-standard

# Automatically fix problems  
ts-standard --fix

# Specify TypeScript config location
ts-standard --project ./tsconfig.eslint.json

# Show help
ts-standard --help

# Show version
ts-standard --version

Capabilities

Programmatic Linting Engine

The main export provides a pre-configured StandardEngine instance for programmatic use.

// Default export - pre-configured StandardEngine instance
declare const tsStandard: StandardEngine;
export default tsStandard;

interface StandardEngine {
  /**
   * Lint multiple files and return results
   * @param files - Array of file paths or glob patterns to lint
   * @returns Promise resolving to array of lint results
   */
  lintFiles(files: string[]): Promise<LintResult[]>;

  /**
   * Lint text content directly and return results
   * @param code - Source code string to lint
   * @param options - Optional configuration for linting
   * @returns Promise resolving to array containing single lint result
   */
  lintText(code: string, options?: { filename?: string }): Promise<LintResult[]>;
}

interface LintResult {
  /** Number of errors found in the linted code */
  errorCount: number;
  /** Number of warnings found in the linted code */
  warningCount: number;
  /** Array of specific lint messages */
  messages: LintMessage[];
  /** File path (when linting files) */
  filePath?: string;
}

interface LintMessage {
  /** Line number where issue occurs */
  line: number;
  /** Column number where issue occurs */
  column: number;
  /** Severity level (1 = warning, 2 = error) */
  severity: number;
  /** Human-readable error message */
  message: string;
  /** ESLint rule identifier */
  ruleId: string | null;
}

The engine is pre-configured with:

  • TypeScript parser options (@typescript-eslint/parser)
  • ESLint configuration extending "standard-with-typescript" and "standard-jsx"
  • Automatically resolved TypeScript configuration file path
  • Default file extensions: js, jsx, mjs, cjs, ts, tsx

Command Line Interface

Complete command-line interface for linting TypeScript projects.

Basic Flags:

  • --fix: Automatically fix problems
  • -p, --project: Specify ts-config location (default: ./tsconfig.eslint.json or ./tsconfig.json)
  • --version: Show current version
  • -h, --help: Show usage information

Advanced Flags:

  • --stdin: Read file text from stdin
  • --ext: Specify JavaScript/TypeScript file extensions
  • --global: Declare global variable
  • --plugin: Use custom eslint plugin
  • --env: Use custom eslint environment
  • --parser: Use custom ts/js parser (default: @typescript-eslint/parser)

TypeScript Configuration Resolution

ts-standard automatically discovers and resolves TypeScript configuration files. The configuration resolution follows this priority:

  1. CLI --project flag value
  2. ts-standard.project in package.json
  3. tsconfig.eslint.json in current directory
  4. tsconfig.json in current directory

Configuration

Package.json Configuration

You can configure ts-standard behavior in your package.json:

{
  "ts-standard": {
    "project": "path/to/tsconfig.json",
    "ignore": [
      "dist",
      "src/**/*.js"
    ]
  }
}

TypeScript Configuration Requirements

ts-standard requires a TypeScript configuration file to function properly. It searches for:

  1. tsconfig.eslint.json (preferred for linting-specific config)
  2. tsconfig.json (fallback)

The configuration file should include the files you want to lint and exclude files you want to ignore.

ESLint Configuration

ts-standard uses a pre-configured ESLint setup that extends:

  • standard-with-typescript: TypeScript-specific Standard rules
  • standard-jsx: JSX support for React components

The ESLint configuration cannot be customized - this is by design to maintain the "zero configuration" philosophy of StandardJS.

File Processing

ts-standard automatically processes these file types:

  • .js - JavaScript files
  • .jsx - React JavaScript files
  • .mjs - ES module JavaScript files
  • .cjs - CommonJS JavaScript files
  • .ts - TypeScript files
  • .tsx - React TypeScript files

Automatically ignored paths:

  • node_modules/
  • coverage/
  • vendor/
  • *.min.js
  • Files/folders beginning with . (like .git/)
  • Paths in project's root .gitignore file

Error Handling

ts-standard will exit with non-zero status codes when issues are encountered:

  • Exit code 1: Linting errors found (and --fix not used or unable to fix all issues)
  • Exit code 1: Unable to locate TypeScript configuration file (tsconfig.json or tsconfig.eslint.json)
  • Exit code 0: No errors found or all errors successfully fixed with --fix flag

Common error scenarios:

  • Missing TypeScript configuration file - ts-standard requires a tsconfig.json or tsconfig.eslint.json
  • Invalid TypeScript configuration - malformed or inaccessible tsconfig file
  • Linting violations - code that doesn't conform to Standard TypeScript style
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/ts-standard@12.0.x
Publish Source
CLI
Badge
tessl/npm-ts-standard badge