js-style-kit 0.6.0 → 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.
Files changed (64) hide show
  1. package/README.md +5 -0
  2. package/dist/index.d.ts +11 -5
  3. package/dist/index.js +48 -77
  4. package/dist/index.js.map +1 -1
  5. package/package.json +36 -33
  6. package/src/eslint/base/README.md +186 -0
  7. package/src/eslint/base/config.ts +37 -0
  8. package/src/eslint/base/rules.ts +444 -0
  9. package/src/eslint/base/types.ts +20 -0
  10. package/src/eslint/constants.ts +52 -0
  11. package/src/eslint/convex/README.md +30 -0
  12. package/src/eslint/convex/config.ts +34 -0
  13. package/src/eslint/convex/rules.ts +8 -0
  14. package/src/eslint/convex/types.ts +8 -0
  15. package/src/eslint/ignores.ts +31 -0
  16. package/src/eslint/import/README.md +397 -0
  17. package/src/eslint/import/config.ts +48 -0
  18. package/src/eslint/import/rules.ts +81 -0
  19. package/src/eslint/index.ts +259 -0
  20. package/src/eslint/jsdoc/README.md +399 -0
  21. package/src/eslint/jsdoc/config.ts +29 -0
  22. package/src/eslint/jsdoc/rules.ts +81 -0
  23. package/src/eslint/jsdoc/types.ts +56 -0
  24. package/src/eslint/nextjs/config.ts +25 -0
  25. package/src/eslint/nextjs/rules.ts +25 -0
  26. package/src/eslint/nextjs/types.ts +27 -0
  27. package/src/eslint/perfectionist/README.md +454 -0
  28. package/src/eslint/perfectionist/config.ts +25 -0
  29. package/src/eslint/perfectionist/rules.ts +39 -0
  30. package/src/eslint/prefer-arrow-function/config.ts +33 -0
  31. package/src/eslint/prefer-arrow-function/types.ts +13 -0
  32. package/src/eslint/process-custom-rules.ts +72 -0
  33. package/src/eslint/query/README.md +254 -0
  34. package/src/eslint/query/config.ts +27 -0
  35. package/src/eslint/query/rules.ts +11 -0
  36. package/src/eslint/query/types.ts +11 -0
  37. package/src/eslint/react/README.md +416 -0
  38. package/src/eslint/react/config.ts +65 -0
  39. package/src/eslint/react/rules.ts +188 -0
  40. package/src/eslint/react/types.ts +26 -0
  41. package/src/eslint/react-refresh/config.ts +28 -0
  42. package/src/eslint/react-refresh/rules.ts +48 -0
  43. package/src/eslint/storybook/README.md +424 -0
  44. package/src/eslint/storybook/config.ts +57 -0
  45. package/src/eslint/testing/README.md +436 -0
  46. package/src/eslint/testing/config.ts +90 -0
  47. package/src/eslint/testing/jest-rules.ts +47 -0
  48. package/src/eslint/testing/vitest-rules.ts +42 -0
  49. package/src/eslint/turbo/README.md +380 -0
  50. package/src/eslint/turbo/config.ts +26 -0
  51. package/src/eslint/turbo/types.ts +7 -0
  52. package/src/eslint/types.ts +29 -0
  53. package/src/eslint/typescript/README.md +229 -0
  54. package/src/eslint/typescript/config.ts +48 -0
  55. package/src/eslint/typescript/rules.ts +137 -0
  56. package/src/eslint/typescript/types.ts +35 -0
  57. package/src/eslint/unicorn/README.md +497 -0
  58. package/src/eslint/unicorn/config.ts +36 -0
  59. package/src/eslint/unicorn/rules.ts +86 -0
  60. package/src/index.ts +3 -0
  61. package/src/modules.d.ts +5 -0
  62. package/src/prettier/README.md +413 -0
  63. package/src/prettier/index.ts +110 -0
  64. 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.6.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,41 +42,42 @@
40
42
  "typecheck": "tsc --noEmit"
41
43
  },
42
44
  "dependencies": {
43
- "@prettier/plugin-oxc": "^0.0.4",
44
- "@tanstack/eslint-plugin-query": "^5.91.0",
45
- "@typescript-eslint/parser": "^8.46.0",
46
- "eslint": "^9.37.0",
47
- "eslint-import-resolver-typescript": "^4.4.4",
48
- "eslint-plugin-import-x": "^4.16.1",
49
- "eslint-plugin-jest": "^29.0.1",
50
- "eslint-plugin-jsdoc": "^61.1.1",
51
- "eslint-plugin-nextjs": "^1.0.6",
52
- "eslint-plugin-perfectionist": "^4.15.1",
53
- "eslint-plugin-prefer-arrow-functions": "^3.9.1",
54
- "eslint-plugin-react": "^7.37.5",
45
+ "@convex-dev/eslint-plugin": "0.0.1-alpha.4",
46
+ "@prettier/plugin-oxc": "0.0.4",
47
+ "@tanstack/eslint-plugin-query": "5.91.2",
48
+ "@typescript-eslint/parser": "8.46.0",
49
+ "eslint": "9.37.0",
50
+ "eslint-import-resolver-typescript": "4.4.4",
51
+ "eslint-plugin-import-x": "4.16.1",
52
+ "eslint-plugin-jest": "29.0.1",
53
+ "eslint-plugin-jsdoc": "61.1.4",
54
+ "eslint-plugin-nextjs": "1.1.0",
55
+ "eslint-plugin-perfectionist": "4.15.1",
56
+ "eslint-plugin-prefer-arrow-functions": "3.9.1",
57
+ "eslint-plugin-react": "7.37.5",
55
58
  "eslint-plugin-react-hooks": "7.0.0",
56
- "eslint-plugin-react-refresh": "^0.4.23",
57
- "eslint-plugin-storybook": "^9.1.10",
58
- "eslint-plugin-turbo": "^2.5.8",
59
- "eslint-plugin-unicorn": "^61.0.2",
60
- "eslint-plugin-vitest": "^0.5.4",
61
- "globals": "^16.4.0",
62
- "prettier": "^3.6.2",
63
- "prettier-plugin-css-order": "^2.1.2",
64
- "prettier-plugin-curly": "^0.3.2",
65
- "prettier-plugin-packagejson": "^2.5.19",
66
- "prettier-plugin-sort-json": "^4.1.1",
67
- "prettier-plugin-tailwindcss": "^0.6.14",
68
- "typescript-eslint": "^8.46.0"
59
+ "eslint-plugin-react-refresh": "0.4.24",
60
+ "eslint-plugin-storybook": "9.1.12",
61
+ "eslint-plugin-turbo": "2.5.8",
62
+ "eslint-plugin-unicorn": "61.0.2",
63
+ "eslint-plugin-vitest": "0.5.4",
64
+ "globals": "16.4.0",
65
+ "prettier": "3.6.2",
66
+ "prettier-plugin-css-order": "2.1.2",
67
+ "prettier-plugin-curly": "0.3.2",
68
+ "prettier-plugin-packagejson": "2.5.19",
69
+ "prettier-plugin-sort-json": "4.1.1",
70
+ "prettier-plugin-tailwindcss": "0.7.0",
71
+ "typescript-eslint": "8.46.0"
69
72
  },
70
73
  "devDependencies": {
71
74
  "@repo/typescript-config": "workspace:*",
72
- "@types/bun": "1.2.3",
73
- "@types/node": "^22.18.10",
74
- "commander": "^14.0.1",
75
- "glob": "^11.0.3",
76
- "tsup": "^8.5.0",
77
- "typescript": "^5.9.3"
75
+ "@types/bun": "1.3.0",
76
+ "@types/node": "22.18.10",
77
+ "commander": "14.0.1",
78
+ "glob": "11.0.3",
79
+ "tsup": "8.5.0",
80
+ "typescript": "5.9.3"
78
81
  },
79
82
  "engines": {
80
83
  "node": "^20.11.0 || >=21.2.0"
@@ -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
+ });