@obinexusltd/obix-config-eslint 0.1.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/base/.gitkeep +0 -0
- package/base/eslint.config.js +43 -0
- package/development/.gitkeep +0 -0
- package/development/eslint.config.js +30 -0
- package/dist/index.d.ts +71 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +155 -0
- package/dist/index.js.map +1 -0
- package/eslint.config.js +48 -0
- package/package.json +46 -0
- package/production/.gitkeep +0 -0
- package/production/eslint.config.js +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
# @obinexusltd/obix-config-eslint
|
|
2
|
+
|
|
3
|
+
> ESLint v9 flat configuration for OBIX SDK packages — part of the `@obinexusltd/obix-monorepo`.
|
|
4
|
+
|
|
5
|
+
Provides typed factory functions, ready-to-use flat config files, and environment-specific rule presets for linting OBIX SDK source code with ESLint 9 + typescript-eslint 8.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
Registered automatically as an npm workspace package:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# From monorepo root
|
|
15
|
+
npm install
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
To add it as a dependency in a consumer package:
|
|
19
|
+
|
|
20
|
+
```json
|
|
21
|
+
{
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@obinexusltd/obix-config-eslint": "workspace:*"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Package Structure
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
packages/config/eslint/
|
|
34
|
+
├── eslint.config.js ← Root flat config (./flat export)
|
|
35
|
+
├── base/
|
|
36
|
+
│ └── eslint.config.js ← Base TypeScript rules
|
|
37
|
+
├── development/
|
|
38
|
+
│ └── eslint.config.js ← Dev config (console allowed, any-type off)
|
|
39
|
+
├── production/
|
|
40
|
+
│ └── eslint.config.js ← Prod config (no-console error, strict types)
|
|
41
|
+
└── src/
|
|
42
|
+
└── index.ts ← TypeScript programmatic API (compiled to dist/)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Requirements
|
|
48
|
+
|
|
49
|
+
This package targets **ESLint v9 flat config** only. The legacy `.eslintrc` format is not supported.
|
|
50
|
+
|
|
51
|
+
Your `eslint.config.js` (or `eslint.config.mjs`) must be present at the project root.
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Programmatic API
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import {
|
|
59
|
+
createBaseConfig,
|
|
60
|
+
createDevConfig,
|
|
61
|
+
createProdConfig,
|
|
62
|
+
resolveConfig,
|
|
63
|
+
} from '@obinexusltd/obix-config-eslint';
|
|
64
|
+
|
|
65
|
+
// Base — TypeScript-eslint recommended + OBIX core rules
|
|
66
|
+
const base = createBaseConfig();
|
|
67
|
+
|
|
68
|
+
// Development — relaxed console/any rules
|
|
69
|
+
const dev = createDevConfig({ typescript: true });
|
|
70
|
+
|
|
71
|
+
// Production — strict, no-console error, explicit return types
|
|
72
|
+
const prod = createProdConfig();
|
|
73
|
+
|
|
74
|
+
// Resolve by environment string
|
|
75
|
+
const config = resolveConfig('production', { files: ['src/**/*.ts'] });
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Factory Functions
|
|
79
|
+
|
|
80
|
+
| Function | Description |
|
|
81
|
+
|----------|-------------|
|
|
82
|
+
| `createBaseConfig(opts?)` | Base TypeScript rules, `no-console: warn` |
|
|
83
|
+
| `createDevConfig(opts?)` | Dev: `no-console: off`, `no-explicit-any: off` |
|
|
84
|
+
| `createProdConfig(opts?)` | Prod: `no-console: error`, `no-explicit-any: error`, strict types |
|
|
85
|
+
| `resolveConfig(env, opts?)` | Delegates by `'base' \| 'development' \| 'production'` |
|
|
86
|
+
|
|
87
|
+
All factories return `Array<Record<string, unknown>>` — a plain flat config array. Spread into your own `tseslint.config(...)` call or use directly.
|
|
88
|
+
|
|
89
|
+
### `ObixEsLintOptions`
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
interface ObixEsLintOptions {
|
|
93
|
+
typescript?: boolean; // default: true — enable @typescript-eslint rules
|
|
94
|
+
imports?: boolean; // default: false — enable eslint-plugin-import
|
|
95
|
+
unicorn?: boolean; // default: false — enable eslint-plugin-unicorn
|
|
96
|
+
files?: string[]; // default: ['**/*.ts', '**/*.tsx']
|
|
97
|
+
ignores?: string[]; // default: ['dist/**', 'node_modules/**', '**/*.d.ts']
|
|
98
|
+
rules?: Record<string, unknown>; // default: {} — merged on top of preset
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Static Descriptors
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
import {
|
|
106
|
+
baseConfig,
|
|
107
|
+
developmentConfig,
|
|
108
|
+
productionConfig,
|
|
109
|
+
} from '@obinexusltd/obix-config-eslint';
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## Using Config Files Directly
|
|
115
|
+
|
|
116
|
+
### Root flat config (recommended)
|
|
117
|
+
|
|
118
|
+
Reference in your project's `eslint.config.js`:
|
|
119
|
+
|
|
120
|
+
```js
|
|
121
|
+
// eslint.config.js
|
|
122
|
+
import obixConfig from '@obinexusltd/obix-config-eslint/flat';
|
|
123
|
+
|
|
124
|
+
export default [
|
|
125
|
+
...obixConfig,
|
|
126
|
+
// your project-specific overrides
|
|
127
|
+
{
|
|
128
|
+
rules: {
|
|
129
|
+
'no-console': 'off', // override for this project
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
];
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Or with the `tseslint.config()` helper:
|
|
136
|
+
|
|
137
|
+
```js
|
|
138
|
+
import tseslint from 'typescript-eslint';
|
|
139
|
+
import obixConfig from '@obinexusltd/obix-config-eslint/flat';
|
|
140
|
+
|
|
141
|
+
export default tseslint.config(
|
|
142
|
+
...obixConfig,
|
|
143
|
+
{
|
|
144
|
+
rules: {
|
|
145
|
+
'@typescript-eslint/no-explicit-any': 'error',
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
);
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Base config
|
|
152
|
+
|
|
153
|
+
```js
|
|
154
|
+
import base from '@obinexusltd/obix-config-eslint/base';
|
|
155
|
+
export default [...base];
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Development config
|
|
159
|
+
|
|
160
|
+
```js
|
|
161
|
+
import devConfig from '@obinexusltd/obix-config-eslint/development';
|
|
162
|
+
export default [...devConfig];
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Production config
|
|
166
|
+
|
|
167
|
+
```js
|
|
168
|
+
import prodConfig from '@obinexusltd/obix-config-eslint/production';
|
|
169
|
+
export default [...prodConfig];
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## Environment Rule Reference
|
|
175
|
+
|
|
176
|
+
| Rule | `base` | `development` | `production` |
|
|
177
|
+
|------|--------|---------------|--------------|
|
|
178
|
+
| `no-console` | `warn` | `off` | `error` |
|
|
179
|
+
| `no-debugger` | `error` | `warn` | `error` |
|
|
180
|
+
| `@typescript-eslint/no-explicit-any` | `warn` | `off` | `error` |
|
|
181
|
+
| `@typescript-eslint/no-unused-vars` | `error` | `error` | `error` |
|
|
182
|
+
| `@typescript-eslint/explicit-function-return-type` | — | — | `warn` |
|
|
183
|
+
| `@typescript-eslint/strict-boolean-expressions` | — | — | `warn` |
|
|
184
|
+
| `@typescript-eslint/consistent-type-imports` | `warn` | `off` | `error` |
|
|
185
|
+
| `@typescript-eslint/no-non-null-assertion` | `warn` | `warn` | `error` |
|
|
186
|
+
| `prefer-const` | `error` | `error` | `error` |
|
|
187
|
+
| `no-var` | `error` | `error` | `error` |
|
|
188
|
+
| `eqeqeq` | `error` | `error` | `error` |
|
|
189
|
+
| `curly` | `error` | `error` | `error` |
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## Peer Dependencies
|
|
194
|
+
|
|
195
|
+
Required:
|
|
196
|
+
|
|
197
|
+
```json
|
|
198
|
+
{
|
|
199
|
+
"devDependencies": {
|
|
200
|
+
"@eslint/js": ">=9.0.0",
|
|
201
|
+
"eslint": ">=9.0.0",
|
|
202
|
+
"typescript-eslint": ">=8.0.0"
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Optional:
|
|
208
|
+
|
|
209
|
+
```json
|
|
210
|
+
{
|
|
211
|
+
"devDependencies": {
|
|
212
|
+
"eslint-plugin-import": "*",
|
|
213
|
+
"eslint-plugin-unicorn": "*"
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
## Comparison with Other OBIX Config Packages
|
|
221
|
+
|
|
222
|
+
| Feature | ESLint | TypeScript | Rollup | Webpack |
|
|
223
|
+
|---------|--------|------------|--------|---------|
|
|
224
|
+
| Primary role | Linting | Type checking | Library bundling | App bundling |
|
|
225
|
+
| TypeScript support | `typescript-eslint` | Native | `@rollup/plugin-typescript` | `ts-loader` |
|
|
226
|
+
| Output format | Report only | `.d.ts` + `.js` | ESM / CJS | Bundle |
|
|
227
|
+
| Best for | Code quality | Type safety | SDK packages | Browser apps |
|
|
228
|
+
|
|
229
|
+
Use ESLint **alongside** your build toolchain — not instead of it.
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## Author
|
|
234
|
+
|
|
235
|
+
**Nnamdi Michael Okpala** — OBINexus <okpalan@protonmail.com>
|
|
236
|
+
|
|
237
|
+
Part of the [OBIX Heart/Soul UI/UX SDK](https://github.com/OBINexusComputing/obix-sdk) monorepo.
|
package/base/.gitkeep
ADDED
|
File without changes
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// @obinexusltd/obix-config-eslint/base
|
|
2
|
+
// Base flat config — TypeScript-eslint recommended + OBIX core rules.
|
|
3
|
+
// Environment-neutral: suitable as a common foundation for dev and prod configs.
|
|
4
|
+
//
|
|
5
|
+
// Usage:
|
|
6
|
+
// import base from '@obinexusltd/obix-config-eslint/base';
|
|
7
|
+
// export default [...base, { rules: { 'no-console': 'off' } }];
|
|
8
|
+
|
|
9
|
+
import js from '@eslint/js';
|
|
10
|
+
import tseslint from 'typescript-eslint';
|
|
11
|
+
|
|
12
|
+
export default tseslint.config(
|
|
13
|
+
// ESLint recommended baseline
|
|
14
|
+
js.configs.recommended,
|
|
15
|
+
|
|
16
|
+
// typescript-eslint recommended rules (flat config array)
|
|
17
|
+
...tseslint.configs.recommended,
|
|
18
|
+
|
|
19
|
+
// OBIX base TypeScript rules
|
|
20
|
+
{
|
|
21
|
+
files: ['**/*.ts', '**/*.tsx'],
|
|
22
|
+
rules: {
|
|
23
|
+
// TypeScript
|
|
24
|
+
'@typescript-eslint/no-explicit-any': 'warn',
|
|
25
|
+
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
|
|
26
|
+
'@typescript-eslint/consistent-type-imports': ['warn', { prefer: 'type-imports' }],
|
|
27
|
+
'@typescript-eslint/no-non-null-assertion': 'warn',
|
|
28
|
+
|
|
29
|
+
// Best practices
|
|
30
|
+
'prefer-const': 'error',
|
|
31
|
+
'no-var': 'error',
|
|
32
|
+
'no-console': 'warn',
|
|
33
|
+
'no-debugger': 'error',
|
|
34
|
+
eqeqeq: ['error', 'always'],
|
|
35
|
+
curly: ['error', 'all'],
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
// Global ignores
|
|
40
|
+
{
|
|
41
|
+
ignores: ['dist/**', 'node_modules/**', '**/*.d.ts'],
|
|
42
|
+
},
|
|
43
|
+
);
|
|
File without changes
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// @obinexusltd/obix-config-eslint/development
|
|
2
|
+
// Development flat config — relaxes console/debugger and any-type rules.
|
|
3
|
+
// Extends the OBIX base config with developer-friendly overrides.
|
|
4
|
+
//
|
|
5
|
+
// Usage:
|
|
6
|
+
// import devConfig from '@obinexusltd/obix-config-eslint/development';
|
|
7
|
+
// export default [...devConfig, ...yourOverrides];
|
|
8
|
+
|
|
9
|
+
import base from '../base/eslint.config.js';
|
|
10
|
+
|
|
11
|
+
export default [
|
|
12
|
+
...base,
|
|
13
|
+
|
|
14
|
+
// Development-specific rule relaxations
|
|
15
|
+
{
|
|
16
|
+
rules: {
|
|
17
|
+
// Allow console during development
|
|
18
|
+
'no-console': 'off',
|
|
19
|
+
|
|
20
|
+
// Downgrade debugger from error to warning
|
|
21
|
+
'no-debugger': 'warn',
|
|
22
|
+
|
|
23
|
+
// Allow `any` during active development
|
|
24
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
25
|
+
|
|
26
|
+
// Type imports not enforced during development
|
|
27
|
+
'@typescript-eslint/consistent-type-imports': 'off',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
];
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/** ESLint build environment */
|
|
2
|
+
export type ESLintEnv = 'base' | 'development' | 'production';
|
|
3
|
+
/** Options accepted by all factory functions */
|
|
4
|
+
export interface ObixEsLintOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Enable TypeScript-specific rules via typescript-eslint.
|
|
7
|
+
* Default: `true`
|
|
8
|
+
*/
|
|
9
|
+
typescript?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Enable import ordering rules (requires optional `eslint-plugin-import`).
|
|
12
|
+
* Default: `false`
|
|
13
|
+
*/
|
|
14
|
+
imports?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Enable unicorn opinionated rules (requires optional `eslint-plugin-unicorn`).
|
|
17
|
+
* Default: `false`
|
|
18
|
+
*/
|
|
19
|
+
unicorn?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Glob patterns for files to lint.
|
|
22
|
+
* Default: `['**\/*.ts', '**\/*.tsx']`
|
|
23
|
+
*/
|
|
24
|
+
files?: string[];
|
|
25
|
+
/**
|
|
26
|
+
* Glob patterns for files to ignore.
|
|
27
|
+
* Default: `['dist/**', 'node_modules/**', '**\/*.d.ts']`
|
|
28
|
+
*/
|
|
29
|
+
ignores?: string[];
|
|
30
|
+
/**
|
|
31
|
+
* Additional rule overrides merged on top of the environment preset.
|
|
32
|
+
* Default: `{}`
|
|
33
|
+
*/
|
|
34
|
+
rules?: Record<string, unknown>;
|
|
35
|
+
}
|
|
36
|
+
/** Fully-resolved options — all fields present */
|
|
37
|
+
export type ResolvedObixEsLintOptions = Required<ObixEsLintOptions>;
|
|
38
|
+
/** Static descriptor used by obix-cli to introspect the config package */
|
|
39
|
+
export interface ObixEsLintConfig {
|
|
40
|
+
env: ESLintEnv;
|
|
41
|
+
options: ResolvedObixEsLintOptions;
|
|
42
|
+
}
|
|
43
|
+
export declare const baseConfig: ObixEsLintConfig;
|
|
44
|
+
export declare const developmentConfig: ObixEsLintConfig;
|
|
45
|
+
export declare const productionConfig: ObixEsLintConfig;
|
|
46
|
+
/**
|
|
47
|
+
* Create a base ESLint flat config array.
|
|
48
|
+
* Includes TypeScript-eslint recommended rules and OBIX base rules.
|
|
49
|
+
* Suitable as a starting point — extends `typescript-eslint/recommended`.
|
|
50
|
+
*
|
|
51
|
+
* Returns a plain array shaped like an ESLint v9 flat config.
|
|
52
|
+
* Consumer must spread with `@eslint/js` and `typescript-eslint` entries.
|
|
53
|
+
*/
|
|
54
|
+
export declare function createBaseConfig(opts?: ObixEsLintOptions): Array<Record<string, unknown>>;
|
|
55
|
+
/**
|
|
56
|
+
* Create a development ESLint flat config array.
|
|
57
|
+
* Relaxed rules: `no-console` off, `no-debugger` warn, `no-explicit-any` off.
|
|
58
|
+
*/
|
|
59
|
+
export declare function createDevConfig(opts?: ObixEsLintOptions): Array<Record<string, unknown>>;
|
|
60
|
+
/**
|
|
61
|
+
* Create a production ESLint flat config array.
|
|
62
|
+
* Strict rules: `no-console` error, `no-debugger` error, `no-explicit-any` error,
|
|
63
|
+
* `explicit-function-return-type` warn, `strict-boolean-expressions` warn.
|
|
64
|
+
*/
|
|
65
|
+
export declare function createProdConfig(opts?: ObixEsLintOptions): Array<Record<string, unknown>>;
|
|
66
|
+
/**
|
|
67
|
+
* Resolve an ESLint flat config array by environment name.
|
|
68
|
+
* Delegates to `createBaseConfig`, `createDevConfig`, or `createProdConfig`.
|
|
69
|
+
*/
|
|
70
|
+
export declare function resolveConfig(env: ESLintEnv, opts?: ObixEsLintOptions): Array<Record<string, unknown>>;
|
|
71
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,+BAA+B;AAC/B,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,aAAa,GAAG,YAAY,CAAC;AAE9D,gDAAgD;AAChD,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED,kDAAkD;AAClD,MAAM,MAAM,yBAAyB,GAAG,QAAQ,CAAC,iBAAiB,CAAC,CAAC;AAEpE,0EAA0E;AAC1E,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,SAAS,CAAC;IACf,OAAO,EAAE,yBAAyB,CAAC;CACpC;AAyBD,eAAO,MAAM,UAAU,EAAE,gBAGxB,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,gBAU/B,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,gBAY9B,CAAC;AAkEF;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,CAAC,EAAE,iBAAiB,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAMzF;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,CAAC,EAAE,iBAAiB,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAMxF;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,CAAC,EAAE,iBAAiB,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAMzF;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,GAAG,EAAE,SAAS,EACd,IAAI,CAAC,EAAE,iBAAiB,GACvB,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAOhC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// @obinexusltd/obix-config-eslint
|
|
2
|
+
// Programmatic ESLint configuration factory for OBIX SDK packages.
|
|
3
|
+
// NOTE: This module does NOT import eslint or typescript-eslint at compile time.
|
|
4
|
+
// All config objects are plain arrays matching ESLint v9 flat config shape.
|
|
5
|
+
// ESLint and typescript-eslint remain peerDependencies consumed at runtime.
|
|
6
|
+
// ─── Defaults ─────────────────────────────────────────────────────────────────
|
|
7
|
+
const DEFAULT_OPTIONS = {
|
|
8
|
+
typescript: true,
|
|
9
|
+
imports: false,
|
|
10
|
+
unicorn: false,
|
|
11
|
+
files: ['**/*.ts', '**/*.tsx'],
|
|
12
|
+
ignores: ['dist/**', 'node_modules/**', '**/*.d.ts'],
|
|
13
|
+
rules: {},
|
|
14
|
+
};
|
|
15
|
+
function resolveOptions(overrides) {
|
|
16
|
+
return {
|
|
17
|
+
...DEFAULT_OPTIONS,
|
|
18
|
+
...overrides,
|
|
19
|
+
files: overrides?.files ?? DEFAULT_OPTIONS.files,
|
|
20
|
+
ignores: overrides?.ignores ?? DEFAULT_OPTIONS.ignores,
|
|
21
|
+
rules: { ...DEFAULT_OPTIONS.rules, ...overrides?.rules },
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
// ─── Static descriptors (for obix-cli indexing) ───────────────────────────────
|
|
25
|
+
export const baseConfig = {
|
|
26
|
+
env: 'base',
|
|
27
|
+
options: { ...DEFAULT_OPTIONS },
|
|
28
|
+
};
|
|
29
|
+
export const developmentConfig = {
|
|
30
|
+
env: 'development',
|
|
31
|
+
options: {
|
|
32
|
+
...DEFAULT_OPTIONS,
|
|
33
|
+
rules: {
|
|
34
|
+
'no-console': 'off',
|
|
35
|
+
'no-debugger': 'warn',
|
|
36
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
export const productionConfig = {
|
|
41
|
+
env: 'production',
|
|
42
|
+
options: {
|
|
43
|
+
...DEFAULT_OPTIONS,
|
|
44
|
+
rules: {
|
|
45
|
+
'no-console': 'error',
|
|
46
|
+
'no-debugger': 'error',
|
|
47
|
+
'@typescript-eslint/no-explicit-any': 'error',
|
|
48
|
+
'@typescript-eslint/explicit-function-return-type': 'warn',
|
|
49
|
+
'@typescript-eslint/strict-boolean-expressions': 'warn',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
// ─── Internal helpers ──────────────────────────────────────────────────────────
|
|
54
|
+
/** Core TypeScript + best-practice rules for all environments */
|
|
55
|
+
function buildBaseRules(opts) {
|
|
56
|
+
const rules = {
|
|
57
|
+
'prefer-const': 'error',
|
|
58
|
+
'no-var': 'error',
|
|
59
|
+
'no-console': 'warn',
|
|
60
|
+
'no-debugger': 'error',
|
|
61
|
+
eqeqeq: ['error', 'always'],
|
|
62
|
+
curly: ['error', 'all'],
|
|
63
|
+
};
|
|
64
|
+
if (opts.typescript) {
|
|
65
|
+
Object.assign(rules, {
|
|
66
|
+
'@typescript-eslint/no-explicit-any': 'warn',
|
|
67
|
+
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
|
|
68
|
+
'@typescript-eslint/consistent-type-imports': ['warn', { prefer: 'type-imports' }],
|
|
69
|
+
'@typescript-eslint/no-non-null-assertion': 'warn',
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return { ...rules, ...opts.rules };
|
|
73
|
+
}
|
|
74
|
+
/** Relaxed rule overrides for development */
|
|
75
|
+
function buildDevRules(opts) {
|
|
76
|
+
return {
|
|
77
|
+
...buildBaseRules(opts),
|
|
78
|
+
'no-console': 'off',
|
|
79
|
+
'no-debugger': 'warn',
|
|
80
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
81
|
+
...opts.rules,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/** Strict rule overrides for production */
|
|
85
|
+
function buildProdRules(opts) {
|
|
86
|
+
return {
|
|
87
|
+
...buildBaseRules(opts),
|
|
88
|
+
'no-console': 'error',
|
|
89
|
+
'no-debugger': 'error',
|
|
90
|
+
'@typescript-eslint/no-explicit-any': 'error',
|
|
91
|
+
'@typescript-eslint/explicit-function-return-type': 'warn',
|
|
92
|
+
'@typescript-eslint/strict-boolean-expressions': 'warn',
|
|
93
|
+
...opts.rules,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/** Build the files config object for a flat config entry */
|
|
97
|
+
function buildFilesEntry(opts, rules) {
|
|
98
|
+
return { files: opts.files, rules };
|
|
99
|
+
}
|
|
100
|
+
/** Build the ignores config object for a flat config entry */
|
|
101
|
+
function buildIgnoresEntry(opts) {
|
|
102
|
+
return { ignores: opts.ignores };
|
|
103
|
+
}
|
|
104
|
+
// ─── Factory functions ─────────────────────────────────────────────────────────
|
|
105
|
+
/**
|
|
106
|
+
* Create a base ESLint flat config array.
|
|
107
|
+
* Includes TypeScript-eslint recommended rules and OBIX base rules.
|
|
108
|
+
* Suitable as a starting point — extends `typescript-eslint/recommended`.
|
|
109
|
+
*
|
|
110
|
+
* Returns a plain array shaped like an ESLint v9 flat config.
|
|
111
|
+
* Consumer must spread with `@eslint/js` and `typescript-eslint` entries.
|
|
112
|
+
*/
|
|
113
|
+
export function createBaseConfig(opts) {
|
|
114
|
+
const o = resolveOptions(opts);
|
|
115
|
+
return [
|
|
116
|
+
buildFilesEntry(o, buildBaseRules(o)),
|
|
117
|
+
buildIgnoresEntry(o),
|
|
118
|
+
];
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Create a development ESLint flat config array.
|
|
122
|
+
* Relaxed rules: `no-console` off, `no-debugger` warn, `no-explicit-any` off.
|
|
123
|
+
*/
|
|
124
|
+
export function createDevConfig(opts) {
|
|
125
|
+
const o = resolveOptions(opts);
|
|
126
|
+
return [
|
|
127
|
+
buildFilesEntry(o, buildDevRules(o)),
|
|
128
|
+
buildIgnoresEntry(o),
|
|
129
|
+
];
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Create a production ESLint flat config array.
|
|
133
|
+
* Strict rules: `no-console` error, `no-debugger` error, `no-explicit-any` error,
|
|
134
|
+
* `explicit-function-return-type` warn, `strict-boolean-expressions` warn.
|
|
135
|
+
*/
|
|
136
|
+
export function createProdConfig(opts) {
|
|
137
|
+
const o = resolveOptions(opts);
|
|
138
|
+
return [
|
|
139
|
+
buildFilesEntry(o, buildProdRules(o)),
|
|
140
|
+
buildIgnoresEntry(o),
|
|
141
|
+
];
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Resolve an ESLint flat config array by environment name.
|
|
145
|
+
* Delegates to `createBaseConfig`, `createDevConfig`, or `createProdConfig`.
|
|
146
|
+
*/
|
|
147
|
+
export function resolveConfig(env, opts) {
|
|
148
|
+
switch (env) {
|
|
149
|
+
case 'production': return createProdConfig(opts);
|
|
150
|
+
case 'development': return createDevConfig(opts);
|
|
151
|
+
case 'base':
|
|
152
|
+
default: return createBaseConfig(opts);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,mEAAmE;AACnE,iFAAiF;AACjF,4EAA4E;AAC5E,4EAA4E;AAkD5E,iFAAiF;AAEjF,MAAM,eAAe,GAA8B;IACjD,UAAU,EAAE,IAAI;IAChB,OAAO,EAAE,KAAK;IACd,OAAO,EAAE,KAAK;IACd,KAAK,EAAE,CAAC,SAAS,EAAE,UAAU,CAAC;IAC9B,OAAO,EAAE,CAAC,SAAS,EAAE,iBAAiB,EAAE,WAAW,CAAC;IACpD,KAAK,EAAE,EAAE;CACV,CAAC;AAEF,SAAS,cAAc,CAAC,SAA6B;IACnD,OAAO;QACL,GAAG,eAAe;QAClB,GAAG,SAAS;QACZ,KAAK,EAAE,SAAS,EAAE,KAAK,IAAI,eAAe,CAAC,KAAK;QAChD,OAAO,EAAE,SAAS,EAAE,OAAO,IAAI,eAAe,CAAC,OAAO;QACtD,KAAK,EAAE,EAAE,GAAG,eAAe,CAAC,KAAK,EAAE,GAAG,SAAS,EAAE,KAAK,EAAE;KACzD,CAAC;AACJ,CAAC;AAED,iFAAiF;AAEjF,MAAM,CAAC,MAAM,UAAU,GAAqB;IAC1C,GAAG,EAAE,MAAM;IACX,OAAO,EAAE,EAAE,GAAG,eAAe,EAAE;CAChC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAqB;IACjD,GAAG,EAAE,aAAa;IAClB,OAAO,EAAE;QACP,GAAG,eAAe;QAClB,K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AAE,cAAc,CAAC,CAAC,CAAC,CAAC;QACrC,iBAAiB,CAAC,CAAC,CAAC;KACrB,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAC3B,GAAc,EACd,IAAwB;IAExB,QAAQ,GAAG,EAAE,CAAC;QACZ,KAAK,YAAY,CAAC,CAAC,OAAO,gBAAgB,CAAC,IAAI,CAAC,CAAC;QACjD,KAAK,aAAa,CAAC,CAAC,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC;QACjD,KAAK,MAAM,CAAC;QACZ,OAAO,CAAC,CAAW,OAAO,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACnD,CAAC;AACH,CAAC"}
|
package/eslint.config.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// @obinexusltd/obix-config-eslint — root flat config (./flat export)
|
|
2
|
+
// Ready-to-use ESLint v9 flat config with OBIX TypeScript defaults.
|
|
3
|
+
//
|
|
4
|
+
// Usage:
|
|
5
|
+
// // eslint.config.js in consumer package
|
|
6
|
+
// import obixConfig from '@obinexusltd/obix-config-eslint/flat';
|
|
7
|
+
// export default [...obixConfig, ...yourOverrides];
|
|
8
|
+
//
|
|
9
|
+
// Or with tseslint.config():
|
|
10
|
+
// import tseslint from 'typescript-eslint';
|
|
11
|
+
// import obixConfig from '@obinexusltd/obix-config-eslint/flat';
|
|
12
|
+
// export default tseslint.config(...obixConfig, { rules: { ... } });
|
|
13
|
+
|
|
14
|
+
import js from '@eslint/js';
|
|
15
|
+
import tseslint from 'typescript-eslint';
|
|
16
|
+
|
|
17
|
+
export default tseslint.config(
|
|
18
|
+
// ESLint recommended baseline
|
|
19
|
+
js.configs.recommended,
|
|
20
|
+
|
|
21
|
+
// typescript-eslint recommended rules (flat config array)
|
|
22
|
+
...tseslint.configs.recommended,
|
|
23
|
+
|
|
24
|
+
// OBIX standard TypeScript rules
|
|
25
|
+
{
|
|
26
|
+
files: ['**/*.ts', '**/*.tsx'],
|
|
27
|
+
rules: {
|
|
28
|
+
// TypeScript
|
|
29
|
+
'@typescript-eslint/no-explicit-any': 'warn',
|
|
30
|
+
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
|
|
31
|
+
'@typescript-eslint/consistent-type-imports': ['warn', { prefer: 'type-imports' }],
|
|
32
|
+
'@typescript-eslint/no-non-null-assertion': 'warn',
|
|
33
|
+
|
|
34
|
+
// Best practices
|
|
35
|
+
'prefer-const': 'error',
|
|
36
|
+
'no-var': 'error',
|
|
37
|
+
'no-console': 'warn',
|
|
38
|
+
'no-debugger': 'error',
|
|
39
|
+
eqeqeq: ['error', 'always'],
|
|
40
|
+
curly: ['error', 'all'],
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
// Global ignores
|
|
45
|
+
{
|
|
46
|
+
ignores: ['dist/**', 'node_modules/**', '**/*.d.ts'],
|
|
47
|
+
},
|
|
48
|
+
);
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@obinexusltd/obix-config-eslint",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "OBIX ESLint configuration for OBIX CLI and SDK packages",
|
|
5
|
+
"author": "Nnamdi Michael Okpala <okpalan@protonmail.com>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts"
|
|
14
|
+
},
|
|
15
|
+
"./base": "./base/eslint.config.js",
|
|
16
|
+
"./development": "./development/eslint.config.js",
|
|
17
|
+
"./production": "./production/eslint.config.js",
|
|
18
|
+
"./flat": "./eslint.config.js"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"eslint.config.js",
|
|
23
|
+
"base",
|
|
24
|
+
"development",
|
|
25
|
+
"production"
|
|
26
|
+
],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc",
|
|
29
|
+
"test": "echo \"No tests for config package\" && exit 0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"typescript": "^5.4.0"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@eslint/js": ">=9.0.0",
|
|
36
|
+
"eslint": ">=9.0.0",
|
|
37
|
+
"typescript-eslint": ">=8.0.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependenciesMeta": {
|
|
40
|
+
"eslint-plugin-import": { "optional": true },
|
|
41
|
+
"eslint-plugin-unicorn": { "optional": true }
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// @obinexusltd/obix-config-eslint/production
|
|
2
|
+
// Production flat config — enforces maximum strictness for release builds.
|
|
3
|
+
// Extends the OBIX base config with production-hardened overrides.
|
|
4
|
+
//
|
|
5
|
+
// Usage:
|
|
6
|
+
// import prodConfig from '@obinexusltd/obix-config-eslint/production';
|
|
7
|
+
// export default [...prodConfig, ...yourOverrides];
|
|
8
|
+
|
|
9
|
+
import base from '../base/eslint.config.js';
|
|
10
|
+
|
|
11
|
+
export default [
|
|
12
|
+
...base,
|
|
13
|
+
|
|
14
|
+
// Production-specific strict overrides
|
|
15
|
+
{
|
|
16
|
+
rules: {
|
|
17
|
+
// No console output in production code
|
|
18
|
+
'no-console': 'error',
|
|
19
|
+
|
|
20
|
+
// No leftover debugger statements
|
|
21
|
+
'no-debugger': 'error',
|
|
22
|
+
|
|
23
|
+
// Disallow `any` — forces explicit typing
|
|
24
|
+
'@typescript-eslint/no-explicit-any': 'error',
|
|
25
|
+
|
|
26
|
+
// Require explicit return types on exported functions
|
|
27
|
+
'@typescript-eslint/explicit-function-return-type': 'warn',
|
|
28
|
+
|
|
29
|
+
// Prevent unintended boolean coercions
|
|
30
|
+
'@typescript-eslint/strict-boolean-expressions': 'warn',
|
|
31
|
+
|
|
32
|
+
// Enforce type imports for tree-shaking
|
|
33
|
+
'@typescript-eslint/consistent-type-imports': ['error', { prefer: 'type-imports' }],
|
|
34
|
+
|
|
35
|
+
// No non-null assertions in production
|
|
36
|
+
'@typescript-eslint/no-non-null-assertion': 'error',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
];
|