JavaScript stylistic rules for ESLint that enforce code formatting and style consistency without changing code logic.
npx @tessl/cli install tessl/npm-stylistic--eslint-plugin-js@4.4.0@stylistic/eslint-plugin-js is an ESLint plugin that provides 70 JavaScript stylistic and formatting rules migrated from ESLint core. It enforces code style consistency without changing code logic, supporting modern JavaScript features including ES6+ syntax, arrow functions, template literals, and providing extensive configuration options for each rule.
⚠️ DEPRECATION NOTICE: This package is deprecated in favor of the unified @stylistic/eslint-plugin. Consider migrating to the main package for ongoing support and updates.
npm install @stylistic/eslint-plugin-js// ESM import
import stylisticJs from '@stylistic/eslint-plugin-js';
// CommonJS import
const stylisticJs = require('@stylistic/eslint-plugin-js');
// Import type definitions for configuration
import type { RuleOptions } from '@stylistic/eslint-plugin-js/rule-options';
// Import individual rules (available for all 70 rules)
import arrayBracketNewline from '@stylistic/eslint-plugin-js/rules/array-bracket-newline';
import quotes from '@stylistic/eslint-plugin-js/rules/quotes';
import semi from '@stylistic/eslint-plugin-js/rules/semi';// ESLint flat config format
import stylisticJs from '@stylistic/eslint-plugin-js';
export default [
{
plugins: {
'@stylistic/js': stylisticJs
},
rules: {
'@stylistic/js/indent': ['error', 2],
'@stylistic/js/quotes': ['error', 'single'],
'@stylistic/js/semi': ['error', 'always']
}
}
];@stylistic/eslint-plugin-js is structured around several key components:
rules and configs collectionsMain plugin object that provides access to all rules and configuration presets. Essential for setting up ESLint with stylistic rules.
interface Plugin {
rules: Rules;
configs: {
/** Disable all legacy rules from eslint core to avoid conflicts */
'disable-legacy': Linter.Config;
/** Enable all 70 stylistic rules with default settings */
'all': Linter.Config;
/** @deprecated use 'all' instead */
'all-flat': Linter.Config;
};
}
declare const plugin: Plugin;
export default plugin;
// Additional exports
export type { RuleOptions } from './rule-options';
export type * from './define-config-support';Rules that control the formatting and styling of JavaScript arrays, including bracket spacing, newlines, and element positioning.
// Key array formatting rules
rules: {
'array-bracket-newline': Rule.RuleModule;
'array-bracket-spacing': Rule.RuleModule;
'array-element-newline': Rule.RuleModule;
}Rules for consistent object literal formatting, including curly brace positioning, property spacing, and multiline object handling.
// Key object formatting rules
rules: {
'object-curly-newline': Rule.RuleModule;
'object-curly-spacing': Rule.RuleModule;
'object-property-newline': Rule.RuleModule;
}Rules that enforce consistent formatting for function declarations, calls, and parameters, including parentheses and argument positioning.
// Key function formatting rules
rules: {
'function-call-spacing': Rule.RuleModule;
'function-call-argument-newline': Rule.RuleModule;
'function-paren-newline': Rule.RuleModule;
'space-before-function-paren': Rule.RuleModule;
}Core spacing rules that control whitespace, indentation, and general code layout for improved readability.
// Key spacing rules
rules: {
'indent': Rule.RuleModule;
'space-before-blocks': Rule.RuleModule;
'space-infix-ops': Rule.RuleModule;
'keyword-spacing': Rule.RuleModule;
'key-spacing': Rule.RuleModule;
}Rules governing the placement and spacing of punctuation marks, operators, and symbols in JavaScript code.
// Key punctuation rules
rules: {
'semi': Rule.RuleModule;
'semi-spacing': Rule.RuleModule;
'comma-dangle': Rule.RuleModule;
'comma-spacing': Rule.RuleModule;
'quotes': Rule.RuleModule;
}Rules that control line breaks, empty lines, and multiline formatting for better code organization and readability.
// Key line break rules
rules: {
'eol-last': Rule.RuleModule;
'no-multiple-empty-lines': Rule.RuleModule;
'padding-line-between-statements': Rule.RuleModule;
'lines-around-comment': Rule.RuleModule;
}Rules specific to modern JavaScript features including arrow functions, template literals, destructuring, and generator functions.
// Key modern JavaScript rules
rules: {
'arrow-parens': Rule.RuleModule;
'arrow-spacing': Rule.RuleModule;
'template-curly-spacing': Rule.RuleModule;
'generator-star-spacing': Rule.RuleModule;
'rest-spread-spacing': Rule.RuleModule;
}Rules that prevent common stylistic issues and enforce consistent patterns across codebases.
// Key consistency rules
rules: {
'no-extra-parens': Rule.RuleModule;
'no-extra-semi': Rule.RuleModule;
'no-mixed-spaces-and-tabs': Rule.RuleModule;
'no-trailing-spaces': Rule.RuleModule;
'max-len': Rule.RuleModule;
}All 70 rules can be imported individually for custom usage patterns or direct rule implementation.
// Individual rule imports (all 70 rules available)
import arrayBracketNewline from '@stylistic/eslint-plugin-js/rules/array-bracket-newline';
import quotes from '@stylistic/eslint-plugin-js/rules/quotes';
import semi from '@stylistic/eslint-plugin-js/rules/semi';
// ... all other rules follow the same pattern
// Each rule export follows this interface
interface RuleModule {
meta: {
type: 'layout';
docs: {
description: string;
category: string;
recommended: boolean;
url: string;
};
fixable?: 'code' | 'whitespace';
schema: JSONSchema;
messages: Record<string, string>;
};
create: (context: any) => any;
}// Core types from the package
export type Rules = {
[K in keyof UnprefixedRuleOptions]: Rule.RuleModule
};
// Complete rule options interface (all 70 rules)
export type UnprefixedRuleOptions = {
'array-bracket-newline': ArrayBracketNewlineRuleOptions;
'array-bracket-spacing': ArrayBracketSpacingRuleOptions;
'array-element-newline': ArrayElementNewlineRuleOptions;
'arrow-parens': ArrowParensRuleOptions;
'arrow-spacing': ArrowSpacingRuleOptions;
'block-spacing': BlockSpacingRuleOptions;
'brace-style': BraceStyleRuleOptions;
'comma-dangle': CommaDangleRuleOptions;
'comma-spacing': CommaSpacingRuleOptions;
'comma-style': CommaStyleRuleOptions;
'computed-property-spacing': ComputedPropertySpacingRuleOptions;
'dot-location': DotLocationRuleOptions;
'eol-last': EolLastRuleOptions;
'func-call-spacing': FunctionCallSpacingRuleOptions;
'function-call-argument-newline': FunctionCallArgumentNewlineRuleOptions;
'function-call-spacing': FunctionCallSpacingRuleOptions;
'function-paren-newline': FunctionParenNewlineRuleOptions;
'generator-star-spacing': GeneratorStarSpacingRuleOptions;
'implicit-arrow-linebreak': ImplicitArrowLinebreakRuleOptions;
'indent': IndentRuleOptions;
'jsx-quotes': JsxQuotesRuleOptions;
'key-spacing': KeySpacingRuleOptions;
'keyword-spacing': KeywordSpacingRuleOptions;
'line-comment-position': LineCommentPositionRuleOptions;
'linebreak-style': LinebreakStyleRuleOptions;
'lines-around-comment': LinesAroundCommentRuleOptions;
'lines-between-class-members': LinesBetweenClassMembersRuleOptions;
'max-len': MaxLenRuleOptions;
'max-statements-per-line': MaxStatementsPerLineRuleOptions;
'multiline-comment-style': MultilineCommentStyleRuleOptions;
'multiline-ternary': MultilineTernaryRuleOptions;
'new-parens': NewParensRuleOptions;
'newline-per-chained-call': NewlinePerChainedCallRuleOptions;
'no-confusing-arrow': NoConfusingArrowRuleOptions;
'no-extra-parens': NoExtraParensRuleOptions;
'no-extra-semi': NoExtraSemiRuleOptions;
'no-floating-decimal': NoFloatingDecimalRuleOptions;
'no-mixed-operators': NoMixedOperatorsRuleOptions;
'no-mixed-spaces-and-tabs': NoMixedSpacesAndTabsRuleOptions;
'no-multi-spaces': NoMultiSpacesRuleOptions;
'no-multiple-empty-lines': NoMultipleEmptyLinesRuleOptions;
'no-tabs': NoTabsRuleOptions;
'no-trailing-spaces': NoTrailingSpacesRuleOptions;
'no-whitespace-before-property': NoWhitespaceBeforePropertyRuleOptions;
'nonblock-statement-body-position': NonblockStatementBodyPositionRuleOptions;
'object-curly-newline': ObjectCurlyNewlineRuleOptions;
'object-curly-spacing': ObjectCurlySpacingRuleOptions;
'object-property-newline': ObjectPropertyNewlineRuleOptions;
'one-var-declaration-per-line': OneVarDeclarationPerLineRuleOptions;
'operator-linebreak': OperatorLinebreakRuleOptions;
'padded-blocks': PaddedBlocksRuleOptions;
'padding-line-between-statements': PaddingLineBetweenStatementsRuleOptions;
'quote-props': QuotePropsRuleOptions;
'quotes': QuotesRuleOptions;
'rest-spread-spacing': RestSpreadSpacingRuleOptions;
'semi': SemiRuleOptions;
'semi-spacing': SemiSpacingRuleOptions;
'semi-style': SemiStyleRuleOptions;
'space-before-blocks': SpaceBeforeBlocksRuleOptions;
'space-before-function-paren': SpaceBeforeFunctionParenRuleOptions;
'space-in-parens': SpaceInParensRuleOptions;
'space-infix-ops': SpaceInfixOpsRuleOptions;
'space-unary-ops': SpaceUnaryOpsRuleOptions;
'spaced-comment': SpacedCommentRuleOptions;
'switch-colon-spacing': SwitchColonSpacingRuleOptions;
'template-curly-spacing': TemplateCurlySpacingRuleOptions;
'template-tag-spacing': TemplateTagSpacingRuleOptions;
'wrap-iife': WrapIifeRuleOptions;
'wrap-regex': WrapRegexRuleOptions;
'yield-star-spacing': YieldStarSpacingRuleOptions;
};
// Prefixed rule options for ESLint configuration
export interface RuleOptions {
[K in keyof UnprefixedRuleOptions as `@stylistic/js/${K}`]: UnprefixedRuleOptions[K];
}
export interface Plugin {
rules: Rules;
configs: {
'disable-legacy': Linter.Config;
'all': Linter.Config;
'all-flat': Linter.Config;
};
}