JavaScript linting tool that enforces Standard Style rules with mandatory semicolons
npx @tessl/cli install tessl/npm-semistandard@17.0.0Semistandard 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.
npm install semistandardimport semistandard from "semistandard";For CommonJS (legacy support):
const semistandard = require("semistandard");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}`);
});
}
});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
});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"
});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/**/*.jsinterface 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[];
}{
"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"]
}
}For projects using advanced JavaScript features or TypeScript:
{
"semistandard": {
"parser": "babel-eslint"
}
}Files automatically ignored:
node_modules/***.min.jsbundle.jscoverage/**.).gitignoreAdditional patterns can be specified:
{
"semistandard": {
"ignore": [
"**/build/",
"/lib/vendor/",
"generated.js"
]
}
}Install the vscode-standardjs extension.
Use SublimeLinter-contrib-semistandard.
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 autoreadSemistandard enforces all JavaScript Standard Style rules with one key difference:
Common violations detected:
console.log('hello') → console.log('hello');"hello" → 'hello'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);
}
});