TypeScript Standard Style linter based on StandardJS that enforces consistent code style and quality rules for TypeScript projects
npx @tessl/cli install tessl/npm-ts-standard@12.0.0ts-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.
npm install --save-dev ts-standardimport tsStandard from "ts-standard";For CommonJS:
const tsStandard = require("ts-standard");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)# 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 --versionThe 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:
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 informationAdvanced 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)ts-standard automatically discovers and resolves TypeScript configuration files. The configuration resolution follows this priority:
--project flag valuets-standard.project in package.jsontsconfig.eslint.json in current directorytsconfig.json in current directoryYou can configure ts-standard behavior in your package.json:
{
"ts-standard": {
"project": "path/to/tsconfig.json",
"ignore": [
"dist",
"src/**/*.js"
]
}
}ts-standard requires a TypeScript configuration file to function properly. It searches for:
tsconfig.eslint.json (preferred for linting-specific config)tsconfig.json (fallback)The configuration file should include the files you want to lint and exclude files you want to ignore.
ts-standard uses a pre-configured ESLint setup that extends:
standard-with-typescript: TypeScript-specific Standard rulesstandard-jsx: JSX support for React componentsThe ESLint configuration cannot be customized - this is by design to maintain the "zero configuration" philosophy of StandardJS.
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 filesAutomatically ignored paths:
node_modules/coverage/vendor/*.min.js. (like .git/).gitignore filets-standard will exit with non-zero status codes when issues are encountered:
Common error scenarios: