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.00
# @stylistic/eslint-plugin-js
1
2
@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.
3
4
**⚠️ 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.
5
6
## Package Information
7
8
- **Package Name**: @stylistic/eslint-plugin-js
9
- **Package Type**: npm
10
- **Language**: JavaScript/TypeScript
11
- **Installation**: `npm install @stylistic/eslint-plugin-js`
12
- **ESLint Version**: Requires ESLint >=9.0.0
13
14
## Core Imports
15
16
```javascript
17
// ESM import
18
import stylisticJs from '@stylistic/eslint-plugin-js';
19
20
// CommonJS import
21
const stylisticJs = require('@stylistic/eslint-plugin-js');
22
23
// Import type definitions for configuration
24
import type { RuleOptions } from '@stylistic/eslint-plugin-js/rule-options';
25
26
// Import individual rules (available for all 70 rules)
27
import arrayBracketNewline from '@stylistic/eslint-plugin-js/rules/array-bracket-newline';
28
import quotes from '@stylistic/eslint-plugin-js/rules/quotes';
29
import semi from '@stylistic/eslint-plugin-js/rules/semi';
30
```
31
32
## Basic Usage
33
34
```javascript
35
// ESLint flat config format
36
import stylisticJs from '@stylistic/eslint-plugin-js';
37
38
export default [
39
{
40
plugins: {
41
'@stylistic/js': stylisticJs
42
},
43
rules: {
44
'@stylistic/js/indent': ['error', 2],
45
'@stylistic/js/quotes': ['error', 'single'],
46
'@stylistic/js/semi': ['error', 'always']
47
}
48
}
49
];
50
```
51
52
## Architecture
53
54
@stylistic/eslint-plugin-js is structured around several key components:
55
56
- **Plugin Object**: Main export containing `rules` and `configs` collections
57
- **Rule Modules**: 70 individual ESLint rule implementations for stylistic formatting
58
- **Configuration Presets**: Pre-built configurations for common use cases
59
- **TypeScript Definitions**: Complete type definitions for all rules and their options
60
61
## Capabilities
62
63
### Plugin Configuration
64
65
Main plugin object that provides access to all rules and configuration presets. Essential for setting up ESLint with stylistic rules.
66
67
```javascript { .api }
68
interface Plugin {
69
rules: Rules;
70
configs: {
71
/** Disable all legacy rules from eslint core to avoid conflicts */
72
'disable-legacy': Linter.Config;
73
/** Enable all 70 stylistic rules with default settings */
74
'all': Linter.Config;
75
/** @deprecated use 'all' instead */
76
'all-flat': Linter.Config;
77
};
78
}
79
80
declare const plugin: Plugin;
81
export default plugin;
82
83
// Additional exports
84
export type { RuleOptions } from './rule-options';
85
export type * from './define-config-support';
86
```
87
88
[Plugin Configuration](./plugin-configuration.md)
89
90
### Array Formatting Rules
91
92
Rules that control the formatting and styling of JavaScript arrays, including bracket spacing, newlines, and element positioning.
93
94
```javascript { .api }
95
// Key array formatting rules
96
rules: {
97
'array-bracket-newline': Rule.RuleModule;
98
'array-bracket-spacing': Rule.RuleModule;
99
'array-element-newline': Rule.RuleModule;
100
}
101
```
102
103
[Array Formatting](./array-formatting.md)
104
105
### Object Formatting Rules
106
107
Rules for consistent object literal formatting, including curly brace positioning, property spacing, and multiline object handling.
108
109
```javascript { .api }
110
// Key object formatting rules
111
rules: {
112
'object-curly-newline': Rule.RuleModule;
113
'object-curly-spacing': Rule.RuleModule;
114
'object-property-newline': Rule.RuleModule;
115
}
116
```
117
118
[Object Formatting](./object-formatting.md)
119
120
### Function Formatting Rules
121
122
Rules that enforce consistent formatting for function declarations, calls, and parameters, including parentheses and argument positioning.
123
124
```javascript { .api }
125
// Key function formatting rules
126
rules: {
127
'function-call-spacing': Rule.RuleModule;
128
'function-call-argument-newline': Rule.RuleModule;
129
'function-paren-newline': Rule.RuleModule;
130
'space-before-function-paren': Rule.RuleModule;
131
}
132
```
133
134
[Function Formatting](./function-formatting.md)
135
136
### Spacing and Indentation Rules
137
138
Core spacing rules that control whitespace, indentation, and general code layout for improved readability.
139
140
```javascript { .api }
141
// Key spacing rules
142
rules: {
143
'indent': Rule.RuleModule;
144
'space-before-blocks': Rule.RuleModule;
145
'space-infix-ops': Rule.RuleModule;
146
'keyword-spacing': Rule.RuleModule;
147
'key-spacing': Rule.RuleModule;
148
}
149
```
150
151
[Spacing and Indentation](./spacing-indentation.md)
152
153
### Punctuation and Operators Rules
154
155
Rules governing the placement and spacing of punctuation marks, operators, and symbols in JavaScript code.
156
157
```javascript { .api }
158
// Key punctuation rules
159
rules: {
160
'semi': Rule.RuleModule;
161
'semi-spacing': Rule.RuleModule;
162
'comma-dangle': Rule.RuleModule;
163
'comma-spacing': Rule.RuleModule;
164
'quotes': Rule.RuleModule;
165
}
166
```
167
168
[Punctuation and Operators](./punctuation-operators.md)
169
170
### Line Break and Newline Rules
171
172
Rules that control line breaks, empty lines, and multiline formatting for better code organization and readability.
173
174
```javascript { .api }
175
// Key line break rules
176
rules: {
177
'eol-last': Rule.RuleModule;
178
'no-multiple-empty-lines': Rule.RuleModule;
179
'padding-line-between-statements': Rule.RuleModule;
180
'lines-around-comment': Rule.RuleModule;
181
}
182
```
183
184
[Line Breaks and Newlines](./line-breaks-newlines.md)
185
186
### ES6+ and Modern JavaScript Rules
187
188
Rules specific to modern JavaScript features including arrow functions, template literals, destructuring, and generator functions.
189
190
```javascript { .api }
191
// Key modern JavaScript rules
192
rules: {
193
'arrow-parens': Rule.RuleModule;
194
'arrow-spacing': Rule.RuleModule;
195
'template-curly-spacing': Rule.RuleModule;
196
'generator-star-spacing': Rule.RuleModule;
197
'rest-spread-spacing': Rule.RuleModule;
198
}
199
```
200
201
[ES6+ and Modern JavaScript](./modern-javascript.md)
202
203
### Code Quality and Consistency Rules
204
205
Rules that prevent common stylistic issues and enforce consistent patterns across codebases.
206
207
```javascript { .api }
208
// Key consistency rules
209
rules: {
210
'no-extra-parens': Rule.RuleModule;
211
'no-extra-semi': Rule.RuleModule;
212
'no-mixed-spaces-and-tabs': Rule.RuleModule;
213
'no-trailing-spaces': Rule.RuleModule;
214
'max-len': Rule.RuleModule;
215
}
216
```
217
218
[Code Quality and Consistency](./code-quality-consistency.md)
219
220
### Individual Rule Imports
221
222
All 70 rules can be imported individually for custom usage patterns or direct rule implementation.
223
224
```javascript { .api }
225
// Individual rule imports (all 70 rules available)
226
import arrayBracketNewline from '@stylistic/eslint-plugin-js/rules/array-bracket-newline';
227
import quotes from '@stylistic/eslint-plugin-js/rules/quotes';
228
import semi from '@stylistic/eslint-plugin-js/rules/semi';
229
// ... all other rules follow the same pattern
230
231
// Each rule export follows this interface
232
interface RuleModule {
233
meta: {
234
type: 'layout';
235
docs: {
236
description: string;
237
category: string;
238
recommended: boolean;
239
url: string;
240
};
241
fixable?: 'code' | 'whitespace';
242
schema: JSONSchema;
243
messages: Record<string, string>;
244
};
245
create: (context: any) => any;
246
}
247
```
248
249
## Type Definitions
250
251
```typescript { .api }
252
// Core types from the package
253
export type Rules = {
254
[K in keyof UnprefixedRuleOptions]: Rule.RuleModule
255
};
256
257
// Complete rule options interface (all 70 rules)
258
export type UnprefixedRuleOptions = {
259
'array-bracket-newline': ArrayBracketNewlineRuleOptions;
260
'array-bracket-spacing': ArrayBracketSpacingRuleOptions;
261
'array-element-newline': ArrayElementNewlineRuleOptions;
262
'arrow-parens': ArrowParensRuleOptions;
263
'arrow-spacing': ArrowSpacingRuleOptions;
264
'block-spacing': BlockSpacingRuleOptions;
265
'brace-style': BraceStyleRuleOptions;
266
'comma-dangle': CommaDangleRuleOptions;
267
'comma-spacing': CommaSpacingRuleOptions;
268
'comma-style': CommaStyleRuleOptions;
269
'computed-property-spacing': ComputedPropertySpacingRuleOptions;
270
'dot-location': DotLocationRuleOptions;
271
'eol-last': EolLastRuleOptions;
272
'func-call-spacing': FunctionCallSpacingRuleOptions;
273
'function-call-argument-newline': FunctionCallArgumentNewlineRuleOptions;
274
'function-call-spacing': FunctionCallSpacingRuleOptions;
275
'function-paren-newline': FunctionParenNewlineRuleOptions;
276
'generator-star-spacing': GeneratorStarSpacingRuleOptions;
277
'implicit-arrow-linebreak': ImplicitArrowLinebreakRuleOptions;
278
'indent': IndentRuleOptions;
279
'jsx-quotes': JsxQuotesRuleOptions;
280
'key-spacing': KeySpacingRuleOptions;
281
'keyword-spacing': KeywordSpacingRuleOptions;
282
'line-comment-position': LineCommentPositionRuleOptions;
283
'linebreak-style': LinebreakStyleRuleOptions;
284
'lines-around-comment': LinesAroundCommentRuleOptions;
285
'lines-between-class-members': LinesBetweenClassMembersRuleOptions;
286
'max-len': MaxLenRuleOptions;
287
'max-statements-per-line': MaxStatementsPerLineRuleOptions;
288
'multiline-comment-style': MultilineCommentStyleRuleOptions;
289
'multiline-ternary': MultilineTernaryRuleOptions;
290
'new-parens': NewParensRuleOptions;
291
'newline-per-chained-call': NewlinePerChainedCallRuleOptions;
292
'no-confusing-arrow': NoConfusingArrowRuleOptions;
293
'no-extra-parens': NoExtraParensRuleOptions;
294
'no-extra-semi': NoExtraSemiRuleOptions;
295
'no-floating-decimal': NoFloatingDecimalRuleOptions;
296
'no-mixed-operators': NoMixedOperatorsRuleOptions;
297
'no-mixed-spaces-and-tabs': NoMixedSpacesAndTabsRuleOptions;
298
'no-multi-spaces': NoMultiSpacesRuleOptions;
299
'no-multiple-empty-lines': NoMultipleEmptyLinesRuleOptions;
300
'no-tabs': NoTabsRuleOptions;
301
'no-trailing-spaces': NoTrailingSpacesRuleOptions;
302
'no-whitespace-before-property': NoWhitespaceBeforePropertyRuleOptions;
303
'nonblock-statement-body-position': NonblockStatementBodyPositionRuleOptions;
304
'object-curly-newline': ObjectCurlyNewlineRuleOptions;
305
'object-curly-spacing': ObjectCurlySpacingRuleOptions;
306
'object-property-newline': ObjectPropertyNewlineRuleOptions;
307
'one-var-declaration-per-line': OneVarDeclarationPerLineRuleOptions;
308
'operator-linebreak': OperatorLinebreakRuleOptions;
309
'padded-blocks': PaddedBlocksRuleOptions;
310
'padding-line-between-statements': PaddingLineBetweenStatementsRuleOptions;
311
'quote-props': QuotePropsRuleOptions;
312
'quotes': QuotesRuleOptions;
313
'rest-spread-spacing': RestSpreadSpacingRuleOptions;
314
'semi': SemiRuleOptions;
315
'semi-spacing': SemiSpacingRuleOptions;
316
'semi-style': SemiStyleRuleOptions;
317
'space-before-blocks': SpaceBeforeBlocksRuleOptions;
318
'space-before-function-paren': SpaceBeforeFunctionParenRuleOptions;
319
'space-in-parens': SpaceInParensRuleOptions;
320
'space-infix-ops': SpaceInfixOpsRuleOptions;
321
'space-unary-ops': SpaceUnaryOpsRuleOptions;
322
'spaced-comment': SpacedCommentRuleOptions;
323
'switch-colon-spacing': SwitchColonSpacingRuleOptions;
324
'template-curly-spacing': TemplateCurlySpacingRuleOptions;
325
'template-tag-spacing': TemplateTagSpacingRuleOptions;
326
'wrap-iife': WrapIifeRuleOptions;
327
'wrap-regex': WrapRegexRuleOptions;
328
'yield-star-spacing': YieldStarSpacingRuleOptions;
329
};
330
331
// Prefixed rule options for ESLint configuration
332
export interface RuleOptions {
333
[K in keyof UnprefixedRuleOptions as `@stylistic/js/${K}`]: UnprefixedRuleOptions[K];
334
}
335
336
export interface Plugin {
337
rules: Rules;
338
configs: {
339
'disable-legacy': Linter.Config;
340
'all': Linter.Config;
341
'all-flat': Linter.Config;
342
};
343
}
344
```