JavaScript stylistic rules for ESLint that enforce code formatting and style consistency without changing code logic.
—
This document covers the main plugin object and configuration presets provided by @stylistic/eslint-plugin-js.
The main export is an ESLint plugin object containing all 70 stylistic rules and pre-built configuration presets.
interface Plugin {
rules: Rules;
configs: {
'disable-legacy': Linter.Config;
'all': Linter.Config;
'all-flat': Linter.Config;
};
}
declare const plugin: Plugin;
export default plugin;import stylisticJs from '@stylistic/eslint-plugin-js';
export default [
{
plugins: {
'@stylistic/js': stylisticJs
},
rules: {
'@stylistic/js/indent': ['error', 2],
'@stylistic/js/semi': ['error', 'always']
}
}
];Enables all 70 stylistic rules with their default/recommended settings. This configuration uses the flat config format and is ideal for projects that want comprehensive stylistic enforcement.
const all: Linter.Config;Usage:
import stylisticJs from '@stylistic/eslint-plugin-js';
export default [
stylisticJs.configs.all
];Disables all 70 legacy ESLint core stylistic rules that conflict with this plugin's rules. This prevents rule conflicts when migrating from ESLint core stylistic rules to @stylistic rules. Works with both flat and legacy config formats.
Important: Use this config when you want to avoid "Definition for rule was not found" errors from deprecated ESLint core rules.
const disableLegacy: Linter.Config;Usage:
import stylisticJs from '@stylistic/eslint-plugin-js';
export default [
stylisticJs.configs['disable-legacy'],
// your other configs...
];Alias for configs.all. Use configs.all instead.
const allFlat: Linter.Config; // @deprecated use 'all' insteadAll 70 rules are available through the rules object or as individual exports from their respective paths:
// Through plugin object
const indentRule = stylisticJs.rules.indent;
const quotesRule = stylisticJs.rules.quotes;
// As individual imports (all 70 rules available)
import indentRule from '@stylistic/eslint-plugin-js/rules/indent';
import quotesRule from '@stylistic/eslint-plugin-js/rules/quotes';
import semiRule from '@stylistic/eslint-plugin-js/rules/semi';
import arrayBracketSpacing from '@stylistic/eslint-plugin-js/rules/array-bracket-spacing';
// ... pattern continues for all 70 rulesAvailable individual rule exports (all follow the pattern @stylistic/eslint-plugin-js/rules/{rule-name}):
array-bracket-newline, array-bracket-spacing, array-element-newlinefunction-call-spacing, function-paren-newline, space-before-function-parenobject-curly-spacing, object-curly-newline, object-property-newlineindent, space-before-blocks, space-infix-ops, keyword-spacingsemi, quotes, comma-dangle, comma-spacingarrow-parens, arrow-spacing, template-curly-spacingComplete TypeScript definitions are provided:
import type { Rules, UnprefixedRuleOptions } from '@stylistic/eslint-plugin-js';
// Type for all rule modules
type Rules = {
[K in keyof UnprefixedRuleOptions]: Rule.RuleModule
};
// Type for rule options
type RuleOptions = {
'@stylistic/js/indent': ['off' | 'warn' | 'error', number | 'tab', IndentOptions?];
'@stylistic/js/semi': ['off' | 'warn' | 'error', 'always' | 'never', SemiOptions?];
// ... all other rules
};// For eslint-define-config users
declare module 'eslint-define-config' {
export interface CustomRuleOptions extends RuleOptions {}
}Install with Tessl CLI
npx tessl i tessl/npm-stylistic--eslint-plugin-js