eslint-plugin-code-style 1.8.1 → 1.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/README.md +80 -2
- package/index.js +924 -54
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
---
|
|
9
9
|
|
|
10
|
+
## [1.8.3] - 2026-02-03
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- **`class-naming-convention`** - Auto-fix now renames all references to the class (including instantiations like `new ClassName()` and type annotations), not just the class declaration
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## [1.8.2] - 2026-02-03
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
|
|
22
|
+
- **`multiline-if-conditions`** - Remove configurable `maxNestingLevel` option; nesting level is now fixed at 2 to prevent overly complex conditions. Nested groups with >maxOperands are formatted multiline inline (not extracted). Extraction only occurs when nesting exceeds 2 levels.
|
|
23
|
+
- **`ternary-condition-multiline`** - Remove configurable `maxNestingLevel` option; nesting level is now fixed at 2 to prevent overly complex conditions. Nested groups with >maxOperands are formatted multiline inline (not extracted). Extraction only occurs when nesting exceeds 2 levels.
|
|
24
|
+
- **`opening-brackets-same-line`** - Skip ternary condition tests and detect intentional multiline format to prevent rule conflicts
|
|
25
|
+
- **`if-statement-format`** - Detect intentional multiline conditions to prevent collapsing formatted conditions
|
|
26
|
+
|
|
27
|
+
### Documentation
|
|
28
|
+
|
|
29
|
+
- Update both rules to show multiline inline formatting examples instead of extraction
|
|
30
|
+
- Remove `maxNestingLevel` option from documentation (now fixed internally)
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
10
34
|
## [1.8.1] - 2026-02-03
|
|
11
35
|
|
|
12
36
|
### Changed
|
package/README.md
CHANGED
|
@@ -1151,13 +1151,59 @@ if (isAuthenticated &&
|
|
|
1151
1151
|
|
|
1152
1152
|
| Option | Type | Default | Description |
|
|
1153
1153
|
|--------|------|---------|-------------|
|
|
1154
|
-
| `maxOperands` | `integer` | `3` | Maximum operands to keep on single line |
|
|
1154
|
+
| `maxOperands` | `integer` | `3` | Maximum operands to keep on single line. Also applies to nested groups |
|
|
1155
1155
|
|
|
1156
1156
|
```javascript
|
|
1157
1157
|
// Example: Allow up to 4 operands on single line
|
|
1158
1158
|
"code-style/multiline-if-conditions": ["error", { maxOperands: 4 }]
|
|
1159
1159
|
```
|
|
1160
1160
|
|
|
1161
|
+
**Auto-formatting:** Nested groups with >maxOperands are formatted multiline inline:
|
|
1162
|
+
|
|
1163
|
+
```javascript
|
|
1164
|
+
// ❌ Before (nested group has 4 operands)
|
|
1165
|
+
if ((a || b || c || d) && e) {}
|
|
1166
|
+
|
|
1167
|
+
// ✅ After auto-fix — formats nested group multiline
|
|
1168
|
+
if ((
|
|
1169
|
+
a
|
|
1170
|
+
|| b
|
|
1171
|
+
|| c
|
|
1172
|
+
|| d
|
|
1173
|
+
) && e) {}
|
|
1174
|
+
```
|
|
1175
|
+
|
|
1176
|
+
**Double nesting:** Both levels expand when both exceed maxOperands:
|
|
1177
|
+
|
|
1178
|
+
```javascript
|
|
1179
|
+
// ❌ Before (both parent and nested have 4 operands)
|
|
1180
|
+
if ((a || (c && d && a && b) || c || d) && e) {}
|
|
1181
|
+
|
|
1182
|
+
// ✅ After auto-fix — both levels formatted multiline
|
|
1183
|
+
if ((
|
|
1184
|
+
a
|
|
1185
|
+
|| (
|
|
1186
|
+
c
|
|
1187
|
+
&& d
|
|
1188
|
+
&& a
|
|
1189
|
+
&& b
|
|
1190
|
+
)
|
|
1191
|
+
|| c
|
|
1192
|
+
|| d
|
|
1193
|
+
) && e) {}
|
|
1194
|
+
```
|
|
1195
|
+
|
|
1196
|
+
**Extraction:** Groups exceeding nesting level 2 are extracted to variables:
|
|
1197
|
+
|
|
1198
|
+
```javascript
|
|
1199
|
+
// ❌ Before (level 3 nesting)
|
|
1200
|
+
if ((a && (b || (c && d))) || e) {}
|
|
1201
|
+
|
|
1202
|
+
// ✅ After auto-fix — extracts deepest nested group
|
|
1203
|
+
const isCAndD = (c && d);
|
|
1204
|
+
if ((a && (b || isCAndD)) || e) {}
|
|
1205
|
+
```
|
|
1206
|
+
|
|
1161
1207
|
---
|
|
1162
1208
|
|
|
1163
1209
|
### `no-empty-lines-in-switch-cases`
|
|
@@ -1217,6 +1263,9 @@ switch (status) {
|
|
|
1217
1263
|
**What it does:** Formats ternary expressions based on condition operand count:
|
|
1218
1264
|
- ≤maxOperands (default: 3): Always collapse to single line regardless of line length
|
|
1219
1265
|
- \>maxOperands: Expand to multiline with each operand on its own line
|
|
1266
|
+
- Simple parenthesized nested ternaries (≤maxOperands) count as 1 operand and collapse
|
|
1267
|
+
- Complex nested ternaries (>maxOperands in their condition) are skipped for manual formatting
|
|
1268
|
+
- Nesting level is fixed at 2 to prevent overly complex conditions
|
|
1220
1269
|
|
|
1221
1270
|
**Why use it:** Consistent formatting based on complexity, not line length. Simple conditions stay readable on one line; complex conditions get proper multiline formatting.
|
|
1222
1271
|
|
|
@@ -1224,13 +1273,16 @@ switch (status) {
|
|
|
1224
1273
|
|
|
1225
1274
|
| Option | Type | Default | Description |
|
|
1226
1275
|
|--------|------|---------|-------------|
|
|
1227
|
-
| `maxOperands` | `integer` | `3` | Maximum condition operands to keep ternary on single line |
|
|
1276
|
+
| `maxOperands` | `integer` | `3` | Maximum condition operands to keep ternary on single line. Also applies to nested groups |
|
|
1228
1277
|
|
|
1229
1278
|
```javascript
|
|
1230
1279
|
// ✅ Good — ≤3 operands always on single line
|
|
1231
1280
|
const x = a && b && c ? "yes" : "no";
|
|
1232
1281
|
const url = lang === "ar" ? `${apiEndpoints.exam.status}/${jobId}?lang=ar` : `${apiEndpoints.exam.status}/${jobId}`;
|
|
1233
1282
|
|
|
1283
|
+
// ✅ Good — parenthesized nested ternary counts as 1 operand
|
|
1284
|
+
const inputType = showToggle ? (showPassword ? "text" : "password") : type;
|
|
1285
|
+
|
|
1234
1286
|
// ✅ Good — >3 operands formatted multiline
|
|
1235
1287
|
const style = variant === "ghost"
|
|
1236
1288
|
|| variant === "ghost-danger"
|
|
@@ -1239,6 +1291,19 @@ const style = variant === "ghost"
|
|
|
1239
1291
|
? "transparent"
|
|
1240
1292
|
: "solid";
|
|
1241
1293
|
|
|
1294
|
+
// ✅ Good — nested group with >3 operands formatted multiline inline
|
|
1295
|
+
const result = (
|
|
1296
|
+
a
|
|
1297
|
+
|| (
|
|
1298
|
+
c
|
|
1299
|
+
&& d
|
|
1300
|
+
&& a
|
|
1301
|
+
&& b
|
|
1302
|
+
)
|
|
1303
|
+
|| c
|
|
1304
|
+
|| d
|
|
1305
|
+
) && e ? "yes" : "no";
|
|
1306
|
+
|
|
1242
1307
|
// ❌ Bad — ≤3 operands split across lines
|
|
1243
1308
|
const x = a && b && c
|
|
1244
1309
|
? "yes"
|
|
@@ -1248,6 +1313,19 @@ const x = a && b && c
|
|
|
1248
1313
|
const style = variant === "ghost" || variant === "ghost-danger" || variant === "muted" || variant === "primary" ? "transparent" : "solid";
|
|
1249
1314
|
```
|
|
1250
1315
|
|
|
1316
|
+
**Auto-extraction:** Nested groups are auto-extracted to variables only when nesting depth exceeds 2 levels:
|
|
1317
|
+
|
|
1318
|
+
```javascript
|
|
1319
|
+
// ❌ Before (level 3 nesting exceeds limit)
|
|
1320
|
+
const result = (a && (b || (c && d))) || e ? "yes" : "no";
|
|
1321
|
+
|
|
1322
|
+
// ✅ After auto-fix — extracts deepest nested group
|
|
1323
|
+
const isCAndD = (c && d);
|
|
1324
|
+
const result = (a && (b || isCAndD)) || e ? "yes" : "no";
|
|
1325
|
+
```
|
|
1326
|
+
|
|
1327
|
+
**Note:** When nested groups exceed `maxOperands` but stay within the 2-level nesting limit, they are formatted multiline inline (not extracted).
|
|
1328
|
+
|
|
1251
1329
|
<br />
|
|
1252
1330
|
|
|
1253
1331
|
## ⚡ Function Rules
|