@jmlweb/eslint-config-base-js 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 +237 -0
- package/dist/index.cjs +57 -0
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +26 -0
- package/package.json +69 -0
package/README.md
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
# @jmlweb/eslint-config-base-js
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@jmlweb/eslint-config-base-js)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://nodejs.org/)
|
|
6
|
+
[](https://eslint.org/)
|
|
7
|
+
|
|
8
|
+
> Base ESLint configuration for JavaScript projects. Foundation for JavaScript-only projects and extended by TypeScript configs. Uses ESLint 9+ flat config format.
|
|
9
|
+
|
|
10
|
+
## ✨ Features
|
|
11
|
+
|
|
12
|
+
- 🎯 **JavaScript Support**: Recommended ESLint rules for modern JavaScript (ES modules)
|
|
13
|
+
- 📦 **Import Sorting**: Automatic import and export sorting via `eslint-plugin-simple-import-sort`
|
|
14
|
+
- 🎨 **Prettier Integration**: Disables all ESLint rules that conflict with Prettier
|
|
15
|
+
- 🌐 **Environment Agnostic**: Works for both Node.js and browser projects
|
|
16
|
+
- 🚀 **Flat Config**: Uses ESLint 9+ flat config format (latest stable)
|
|
17
|
+
- 🔧 **Modular Design**: Designed to be extended by other configs (e.g., TypeScript)
|
|
18
|
+
|
|
19
|
+
## 📦 Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install --save-dev @jmlweb/eslint-config-base-js eslint @eslint/js eslint-config-prettier eslint-plugin-simple-import-sort
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 🚀 Quick Start
|
|
26
|
+
|
|
27
|
+
Create an `eslint.config.js` file in your project root:
|
|
28
|
+
|
|
29
|
+
```javascript
|
|
30
|
+
import baseJsConfig from '@jmlweb/eslint-config-base-js';
|
|
31
|
+
|
|
32
|
+
export default [
|
|
33
|
+
...baseJsConfig,
|
|
34
|
+
// Add your project-specific overrides here
|
|
35
|
+
];
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## 💡 Examples
|
|
39
|
+
|
|
40
|
+
### Basic Setup
|
|
41
|
+
|
|
42
|
+
```javascript
|
|
43
|
+
// eslint.config.js
|
|
44
|
+
import baseJsConfig from '@jmlweb/eslint-config-base-js';
|
|
45
|
+
|
|
46
|
+
export default [...baseJsConfig];
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### With Project-Specific Rules
|
|
50
|
+
|
|
51
|
+
```javascript
|
|
52
|
+
// eslint.config.js
|
|
53
|
+
import baseJsConfig from '@jmlweb/eslint-config-base-js';
|
|
54
|
+
|
|
55
|
+
export default [
|
|
56
|
+
...baseJsConfig,
|
|
57
|
+
{
|
|
58
|
+
files: ['**/*.test.js', '**/*.spec.js'],
|
|
59
|
+
rules: {
|
|
60
|
+
'no-console': 'off', // Allow console in tests
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
ignores: ['dist/', 'build/', 'node_modules/', '*.config.js'],
|
|
65
|
+
},
|
|
66
|
+
];
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Node.js Project
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
// eslint.config.js
|
|
73
|
+
import baseJsConfig from '@jmlweb/eslint-config-base-js';
|
|
74
|
+
|
|
75
|
+
export default [
|
|
76
|
+
...baseJsConfig,
|
|
77
|
+
{
|
|
78
|
+
languageOptions: {
|
|
79
|
+
globals: {
|
|
80
|
+
// Add Node.js globals if needed
|
|
81
|
+
process: 'readonly',
|
|
82
|
+
__dirname: 'readonly',
|
|
83
|
+
__filename: 'readonly',
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
];
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Browser Project
|
|
91
|
+
|
|
92
|
+
```javascript
|
|
93
|
+
// eslint.config.js
|
|
94
|
+
import baseJsConfig from '@jmlweb/eslint-config-base-js';
|
|
95
|
+
import globals from 'globals';
|
|
96
|
+
|
|
97
|
+
export default [
|
|
98
|
+
...baseJsConfig,
|
|
99
|
+
{
|
|
100
|
+
languageOptions: {
|
|
101
|
+
globals: {
|
|
102
|
+
...globals.browser,
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
];
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## 📋 Configuration Details
|
|
110
|
+
|
|
111
|
+
### JavaScript Files
|
|
112
|
+
|
|
113
|
+
The base configuration applies to:
|
|
114
|
+
|
|
115
|
+
- `**/*.js` - Standard JavaScript files
|
|
116
|
+
- `**/*.mjs` - ES modules
|
|
117
|
+
- `**/*.cjs` - CommonJS files
|
|
118
|
+
|
|
119
|
+
### Included Rules
|
|
120
|
+
|
|
121
|
+
- ✅ ESLint recommended rules (`@eslint/js`)
|
|
122
|
+
- ✅ Automatic import/export sorting
|
|
123
|
+
- ✅ Prettier conflict resolution
|
|
124
|
+
|
|
125
|
+
## 🔄 Import Sorting
|
|
126
|
+
|
|
127
|
+
The configuration automatically sorts imports and exports. The default sorting order is:
|
|
128
|
+
|
|
129
|
+
1. **Side effect imports** (e.g., `import 'polyfill'`)
|
|
130
|
+
2. **Node.js built-in modules** (e.g., `import fs from 'fs'`)
|
|
131
|
+
3. **External packages** (e.g., `import react from 'react'`)
|
|
132
|
+
4. **Internal absolute imports** (e.g., `import utils from '@/utils'`)
|
|
133
|
+
5. **Relative imports** (e.g., `import './component'`)
|
|
134
|
+
|
|
135
|
+
### Example
|
|
136
|
+
|
|
137
|
+
**Before:**
|
|
138
|
+
|
|
139
|
+
```javascript
|
|
140
|
+
import './styles.css';
|
|
141
|
+
import { Component } from './component';
|
|
142
|
+
import React from 'react';
|
|
143
|
+
import fs from 'fs';
|
|
144
|
+
import { utils } from '@/utils';
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
**After auto-fix:**
|
|
148
|
+
|
|
149
|
+
```javascript
|
|
150
|
+
import './styles.css';
|
|
151
|
+
import fs from 'fs';
|
|
152
|
+
import React from 'react';
|
|
153
|
+
import { utils } from '@/utils';
|
|
154
|
+
import { Component } from './component';
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Fix import order automatically:
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
npx eslint --fix .
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## 🎨 Prettier Integration
|
|
164
|
+
|
|
165
|
+
This configuration disables all ESLint rules that conflict with Prettier, allowing Prettier to handle all code formatting.
|
|
166
|
+
|
|
167
|
+
**Recommended**: Use [`@jmlweb/prettier-config-base`](../prettier-config-base) for consistent formatting.
|
|
168
|
+
|
|
169
|
+
## 🔗 TypeScript Projects
|
|
170
|
+
|
|
171
|
+
For TypeScript projects, use [`@jmlweb/eslint-config-base`](../eslint-config-base) which extends this config with strict type checking:
|
|
172
|
+
|
|
173
|
+
```javascript
|
|
174
|
+
import baseConfig from '@jmlweb/eslint-config-base';
|
|
175
|
+
|
|
176
|
+
export default [...baseConfig];
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## 🔧 Extending the Configuration
|
|
180
|
+
|
|
181
|
+
You can extend or override the configuration for your specific needs:
|
|
182
|
+
|
|
183
|
+
```javascript
|
|
184
|
+
import baseJsConfig from '@jmlweb/eslint-config-base-js';
|
|
185
|
+
|
|
186
|
+
export default [
|
|
187
|
+
...baseJsConfig,
|
|
188
|
+
{
|
|
189
|
+
files: ['**/*.test.js'],
|
|
190
|
+
rules: {
|
|
191
|
+
// Test-specific rules
|
|
192
|
+
'no-console': 'off',
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
ignores: ['dist/', 'build/', 'node_modules/'],
|
|
197
|
+
},
|
|
198
|
+
];
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## 📝 Usage with Scripts
|
|
202
|
+
|
|
203
|
+
Add linting scripts to your `package.json`:
|
|
204
|
+
|
|
205
|
+
```json
|
|
206
|
+
{
|
|
207
|
+
"scripts": {
|
|
208
|
+
"lint": "eslint .",
|
|
209
|
+
"lint:fix": "eslint . --fix"
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## 📋 Requirements
|
|
215
|
+
|
|
216
|
+
- **Node.js** >= 18.0.0
|
|
217
|
+
- **ESLint** >= 9.0.0 (flat config format)
|
|
218
|
+
|
|
219
|
+
## 📦 Peer Dependencies
|
|
220
|
+
|
|
221
|
+
This package requires the following peer dependencies:
|
|
222
|
+
|
|
223
|
+
- `eslint` (^9.0.0)
|
|
224
|
+
- `@eslint/js` (^9.0.0)
|
|
225
|
+
- `eslint-config-prettier` (^9.1.0)
|
|
226
|
+
- `eslint-plugin-simple-import-sort` (^12.0.0)
|
|
227
|
+
|
|
228
|
+
**Note**: This package does NOT require `typescript-eslint` as it's for JavaScript-only projects.
|
|
229
|
+
|
|
230
|
+
## 🔗 Related Packages
|
|
231
|
+
|
|
232
|
+
- [`@jmlweb/eslint-config-base`](../eslint-config-base) - TypeScript ESLint config (extends this package)
|
|
233
|
+
- [`@jmlweb/prettier-config-base`](../prettier-config-base) - Prettier config for consistent formatting
|
|
234
|
+
|
|
235
|
+
## 📄 License
|
|
236
|
+
|
|
237
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
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_js = __toESM(require("@eslint/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 config = [
|
|
40
|
+
{
|
|
41
|
+
files: ["**/*.js", "**/*.mjs", "**/*.cjs"],
|
|
42
|
+
languageOptions: {
|
|
43
|
+
ecmaVersion: "latest",
|
|
44
|
+
sourceType: "module"
|
|
45
|
+
},
|
|
46
|
+
plugins: {
|
|
47
|
+
"simple-import-sort": import_eslint_plugin_simple_import_sort.default
|
|
48
|
+
},
|
|
49
|
+
rules: {
|
|
50
|
+
...import_js.default.configs.recommended.rules,
|
|
51
|
+
...import_eslint_config_prettier.default.rules,
|
|
52
|
+
"simple-import-sort/imports": "error",
|
|
53
|
+
"simple-import-sort/exports": "error"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
];
|
|
57
|
+
var index_default = config;
|
package/dist/index.d.cts
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import js from "@eslint/js";
|
|
3
|
+
import prettierConfig from "eslint-config-prettier";
|
|
4
|
+
import simpleImportSort from "eslint-plugin-simple-import-sort";
|
|
5
|
+
var config = [
|
|
6
|
+
{
|
|
7
|
+
files: ["**/*.js", "**/*.mjs", "**/*.cjs"],
|
|
8
|
+
languageOptions: {
|
|
9
|
+
ecmaVersion: "latest",
|
|
10
|
+
sourceType: "module"
|
|
11
|
+
},
|
|
12
|
+
plugins: {
|
|
13
|
+
"simple-import-sort": simpleImportSort
|
|
14
|
+
},
|
|
15
|
+
rules: {
|
|
16
|
+
...js.configs.recommended.rules,
|
|
17
|
+
...prettierConfig.rules,
|
|
18
|
+
"simple-import-sort/imports": "error",
|
|
19
|
+
"simple-import-sort/exports": "error"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
];
|
|
23
|
+
var index_default = config;
|
|
24
|
+
export {
|
|
25
|
+
index_default as default
|
|
26
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jmlweb/eslint-config-base-js",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Base ESLint configuration for JavaScript-only projects - foundation extended by @jmlweb/eslint-config-base",
|
|
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
|
+
"javascript",
|
|
34
|
+
"linting",
|
|
35
|
+
"code-quality"
|
|
36
|
+
],
|
|
37
|
+
"author": "jmlweb",
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "https://github.com/jmlweb/tooling.git"
|
|
42
|
+
},
|
|
43
|
+
"bugs": {
|
|
44
|
+
"url": "https://github.com/jmlweb/tooling/issues"
|
|
45
|
+
},
|
|
46
|
+
"homepage": "https://github.com/jmlweb/tooling/tree/main/packages/eslint-config-base-js#readme",
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": ">=18.0.0"
|
|
49
|
+
},
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"@eslint/js": "^9.0.0",
|
|
55
|
+
"eslint": "^9.0.0",
|
|
56
|
+
"eslint-config-prettier": "^9.1.0",
|
|
57
|
+
"eslint-plugin-simple-import-sort": "^12.0.0"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@eslint/js": "^9.39.2",
|
|
61
|
+
"@jmlweb/tsconfig-internal": "workspace:*",
|
|
62
|
+
"@types/eslint": "^9.6.1",
|
|
63
|
+
"eslint": "^9.39.2",
|
|
64
|
+
"eslint-config-prettier": "^10.1.8",
|
|
65
|
+
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
66
|
+
"tsup": "^8.5.1",
|
|
67
|
+
"typescript": "^5.9.3"
|
|
68
|
+
}
|
|
69
|
+
}
|