eslint-plugin-code-style 2.0.0 → 2.0.2

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/CLAUDE.md DELETED
@@ -1,12 +0,0 @@
1
- # Claude Code Configuration
2
-
3
- > For general project instructions, see [AGENTS.md](./AGENTS.md).
4
-
5
- ## Claude-Specific Behavior
6
-
7
- When working on this codebase, Claude Code should:
8
-
9
- - Do NOT include `Co-Authored-By` lines in commits
10
- - Do NOT include Claude Code signature/footer in commits
11
- - Keep commit messages clean and standard (no AI attribution)
12
- - When user asks to "commit" with approval, follow the full release workflow in [AGENTS.md](./AGENTS.md#release-steps)
@@ -1,31 +0,0 @@
1
- # Rules Reference
2
-
3
- > **79 rules total** — 70 with auto-fix 🔧, 19 configurable ⚙️, 9 report-only
4
- >
5
- > **Legend:** 🔧 Auto-fixable with `eslint --fix` • ⚙️ Customizable options
6
-
7
- ## Categories
8
-
9
- | Category | Rules | Description |
10
- |----------|-------|-------------|
11
- | [Array Rules](./arrays.md) | 3 | Array formatting, callback destructuring, object-in-array line breaks |
12
- | [Arrow Function Rules](./arrow-functions.md) | 4 | Block body, simple JSX collapse, implicit return, curried arrows |
13
- | [Call Expression Rules](./call-expressions.md) | 6 | Argument formatting, nested brackets, opening brackets, single-line calls |
14
- | [Class Rules](./classes.md) | 2 | Class method formatting, naming conventions |
15
- | [Comment Rules](./comments.md) | 1 | Comment spacing and formatting |
16
- | [Component Rules](./components.md) | 6 | Props destructuring, folder naming, structure consistency, SVG icons |
17
- | [Control Flow Rules](./control-flow.md) | 8 | Block newlines, if/else formatting, logical expressions, ternaries, switch cases |
18
- | [Function Rules](./functions.md) | 6 | Call spacing, declaration style, naming, params, destructuring |
19
- | [Hook Rules](./hooks.md) | 3 | Callback formatting, deps-per-line, useState naming |
20
- | [Import/Export Rules](./imports-exports.md) | 8 | Absolute imports, format, index exports, module exports |
21
- | [JSX Rules](./jsx.md) | 14 | ClassName handling, children formatting, logical expressions, ternaries |
22
- | [Object Rules](./objects.md) | 5 | Property formatting, empty lines, string property spacing |
23
- | [React Rules](./react.md) | 1 | Component/hook code ordering |
24
- | [Spacing Rules](./spacing.md) | 2 | Assignment values, bracket spacing |
25
- | [String Rules](./strings.md) | 1 | No hardcoded strings |
26
- | [TypeScript Rules](./typescript.md) | 8 | Enum/interface/type formatting, definition location, prop naming |
27
- | [Variable Rules](./variables.md) | 1 | Variable naming conventions (camelCase, PascalCase) |
28
-
29
- ---
30
-
31
- [← Back to Main README](../../README.md)
@@ -1,107 +0,0 @@
1
- # Array Rules
2
-
3
- ### `array-callback-destructure`
4
-
5
- **What it does:** When destructuring parameters in array method callbacks (map, filter, find, etc.), enforces each property on its own line when there are 2 or more properties.
6
-
7
- **Why use it:** Improves readability of array transformations by making destructured properties easy to scan vertically.
8
-
9
- ```javascript
10
- // Good — each destructured property on its own line
11
- const result = items.map(({
12
- name,
13
- value,
14
- }) => `${name}: ${value}`);
15
-
16
- const filtered = users.filter(({
17
- age,
18
- isActive,
19
- }) => age > 18 && isActive);
20
-
21
- // Good — single property stays inline
22
- const names = items.map(({ name }) => name);
23
-
24
- // Bad — multiple properties on same line
25
- const result = items.map(({ name, value, id }) => `${name}: ${value}`);
26
-
27
- // Bad — hard to scan properties
28
- const data = records.filter(({ status, type, category }) => status === "active");
29
- ```
30
-
31
- ---
32
-
33
- ### `array-items-per-line`
34
-
35
- **What it does:** Controls array formatting based on the number of items. Short arrays stay on one line for compactness, while longer arrays get expanded with each item on its own line for better readability.
36
-
37
- **Why use it:** Prevents overly long single-line arrays that are hard to scan, while avoiding unnecessary vertical expansion for simple arrays.
38
-
39
- ```javascript
40
- // Good — 3 or fewer items stay compact
41
- const colors = ["red", "green", "blue"];
42
- const nums = [1, 2, 3];
43
-
44
- // Good — 4+ items expand for readability
45
- const weekdays = [
46
- "Monday",
47
- "Tuesday",
48
- "Wednesday",
49
- "Thursday",
50
- "Friday",
51
- ];
52
-
53
- // Bad — too many items on one line
54
- const weekdays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"];
55
-
56
- // Bad — inconsistent formatting
57
- const items = [item1,
58
- item2, item3,
59
- item4];
60
- ```
61
-
62
- **Options:**
63
-
64
- | Option | Type | Default | Description |
65
- |--------|------|---------|-------------|
66
- | `maxItems` | `integer` | `3` | Maximum items to keep on single line |
67
-
68
- ```javascript
69
- // Example: Allow up to 4 items on single line
70
- "code-style/array-items-per-line": ["error", { maxItems: 4 }]
71
- ```
72
-
73
- ---
74
-
75
- ### `array-objects-on-new-lines`
76
-
77
- **What it does:** In arrays containing objects, ensures each object starts on its own line regardless of object size.
78
-
79
- **Why use it:** Object literals in arrays are visually complex. Putting each on its own line makes it easier to scan, compare, and edit individual items.
80
-
81
- ```javascript
82
- // Good — each object clearly separated
83
- const users = [
84
- { id: 1, name: "Alice", role: "admin" },
85
- { id: 2, name: "Bob", role: "user" },
86
- { id: 3, name: "Charlie", role: "user" },
87
- ];
88
-
89
- // Good — even short objects get their own line
90
- const points = [
91
- { x: 0, y: 0 },
92
- { x: 10, y: 20 },
93
- ];
94
-
95
- // Bad — objects crammed together
96
- const users = [{ id: 1, name: "Alice" }, { id: 2, name: "Bob" }];
97
-
98
- // Bad — inconsistent line breaks
99
- const items = [{ id: 1 },
100
- { id: 2 }, { id: 3 }];
101
- ```
102
-
103
- <br />
104
-
105
- ---
106
-
107
- [<- Back to Rules Index](./README.md) | [<- Back to Main README](../../README.md)
@@ -1,115 +0,0 @@
1
- # Arrow Function Rules
2
-
3
- ### `arrow-function-block-body`
4
-
5
- **What it does:** Ensures arrow functions with multiline expressions use block body with explicit return, wrapped in parentheses when needed.
6
-
7
- **Why use it:** Multiline expressions without block body can be confusing. Clear boundaries with `{` and `}` make the function body obvious.
8
-
9
- ```javascript
10
- // Good — block body for complex logic
11
- const handleSubmit = () => {
12
- validateForm();
13
- submitData();
14
- return result;
15
- };
16
-
17
- // Good — multiline JSX wrapped properly
18
- const Button = () => (
19
- <button className="primary">
20
- Click me
21
- </button>
22
- );
23
-
24
- // Bad — comma operator is confusing
25
- const handleSubmit = () => (validateForm(), submitData(), result);
26
-
27
- // Bad — multiline without clear boundaries
28
- const Button = () => <button className="primary">
29
- Click me
30
- </button>;
31
- ```
32
-
33
- ---
34
-
35
- ### `arrow-function-simple-jsx`
36
-
37
- **What it does:** Collapses arrow functions that return a single simple JSX element onto one line by removing unnecessary parentheses and line breaks.
38
-
39
- **Why use it:** Simple component wrappers don't need multi-line formatting. Single-line is more scannable and reduces vertical space.
40
-
41
- ```javascript
42
- // Good — simple JSX on one line
43
- export const Layout = ({ children }) => <Container>{children}</Container>;
44
- export const Icon = () => <SVGIcon />;
45
- const Wrapper = (props) => <div {...props} />;
46
-
47
- // Bad — unnecessary multi-line for simple JSX
48
- export const Layout = ({ children }) => (
49
- <Container>{children}</Container>
50
- );
51
-
52
- // Bad — extra parentheses not needed
53
- const Icon = () => (
54
- <SVGIcon />
55
- );
56
- ```
57
-
58
- ---
59
-
60
- ### `arrow-function-simplify`
61
-
62
- **What it does:** Converts arrow functions with a single return statement to use implicit return, removing the block body and `return` keyword.
63
-
64
- **Why use it:** Implicit returns are more concise and idiomatic JavaScript. They reduce noise and make the code easier to read.
65
-
66
- ```javascript
67
- // Good — implicit return
68
- const double = (x) => x * 2;
69
- const getName = (user) => user.name;
70
- const items = data.map((item) => item.value);
71
- const isValid = (x) => x > 0 && x < 100;
72
-
73
- // Bad — unnecessary block body and return
74
- const double = (x) => { return x * 2; };
75
- const getName = (user) => { return user.name; };
76
- const items = data.map((item) => { return item.value; });
77
- const isValid = (x) => { return x > 0 && x < 100; };
78
- ```
79
-
80
- ---
81
-
82
- ### `curried-arrow-same-line`
83
-
84
- **What it does:** Ensures that when an arrow function returns another function, the returned function starts on the same line as `=>`.
85
-
86
- **Why use it:** Curried functions are easier to read when the chain is visible. Breaking after `=>` obscures the function structure.
87
-
88
- ```javascript
89
- // Good — curried function visible on same line
90
- const createAction = (type) => (payload) => ({ type, payload });
91
-
92
- const withLogger = (fn) => (...args) => {
93
- console.log("Called with:", args);
94
- return fn(...args);
95
- };
96
-
97
- const mapDispatch = () => async (dispatch) => {
98
- await dispatch(fetchData());
99
- };
100
-
101
- // Bad — chain broken across lines
102
- const createAction = (type) =>
103
- (payload) => ({ type, payload });
104
-
105
- const mapDispatch = () =>
106
- async (dispatch) => {
107
- await dispatch(fetchData());
108
- };
109
- ```
110
-
111
- <br />
112
-
113
- ---
114
-
115
- [<- Back to Rules Index](./README.md) | [<- Back to Main README](../../README.md)
@@ -1,275 +0,0 @@
1
- # Call Expression Rules
2
-
3
- ### `function-arguments-format`
4
-
5
- **What it does:** Enforces consistent formatting for function call arguments:
6
- - Single simple argument stays on one line
7
- - 2+ arguments get one per line
8
- - Multiline arguments trigger full expansion
9
- - React hooks are skipped by default (they have their own rule)
10
-
11
- **Why use it:** Consistent argument formatting makes function calls scannable and diffs clean when adding/removing arguments.
12
-
13
- ```javascript
14
- // Good — single argument stays compact
15
- fetchUser(userId);
16
- console.log(message);
17
- dispatch(action);
18
-
19
- // Good — 2+ arguments get one per line
20
- setValue(
21
- "email",
22
- "user@example.com",
23
- );
24
-
25
- createUser(
26
- name,
27
- email,
28
- password,
29
- );
30
-
31
- // Good — multiline argument triggers expansion
32
- processData(
33
- {
34
- id: 1,
35
- name: "test",
36
- },
37
- );
38
-
39
- // Good — callback with body triggers expansion
40
- items.forEach(
41
- (item) => {
42
- process(item);
43
- save(item);
44
- },
45
- );
46
-
47
- // Bad — multiple arguments on same line
48
- setValue("email", "user@example.com");
49
- createUser(name, email, password);
50
-
51
- // Bad — inconsistent formatting
52
- fn(arg1,
53
- arg2, arg3);
54
- ```
55
-
56
- **Options:**
57
-
58
- | Option | Type | Default | Description |
59
- |--------|------|---------|-------------|
60
- | `minArgs` | `integer` | `2` | Minimum arguments to enforce multiline |
61
- | `skipHooks` | `boolean` | `true` | Skip React hooks (useEffect, etc.) |
62
- | `skipSingleArg` | `boolean` | `true` | Skip calls with single complex argument |
63
-
64
- ```javascript
65
- // Example: Require multiline for 3+ arguments
66
- "code-style/function-arguments-format": ["error", { minArgs: 3 }]
67
-
68
- // Example: Don't skip React hooks
69
- "code-style/function-arguments-format": ["error", { skipHooks: false }]
70
- ```
71
-
72
- ---
73
-
74
- ### `nested-call-closing-brackets`
75
-
76
- **What it does:** Ensures nested function calls (common in styled-components, HOCs) have closing brackets on the same line: `}));`
77
-
78
- **Why use it:** Scattered closing brackets (`}\n);\n` ) waste vertical space and make it harder to see where expressions end.
79
-
80
- ```javascript
81
- // Good — closing brackets together
82
- const StyledCard = styled(Card)(({ theme }) => ({
83
- color: theme.palette.text.primary,
84
- padding: theme.spacing(2),
85
- }));
86
-
87
- const StyledButton = styled("button")(({ theme }) => ({
88
- backgroundColor: theme.colors.primary,
89
- }));
90
-
91
- // Good — multiple levels
92
- const Component = connect(
93
- mapStateToProps,
94
- mapDispatchToProps,
95
- )(withRouter(MyComponent));
96
-
97
- // Bad — closing brackets scattered
98
- const StyledCard = styled(Card)(({ theme }) => ({
99
- color: theme.palette.text.primary,
100
- })
101
- );
102
-
103
- // Bad — each bracket on its own line
104
- const StyledCard = styled(Card)(({ theme }) => ({
105
- color: theme.colors.primary,
106
- })
107
- )
108
- ;
109
- ```
110
-
111
- ---
112
-
113
- ### `no-empty-lines-in-function-calls`
114
-
115
- **What it does:** Removes empty lines within function call argument lists — between arguments and after opening/before closing parentheses.
116
-
117
- **Why use it:** Empty lines between arguments break visual grouping. Arguments should flow as a cohesive list.
118
-
119
- ```javascript
120
- // Good — no empty lines
121
- createUser(
122
- name,
123
- email,
124
- password,
125
- role,
126
- );
127
-
128
- fetchData(
129
- url,
130
- {
131
- method: "POST",
132
- body: data,
133
- },
134
- );
135
-
136
- // Bad — empty line between arguments
137
- createUser(
138
- name,
139
-
140
- email,
141
-
142
- password,
143
- );
144
-
145
- // Bad — empty line after opening paren
146
- fetchData(
147
-
148
- url,
149
- options,
150
- );
151
-
152
- // Bad — empty line before closing paren
153
- fetchData(
154
- url,
155
- options,
156
-
157
- );
158
- ```
159
-
160
- ---
161
-
162
- ### `opening-brackets-same-line`
163
-
164
- **What it does:** Ensures opening brackets (`{`, `[`, `(`) in function arguments stay on the same line as the function call.
165
-
166
- **Why use it:** Opening brackets on new lines create unnecessary indentation and vertical space.
167
-
168
- ```javascript
169
- // Good — brackets on same line as call
170
- fn({ key: value });
171
- process([1, 2, 3]);
172
- items.map(({ id }) => id);
173
- configure({ debug: true });
174
-
175
- // Good — multiline content is fine
176
- fn({
177
- key: value,
178
- other: data,
179
- });
180
-
181
- items.map(({ id, name }) => (
182
- <Item key={id} name={name} />
183
- ));
184
-
185
- // Bad — opening bracket on new line
186
- fn(
187
- { key: value }
188
- );
189
-
190
- process(
191
- [1, 2, 3]
192
- );
193
-
194
- items.map(
195
- ({ id }) => id
196
- );
197
- ```
198
-
199
- ---
200
-
201
- ### `simple-call-single-line`
202
-
203
- **What it does:** Collapses simple function calls with an arrow function onto one line when the result fits within 120 characters. Handles:
204
- - Zero-param callbacks: `lazy(() => import("./Page"))`
205
- - Callbacks with params and simple expression bodies: `.find((f) => f.code === x)`
206
- - Optional chaining: `.find(...)?.symbol`
207
-
208
- **Why use it:** Common patterns like `lazy(() => import(...))` and `.find((item) => item.id === id)` don't need multiline formatting. Single line is cleaner.
209
-
210
- ```javascript
211
- // Good — simple patterns on one line
212
- const Page = lazy(() => import("./Page"));
213
- setTimeout(() => callback(), 100);
214
- const symbol = items.find(({ code }) => code === currency)?.symbol;
215
-
216
- // Good — complex callbacks stay multiline
217
- const Page = lazy(() => {
218
- console.log("Loading page");
219
- return import("./Page");
220
- });
221
-
222
- // Bad — unnecessary multiline for simple pattern
223
- const Page = lazy(
224
- () => import("./Page"),
225
- );
226
-
227
- const symbol = items.find(({ code }) =>
228
- code === currency)?.symbol;
229
-
230
- const symbol = items.find(({ code }) => code === currency)?.
231
- symbol;
232
- ```
233
-
234
- ---
235
-
236
- ### `single-argument-on-one-line`
237
-
238
- **What it does:** Ensures function calls with a single simple argument (literal, identifier, member expression) stay on one line.
239
-
240
- **Why use it:** Single-argument calls don't need multiline formatting. Expanding them wastes vertical space.
241
-
242
- ```javascript
243
- // Good — single argument on one line
244
- fetchUser(userId);
245
- console.log(message);
246
- process(data.items);
247
- dispatch(action);
248
- setValue("key");
249
- getElement(document.body);
250
-
251
- // Good — complex single argument can be multiline
252
- processConfig({
253
- key: value,
254
- other: data,
255
- });
256
-
257
- // Bad — simple argument expanded unnecessarily
258
- fetchUser(
259
- userId,
260
- );
261
-
262
- console.log(
263
- message,
264
- );
265
-
266
- dispatch(
267
- action,
268
- );
269
- ```
270
-
271
- <br />
272
-
273
- ---
274
-
275
- [<- Back to Rules Index](./README.md) | [<- Back to Main README](../../README.md)
@@ -1,88 +0,0 @@
1
- # Class Rules
2
-
3
- ### `class-method-definition-format`
4
-
5
- **What it does:** Enforces consistent spacing in class and method definitions:
6
- - Space before opening brace `{` in class declarations
7
- - No space between method name and opening parenthesis `(`
8
- - Space before opening brace `{` in method definitions
9
- - Opening brace must be on same line as class/method signature
10
-
11
- **Why use it:** Consistent formatting makes code more readable and prevents common spacing inconsistencies in class definitions.
12
-
13
- ```javascript
14
- // Good — proper spacing in class and methods
15
- class ApiServiceClass {
16
- getDataHandler(): string {
17
- return "data";
18
- }
19
-
20
- async fetchUserHandler(id: string): Promise<User> {
21
- return await this.fetch(id);
22
- }
23
- }
24
-
25
- // Bad — missing space before { in class
26
- class ApiServiceClass{
27
- getDataHandler(): string {
28
- return "data";
29
- }
30
- }
31
-
32
- // Bad — space between method name and (
33
- class ApiServiceClass {
34
- getDataHandler (): string {
35
- return "data";
36
- }
37
- }
38
-
39
- // Bad — missing space before { in method
40
- class ApiServiceClass {
41
- getDataHandler(): string{
42
- return "data";
43
- }
44
- }
45
-
46
- // Bad — opening brace on different line
47
- class ApiServiceClass {
48
- getDataHandler(): string
49
- {
50
- return "data";
51
- }
52
- }
53
- ```
54
-
55
- ---
56
-
57
- ### `class-naming-convention`
58
-
59
- **What it does:** Enforces that class declarations must end with "Class" suffix. This distinguishes class definitions from other PascalCase names like React components or type definitions.
60
-
61
- **Why use it:** Clear naming conventions prevent confusion between classes, components, and types. The "Class" suffix immediately identifies the construct.
62
-
63
- ```javascript
64
- // Good — class ends with "Class"
65
- class ApiServiceClass {
66
- constructor() {}
67
- fetch() {}
68
- }
69
-
70
- class UserRepositoryClass {
71
- save(user) {}
72
- }
73
-
74
- // Bad — missing "Class" suffix
75
- class ApiService {
76
- constructor() {}
77
- }
78
-
79
- class UserRepository {
80
- save(user) {}
81
- }
82
- ```
83
-
84
- <br />
85
-
86
- ---
87
-
88
- [<- Back to Rules Index](./README.md) | [<- Back to Main README](../../README.md)
@@ -1,42 +0,0 @@
1
- # Comment Rules
2
-
3
- ### `comment-format`
4
-
5
- **What it does:** Enforces proper comment formatting:
6
- - Space after `//` in line comments
7
- - Space after `/*` and before `*/` in block comments
8
- - Single-line block comments converted to line comments
9
- - No blank lines between consecutive comments at file top
10
-
11
- **Why use it:** Consistent comment formatting improves readability and maintains a clean, professional codebase.
12
-
13
- ```javascript
14
- // Good — proper spacing
15
- // This is a comment
16
- /* This is a block comment */
17
-
18
- /*
19
- * This is a multi-line
20
- * block comment
21
- */
22
-
23
- // Good — file-top comments without gaps
24
- // File: utils.js
25
- // Author: John Doe
26
- // License: MIT
27
-
28
- // Bad — missing space after //
29
- //This is a comment
30
-
31
- // Bad — no space in block comment
32
- /*No space*/
33
-
34
- // Bad — single-line block should be line comment
35
- /* This should use // syntax */
36
- ```
37
-
38
- <br />
39
-
40
- ---
41
-
42
- [<- Back to Rules Index](./README.md) | [<- Back to Main README](../../README.md)