@jmlweb/eslint-config-node 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,258 @@
1
+ # @jmlweb/eslint-config-node
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@jmlweb/eslint-config-node)](https://www.npmjs.com/package/@jmlweb/eslint-config-node)
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
+ > ESLint configuration for Node.js projects with TypeScript. Extends `@jmlweb/eslint-config-base` with Node.js-specific rules, globals, and best practices for Node.js development.
10
+
11
+ ## ✨ Features
12
+
13
+ - 🔒 **Strict Type Checking**: Inherits all strict TypeScript rules from base config
14
+ - 🟢 **Node.js Best Practices**: Enforces Node.js-specific rules and patterns
15
+ - 🌐 **Node.js Globals**: Automatically enables Node.js global variables
16
+ - 📦 **Import Management**: Enforces type-only imports with inline style + automatic sorting
17
+ - 🎯 **Code Quality**: Prevents common Node.js pitfalls and anti-patterns
18
+ - 🎨 **Prettier Integration**: Disables all ESLint rules that conflict with Prettier
19
+ - 🚀 **Flat Config**: Uses ESLint 9+ flat config format (latest stable)
20
+
21
+ ## 📦 Installation
22
+
23
+ ```bash
24
+ npm install --save-dev @jmlweb/eslint-config-node eslint @eslint/js typescript-eslint eslint-config-prettier eslint-plugin-n eslint-plugin-simple-import-sort globals @jmlweb/eslint-config-base
25
+ ```
26
+
27
+ ## 🚀 Quick Start
28
+
29
+ Create an `eslint.config.js` file in your project root:
30
+
31
+ ```javascript
32
+ import nodeConfig from '@jmlweb/eslint-config-node';
33
+
34
+ export default [
35
+ ...nodeConfig,
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 nodeConfig from '@jmlweb/eslint-config-node';
47
+
48
+ export default [...nodeConfig];
49
+ ```
50
+
51
+ ### With Project-Specific Overrides
52
+
53
+ ```javascript
54
+ // eslint.config.js
55
+ import nodeConfig from '@jmlweb/eslint-config-node';
56
+
57
+ export default [
58
+ ...nodeConfig,
59
+ {
60
+ files: ['**/*.test.ts', '**/*.spec.ts'],
61
+ rules: {
62
+ // Allow any in tests
63
+ '@typescript-eslint/no-explicit-any': 'off',
64
+ // Allow console in tests
65
+ 'no-console': 'off',
66
+ // Relax Node.js rules in tests
67
+ 'n/no-process-exit': 'off',
68
+ },
69
+ },
70
+ {
71
+ ignores: ['dist/', 'build/', 'node_modules/', '*.config.ts'],
72
+ },
73
+ ];
74
+ ```
75
+
76
+ ### With Custom Node.js Settings
77
+
78
+ ```javascript
79
+ // eslint.config.js
80
+ import nodeConfig from '@jmlweb/eslint-config-node';
81
+
82
+ export default [
83
+ ...nodeConfig,
84
+ {
85
+ files: ['**/*.ts', '**/*.js'],
86
+ rules: {
87
+ // Customize Node.js rules
88
+ 'n/no-process-exit': 'warn', // Warn instead of error
89
+ 'n/no-deprecated-api': 'error', // Error on deprecated APIs
90
+ },
91
+ },
92
+ ];
93
+ ```
94
+
95
+ ## 📋 Configuration Details
96
+
97
+ ### Node.js Files
98
+
99
+ This configuration applies Node.js-specific rules to:
100
+
101
+ - `**/*.ts` - TypeScript files
102
+ - `**/*.js` - JavaScript files
103
+ - `**/*.mjs` - ES modules
104
+ - `**/*.cjs` - CommonJS files
105
+
106
+ ### Key Rules Enforced
107
+
108
+ | Rule | Level | Description |
109
+ | -------------------------- | ------- | --------------------------------------------- |
110
+ | `n/no-process-exit` | `error` | Prevents direct `process.exit()` calls |
111
+ | `n/no-missing-import` | `error` | Prevents missing imports |
112
+ | `n/no-missing-require` | `error` | Prevents missing require statements |
113
+ | `n/no-unpublished-import` | `error` | Prevents importing unpublished packages |
114
+ | `n/no-unpublished-require` | `error` | Prevents requiring unpublished packages |
115
+ | `n/no-extraneous-import` | `error` | Prevents extraneous imports |
116
+ | `n/no-extraneous-require` | `error` | Prevents extraneous require statements |
117
+ | `n/no-deprecated-api` | `warn` | Warns about deprecated Node.js APIs |
118
+ | `n/process-exit-as-throw` | `error` | Treats process.exit as throw |
119
+ | `n/no-callback-literal` | `error` | Prevents callback literal patterns |
120
+ | `n/no-new-require` | `error` | Prevents `new require()` |
121
+ | `n/no-path-concat` | `error` | Prevents string concatenation for paths |
122
+ | `n/prefer-global/buffer` | `error` | Prefers global Buffer |
123
+ | `n/prefer-global/console` | `error` | Prefers global console |
124
+ | `n/prefer-global/process` | `error` | Prefers global process |
125
+ | `n/prefer-promises/dns` | `error` | Prefers promise-based DNS APIs |
126
+ | `n/prefer-promises/fs` | `error` | Prefers promise-based fs APIs |
127
+ | `n/prefer-node-protocol` | `error` | Prefers `node:` protocol for built-in modules |
128
+
129
+ ### What's Included
130
+
131
+ - ✅ All TypeScript ESLint rules from `@jmlweb/eslint-config-base`
132
+ - ✅ Node.js recommended rules from `eslint-plugin-n`
133
+ - ✅ Node.js globals automatically enabled
134
+ - ✅ Node.js best practices and anti-pattern prevention
135
+ - ✅ Automatic import/export sorting
136
+ - ✅ Prettier conflict resolution
137
+
138
+ ## 🔄 Import Sorting
139
+
140
+ The configuration automatically sorts imports and enforces type-only imports:
141
+
142
+ **Before:**
143
+
144
+ ```typescript
145
+ import { Component } from './component';
146
+ import fs from 'fs';
147
+ import type { User } from './types';
148
+ import express from 'express';
149
+ ```
150
+
151
+ **After auto-fix:**
152
+
153
+ ```typescript
154
+ import fs from 'fs';
155
+ import express from 'express';
156
+ import type { User } from './types';
157
+ import { Component } from './component';
158
+ ```
159
+
160
+ Fix import order automatically:
161
+
162
+ ```bash
163
+ npx eslint --fix .
164
+ ```
165
+
166
+ ## 🎯 When to Use
167
+
168
+ Use this configuration when you want:
169
+
170
+ - ✅ Node.js library or application development with TypeScript
171
+ - ✅ Maximum type safety with Node.js
172
+ - ✅ Strict code quality standards for Node.js code
173
+ - ✅ Consistent Node.js patterns across the team
174
+ - ✅ Prevention of common Node.js pitfalls
175
+ - ✅ Best practices enforcement for Node.js APIs
176
+
177
+ **For non-Node.js TypeScript projects**, use [`@jmlweb/eslint-config-base`](../eslint-config-base) instead.
178
+
179
+ **For JavaScript-only Node.js projects**, you can extend `@jmlweb/eslint-config-base-js` and add Node.js plugins manually.
180
+
181
+ ## 🔧 Extending the Configuration
182
+
183
+ You can extend or override the configuration for your specific needs:
184
+
185
+ ```javascript
186
+ import nodeConfig from '@jmlweb/eslint-config-node';
187
+
188
+ export default [
189
+ ...nodeConfig,
190
+ {
191
+ files: ['**/*.test.ts', '**/*.spec.ts'],
192
+ rules: {
193
+ // Test-specific rules
194
+ '@typescript-eslint/no-explicit-any': 'off',
195
+ 'n/no-process-exit': 'off',
196
+ },
197
+ },
198
+ {
199
+ ignores: ['dist/', 'build/', 'node_modules/'],
200
+ },
201
+ ];
202
+ ```
203
+
204
+ ## 📝 Usage with Scripts
205
+
206
+ Add linting scripts to your `package.json`:
207
+
208
+ ```json
209
+ {
210
+ "scripts": {
211
+ "lint": "eslint .",
212
+ "lint:fix": "eslint . --fix"
213
+ }
214
+ }
215
+ ```
216
+
217
+ Then run:
218
+
219
+ ```bash
220
+ npm run lint # Lint all files
221
+ npm run lint:fix # Fix auto-fixable issues
222
+ ```
223
+
224
+ ## 📋 Requirements
225
+
226
+ - **Node.js** >= 20.11.0 (required for `import.meta.dirname` in config files)
227
+ - **ESLint** >= 9.0.0 (flat config format)
228
+ - **TypeScript** project with `tsconfig.json`
229
+ - **TypeScript project service** enabled (automatic with this config)
230
+
231
+ ## 📦 Peer Dependencies
232
+
233
+ This package requires the following peer dependencies:
234
+
235
+ - `eslint` (^9.0.0)
236
+ - `@eslint/js` (^9.0.0)
237
+ - `typescript-eslint` (^8.0.0)
238
+ - `eslint-config-prettier` (^9.1.0)
239
+ - `eslint-plugin-n` (^0.4.0)
240
+ - `eslint-plugin-simple-import-sort` (^12.0.0)
241
+ - `globals` (^15.0.0)
242
+ - `@jmlweb/eslint-config-base` (^1.0.0)
243
+
244
+ ## 📚 Examples
245
+
246
+ See real-world usage examples:
247
+
248
+ - [`example-nodejs-typescript-api`](../../apps/example-nodejs-typescript-api) - Node.js TypeScript API example
249
+
250
+ ## 🔗 Related Packages
251
+
252
+ - [`@jmlweb/eslint-config-base`](../eslint-config-base) - Base TypeScript ESLint config (extended by this package)
253
+ - [`@jmlweb/tsconfig-node`](../tsconfig-node) - TypeScript configuration for Node.js libraries
254
+ - [`@jmlweb/prettier-config-base`](../prettier-config-base) - Prettier config for consistent formatting
255
+
256
+ ## 📄 License
257
+
258
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,83 @@
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 = __toESM(require("@jmlweb/eslint-config-base"), 1);
37
+ var import_eslint_config_prettier = __toESM(require("eslint-config-prettier"), 1);
38
+ var import_eslint_plugin_n = __toESM(require("eslint-plugin-n"), 1);
39
+ var import_globals = __toESM(require("globals"), 1);
40
+ var import_eslint_plugin_simple_import_sort = __toESM(require("eslint-plugin-simple-import-sort"), 1);
41
+ var config = [
42
+ ...import_eslint_config_base.default,
43
+ // Node.js recommended config (includes plugin and recommended rules)
44
+ import_eslint_plugin_n.default.configs["flat/recommended"],
45
+ {
46
+ files: ["**/*.ts", "**/*.js", "**/*.mjs", "**/*.cjs"],
47
+ plugins: {
48
+ "simple-import-sort": import_eslint_plugin_simple_import_sort.default
49
+ },
50
+ languageOptions: {
51
+ globals: {
52
+ ...import_globals.default.node
53
+ }
54
+ },
55
+ rules: {
56
+ ...import_eslint_config_prettier.default.rules,
57
+ "simple-import-sort/imports": "error",
58
+ "simple-import-sort/exports": "error",
59
+ // Node.js best practices (override/extend recommended rules)
60
+ "n/no-process-exit": "error",
61
+ "n/no-missing-import": "error",
62
+ "n/no-missing-require": "error",
63
+ "n/no-unpublished-import": "error",
64
+ "n/no-unpublished-require": "error",
65
+ "n/no-extraneous-import": "error",
66
+ "n/no-extraneous-require": "error",
67
+ "n/no-deprecated-api": "warn",
68
+ "n/process-exit-as-throw": "error",
69
+ "n/no-callback-literal": "error",
70
+ "n/no-new-require": "error",
71
+ "n/no-path-concat": "error",
72
+ "n/prefer-global/buffer": ["error", "always"],
73
+ "n/prefer-global/console": ["error", "always"],
74
+ "n/prefer-global/process": ["error", "always"],
75
+ "n/prefer-global/url-search-params": ["error", "always"],
76
+ "n/prefer-global/url": ["error", "always"],
77
+ "n/prefer-promises/dns": "error",
78
+ "n/prefer-promises/fs": "error",
79
+ "n/prefer-node-protocol": "error"
80
+ }
81
+ }
82
+ ];
83
+ var index_default = config;
@@ -0,0 +1,10 @@
1
+ import { Linter } from 'eslint';
2
+
3
+ /**
4
+ * Node.js ESLint configuration that extends the base TypeScript config.
5
+ * Includes Node.js-specific rules, globals, and best practices for Node.js development.
6
+ * For Node.js library and application development with TypeScript.
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
+ * Node.js ESLint configuration that extends the base TypeScript config.
5
+ * Includes Node.js-specific rules, globals, and best practices for Node.js development.
6
+ * For Node.js library and application development with TypeScript.
7
+ */
8
+ declare const config: Linter.Config[];
9
+
10
+ export { config as default };
package/dist/index.js ADDED
@@ -0,0 +1,52 @@
1
+ // src/index.ts
2
+ import baseConfig from "@jmlweb/eslint-config-base";
3
+ import prettierConfig from "eslint-config-prettier";
4
+ import eslintPluginN from "eslint-plugin-n";
5
+ import globals from "globals";
6
+ import simpleImportSort from "eslint-plugin-simple-import-sort";
7
+ var config = [
8
+ ...baseConfig,
9
+ // Node.js recommended config (includes plugin and recommended rules)
10
+ eslintPluginN.configs["flat/recommended"],
11
+ {
12
+ files: ["**/*.ts", "**/*.js", "**/*.mjs", "**/*.cjs"],
13
+ plugins: {
14
+ "simple-import-sort": simpleImportSort
15
+ },
16
+ languageOptions: {
17
+ globals: {
18
+ ...globals.node
19
+ }
20
+ },
21
+ rules: {
22
+ ...prettierConfig.rules,
23
+ "simple-import-sort/imports": "error",
24
+ "simple-import-sort/exports": "error",
25
+ // Node.js best practices (override/extend recommended rules)
26
+ "n/no-process-exit": "error",
27
+ "n/no-missing-import": "error",
28
+ "n/no-missing-require": "error",
29
+ "n/no-unpublished-import": "error",
30
+ "n/no-unpublished-require": "error",
31
+ "n/no-extraneous-import": "error",
32
+ "n/no-extraneous-require": "error",
33
+ "n/no-deprecated-api": "warn",
34
+ "n/process-exit-as-throw": "error",
35
+ "n/no-callback-literal": "error",
36
+ "n/no-new-require": "error",
37
+ "n/no-path-concat": "error",
38
+ "n/prefer-global/buffer": ["error", "always"],
39
+ "n/prefer-global/console": ["error", "always"],
40
+ "n/prefer-global/process": ["error", "always"],
41
+ "n/prefer-global/url-search-params": ["error", "always"],
42
+ "n/prefer-global/url": ["error", "always"],
43
+ "n/prefer-promises/dns": "error",
44
+ "n/prefer-promises/fs": "error",
45
+ "n/prefer-node-protocol": "error"
46
+ }
47
+ }
48
+ ];
49
+ var index_default = config;
50
+ export {
51
+ index_default as default
52
+ };
package/package.json ADDED
@@ -0,0 +1,77 @@
1
+ {
2
+ "name": "@jmlweb/eslint-config-node",
3
+ "version": "1.0.0",
4
+ "description": "ESLint configuration for Node.js projects with TypeScript, extending base config with Node.js-specific rules",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ }
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "README.md",
24
+ "CHANGELOG.md"
25
+ ],
26
+ "keywords": [
27
+ "code-quality",
28
+ "eslint",
29
+ "eslint-config",
30
+ "linting",
31
+ "node",
32
+ "nodejs",
33
+ "typescript"
34
+ ],
35
+ "author": "jmlweb",
36
+ "license": "MIT",
37
+ "repository": "jmlweb/tooling.git",
38
+ "bugs": "https://github.com/jmlweb/tooling/issues",
39
+ "homepage": "https://github.com/jmlweb/tooling/tree/main/packages/eslint-config-node#readme",
40
+ "engines": {
41
+ "node": ">=20.11.0"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public"
45
+ },
46
+ "peerDependencies": {
47
+ "@eslint/js": "^9.0.0",
48
+ "@jmlweb/eslint-config-base": "^1.0.0",
49
+ "eslint": "^9.0.0",
50
+ "eslint-config-prettier": "^9.1.0",
51
+ "eslint-plugin-n": "^17.0.0",
52
+ "eslint-plugin-simple-import-sort": "^12.0.0",
53
+ "globals": "^15.0.0",
54
+ "typescript-eslint": "^8.0.0"
55
+ },
56
+ "dependencies": {
57
+ "@jmlweb/eslint-config-base": "1.0.0"
58
+ },
59
+ "devDependencies": {
60
+ "@eslint/js": "^9.39.2",
61
+ "@types/eslint": "^9.6.1",
62
+ "eslint": "^9.39.2",
63
+ "eslint-config-prettier": "^10.1.8",
64
+ "eslint-plugin-n": "^17.0.0",
65
+ "eslint-plugin-simple-import-sort": "^12.1.1",
66
+ "globals": "^15.0.0",
67
+ "tsup": "^8.5.1",
68
+ "typescript": "^5.9.3",
69
+ "typescript-eslint": "^8.34.1",
70
+ "@jmlweb/eslint-config-base": "1.0.0",
71
+ "@jmlweb/tsconfig-internal": "0.0.1"
72
+ },
73
+ "scripts": {
74
+ "build": "tsup",
75
+ "clean": "rm -rf dist"
76
+ }
77
+ }