js-style-kit 0.6.1 → 0.7.0
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/README.md +5 -0
- package/dist/index.d.ts +11 -5
- package/dist/index.js +48 -7
- package/dist/index.js.map +1 -1
- package/package.json +8 -5
- package/src/eslint/base/README.md +186 -0
- package/src/eslint/base/config.ts +37 -0
- package/src/eslint/base/rules.ts +444 -0
- package/src/eslint/base/types.ts +20 -0
- package/src/eslint/constants.ts +52 -0
- package/src/eslint/convex/README.md +30 -0
- package/src/eslint/convex/config.ts +34 -0
- package/src/eslint/convex/rules.ts +8 -0
- package/src/eslint/convex/types.ts +8 -0
- package/src/eslint/ignores.ts +31 -0
- package/src/eslint/import/README.md +397 -0
- package/src/eslint/import/config.ts +48 -0
- package/src/eslint/import/rules.ts +81 -0
- package/src/eslint/index.ts +259 -0
- package/src/eslint/jsdoc/README.md +399 -0
- package/src/eslint/jsdoc/config.ts +29 -0
- package/src/eslint/jsdoc/rules.ts +81 -0
- package/src/eslint/jsdoc/types.ts +56 -0
- package/src/eslint/nextjs/config.ts +25 -0
- package/src/eslint/nextjs/rules.ts +25 -0
- package/src/eslint/nextjs/types.ts +27 -0
- package/src/eslint/perfectionist/README.md +454 -0
- package/src/eslint/perfectionist/config.ts +25 -0
- package/src/eslint/perfectionist/rules.ts +39 -0
- package/src/eslint/prefer-arrow-function/config.ts +33 -0
- package/src/eslint/prefer-arrow-function/types.ts +13 -0
- package/src/eslint/process-custom-rules.ts +72 -0
- package/src/eslint/query/README.md +254 -0
- package/src/eslint/query/config.ts +27 -0
- package/src/eslint/query/rules.ts +11 -0
- package/src/eslint/query/types.ts +11 -0
- package/src/eslint/react/README.md +416 -0
- package/src/eslint/react/config.ts +65 -0
- package/src/eslint/react/rules.ts +188 -0
- package/src/eslint/react/types.ts +26 -0
- package/src/eslint/react-refresh/config.ts +28 -0
- package/src/eslint/react-refresh/rules.ts +48 -0
- package/src/eslint/storybook/README.md +424 -0
- package/src/eslint/storybook/config.ts +57 -0
- package/src/eslint/testing/README.md +436 -0
- package/src/eslint/testing/config.ts +90 -0
- package/src/eslint/testing/jest-rules.ts +47 -0
- package/src/eslint/testing/vitest-rules.ts +42 -0
- package/src/eslint/turbo/README.md +380 -0
- package/src/eslint/turbo/config.ts +26 -0
- package/src/eslint/turbo/types.ts +7 -0
- package/src/eslint/types.ts +29 -0
- package/src/eslint/typescript/README.md +229 -0
- package/src/eslint/typescript/config.ts +48 -0
- package/src/eslint/typescript/rules.ts +137 -0
- package/src/eslint/typescript/types.ts +35 -0
- package/src/eslint/unicorn/README.md +497 -0
- package/src/eslint/unicorn/config.ts +36 -0
- package/src/eslint/unicorn/rules.ts +86 -0
- package/src/index.ts +3 -0
- package/src/modules.d.ts +5 -0
- package/src/prettier/README.md +413 -0
- package/src/prettier/index.ts +110 -0
- package/src/utils/is-type.ts +60 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "js-style-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "A zero configuration style guide for ESLint and Prettier",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -25,7 +25,9 @@
|
|
|
25
25
|
"types": "./dist/index.d.ts",
|
|
26
26
|
"bin": "./dist/bin/index.cjs",
|
|
27
27
|
"files": [
|
|
28
|
-
"dist"
|
|
28
|
+
"dist",
|
|
29
|
+
"src",
|
|
30
|
+
"!src/**/*.test.ts"
|
|
29
31
|
],
|
|
30
32
|
"scripts": {
|
|
31
33
|
"build": "tsup",
|
|
@@ -40,21 +42,22 @@
|
|
|
40
42
|
"typecheck": "tsc --noEmit"
|
|
41
43
|
},
|
|
42
44
|
"dependencies": {
|
|
45
|
+
"@convex-dev/eslint-plugin": "0.0.1-alpha.4",
|
|
43
46
|
"@prettier/plugin-oxc": "0.0.4",
|
|
44
|
-
"@tanstack/eslint-plugin-query": "5.91.
|
|
47
|
+
"@tanstack/eslint-plugin-query": "5.91.2",
|
|
45
48
|
"@typescript-eslint/parser": "8.46.0",
|
|
46
49
|
"eslint": "9.37.0",
|
|
47
50
|
"eslint-import-resolver-typescript": "4.4.4",
|
|
48
51
|
"eslint-plugin-import-x": "4.16.1",
|
|
49
52
|
"eslint-plugin-jest": "29.0.1",
|
|
50
53
|
"eslint-plugin-jsdoc": "61.1.4",
|
|
51
|
-
"eslint-plugin-nextjs": "1.0
|
|
54
|
+
"eslint-plugin-nextjs": "1.1.0",
|
|
52
55
|
"eslint-plugin-perfectionist": "4.15.1",
|
|
53
56
|
"eslint-plugin-prefer-arrow-functions": "3.9.1",
|
|
54
57
|
"eslint-plugin-react": "7.37.5",
|
|
55
58
|
"eslint-plugin-react-hooks": "7.0.0",
|
|
56
59
|
"eslint-plugin-react-refresh": "0.4.24",
|
|
57
|
-
"eslint-plugin-storybook": "9.1.
|
|
60
|
+
"eslint-plugin-storybook": "9.1.12",
|
|
58
61
|
"eslint-plugin-turbo": "2.5.8",
|
|
59
62
|
"eslint-plugin-unicorn": "61.0.2",
|
|
60
63
|
"eslint-plugin-vitest": "0.5.4",
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# Base ESLint Configuration
|
|
2
|
+
|
|
3
|
+
The base configuration includes core ESLint rules that apply to all JavaScript and TypeScript projects. These rules are carefully selected from ESLint's recommended set with additional best practices.
|
|
4
|
+
|
|
5
|
+
[← Back to main README](../../../README.md)
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
This configuration is always enabled and provides:
|
|
10
|
+
|
|
11
|
+
- Modern JavaScript best practices
|
|
12
|
+
- Error prevention
|
|
13
|
+
- Code quality improvements
|
|
14
|
+
- Function style enforcement
|
|
15
|
+
|
|
16
|
+
All rules are configured as **warnings** (not errors) to distinguish them from TypeScript errors in your IDE.
|
|
17
|
+
|
|
18
|
+
[See all rules here](./rules.ts)
|
|
19
|
+
|
|
20
|
+
## Function Style
|
|
21
|
+
|
|
22
|
+
Control how functions should be written throughout your codebase:
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
import { eslintConfig } from "js-style-kit";
|
|
26
|
+
|
|
27
|
+
export default eslintConfig({
|
|
28
|
+
functionStyle: "arrow", // Default
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Options
|
|
33
|
+
|
|
34
|
+
#### `"arrow"` (default)
|
|
35
|
+
|
|
36
|
+
Enforces arrow function expressions:
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
// ✅ Good
|
|
40
|
+
const add = (a, b) => a + b;
|
|
41
|
+
const greet = () => console.log("Hello");
|
|
42
|
+
|
|
43
|
+
// ❌ Bad
|
|
44
|
+
function add(a, b) {
|
|
45
|
+
return a + b;
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
#### `"declaration"`
|
|
50
|
+
|
|
51
|
+
Enforces function declarations:
|
|
52
|
+
|
|
53
|
+
```js
|
|
54
|
+
// ✅ Good
|
|
55
|
+
function add(a, b) {
|
|
56
|
+
return a + b;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// ❌ Bad
|
|
60
|
+
const add = (a, b) => a + b;
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
#### `"expression"`
|
|
64
|
+
|
|
65
|
+
Enforces function expressions:
|
|
66
|
+
|
|
67
|
+
```js
|
|
68
|
+
// ✅ Good
|
|
69
|
+
const add = function (a, b) {
|
|
70
|
+
return a + b;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// ❌ Bad
|
|
74
|
+
function add(a, b) {
|
|
75
|
+
return a + b;
|
|
76
|
+
}
|
|
77
|
+
const add = (a, b) => a + b;
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
#### `"off"`
|
|
81
|
+
|
|
82
|
+
Disables function style enforcement - use any style you prefer.
|
|
83
|
+
|
|
84
|
+
## Key Rules
|
|
85
|
+
|
|
86
|
+
### Type Safety
|
|
87
|
+
|
|
88
|
+
- **`eqeqeq`** - Require `===` and `!==` instead of `==` and `!=`
|
|
89
|
+
- **`valid-typeof`** - Enforce comparing typeof expressions to valid strings
|
|
90
|
+
- **`use-isnan`** - Require `isNaN()` when checking for NaN
|
|
91
|
+
|
|
92
|
+
### Modern JavaScript
|
|
93
|
+
|
|
94
|
+
- **`no-var`** - Require `let` or `const` instead of `var`
|
|
95
|
+
- **`prefer-const`** - Prefer `const` over `let` when variables are never reassigned
|
|
96
|
+
- **`prefer-arrow-callback`** - Prefer arrow functions as callbacks (when `functionStyle: "arrow"`)
|
|
97
|
+
- **`prefer-template`** - Prefer template literals over string concatenation
|
|
98
|
+
- **`prefer-spread`** - Prefer spread operator over `.apply()`
|
|
99
|
+
- **`prefer-rest-params`** - Prefer rest parameters over `arguments`
|
|
100
|
+
- **`object-shorthand`** - Require object literal shorthand syntax
|
|
101
|
+
|
|
102
|
+
### Error Prevention
|
|
103
|
+
|
|
104
|
+
- **`no-console`** - Disallow `console` except `console.info/warn/error`
|
|
105
|
+
- **`no-debugger`** - Disallow `debugger` statements
|
|
106
|
+
- **`no-alert`** - Disallow `alert`, `confirm`, and `prompt`
|
|
107
|
+
- **`no-eval`** - Disallow `eval()`
|
|
108
|
+
- **`no-implied-eval`** - Disallow implied `eval()` via `setTimeout`/`setInterval`
|
|
109
|
+
- **`no-new-func`** - Disallow `Function` constructor
|
|
110
|
+
- **`no-param-reassign`** - Disallow reassigning function parameters
|
|
111
|
+
- **`array-callback-return`** - Require `return` statements in array method callbacks
|
|
112
|
+
|
|
113
|
+
### Code Quality
|
|
114
|
+
|
|
115
|
+
- **`curly`** - Require curly braces for multiline blocks
|
|
116
|
+
- **`no-else-return`** - Disallow `else` after `return` in `if`
|
|
117
|
+
- **`no-lonely-if`** - Disallow `if` as the only statement in `else`
|
|
118
|
+
- **`no-unneeded-ternary`** - Disallow ternary operators when simpler alternatives exist
|
|
119
|
+
- **`no-useless-return`** - Disallow redundant `return` statements
|
|
120
|
+
- **`no-implicit-coercion`** - Disallow type conversion with shorter notations (prefer explicit conversion)
|
|
121
|
+
|
|
122
|
+
### Naming Conventions
|
|
123
|
+
|
|
124
|
+
- **`camelcase`** - Enforce camelCase naming (with exceptions for `UNSAFE_` React lifecycle methods)
|
|
125
|
+
- **`new-cap`** - Require constructor names to begin with a capital letter
|
|
126
|
+
- **`func-names`** - Require named function expressions
|
|
127
|
+
|
|
128
|
+
### Dangerous Patterns
|
|
129
|
+
|
|
130
|
+
- **`no-extend-native`** - Disallow extending native objects
|
|
131
|
+
- **`no-proto`** - Disallow `__proto__` property
|
|
132
|
+
- **`no-iterator`** - Disallow `__iterator__` property
|
|
133
|
+
- **`no-new-wrappers`** - Disallow `new` for `String`, `Number`, and `Boolean`
|
|
134
|
+
- **`no-bitwise`** - Disallow bitwise operators
|
|
135
|
+
|
|
136
|
+
## TypeScript Integration
|
|
137
|
+
|
|
138
|
+
When TypeScript is enabled, certain rules are automatically disabled to avoid conflicts with TypeScript's own checks:
|
|
139
|
+
|
|
140
|
+
- `no-unused-vars` - Handled by `@typescript-eslint/no-unused-vars`
|
|
141
|
+
- `no-unused-expressions` - Handled by `@typescript-eslint/no-unused-expressions`
|
|
142
|
+
|
|
143
|
+
## Fixable Rules
|
|
144
|
+
|
|
145
|
+
Many rules in this config are auto-fixable with `eslint --fix`:
|
|
146
|
+
|
|
147
|
+
- ✅ `prefer-const` - Auto-converts `let` to `const`
|
|
148
|
+
- ✅ `prefer-template` - Auto-converts string concatenation to template literals
|
|
149
|
+
- ✅ `object-shorthand` - Auto-converts to shorthand syntax
|
|
150
|
+
- ✅ `no-useless-rename` - Auto-removes useless renaming
|
|
151
|
+
- ✅ `no-var` - Auto-converts `var` to `let`/`const`
|
|
152
|
+
- ✅ And many more!
|
|
153
|
+
|
|
154
|
+
Run `eslint . --fix` to automatically fix these issues.
|
|
155
|
+
|
|
156
|
+
## Customization
|
|
157
|
+
|
|
158
|
+
Override specific base rules using the `rules` option:
|
|
159
|
+
|
|
160
|
+
```js
|
|
161
|
+
import { eslintConfig } from "js-style-kit";
|
|
162
|
+
|
|
163
|
+
export default eslintConfig({
|
|
164
|
+
rules: {
|
|
165
|
+
// Allow console.log in development
|
|
166
|
+
"no-console": "off",
|
|
167
|
+
|
|
168
|
+
// Make camelcase an error instead of warning
|
|
169
|
+
camelcase: "error",
|
|
170
|
+
|
|
171
|
+
// Allow bitwise operators
|
|
172
|
+
"no-bitwise": "off",
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Related Configurations
|
|
178
|
+
|
|
179
|
+
- [TypeScript](../typescript/README.md) - TypeScript-specific rules
|
|
180
|
+
- [Import Plugin](../import/README.md) - Import/export validation
|
|
181
|
+
- [Unicorn](../unicorn/README.md) - Additional best practices
|
|
182
|
+
|
|
183
|
+
## Learn More
|
|
184
|
+
|
|
185
|
+
- [ESLint Rules Documentation](https://eslint.org/docs/latest/rules/)
|
|
186
|
+
- [Main README](../../../README.md)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
EslintConfigObject,
|
|
3
|
+
EslintRuleConfig,
|
|
4
|
+
FunctionStyle,
|
|
5
|
+
} from "../types.js";
|
|
6
|
+
|
|
7
|
+
import { configNames } from "../constants.js";
|
|
8
|
+
import { baseEslintRules } from "./rules.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Creates a base ESLint configuration object with specified function style rules.
|
|
12
|
+
*
|
|
13
|
+
* @param functionStyle - Controls how functions should be written. Can be:
|
|
14
|
+
* - "off": Disables function style enforcement
|
|
15
|
+
* - "arrow": Enforces arrow function expressions
|
|
16
|
+
* - "declaration": Enforces function declarations
|
|
17
|
+
* - "expression": Enforces function expressions
|
|
18
|
+
* @param typescript - Whether TypeScript is being used in the project. When true, some rules are adjusted to be more TypeScript-friendly.
|
|
19
|
+
* @param customRules - Optional object containing custom rules to override or add to the base configuration.
|
|
20
|
+
* @returns ESLint configuration object
|
|
21
|
+
*/
|
|
22
|
+
export const baseEslintConfig = (
|
|
23
|
+
functionStyle: "off" | FunctionStyle,
|
|
24
|
+
typescript: boolean,
|
|
25
|
+
customRules?: Record<string, EslintRuleConfig>,
|
|
26
|
+
): EslintConfigObject => ({
|
|
27
|
+
languageOptions: {
|
|
28
|
+
ecmaVersion: "latest",
|
|
29
|
+
sourceType: "module",
|
|
30
|
+
},
|
|
31
|
+
linterOptions: { reportUnusedDisableDirectives: true },
|
|
32
|
+
name: configNames.base,
|
|
33
|
+
rules: {
|
|
34
|
+
...baseEslintRules(functionStyle, typescript),
|
|
35
|
+
...(customRules ?? {}),
|
|
36
|
+
},
|
|
37
|
+
});
|