0
# @modern-js/eslint-config
1
2
@modern-js/eslint-config provides comprehensive ESLint configuration for Modern.js projects with TypeScript support, type-aware linting, Prettier integration, and Node.js-specific rules. It serves as a centralized ESLint configuration package within the Modern.js ecosystem, extending base configurations with additional features for modern JavaScript/TypeScript development.
3
4
## Package Information
5
6
- **Package Name**: @modern-js/eslint-config
7
- **Package Type**: npm
8
- **Language**: JavaScript (CommonJS)
9
- **Installation**: `npm install @modern-js/eslint-config` (requires Modern.js workspace environment)
10
11
## Core Imports
12
13
```javascript
14
// Main configuration (full-featured with type checking)
15
const config = require('@modern-js/eslint-config');
16
17
// Lite configuration (without type checking)
18
const liteConfig = require('@modern-js/eslint-config/lite');
19
20
// Node.js specific configuration (typically used internally)
21
const nodeConfig = require('@modern-js/eslint-config/eslintrc.node');
22
23
// Jest configuration for testing environments
24
const jestConfig = require('@modern-js/eslint-config/jest.config');
25
```
26
27
## Basic Usage
28
29
The most common usage is to extend one of the configurations in your ESLint configuration file:
30
31
```javascript
32
// .eslintrc.js
33
module.exports = {
34
extends: ['@modern-js/eslint-config'],
35
// Your custom rules here
36
};
37
```
38
39
For lighter configuration without type checking:
40
41
```javascript
42
// .eslintrc.js
43
module.exports = {
44
extends: ['@modern-js/eslint-config/lite'],
45
// Your custom rules here
46
};
47
```
48
49
## Architecture
50
51
@modern-js/eslint-config is built as a layered configuration system:
52
53
- **Base Layer**: Extends @modern-js-app/eslint-config for core JavaScript/TypeScript rules
54
- **Type Layer**: Adds TypeScript type-aware linting (main config only)
55
- **Node.js Layer**: Adds Node.js-specific environment settings and rules
56
- **Prettier Layer**: Integrates with Prettier for consistent code formatting
57
58
**Note**: This package depends on @modern-js-app/eslint-config, which is an internal workspace dependency within the Modern.js monorepo. For standalone usage, you would need access to the complete Modern.js workspace or its published dependencies.
59
60
The package uses a composition approach where each configuration variant combines different layers to provide targeted rule sets for different use cases.
61
62
## Capabilities
63
64
### Main Configuration
65
66
Complete ESLint configuration with full TypeScript support, type-aware linting, Prettier integration, and Node.js-specific rules.
67
68
```javascript { .api }
69
/**
70
* Main ESLint configuration export
71
* Includes: base rules, TypeScript, type checking, Prettier, Node.js rules
72
*/
73
module.exports = {
74
extends: [
75
'@modern-js-app/eslint-config/base',
76
'@modern-js-app/eslint-config/ts',
77
'@modern-js-app/eslint-config/ts.withType',
78
'@modern-js-app/eslint-config/prettier',
79
'./eslintrc.node.js'
80
]
81
};
82
```
83
84
**Usage:**
85
```javascript
86
// .eslintrc.js
87
module.exports = {
88
extends: ['@modern-js/eslint-config']
89
};
90
```
91
92
### Lite Configuration
93
94
Lighter ESLint configuration without type-aware linting, suitable for faster linting in development or CI environments.
95
96
```javascript { .api }
97
/**
98
* Lite ESLint configuration export
99
* Includes: base rules, TypeScript (no type checking), Prettier, Node.js rules
100
*/
101
module.exports = {
102
extends: [
103
'@modern-js-app/eslint-config/base',
104
'@modern-js-app/eslint-config/ts',
105
'@modern-js-app/eslint-config/prettier',
106
'./eslintrc.node.js'
107
]
108
};
109
```
110
111
**Usage:**
112
```javascript
113
// .eslintrc.js for faster linting
114
module.exports = {
115
extends: ['@modern-js/eslint-config/lite']
116
};
117
```
118
119
### Node.js Configuration
120
121
Node.js-specific ESLint rules and environment configuration, typically used as part of the main and lite configurations but can be used standalone.
122
123
```javascript { .api }
124
/**
125
* Node.js-specific ESLint configuration
126
* Includes: Node.js environment, import resolver, Node.js plugin rules
127
*/
128
module.exports = {
129
env: {
130
commonjs: false,
131
browser: false,
132
node: true
133
},
134
settings: {
135
'import/resolver': 'node'
136
},
137
rules: {
138
// Node.js specific rules
139
'node/no-unsupported-features/es-builtins': 2,
140
'node/no-unsupported-features/es-syntax': 0,
141
'node/no-unsupported-features/node-builtins': 2,
142
'node/prefer-global/url': [2, 'never'],
143
'node/prefer-global/url-search-params': [2, 'never'],
144
'node/prefer-global/buffer': [2, 'never'],
145
'node/prefer-global/text-decoder': [2, 'never'],
146
'node/prefer-global/text-encoder': [2, 'never'],
147
'node/process-exit-as-throw': 2,
148
'node/no-deprecated-api': 2,
149
'node/prefer-promises/dns': 2,
150
'node/prefer-promises/fs': 0,
151
'filenames/match-regex': 0,
152
'import/default': 0,
153
'import/no-dynamic-require': 0,
154
'import/no-unused-modules': 0,
155
'import/no-commonjs': 0
156
},
157
overrides: [
158
{
159
files: ['*.ts', '*.d.ts', '*.tsx'],
160
settings: {
161
'import/external-module-folders': ['node_modules', 'node_modules/@types'],
162
'import/parsers': {
163
'@typescript-eslint/parser': ['.ts', '.tsx', '.d.ts']
164
},
165
'import/resolver': {
166
node: { extensions: jsExtensions } // References @modern-js-app/eslint-config/utils
167
}
168
},
169
rules: {
170
'import/named': 'off',
171
'node/no-unsupported-features/es-syntax': 0,
172
'@typescript-eslint/no-var-requires': 0,
173
'@typescript-eslint/no-require-imports': 0
174
}
175
}
176
]
177
};
178
```
179
180
**Usage:**
181
```javascript
182
// Standalone Node.js configuration
183
module.exports = {
184
extends: ['@modern-js/eslint-config/eslintrc.node']
185
};
186
```
187
188
## Types
189
190
### ESLint Configuration Object
191
192
```javascript { .api }
193
/**
194
* Standard ESLint configuration object structure
195
* All exports return this format
196
*/
197
interface ESLintConfig {
198
extends?: string[]; // Extended configurations
199
env?: { // Environment settings
200
[key: string]: boolean;
201
};
202
settings?: { // Plugin settings
203
[key: string]: any;
204
};
205
rules?: { // ESLint rules
206
[ruleName: string]: any;
207
};
208
overrides?: { // File-specific overrides
209
files: string[];
210
settings?: { [key: string]: any };
211
rules?: { [ruleName: string]: any };
212
}[];
213
}
214
```
215
216
### Jest Configuration
217
218
Jest-specific testing configuration that extends shared Jest configuration from the Modern.js build scripts.
219
220
```javascript { .api }
221
/**
222
* Jest configuration for testing environments
223
* Extends shared configuration with package-specific settings
224
*/
225
const sharedConfig = require('@scripts/jest-config');
226
227
module.exports = {
228
...sharedConfig,
229
rootDir: __dirname
230
};
231
```
232
233
**Usage:**
234
```javascript
235
// jest.config.js
236
module.exports = require('@modern-js/eslint-config/jest.config');
237
```
238
239
## Configuration Variants Comparison
240
241
| Feature | Main Config | Lite Config | Node.js Config | Jest Config |
242
|---------|-------------|-------------|----------------|-------------|
243
| Base Rules | ✅ | ✅ | ❌ | ❌ |
244
| TypeScript | ✅ | ✅ | Override only | ❌ |
245
| Type Checking | ✅ | ❌ | ❌ | ❌ |
246
| Prettier | ✅ | ✅ | ❌ | ❌ |
247
| Node.js Rules | ✅ | ✅ | ✅ | ❌ |
248
| Jest Support | ❌ | ❌ | ❌ | ✅ |
249
| Performance | Slower | Faster | Fastest | Fast |
250
| Use Case | Full linting | Development/CI | Node.js only | Testing |