@dloizides/frontend-devtools 1.0.1

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.
Files changed (37) hide show
  1. package/.eslintrc.js +34 -0
  2. package/CHANGELOG.md +26 -0
  3. package/LICENSE +21 -0
  4. package/README.md +131 -0
  5. package/jest.config.js +24 -0
  6. package/package.json +104 -0
  7. package/publish.ps1 +107 -0
  8. package/src/eslint/index.ts +16 -0
  9. package/src/eslint/legacy.ts +44 -0
  10. package/src/eslint/plugin.test.ts +60 -0
  11. package/src/eslint/plugin.ts +87 -0
  12. package/src/eslint/rules.behaviour.test.ts +86 -0
  13. package/src/eslint/rules.d.ts +16 -0
  14. package/src/eslint/types.ts +27 -0
  15. package/src/i18n/initI18n.test.ts +101 -0
  16. package/src/i18n/initI18n.ts +109 -0
  17. package/src/index.ts +31 -0
  18. package/src/rules/enforce-function-style.js +278 -0
  19. package/src/rules/enforce-module-structure.js +323 -0
  20. package/src/rules/enforce-route-preload.js +288 -0
  21. package/src/rules/enforce-test-colocation.js +82 -0
  22. package/src/rules/enum-file-isolation.js +149 -0
  23. package/src/rules/i18n-interpolation.js +185 -0
  24. package/src/rules/i18n-param-names.js +119 -0
  25. package/src/rules/no-barrel-companion-file.js +142 -0
  26. package/src/rules/no-duplicate-nav-prefix.js +107 -0
  27. package/src/rules/no-duplicate-shared-patterns.js +166 -0
  28. package/src/rules/no-generated-models-barrel-value-import.js +70 -0
  29. package/src/rules/no-null-check.js +171 -0
  30. package/src/rules/no-optional-undefined.js +99 -0
  31. package/src/rules/no-product-imports-in-shared.js +164 -0
  32. package/src/rules/prefer-const-enum.js +127 -0
  33. package/src/rules/require-stable-hook-args.js +372 -0
  34. package/src/rules/smart-max-lines.js +344 -0
  35. package/tsconfig.json +25 -0
  36. package/tsconfig.test.json +11 -0
  37. package/tsup.config.ts +14 -0
package/.eslintrc.js ADDED
@@ -0,0 +1,34 @@
1
+ /** @type {import('eslint').Linter.Config} */
2
+ module.exports = {
3
+ root: true,
4
+ parser: '@typescript-eslint/parser',
5
+ parserOptions: {
6
+ ecmaVersion: 2020,
7
+ sourceType: 'module',
8
+ project: './tsconfig.json',
9
+ },
10
+ plugins: ['@typescript-eslint', 'import'],
11
+ extends: [
12
+ 'eslint:recommended',
13
+ 'plugin:@typescript-eslint/recommended',
14
+ 'plugin:@typescript-eslint/recommended-requiring-type-checking',
15
+ 'plugin:import/recommended',
16
+ 'plugin:import/typescript',
17
+ ],
18
+ env: {
19
+ node: true,
20
+ es2020: true,
21
+ },
22
+ rules: {
23
+ '@typescript-eslint/no-explicit-any': 'error',
24
+ '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
25
+ '@typescript-eslint/explicit-function-return-type': 'error',
26
+ '@typescript-eslint/no-non-null-assertion': 'error',
27
+ 'no-console': 'error',
28
+ 'eqeqeq': ['error', 'always'],
29
+ 'curly': ['error', 'all'],
30
+ },
31
+ // The .mjs rule implementations are vendored ESLint rules (not part of the
32
+ // package's own typed source) and the generated dist/test files are excluded.
33
+ ignorePatterns: ['dist/', 'node_modules/', '*.js', '**/*.mjs', '**/*.test.ts'],
34
+ };
package/CHANGELOG.md ADDED
@@ -0,0 +1,26 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@dloizides/frontend-devtools` are documented here.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [1.0.0] - 2026-06-14
9
+
10
+ ### Added
11
+
12
+ - Initial extraction of the shared RN-web dev tooling duplicated across
13
+ erevna-web, katalogos-web, and kefi-web.
14
+ - **ESLint custom rule pack** (17 rules) exported as `plugin` / `rules` /
15
+ `legacyPlugins`, also available under the `@dloizides/frontend-devtools/eslint`
16
+ subpath. Rule names preserved byte-for-byte so existing config keys and
17
+ `eslint-disable-next-line <rule>` comments keep working:
18
+ `enforce-function-style`, `enforce-module-structure`, `enforce-route-preload`,
19
+ `enforce-test-colocation`, `enum-file-isolation`, `i18n-interpolation`,
20
+ `i18n-param-names`, `no-barrel-companion-file`, `no-duplicate-nav-prefix`,
21
+ `no-duplicate-shared-patterns`, `no-generated-models-barrel-value-import`,
22
+ `no-null-check`, `no-optional-undefined`, `no-product-imports-in-shared`,
23
+ `prefer-const-enum`, `require-stable-hook-args`, `smart-max-lines`.
24
+ - **`initI18n(options)`** — parameterized i18next + react-i18next init factory.
25
+ Carries the `import/no-named-as-default-member` disable so apps stop repeating
26
+ it. The app owns its `locales/*.json` strings and the active language.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 dloizides
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,131 @@
1
+ # @dloizides/frontend-devtools
2
+
3
+ Shared **RN-web dev tooling** for the dloizides.com SaaS frontends. Extracts two
4
+ product-agnostic concerns that were duplicated byte-for-byte across
5
+ `erevna-web`, `katalogos-web`, and `kefi-web`:
6
+
7
+ 1. The **custom ESLint rule pack** (17 rules) — previously 17 identical
8
+ `eslint-plugins/*.mjs` files in each app.
9
+ 2. **`initI18n()`** — the parameterized i18next + react-i18next init factory —
10
+ previously an identical `src/localization/i18n.ts` in each app.
11
+
12
+ > **Decoupling:** the package owns the *logic* (rule implementations + the
13
+ > i18next `.use().init()` chain). Each app owns its *config* — which rules it
14
+ > enables and with what options, plus its own `locales/*.json` strings.
15
+ > This package **never imports a product**.
16
+
17
+ ## Install
18
+
19
+ ```sh
20
+ npm install -D @dloizides/frontend-devtools
21
+ ```
22
+
23
+ `eslint`, `i18next`, and `react-i18next` are optional peer dependencies — apps
24
+ that only use one half don't need the other's peers.
25
+
26
+ ## ESLint rule pack
27
+
28
+ Import from the root or the `/eslint` subpath. Three shapes are exported:
29
+
30
+ | Export | Use when |
31
+ | --- | --- |
32
+ | `plugin` | You want one namespaced plugin, e.g. `'@dloizides/no-null-check'`. |
33
+ | `rules` | You want the raw `Record<name, rule>` map. |
34
+ | `legacyPlugins` | **Migration:** keep the exact `<name>/<name>` keys the apps already use. |
35
+
36
+ ### Migrating the apps (zero config-key churn)
37
+
38
+ The apps registered each rule under a namespace equal to its name
39
+ (`'no-null-check/no-null-check'`, `'smart-max-lines/smart-max-lines'`, …), and
40
+ inline `eslint-disable-next-line no-null-check/no-null-check` comments depend on
41
+ that. Spread `legacyPlugins` to preserve every key:
42
+
43
+ ```js
44
+ // eslint.config.mjs
45
+ import { legacyPlugins } from '@dloizides/frontend-devtools/eslint';
46
+
47
+ export default [
48
+ {
49
+ files: ['**/*.ts', '**/*.tsx'],
50
+ plugins: { ...legacyPlugins },
51
+ rules: {
52
+ 'no-null-check/no-null-check': 'error',
53
+ 'smart-max-lines/smart-max-lines': ['error', { functionMax: 50 }],
54
+ // ...existing keys unchanged
55
+ },
56
+ },
57
+ ];
58
+ ```
59
+
60
+ Delete the local `eslint-plugins/*.mjs` files and their imports; the rule names,
61
+ options, and severities stay exactly as they were.
62
+
63
+ ### Namespaced plugin (alternative)
64
+
65
+ ```js
66
+ import { plugin as devtools } from '@dloizides/frontend-devtools/eslint';
67
+
68
+ export default [
69
+ {
70
+ plugins: { '@dloizides': devtools },
71
+ rules: { '@dloizides/no-null-check': 'error' },
72
+ },
73
+ ];
74
+ ```
75
+
76
+ ### Rules
77
+
78
+ `enforce-function-style`, `enforce-module-structure`, `enforce-route-preload`,
79
+ `enforce-test-colocation`, `enum-file-isolation`, `i18n-interpolation`,
80
+ `i18n-param-names`, `no-barrel-companion-file`, `no-duplicate-nav-prefix`,
81
+ `no-duplicate-shared-patterns`, `no-generated-models-barrel-value-import`,
82
+ `no-null-check`, `no-optional-undefined`, `no-product-imports-in-shared`,
83
+ `prefer-const-enum`, `require-stable-hook-args`, `smart-max-lines`.
84
+
85
+ `ruleNames` exports the sorted list for migration assertions (prove no rule was
86
+ dropped).
87
+
88
+ ## i18n init factory
89
+
90
+ ```ts
91
+ // src/localization/i18n.ts
92
+ import { initI18n } from '@dloizides/frontend-devtools';
93
+ import * as Localization from 'expo-localization';
94
+ import en from './locales/en.json';
95
+
96
+ const i18n = initI18n({
97
+ resources: { en: { translation: en } },
98
+ lng: Localization.getLocales()[0]?.languageCode, // optional; defaults to fallback
99
+ });
100
+
101
+ export default i18n;
102
+ ```
103
+
104
+ ### `InitI18nOptions`
105
+
106
+ | Field | Type | Default | Notes |
107
+ | --- | --- | --- | --- |
108
+ | `resources` | `Resource` | — (required) | App-owned strings bundle. |
109
+ | `lng` | `string` | `fallbackLng` | Active language. |
110
+ | `fallbackLng` | `string` | `'en'` | Fallback for missing keys. |
111
+ | `escapeValue` | `boolean` | `false` | React already escapes output. |
112
+ | `defaultNS` | `string \| string[]` | i18next default | Optional. |
113
+ | `ns` | `string \| string[]` | — | Optional; for multi-namespace apps. |
114
+
115
+ The factory wires `react-i18next` into the i18next singleton, runs `.init()`,
116
+ swallows the (synchronous-for-in-memory) init rejection, and returns the
117
+ singleton. The `FM()` / `FD()` helpers + `locales/*.json` stay **app-owned**
118
+ (per the SaaS code standards).
119
+
120
+ ## Scripts
121
+
122
+ | Script | What |
123
+ | --- | --- |
124
+ | `npm run build` | Bundle with tsup (CJS + ESM + d.ts). |
125
+ | `npm test` | Jest (rule behaviour via `RuleTester` + i18n init). |
126
+ | `npm run typecheck` | `tsc --noEmit`. |
127
+ | `npm run lint` | ESLint over `src`. |
128
+
129
+ ## License
130
+
131
+ MIT © dloizides
package/jest.config.js ADDED
@@ -0,0 +1,24 @@
1
+ /** @type {import('jest').Config} */
2
+ module.exports = {
3
+ preset: 'ts-jest',
4
+ testEnvironment: 'jsdom',
5
+ roots: ['<rootDir>/src'],
6
+ testMatch: ['**/*.test.ts'],
7
+ // The custom ESLint rules are authored as plain ESM JS (`src/rules/*.js`);
8
+ // ts-jest compiles them (allowJs) so they can be imported from the TS
9
+ // plugin aggregator.
10
+ moduleFileExtensions: ['ts', 'js', 'json'],
11
+ collectCoverageFrom: [
12
+ 'src/**/*.ts',
13
+ 'src/rules/*.js',
14
+ '!src/**/*.d.ts',
15
+ '!src/**/index.ts',
16
+ ],
17
+ coverageReporters: ['text', 'lcov', 'html'],
18
+ transform: {
19
+ // isolatedModules: transpile-only. Type-safety is enforced by the separate
20
+ // `tsc --noEmit` typecheck (which uses the ambient `*.js` declaration); here
21
+ // we only need the rule files compiled to runnable CJS for the tests.
22
+ '^.+\\.(ts|js)$': ['ts-jest', { tsconfig: 'tsconfig.test.json' }],
23
+ },
24
+ };
package/package.json ADDED
@@ -0,0 +1,104 @@
1
+ {
2
+ "name": "@dloizides/frontend-devtools",
3
+ "version": "1.0.1",
4
+ "description": "Shared RN-web dev tooling for the dloizides.com SaaS frontends: the 17-rule custom ESLint plugin pack (also at the /eslint subpath) and the parameterized initI18n() i18next + react-i18next init factory. Owned shape erevna-web / katalogos-web / kefi-web shared byte-for-byte; never imports a product.",
5
+ "keywords": [
6
+ "eslint",
7
+ "eslint-plugin",
8
+ "i18next",
9
+ "react-i18next",
10
+ "react-native",
11
+ "dev-tooling",
12
+ "dloizides"
13
+ ],
14
+ "author": "dloizides",
15
+ "license": "MIT",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/openmindednewby/frontend-devtools.git"
19
+ },
20
+ "homepage": "https://github.com/openmindednewby/frontend-devtools#readme",
21
+ "bugs": {
22
+ "url": "https://github.com/openmindednewby/frontend-devtools/issues"
23
+ },
24
+ "main": "./dist/index.js",
25
+ "module": "./dist/index.mjs",
26
+ "types": "./dist/index.d.ts",
27
+ "exports": {
28
+ ".": {
29
+ "require": {
30
+ "types": "./dist/index.d.ts",
31
+ "default": "./dist/index.js"
32
+ },
33
+ "import": {
34
+ "types": "./dist/index.d.mts",
35
+ "default": "./dist/index.mjs"
36
+ }
37
+ },
38
+ "./eslint": {
39
+ "require": {
40
+ "types": "./dist/eslint/index.d.ts",
41
+ "default": "./dist/eslint/index.js"
42
+ },
43
+ "import": {
44
+ "types": "./dist/eslint/index.d.mts",
45
+ "default": "./dist/eslint/index.mjs"
46
+ }
47
+ }
48
+ },
49
+ "sideEffects": false,
50
+ "engines": {
51
+ "node": ">=18.0.0"
52
+ },
53
+ "scripts": {
54
+ "build": "rimraf dist && tsup",
55
+ "build:watch": "tsup --watch",
56
+ "test": "jest",
57
+ "test:watch": "jest --watch",
58
+ "test:coverage": "jest --coverage",
59
+ "lint": "eslint src --ext .ts",
60
+ "lint:fix": "eslint src --ext .ts --fix",
61
+ "typecheck": "tsc --noEmit",
62
+ "clean": "rimraf dist",
63
+ "security:audit": "npm audit --audit-level=high",
64
+ "deps:outdated": "npm outdated || exit 0",
65
+ "deps:unused": "npx depcheck --ignores \"@types/jest,@types/node,rimraf,@typescript-eslint/parser\"",
66
+ "deps:licenses": "npx license-checker --onlyAllow \"MIT;Apache-2.0;ISC;BSD-2-Clause;BSD-3-Clause;0BSD;Unlicense;CC0-1.0\"",
67
+ "deps:health": "npm run deps:outdated && npm run deps:unused",
68
+ "prepublishOnly": "npm run clean && npm run build && npm run test"
69
+ },
70
+ "peerDependencies": {
71
+ "eslint": ">=8.0.0",
72
+ "i18next": ">=23.0.0",
73
+ "react-i18next": ">=13.0.0"
74
+ },
75
+ "peerDependenciesMeta": {
76
+ "eslint": {
77
+ "optional": true
78
+ },
79
+ "i18next": {
80
+ "optional": true
81
+ },
82
+ "react-i18next": {
83
+ "optional": true
84
+ }
85
+ },
86
+ "devDependencies": {
87
+ "@types/eslint": "^8.56.12",
88
+ "@types/jest": "^29.5.0",
89
+ "@types/node": "^20.19.32",
90
+ "@typescript-eslint/eslint-plugin": "^7.0.0",
91
+ "@typescript-eslint/parser": "^7.0.0",
92
+ "eslint": "^8.57.0",
93
+ "eslint-plugin-import": "^2.32.0",
94
+ "i18next": "^23.0.0",
95
+ "jest": "^29.7.0",
96
+ "jest-environment-jsdom": "^29.7.0",
97
+ "react": "^18.0.0",
98
+ "react-i18next": "^13.0.0",
99
+ "rimraf": "^5.0.0",
100
+ "ts-jest": "^29.1.0",
101
+ "tsup": "^8.0.0",
102
+ "typescript": "^5.4.0"
103
+ }
104
+ }
package/publish.ps1 ADDED
@@ -0,0 +1,107 @@
1
+ [CmdletBinding()]
2
+ param(
3
+ [Parameter(Mandatory = $true)]
4
+ [ValidateSet("patch", "minor", "major")]
5
+ [string]$Bump
6
+ )
7
+
8
+ Set-StrictMode -Version Latest
9
+ $ErrorActionPreference = "Stop"
10
+
11
+ # Use npm.cmd on Windows to avoid PowerShell wrapper issues with strict mode
12
+ $npmCmd = if ($env:OS -match "Windows") { "npm.cmd" } else { "npm" }
13
+
14
+ $repoRoot = $PSScriptRoot
15
+ $packageJsonPath = Join-Path $repoRoot "package.json"
16
+
17
+ if (-not (Test-Path $packageJsonPath)) {
18
+ throw "Missing file: $packageJsonPath"
19
+ }
20
+
21
+ # Read package.json
22
+ # Defensive: strip BOM if a prior failed publish corrupted package.json.
23
+ $rawPkg = Get-Content -Path $packageJsonPath -Raw
24
+ if ($rawPkg.Length -gt 0 -and $rawPkg[0] -eq [char]0xFEFF) { $rawPkg = $rawPkg.Substring(1) }
25
+ $packageJson = $rawPkg | ConvertFrom-Json
26
+ $packageName = $packageJson.name
27
+ $currentVersion = $packageJson.version
28
+
29
+ Write-Host "Building and publishing $packageName package..." -ForegroundColor Cyan
30
+ Write-Host "Current Version: $currentVersion"
31
+ Write-Host "Bump Type: $Bump"
32
+ Write-Host ""
33
+
34
+ try {
35
+ Push-Location $repoRoot
36
+
37
+ # Step 1: Clean
38
+ Write-Host "Step 1: Cleaning previous build..." -ForegroundColor Yellow
39
+ & $npmCmd run clean
40
+ if ($LASTEXITCODE -ne 0) { throw "& $npmCmd run clean failed" }
41
+
42
+ # Step 2: Install dependencies
43
+ Write-Host ""
44
+ Write-Host "Step 2: Installing dependencies..." -ForegroundColor Yellow
45
+ & $npmCmd ci
46
+ if ($LASTEXITCODE -ne 0) { throw "& $npmCmd ci failed" }
47
+
48
+ # Step 3: Lint
49
+ Write-Host ""
50
+ Write-Host "Step 3: Linting..." -ForegroundColor Yellow
51
+ & $npmCmd run lint
52
+ if ($LASTEXITCODE -ne 0) { throw "& $npmCmd run lint failed" }
53
+
54
+ # Step 4: Type check
55
+ Write-Host ""
56
+ Write-Host "Step 4: Type checking..." -ForegroundColor Yellow
57
+ & $npmCmd run typecheck
58
+ if ($LASTEXITCODE -ne 0) { throw "& $npmCmd run typecheck failed" }
59
+
60
+ # Step 5: Test
61
+ Write-Host ""
62
+ Write-Host "Step 5: Running tests..." -ForegroundColor Yellow
63
+ & $npmCmd test
64
+ if ($LASTEXITCODE -ne 0) { throw "& $npmCmd test failed" }
65
+
66
+ # Step 6: Build
67
+ Write-Host ""
68
+ Write-Host "Step 6: Building..." -ForegroundColor Yellow
69
+ & $npmCmd run build
70
+ if ($LASTEXITCODE -ne 0) { throw "& $npmCmd run build failed" }
71
+
72
+ # Step 7: Version bump
73
+ Write-Host ""
74
+ Write-Host "Step 7: Bumping version ($Bump)..." -ForegroundColor Yellow
75
+ & $npmCmd version $Bump --no-git-tag-version
76
+ if ($LASTEXITCODE -ne 0) { throw "npm version failed" }
77
+
78
+ # Read new version
79
+ $packageJson = Get-Content -Path $packageJsonPath -Raw | ConvertFrom-Json
80
+ $newVersion = $packageJson.version
81
+
82
+ Write-Host "Version: $currentVersion -> $newVersion" -ForegroundColor Green
83
+
84
+ # Step 8: Publish
85
+ Write-Host ""
86
+ Write-Host "Step 8: Publishing to npm..." -ForegroundColor Yellow
87
+ & $npmCmd publish --access public
88
+ if ($LASTEXITCODE -ne 0) { throw "npm publish failed" }
89
+
90
+ Write-Host ""
91
+ Write-Host "Successfully published $packageName@$newVersion to npm!" -ForegroundColor Green
92
+ }
93
+ catch {
94
+ # Rollback version on failure
95
+ Write-Warning "Build/publish failed. Attempting to rollback version change..."
96
+ $packageJson = Get-Content -Path $packageJsonPath -Raw | ConvertFrom-Json
97
+ $packageJson.version = $currentVersion
98
+ # PS 5.x 'utf8' includes a BOM that breaks downstream JSON parsers (e.g. Metro).
99
+ # Write UTF-8 without BOM explicitly.
100
+ $utf8NoBom = [System.Text.UTF8Encoding]::new($false)
101
+ [System.IO.File]::WriteAllText($packageJsonPath, ($packageJson | ConvertTo-Json -Depth 100), $utf8NoBom)
102
+ Write-Warning "Rolled back version in package.json to $currentVersion"
103
+ throw
104
+ }
105
+ finally {
106
+ Pop-Location
107
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * `@dloizides/frontend-devtools/eslint` — the shared custom ESLint rule pack.
3
+ *
4
+ * The 17 rule implementations are owned here (they were previously duplicated
5
+ * byte-for-byte in erevna-web and katalogos-web `eslint-plugins/*.mjs`). The app
6
+ * owns WHICH rules it enables and their options + severities; the package owns
7
+ * the rule logic.
8
+ */
9
+ export { plugin, rules, ruleNames } from './plugin';
10
+ export { legacyPlugins } from './legacy';
11
+ export type {
12
+ CustomRule,
13
+ FlatConfigPlugin,
14
+ FlatConfig,
15
+ SingleRulePlugin,
16
+ } from './types';
@@ -0,0 +1,44 @@
1
+ import type { CustomRule, FlatConfigPlugin } from './types';
2
+
3
+ import { rules } from './plugin';
4
+
5
+ /**
6
+ * The apps historically registered each custom rule under a namespace EQUAL to
7
+ * its rule name, e.g. `plugins: { 'no-null-check': plugin }` with the rule keyed
8
+ * as `'no-null-check/no-null-check'`. Inline `eslint-disable-next-line
9
+ * no-null-check/no-null-check` comments and config keys depend on that exact
10
+ * `<name>/<name>` shape.
11
+ *
12
+ * To migrate WITHOUT changing a single config key or disable comment, the app
13
+ * spreads {@link legacyPlugins} into its flat config's `plugins` map. Each rule
14
+ * name maps to a one-rule plugin object holding that rule — reproducing the old
15
+ * `import xPlugin from './eslint-plugins/x.mjs'` registration byte-for-byte.
16
+ *
17
+ * ```js
18
+ * import { legacyPlugins } from '@dloizides/frontend-devtools/eslint';
19
+ * export default [{
20
+ * plugins: { ...legacyPlugins },
21
+ * rules: {
22
+ * 'no-null-check/no-null-check': 'error', // unchanged
23
+ * 'smart-max-lines/smart-max-lines': ['error', { functionMax: 50 }],
24
+ * },
25
+ * }];
26
+ * ```
27
+ */
28
+ export const legacyPlugins: Record<string, FlatConfigPlugin> = buildLegacyPlugins();
29
+
30
+ function buildLegacyPlugins(): Record<string, FlatConfigPlugin> {
31
+ const out: Record<string, FlatConfigPlugin> = {};
32
+ for (const [name, rule] of Object.entries(rules)) {
33
+ out[name] = oneRulePlugin(name, rule);
34
+ }
35
+
36
+ return out;
37
+ }
38
+
39
+ function oneRulePlugin(name: string, rule: CustomRule): FlatConfigPlugin {
40
+ return {
41
+ meta: { name, version: '1.0.0' },
42
+ rules: { [name]: rule },
43
+ };
44
+ }
@@ -0,0 +1,60 @@
1
+ import { plugin, rules, ruleNames } from './plugin';
2
+ import { legacyPlugins } from './legacy';
3
+
4
+ // The exact 17 rule names that lived in the apps' `eslint-plugins/*.mjs`.
5
+ // If a rule is dropped or renamed during migration, this list breaks — which is
6
+ // the whole point (config keys + `eslint-disable-next-line <name>` must stay
7
+ // stable across the extraction).
8
+ const EXPECTED_RULE_NAMES = [
9
+ 'enforce-function-style',
10
+ 'enforce-module-structure',
11
+ 'enforce-route-preload',
12
+ 'enforce-test-colocation',
13
+ 'enum-file-isolation',
14
+ 'i18n-interpolation',
15
+ 'i18n-param-names',
16
+ 'no-barrel-companion-file',
17
+ 'no-duplicate-nav-prefix',
18
+ 'no-duplicate-shared-patterns',
19
+ 'no-generated-models-barrel-value-import',
20
+ 'no-null-check',
21
+ 'no-optional-undefined',
22
+ 'no-product-imports-in-shared',
23
+ 'prefer-const-enum',
24
+ 'require-stable-hook-args',
25
+ 'smart-max-lines',
26
+ ].sort();
27
+
28
+ describe('frontend-devtools eslint plugin', () => {
29
+ it('exposes all 17 shared rules', () => {
30
+ expect(ruleNames).toEqual(EXPECTED_RULE_NAMES);
31
+ });
32
+
33
+ it('exposes the rule map under plugin.rules and the rules export', () => {
34
+ expect(Object.keys(plugin.rules).sort()).toEqual(EXPECTED_RULE_NAMES);
35
+ expect(rules).toBe(plugin.rules);
36
+ });
37
+
38
+ it('carries plugin meta', () => {
39
+ expect(plugin.meta.name).toBe('@dloizides/frontend-devtools');
40
+ expect(typeof plugin.meta.version).toBe('string');
41
+ });
42
+
43
+ it('every rule is a valid rule module with create()', () => {
44
+ for (const name of ruleNames)
45
+ expect(typeof rules[name].create).toBe('function');
46
+ });
47
+
48
+ it('builds one legacy plugin per rule, keyed by rule name', () => {
49
+ expect(Object.keys(legacyPlugins).sort()).toEqual(EXPECTED_RULE_NAMES);
50
+ });
51
+
52
+ it('each legacy plugin holds exactly its own rule under <name>/<name>', () => {
53
+ for (const name of ruleNames) {
54
+ const legacy = legacyPlugins[name];
55
+ expect(Object.keys(legacy.rules)).toEqual([name]);
56
+ // The same rule object the merged plugin exposes (no copy/drift).
57
+ expect(legacy.rules[name]).toBe(rules[name]);
58
+ }
59
+ });
60
+ });
@@ -0,0 +1,87 @@
1
+ import type { CustomRule, FlatConfigPlugin, SingleRulePlugin } from './types';
2
+
3
+ // The 17 shared custom rules (byte-for-byte the rule logic that lived in
4
+ // erevna-web / katalogos-web `eslint-plugins/*.mjs`). Each module
5
+ // default-exports `{ rules: { '<name>': rule } }`.
6
+ import enforceFunctionStyle from '../rules/enforce-function-style.js';
7
+ import enforceModuleStructure from '../rules/enforce-module-structure.js';
8
+ import enforceRoutePreload from '../rules/enforce-route-preload.js';
9
+ import enforceTestColocation from '../rules/enforce-test-colocation.js';
10
+ import enumFileIsolation from '../rules/enum-file-isolation.js';
11
+ import i18nInterpolation from '../rules/i18n-interpolation.js';
12
+ import i18nParamNames from '../rules/i18n-param-names.js';
13
+ import noBarrelCompanionFile from '../rules/no-barrel-companion-file.js';
14
+ import noDuplicateNavPrefix from '../rules/no-duplicate-nav-prefix.js';
15
+ import noDuplicateSharedPatterns from '../rules/no-duplicate-shared-patterns.js';
16
+ import noGeneratedModelsBarrelValueImport from '../rules/no-generated-models-barrel-value-import.js';
17
+ import noNullCheck from '../rules/no-null-check.js';
18
+ import noOptionalUndefined from '../rules/no-optional-undefined.js';
19
+ import noProductImportsInShared from '../rules/no-product-imports-in-shared.js';
20
+ import preferConstEnum from '../rules/prefer-const-enum.js';
21
+ import requireStableHookArgs from '../rules/require-stable-hook-args.js';
22
+ import smartMaxLines from '../rules/smart-max-lines.js';
23
+
24
+ // Package version — kept in sync with package.json by the publish flow.
25
+ const PLUGIN_VERSION = '1.0.0';
26
+
27
+ const ruleModules: readonly SingleRulePlugin[] = [
28
+ enforceFunctionStyle,
29
+ enforceModuleStructure,
30
+ enforceRoutePreload,
31
+ enforceTestColocation,
32
+ enumFileIsolation,
33
+ i18nInterpolation,
34
+ i18nParamNames,
35
+ noBarrelCompanionFile,
36
+ noDuplicateNavPrefix,
37
+ noDuplicateSharedPatterns,
38
+ noGeneratedModelsBarrelValueImport,
39
+ noNullCheck,
40
+ noOptionalUndefined,
41
+ noProductImportsInShared,
42
+ preferConstEnum,
43
+ requireStableHookArgs,
44
+ smartMaxLines,
45
+ ];
46
+
47
+ function mergeRules(modules: readonly SingleRulePlugin[]): Record<string, CustomRule> {
48
+ const merged: Record<string, CustomRule> = {};
49
+ for (const mod of modules) {
50
+ for (const [name, rule] of Object.entries(mod.rules)) {
51
+ if (merged[name] !== undefined) {
52
+ throw new Error(`Duplicate ESLint rule name: "${name}"`);
53
+ }
54
+ merged[name] = rule;
55
+ }
56
+ }
57
+
58
+ return merged;
59
+ }
60
+
61
+ /**
62
+ * The flat-config plugin object. Register it under a namespace in the app's
63
+ * `eslint.config.mjs`:
64
+ *
65
+ * ```js
66
+ * import { plugin as devtools } from '@dloizides/frontend-devtools/eslint';
67
+ * export default [{ plugins: { '@dloizides': devtools }, rules: {
68
+ * '@dloizides/no-null-check': 'error',
69
+ * } }];
70
+ * ```
71
+ */
72
+ export const plugin: FlatConfigPlugin = {
73
+ meta: { name: '@dloizides/frontend-devtools', version: PLUGIN_VERSION },
74
+ rules: mergeRules(ruleModules),
75
+ };
76
+
77
+ /**
78
+ * The merged rule map alone (the same `Record<name, rule>` that the apps used to
79
+ * spread from 17 separate `eslint-plugins/*.mjs` files).
80
+ */
81
+ export const rules: Record<string, CustomRule> = plugin.rules;
82
+
83
+ /**
84
+ * The list of rule names this plugin provides. Useful for migration assertions
85
+ * (prove no rule was dropped vs. the old 17 local files).
86
+ */
87
+ export const ruleNames: readonly string[] = Object.keys(plugin.rules).sort();