@jmlweb/eslint-config-base 1.0.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 ADDED
@@ -0,0 +1,276 @@
1
+ # @jmlweb/eslint-config-base
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@jmlweb/eslint-config-base)](https://www.npmjs.com/package/@jmlweb/eslint-config-base)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
5
+ [![Node.js](https://img.shields.io/badge/Node.js-%3E%3D20.11.0-339933.svg)](https://nodejs.org/)
6
+ [![ESLint](https://img.shields.io/badge/ESLint-9.0%2B-4B32C3.svg)](https://eslint.org/)
7
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.0%2B-3178C6.svg)](https://www.typescriptlang.org/)
8
+
9
+ > Strict ESLint configuration for TypeScript projects. Maximum type safety, best practices, and consistent code quality. Extends `@jmlweb/eslint-config-base-js` with strict type checking.
10
+
11
+ ## ✨ Features
12
+
13
+ - 🔒 **Strict Type Checking**: Enables `strictTypeChecked` and `stylisticTypeChecked` configs
14
+ - 🛡️ **Type Safety**: Enforces explicit return types and prevents `any` usage
15
+ - 📦 **Import Management**: Enforces type-only imports with inline style + automatic sorting
16
+ - 🎯 **Best Practices**: Prevents enum usage, encourages immutability, enforces naming conventions
17
+ - 🎨 **Prettier Integration**: Disables all ESLint rules that conflict with Prettier
18
+ - 🚀 **Flat Config**: Uses ESLint 9+ flat config format (latest stable)
19
+ - 🔧 **Extensible**: Built on `@jmlweb/eslint-config-base-js` foundation
20
+
21
+ ## 📦 Installation
22
+
23
+ ```bash
24
+ npm install --save-dev @jmlweb/eslint-config-base eslint @eslint/js typescript-eslint eslint-config-prettier eslint-plugin-simple-import-sort @jmlweb/eslint-config-base-js
25
+ ```
26
+
27
+ ## 🚀 Quick Start
28
+
29
+ Create an `eslint.config.js` file in your project root:
30
+
31
+ ```javascript
32
+ import baseConfig from '@jmlweb/eslint-config-base';
33
+
34
+ export default [
35
+ ...baseConfig,
36
+ // Add your project-specific overrides here
37
+ ];
38
+ ```
39
+
40
+ ## 💡 Examples
41
+
42
+ ### Basic Setup
43
+
44
+ ```javascript
45
+ // eslint.config.js
46
+ import baseConfig from '@jmlweb/eslint-config-base';
47
+
48
+ export default [...baseConfig];
49
+ ```
50
+
51
+ ### With Project-Specific Overrides
52
+
53
+ ```javascript
54
+ // eslint.config.js
55
+ import baseConfig from '@jmlweb/eslint-config-base';
56
+
57
+ export default [
58
+ ...baseConfig,
59
+ {
60
+ files: ['**/*.test.ts', '**/*.test.tsx'],
61
+ rules: {
62
+ // Allow any in tests
63
+ '@typescript-eslint/no-explicit-any': 'off',
64
+ // Allow console in tests
65
+ 'no-console': 'off',
66
+ },
67
+ },
68
+ {
69
+ ignores: ['dist/', 'build/', 'node_modules/', '*.config.ts'],
70
+ },
71
+ ];
72
+ ```
73
+
74
+ ### React Project Example
75
+
76
+ ```javascript
77
+ // eslint.config.js
78
+ import baseConfig from '@jmlweb/eslint-config-base';
79
+
80
+ export default [
81
+ ...baseConfig,
82
+ {
83
+ files: ['**/*.tsx'],
84
+ rules: {
85
+ // React-specific overrides if needed
86
+ },
87
+ },
88
+ ];
89
+ ```
90
+
91
+ ### Less Strict Configuration
92
+
93
+ This config uses strict type checking by default. If you need non-strict rules, you have two options:
94
+
95
+ **Option 1: Use base-js config and add only recommended TypeScript rules**
96
+
97
+ ```javascript
98
+ import baseJsConfig from '@jmlweb/eslint-config-base-js';
99
+ import tseslint from 'typescript-eslint';
100
+ import prettierConfig from 'eslint-config-prettier';
101
+ import simpleImportSort from 'eslint-plugin-simple-import-sort';
102
+
103
+ export default [
104
+ ...baseJsConfig,
105
+ // Use only recommended TypeScript rules (non-strict)
106
+ ...tseslint.configs.recommended.map((config) => ({
107
+ ...config,
108
+ files: ['**/*.ts', '**/*.tsx'],
109
+ plugins: {
110
+ ...config.plugins,
111
+ 'simple-import-sort': simpleImportSort,
112
+ },
113
+ rules: {
114
+ ...config.rules,
115
+ ...prettierConfig.rules,
116
+ 'simple-import-sort/imports': 'error',
117
+ 'simple-import-sort/exports': 'error',
118
+ },
119
+ })),
120
+ ];
121
+ ```
122
+
123
+ **Option 2: Override specific strict rules**
124
+
125
+ ```javascript
126
+ import baseConfig from '@jmlweb/eslint-config-base';
127
+
128
+ export default [
129
+ ...baseConfig,
130
+ {
131
+ files: ['**/*.ts', '**/*.tsx'],
132
+ rules: {
133
+ // Override strict rules to be less strict
134
+ '@typescript-eslint/explicit-function-return-type': 'off',
135
+ '@typescript-eslint/no-explicit-any': 'warn',
136
+ '@typescript-eslint/consistent-type-imports': 'off',
137
+ },
138
+ },
139
+ ];
140
+ ```
141
+
142
+ ## 📋 Configuration Details
143
+
144
+ ### TypeScript Files
145
+
146
+ This configuration applies strict TypeScript rules to:
147
+
148
+ - `**/*.ts` - TypeScript files
149
+ - `**/*.tsx` - TypeScript React files
150
+
151
+ ### Key Rules Enforced
152
+
153
+ | Rule | Level | Description |
154
+ | -------------------------------------------------- | ------- | -------------------------------------------- |
155
+ | `@typescript-eslint/no-explicit-any` | `error` | Prevents `any` type usage |
156
+ | `@typescript-eslint/explicit-function-return-type` | `error` | Requires explicit return types |
157
+ | `@typescript-eslint/consistent-type-imports` | `error` | Enforces `import type` for type-only imports |
158
+ | `@typescript-eslint/consistent-type-definitions` | `error` | Prefers `type` over `interface` |
159
+ | `@typescript-eslint/no-enum` | `error` | Prevents enum usage (prefer const maps) |
160
+ | `@typescript-eslint/no-parameter-properties` | `error` | Prevents parameter properties |
161
+ | `@typescript-eslint/naming-convention` | `error` | Enforces naming conventions |
162
+
163
+ ### What's Included
164
+
165
+ - ✅ TypeScript ESLint recommended rules
166
+ - ✅ Strict type checking (`strictTypeChecked`)
167
+ - ✅ Stylistic type checking (`stylisticTypeChecked`)
168
+ - ✅ TypeScript parser configuration with project service
169
+ - ✅ Automatic import/export sorting
170
+ - ✅ Prettier conflict resolution
171
+ - ✅ All JavaScript rules from `@jmlweb/eslint-config-base-js`
172
+
173
+ ## 🔄 Import Sorting
174
+
175
+ The configuration automatically sorts imports and enforces type-only imports:
176
+
177
+ **Before:**
178
+
179
+ ```typescript
180
+ import { Component } from './component';
181
+ import React, { useState } from 'react';
182
+ import { User } from './types';
183
+ import fs from 'fs';
184
+ ```
185
+
186
+ **After auto-fix:**
187
+
188
+ ```typescript
189
+ import fs from 'fs';
190
+ import React, { useState } from 'react';
191
+ import type { User } from './types';
192
+ import { Component } from './component';
193
+ ```
194
+
195
+ Fix import order automatically:
196
+
197
+ ```bash
198
+ npx eslint --fix .
199
+ ```
200
+
201
+ ## 🎯 When to Use
202
+
203
+ Use this configuration when you want:
204
+
205
+ - ✅ Maximum type safety
206
+ - ✅ Strict code quality standards
207
+ - ✅ Consistent code style across the team
208
+ - ✅ Prevention of common TypeScript pitfalls
209
+ - ✅ Best practices enforcement
210
+
211
+ **For JavaScript-only projects**, use [`@jmlweb/eslint-config-base-js`](../eslint-config-base-js) instead.
212
+
213
+ **For less strict projects**, you can override the strict rules as shown in the examples above.
214
+
215
+ ## 🔧 Extending the Configuration
216
+
217
+ You can extend or override the configuration for your specific needs:
218
+
219
+ ```javascript
220
+ import baseConfig from '@jmlweb/eslint-config-base';
221
+
222
+ export default [
223
+ ...baseConfig,
224
+ {
225
+ files: ['**/*.test.ts', '**/*.test.tsx'],
226
+ rules: {
227
+ // Test-specific rules
228
+ '@typescript-eslint/no-explicit-any': 'off',
229
+ },
230
+ },
231
+ {
232
+ ignores: ['dist/', 'build/', 'node_modules/'],
233
+ },
234
+ ];
235
+ ```
236
+
237
+ ## 📝 Usage with Scripts
238
+
239
+ Add linting scripts to your `package.json`:
240
+
241
+ ```json
242
+ {
243
+ "scripts": {
244
+ "lint": "eslint .",
245
+ "lint:fix": "eslint . --fix"
246
+ }
247
+ }
248
+ ```
249
+
250
+ ## 📋 Requirements
251
+
252
+ - **Node.js** >= 20.11.0 (required for `import.meta.dirname` in config files)
253
+ - **ESLint** >= 9.0.0 (flat config format)
254
+ - **TypeScript** project with `tsconfig.json`
255
+ - **TypeScript project service** enabled (automatic with this config)
256
+
257
+ ## 📦 Peer Dependencies
258
+
259
+ This package requires the following peer dependencies:
260
+
261
+ - `eslint` (^9.0.0)
262
+ - `@eslint/js` (^9.0.0)
263
+ - `typescript-eslint` (^8.0.0)
264
+ - `eslint-config-prettier` (^9.1.0)
265
+ - `eslint-plugin-simple-import-sort` (^12.0.0)
266
+ - `@jmlweb/eslint-config-base-js` (workspace or published version)
267
+
268
+ ## 🔗 Related Packages
269
+
270
+ - [`@jmlweb/eslint-config-base-js`](../eslint-config-base-js) - JavaScript ESLint config (extended by this package)
271
+ - [`@jmlweb/prettier-config-base`](../prettier-config-base) - Prettier config for consistent formatting
272
+ - [`@jmlweb/tsconfig-base`](../tsconfig-base) - TypeScript configuration
273
+
274
+ ## 📄 License
275
+
276
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ default: () => index_default
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+ var import_eslint_config_base_js = __toESM(require("@jmlweb/eslint-config-base-js"), 1);
37
+ var import_eslint_config_prettier = __toESM(require("eslint-config-prettier"), 1);
38
+ var import_eslint_plugin_simple_import_sort = __toESM(require("eslint-plugin-simple-import-sort"), 1);
39
+ var import_typescript_eslint = __toESM(require("typescript-eslint"), 1);
40
+ var config = import_typescript_eslint.default.config(
41
+ ...import_eslint_config_base_js.default,
42
+ ...import_typescript_eslint.default.configs.recommended,
43
+ ...import_typescript_eslint.default.configs.strictTypeChecked,
44
+ ...import_typescript_eslint.default.configs.stylisticTypeChecked,
45
+ {
46
+ files: ["**/*.ts", "**/*.tsx"],
47
+ plugins: {
48
+ "simple-import-sort": import_eslint_plugin_simple_import_sort.default
49
+ },
50
+ languageOptions: {
51
+ parserOptions: {
52
+ projectService: true
53
+ }
54
+ },
55
+ rules: {
56
+ ...import_eslint_config_prettier.default.rules,
57
+ "simple-import-sort/imports": "error",
58
+ "simple-import-sort/exports": "error",
59
+ // TypeScript strict rules
60
+ "@typescript-eslint/no-explicit-any": "error",
61
+ "@typescript-eslint/explicit-function-return-type": "error",
62
+ "@typescript-eslint/no-unused-vars": [
63
+ "error",
64
+ { argsIgnorePattern: "^_", varsIgnorePattern: "^_" }
65
+ ],
66
+ "@typescript-eslint/consistent-type-imports": [
67
+ "error",
68
+ { prefer: "type-imports", fixStyle: "inline-type-imports" }
69
+ ],
70
+ "@typescript-eslint/consistent-type-definitions": ["error", "type"],
71
+ // Import rules
72
+ "@typescript-eslint/no-require-imports": "error",
73
+ // Naming conventions
74
+ "@typescript-eslint/naming-convention": [
75
+ "error",
76
+ { selector: "typeLike", format: ["PascalCase"] },
77
+ { selector: "variable", format: ["camelCase", "UPPER_CASE"] },
78
+ {
79
+ selector: "variable",
80
+ modifiers: ["const", "exported"],
81
+ format: ["camelCase", "UPPER_CASE", "PascalCase"]
82
+ },
83
+ { selector: "function", format: ["camelCase"] }
84
+ ],
85
+ // Prevent enum usage (prefer const maps)
86
+ "no-restricted-syntax": [
87
+ "error",
88
+ {
89
+ selector: "TSEnumDeclaration",
90
+ message: "Use const maps instead of enums"
91
+ }
92
+ ],
93
+ // Encourage immutability (functional programming)
94
+ "no-param-reassign": ["error", { props: true }]
95
+ }
96
+ }
97
+ );
98
+ var index_default = config;
@@ -0,0 +1,10 @@
1
+ import { Linter } from 'eslint';
2
+
3
+ /**
4
+ * TypeScript ESLint configuration that extends the base config.
5
+ * Includes strict type checking, stylistic rules, and best practices.
6
+ * For non-strict projects, override the strict rules in your eslint.config.js.
7
+ */
8
+ declare const config: Linter.Config[];
9
+
10
+ export { config as default };
@@ -0,0 +1,10 @@
1
+ import { Linter } from 'eslint';
2
+
3
+ /**
4
+ * TypeScript ESLint configuration that extends the base config.
5
+ * Includes strict type checking, stylistic rules, and best practices.
6
+ * For non-strict projects, override the strict rules in your eslint.config.js.
7
+ */
8
+ declare const config: Linter.Config[];
9
+
10
+ export { config as default };
package/dist/index.js ADDED
@@ -0,0 +1,67 @@
1
+ // src/index.ts
2
+ import baseConfig from "@jmlweb/eslint-config-base-js";
3
+ import prettierConfig from "eslint-config-prettier";
4
+ import simpleImportSort from "eslint-plugin-simple-import-sort";
5
+ import tseslint from "typescript-eslint";
6
+ var config = tseslint.config(
7
+ ...baseConfig,
8
+ ...tseslint.configs.recommended,
9
+ ...tseslint.configs.strictTypeChecked,
10
+ ...tseslint.configs.stylisticTypeChecked,
11
+ {
12
+ files: ["**/*.ts", "**/*.tsx"],
13
+ plugins: {
14
+ "simple-import-sort": simpleImportSort
15
+ },
16
+ languageOptions: {
17
+ parserOptions: {
18
+ projectService: true
19
+ }
20
+ },
21
+ rules: {
22
+ ...prettierConfig.rules,
23
+ "simple-import-sort/imports": "error",
24
+ "simple-import-sort/exports": "error",
25
+ // TypeScript strict rules
26
+ "@typescript-eslint/no-explicit-any": "error",
27
+ "@typescript-eslint/explicit-function-return-type": "error",
28
+ "@typescript-eslint/no-unused-vars": [
29
+ "error",
30
+ { argsIgnorePattern: "^_", varsIgnorePattern: "^_" }
31
+ ],
32
+ "@typescript-eslint/consistent-type-imports": [
33
+ "error",
34
+ { prefer: "type-imports", fixStyle: "inline-type-imports" }
35
+ ],
36
+ "@typescript-eslint/consistent-type-definitions": ["error", "type"],
37
+ // Import rules
38
+ "@typescript-eslint/no-require-imports": "error",
39
+ // Naming conventions
40
+ "@typescript-eslint/naming-convention": [
41
+ "error",
42
+ { selector: "typeLike", format: ["PascalCase"] },
43
+ { selector: "variable", format: ["camelCase", "UPPER_CASE"] },
44
+ {
45
+ selector: "variable",
46
+ modifiers: ["const", "exported"],
47
+ format: ["camelCase", "UPPER_CASE", "PascalCase"]
48
+ },
49
+ { selector: "function", format: ["camelCase"] }
50
+ ],
51
+ // Prevent enum usage (prefer const maps)
52
+ "no-restricted-syntax": [
53
+ "error",
54
+ {
55
+ selector: "TSEnumDeclaration",
56
+ message: "Use const maps instead of enums"
57
+ }
58
+ ],
59
+ // Encourage immutability (functional programming)
60
+ "no-param-reassign": ["error", { props: true }]
61
+ }
62
+ }
63
+ );
64
+ var index_default = config;
65
+ export {
66
+ index_default as default
67
+ };
package/package.json ADDED
@@ -0,0 +1,75 @@
1
+ {
2
+ "name": "@jmlweb/eslint-config-base",
3
+ "version": "1.0.0",
4
+ "description": "Base ESLint configuration for TypeScript projects with strict type checking and best practices",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "require": {
12
+ "types": "./dist/index.d.cts",
13
+ "default": "./dist/index.cjs"
14
+ },
15
+ "import": {
16
+ "types": "./dist/index.d.ts",
17
+ "default": "./dist/index.js"
18
+ }
19
+ }
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "README.md"
24
+ ],
25
+ "scripts": {
26
+ "build": "tsup",
27
+ "clean": "rm -rf dist",
28
+ "prepublishOnly": "pnpm build"
29
+ },
30
+ "keywords": [
31
+ "eslint",
32
+ "eslint-config",
33
+ "typescript",
34
+ "javascript",
35
+ "linting",
36
+ "code-quality"
37
+ ],
38
+ "author": "jmlweb",
39
+ "license": "MIT",
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "https://github.com/jmlweb/tooling.git"
43
+ },
44
+ "bugs": {
45
+ "url": "https://github.com/jmlweb/tooling/issues"
46
+ },
47
+ "homepage": "https://github.com/jmlweb/tooling/tree/main/packages/eslint-config-base#readme",
48
+ "engines": {
49
+ "node": ">=20.11.0"
50
+ },
51
+ "publishConfig": {
52
+ "access": "public"
53
+ },
54
+ "peerDependencies": {
55
+ "@eslint/js": "^9.0.0",
56
+ "eslint": "^9.0.0",
57
+ "eslint-config-prettier": "^9.1.0",
58
+ "eslint-plugin-simple-import-sort": "^12.0.0",
59
+ "typescript-eslint": "^8.0.0"
60
+ },
61
+ "dependencies": {
62
+ "@jmlweb/eslint-config-base-js": "workspace:*"
63
+ },
64
+ "devDependencies": {
65
+ "@eslint/js": "^9.39.2",
66
+ "@jmlweb/tsconfig-internal": "workspace:*",
67
+ "@types/eslint": "^9.6.1",
68
+ "eslint": "^9.39.2",
69
+ "eslint-config-prettier": "^10.1.8",
70
+ "eslint-plugin-simple-import-sort": "^12.1.1",
71
+ "tsup": "^8.5.1",
72
+ "typescript": "^5.9.3",
73
+ "typescript-eslint": "^8.34.1"
74
+ }
75
+ }