@dloizides/frontend-devtools 1.0.1 → 1.0.3
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/dist/eslint/index.d.mts +77 -0
- package/dist/eslint/index.d.ts +77 -0
- package/dist/eslint/index.js +2000 -0
- package/dist/eslint/index.js.map +1 -0
- package/dist/eslint/index.mjs +1990 -0
- package/dist/eslint/index.mjs.map +1 -0
- package/dist/index.d.mts +69 -0
- package/dist/index.d.ts +69 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +31 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +6 -1
- package/.eslintrc.js +0 -34
- package/jest.config.js +0 -24
- package/publish.ps1 +0 -107
- package/src/eslint/index.ts +0 -16
- package/src/eslint/legacy.ts +0 -44
- package/src/eslint/plugin.test.ts +0 -60
- package/src/eslint/plugin.ts +0 -87
- package/src/eslint/rules.behaviour.test.ts +0 -86
- package/src/eslint/rules.d.ts +0 -16
- package/src/eslint/types.ts +0 -27
- package/src/i18n/initI18n.test.ts +0 -101
- package/src/i18n/initI18n.ts +0 -109
- package/src/index.ts +0 -31
- package/src/rules/enforce-function-style.js +0 -278
- package/src/rules/enforce-module-structure.js +0 -323
- package/src/rules/enforce-route-preload.js +0 -288
- package/src/rules/enforce-test-colocation.js +0 -82
- package/src/rules/enum-file-isolation.js +0 -149
- package/src/rules/i18n-interpolation.js +0 -185
- package/src/rules/i18n-param-names.js +0 -119
- package/src/rules/no-barrel-companion-file.js +0 -142
- package/src/rules/no-duplicate-nav-prefix.js +0 -107
- package/src/rules/no-duplicate-shared-patterns.js +0 -166
- package/src/rules/no-generated-models-barrel-value-import.js +0 -70
- package/src/rules/no-null-check.js +0 -171
- package/src/rules/no-optional-undefined.js +0 -99
- package/src/rules/no-product-imports-in-shared.js +0 -164
- package/src/rules/prefer-const-enum.js +0 -127
- package/src/rules/require-stable-hook-args.js +0 -372
- package/src/rules/smart-max-lines.js +0 -344
- package/tsconfig.json +0 -25
- package/tsconfig.test.json +0 -11
- package/tsup.config.ts +0 -14
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/i18n/initI18n.ts"],"names":["i18n","initReactI18next"],"mappings":";;;;;;;;;;AAsDA,IAAM,oBAAA,GAAuB,IAAA;AA0BtB,SAAS,SAAS,OAAA,EAAwC;AAC/D,EAAA,MAAM;AAAA,IACJ,SAAA;AAAA,IACA,GAAA;AAAA,IACA,WAAA,GAAc,oBAAA;AAAA,IACd,WAAA,GAAc,KAAA;AAAA,IACd,SAAA;AAAA,IACA;AAAA,GACF,GAAI,OAAA;AAEJ,EAAAA,qBAAA,CACG,GAAA,CAAIC,6BAAgB,CAAA,CACpB,IAAA,CAAK;AAAA,IACJ,KAAK,GAAA,IAAO,WAAA;AAAA,IACZ,WAAA;AAAA,IACA,SAAA;AAAA,IACA,GAAI,SAAA,KAAc,MAAA,GAAY,EAAE,SAAA,KAAc,EAAC;AAAA,IAC/C,GAAI,EAAA,KAAO,MAAA,GAAY,EAAE,EAAA,KAAO,EAAC;AAAA,IACjC,aAAA,EAAe;AAAA,MACb;AAAA;AACF,GACD,CAAA,CACA,KAAA,CAAM,MAAM;AAAA,EAGb,CAAC,CAAA;AAEH,EAAA,OAAOD,qBAAA;AACT","file":"index.js","sourcesContent":["// i18next's default export is the configurable singleton; `.use()` / `.init()`\n// are members on it — this is the documented i18next initialization pattern,\n// which trips `import/no-named-as-default-member` for the whole fluent chain.\n// The disable is owned by the package so the consuming apps don't repeat it.\n/* eslint-disable import/no-named-as-default-member */\nimport i18n, { type i18n as I18nInstance, type Resource } from 'i18next';\nimport { initReactI18next } from 'react-i18next';\n\n/**\n * Options for {@link initI18n}.\n *\n * Everything app-specific (the strings, the locales, the fallback language and\n * the active language) is passed in — the package owns only the init *chain*.\n */\nexport interface InitI18nOptions {\n /**\n * The i18next resource bundle, e.g. `{ en: { translation: en } }`.\n * The app owns its own `locales/*.json` — only the init logic is shared.\n */\n resources: Resource;\n\n /**\n * The active language. Apps typically derive this from device locale,\n * e.g. `expo-localization`'s `getLocales()[0]?.languageCode`.\n *\n * When omitted (or undefined), defaults to {@link fallbackLng}.\n */\n lng?: string;\n\n /**\n * The fallback language used when a key is missing in {@link lng}.\n * Defaults to `'en'`.\n */\n fallbackLng?: string;\n\n /**\n * Whether to escape interpolated values. React already escapes output, so\n * the SaaS apps run with `escapeValue: false`. Defaults to `false`.\n */\n escapeValue?: boolean;\n\n /**\n * Default namespace(s). i18next's default is `'translation'`; the SaaS apps\n * keep that single-namespace convention, so this is optional.\n */\n defaultNS?: string | readonly string[];\n\n /**\n * Namespace list. Optional — only needed when the app splits strings across\n * multiple namespaces. Single-namespace apps can omit it.\n */\n ns?: string | readonly string[];\n}\n\nconst DEFAULT_FALLBACK_LNG = 'en';\n\n/**\n * Initialize the shared i18next + react-i18next singleton.\n *\n * This is the parameterized factory that replaces the per-app `i18n.ts`. It\n * wires `react-i18next` into the i18next singleton and runs `.init()` with the\n * app-supplied resources/language, swallowing the async init rejection the same\n * way every app did (i18next resolves synchronously for in-memory resources).\n *\n * The returned value is the i18next singleton — apps `export default` it and\n * call `.t()` through their own `FM()` helper.\n *\n * @example\n * ```ts\n * import { initI18n } from '@dloizides/frontend-devtools';\n * import * as Localization from 'expo-localization';\n * import en from './locales/en.json';\n *\n * const i18n = initI18n({\n * resources: { en: { translation: en } },\n * lng: Localization.getLocales()[0]?.languageCode,\n * });\n * export default i18n;\n * ```\n */\nexport function initI18n(options: InitI18nOptions): I18nInstance {\n const {\n resources,\n lng,\n fallbackLng = DEFAULT_FALLBACK_LNG,\n escapeValue = false,\n defaultNS,\n ns,\n } = options;\n\n i18n\n .use(initReactI18next)\n .init({\n lng: lng ?? fallbackLng,\n fallbackLng,\n resources,\n ...(defaultNS !== undefined ? { defaultNS } : {}),\n ...(ns !== undefined ? { ns } : {}),\n interpolation: {\n escapeValue,\n },\n })\n .catch(() => {\n // i18next resolves synchronously for in-memory resources; the apps have\n // always swallowed this rejection. Kept identical to avoid behaviour drift.\n });\n\n return i18n;\n}\n"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import i18n from 'i18next';
|
|
2
|
+
import { initReactI18next } from 'react-i18next';
|
|
3
|
+
|
|
4
|
+
// src/i18n/initI18n.ts
|
|
5
|
+
var DEFAULT_FALLBACK_LNG = "en";
|
|
6
|
+
function initI18n(options) {
|
|
7
|
+
const {
|
|
8
|
+
resources,
|
|
9
|
+
lng,
|
|
10
|
+
fallbackLng = DEFAULT_FALLBACK_LNG,
|
|
11
|
+
escapeValue = false,
|
|
12
|
+
defaultNS,
|
|
13
|
+
ns
|
|
14
|
+
} = options;
|
|
15
|
+
i18n.use(initReactI18next).init({
|
|
16
|
+
lng: lng ?? fallbackLng,
|
|
17
|
+
fallbackLng,
|
|
18
|
+
resources,
|
|
19
|
+
...defaultNS !== void 0 ? { defaultNS } : {},
|
|
20
|
+
...ns !== void 0 ? { ns } : {},
|
|
21
|
+
interpolation: {
|
|
22
|
+
escapeValue
|
|
23
|
+
}
|
|
24
|
+
}).catch(() => {
|
|
25
|
+
});
|
|
26
|
+
return i18n;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { initI18n };
|
|
30
|
+
//# sourceMappingURL=index.mjs.map
|
|
31
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/i18n/initI18n.ts"],"names":[],"mappings":";;;;AAsDA,IAAM,oBAAA,GAAuB,IAAA;AA0BtB,SAAS,SAAS,OAAA,EAAwC;AAC/D,EAAA,MAAM;AAAA,IACJ,SAAA;AAAA,IACA,GAAA;AAAA,IACA,WAAA,GAAc,oBAAA;AAAA,IACd,WAAA,GAAc,KAAA;AAAA,IACd,SAAA;AAAA,IACA;AAAA,GACF,GAAI,OAAA;AAEJ,EAAA,IAAA,CACG,GAAA,CAAI,gBAAgB,CAAA,CACpB,IAAA,CAAK;AAAA,IACJ,KAAK,GAAA,IAAO,WAAA;AAAA,IACZ,WAAA;AAAA,IACA,SAAA;AAAA,IACA,GAAI,SAAA,KAAc,MAAA,GAAY,EAAE,SAAA,KAAc,EAAC;AAAA,IAC/C,GAAI,EAAA,KAAO,MAAA,GAAY,EAAE,EAAA,KAAO,EAAC;AAAA,IACjC,aAAA,EAAe;AAAA,MACb;AAAA;AACF,GACD,CAAA,CACA,KAAA,CAAM,MAAM;AAAA,EAGb,CAAC,CAAA;AAEH,EAAA,OAAO,IAAA;AACT","file":"index.mjs","sourcesContent":["// i18next's default export is the configurable singleton; `.use()` / `.init()`\n// are members on it — this is the documented i18next initialization pattern,\n// which trips `import/no-named-as-default-member` for the whole fluent chain.\n// The disable is owned by the package so the consuming apps don't repeat it.\n/* eslint-disable import/no-named-as-default-member */\nimport i18n, { type i18n as I18nInstance, type Resource } from 'i18next';\nimport { initReactI18next } from 'react-i18next';\n\n/**\n * Options for {@link initI18n}.\n *\n * Everything app-specific (the strings, the locales, the fallback language and\n * the active language) is passed in — the package owns only the init *chain*.\n */\nexport interface InitI18nOptions {\n /**\n * The i18next resource bundle, e.g. `{ en: { translation: en } }`.\n * The app owns its own `locales/*.json` — only the init logic is shared.\n */\n resources: Resource;\n\n /**\n * The active language. Apps typically derive this from device locale,\n * e.g. `expo-localization`'s `getLocales()[0]?.languageCode`.\n *\n * When omitted (or undefined), defaults to {@link fallbackLng}.\n */\n lng?: string;\n\n /**\n * The fallback language used when a key is missing in {@link lng}.\n * Defaults to `'en'`.\n */\n fallbackLng?: string;\n\n /**\n * Whether to escape interpolated values. React already escapes output, so\n * the SaaS apps run with `escapeValue: false`. Defaults to `false`.\n */\n escapeValue?: boolean;\n\n /**\n * Default namespace(s). i18next's default is `'translation'`; the SaaS apps\n * keep that single-namespace convention, so this is optional.\n */\n defaultNS?: string | readonly string[];\n\n /**\n * Namespace list. Optional — only needed when the app splits strings across\n * multiple namespaces. Single-namespace apps can omit it.\n */\n ns?: string | readonly string[];\n}\n\nconst DEFAULT_FALLBACK_LNG = 'en';\n\n/**\n * Initialize the shared i18next + react-i18next singleton.\n *\n * This is the parameterized factory that replaces the per-app `i18n.ts`. It\n * wires `react-i18next` into the i18next singleton and runs `.init()` with the\n * app-supplied resources/language, swallowing the async init rejection the same\n * way every app did (i18next resolves synchronously for in-memory resources).\n *\n * The returned value is the i18next singleton — apps `export default` it and\n * call `.t()` through their own `FM()` helper.\n *\n * @example\n * ```ts\n * import { initI18n } from '@dloizides/frontend-devtools';\n * import * as Localization from 'expo-localization';\n * import en from './locales/en.json';\n *\n * const i18n = initI18n({\n * resources: { en: { translation: en } },\n * lng: Localization.getLocales()[0]?.languageCode,\n * });\n * export default i18n;\n * ```\n */\nexport function initI18n(options: InitI18nOptions): I18nInstance {\n const {\n resources,\n lng,\n fallbackLng = DEFAULT_FALLBACK_LNG,\n escapeValue = false,\n defaultNS,\n ns,\n } = options;\n\n i18n\n .use(initReactI18next)\n .init({\n lng: lng ?? fallbackLng,\n fallbackLng,\n resources,\n ...(defaultNS !== undefined ? { defaultNS } : {}),\n ...(ns !== undefined ? { ns } : {}),\n interpolation: {\n escapeValue,\n },\n })\n .catch(() => {\n // i18next resolves synchronously for in-memory resources; the apps have\n // always swallowed this rejection. Kept identical to avoid behaviour drift.\n });\n\n return i18n;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dloizides/frontend-devtools",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
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
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -21,6 +21,11 @@
|
|
|
21
21
|
"bugs": {
|
|
22
22
|
"url": "https://github.com/openmindednewby/frontend-devtools/issues"
|
|
23
23
|
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"README.md",
|
|
27
|
+
"CHANGELOG.md"
|
|
28
|
+
],
|
|
24
29
|
"main": "./dist/index.js",
|
|
25
30
|
"module": "./dist/index.mjs",
|
|
26
31
|
"types": "./dist/index.d.ts",
|
package/.eslintrc.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
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/jest.config.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
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/publish.ps1
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
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
|
-
}
|
package/src/eslint/index.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
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';
|
package/src/eslint/legacy.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
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
|
-
});
|
package/src/eslint/plugin.ts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
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();
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { RuleTester } from 'eslint';
|
|
2
|
-
|
|
3
|
-
import { rules } from './plugin';
|
|
4
|
-
|
|
5
|
-
// ESLint's RuleTester registers its own describe/it via the global test runner,
|
|
6
|
-
// so `.run()` is called at the top level (not nested inside a jest `it()`, which
|
|
7
|
-
// RuleTester forbids). ESLint 8's RuleTester uses the eslintrc config shape.
|
|
8
|
-
|
|
9
|
-
// Plain-JS parser RuleTester (for AST that exists in vanilla ESTree).
|
|
10
|
-
const jsTester = new RuleTester({
|
|
11
|
-
parserOptions: { ecmaVersion: 2022, sourceType: 'module' },
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
// TypeScript-AST RuleTester (for TS-only nodes: TSUnionType, TSTypeAliasDeclaration).
|
|
15
|
-
const tsTester = new RuleTester({
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
17
|
-
parser: require.resolve('@typescript-eslint/parser'),
|
|
18
|
-
parserOptions: { ecmaVersion: 2022, sourceType: 'module' },
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
// no-null-check — representative fixable JS rule.
|
|
22
|
-
jsTester.run('no-null-check', rules['no-null-check'], {
|
|
23
|
-
valid: [
|
|
24
|
-
{ code: 'if (isValueDefined(x)) doThing();' },
|
|
25
|
-
{ code: 'if (a === b) doThing();' },
|
|
26
|
-
],
|
|
27
|
-
invalid: [
|
|
28
|
-
{
|
|
29
|
-
code: 'const ok = x !== null;',
|
|
30
|
-
output: 'const ok = isValueDefined(x);',
|
|
31
|
-
errors: [{ messageId: 'noNotEqualsNull' }],
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
code: 'const ok = x === null;',
|
|
35
|
-
output: 'const ok = !isValueDefined(x);',
|
|
36
|
-
errors: [{ messageId: 'noEqualsNull' }],
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
code: 'const ok = x !== undefined;',
|
|
40
|
-
output: 'const ok = isValueDefined(x);',
|
|
41
|
-
errors: [{ messageId: 'noNotEqualsUndefined' }],
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
code: 'const ok = x === undefined;',
|
|
45
|
-
output: 'const ok = !isValueDefined(x);',
|
|
46
|
-
errors: [{ messageId: 'noEqualsUndefined' }],
|
|
47
|
-
},
|
|
48
|
-
],
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
// prefer-const-enum — representative TS-AST rule.
|
|
52
|
-
tsTester.run('prefer-const-enum', rules['prefer-const-enum'], {
|
|
53
|
-
valid: [
|
|
54
|
-
{ code: "type Single = 'only';" },
|
|
55
|
-
{ code: 'type Nullable = Foo | null;' },
|
|
56
|
-
{ code: "type Mixed = 'a' | number;" },
|
|
57
|
-
],
|
|
58
|
-
invalid: [
|
|
59
|
-
{
|
|
60
|
-
code: "type Mode = 'light' | 'dark';",
|
|
61
|
-
errors: [{ messageId: 'preferConstEnum' }],
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
code: "export type Status = 'active' | 'inactive' | 'pending';",
|
|
65
|
-
errors: [{ messageId: 'preferConstEnum' }],
|
|
66
|
-
},
|
|
67
|
-
],
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
// no-optional-undefined — representative TS-AST rule.
|
|
71
|
-
tsTester.run('no-optional-undefined', rules['no-optional-undefined'], {
|
|
72
|
-
valid: [
|
|
73
|
-
{ code: 'interface A { pageCount?: number; }' },
|
|
74
|
-
{ code: 'function foo(bar?: string) {}' },
|
|
75
|
-
],
|
|
76
|
-
invalid: [
|
|
77
|
-
{
|
|
78
|
-
code: 'interface A { pageCount?: number | undefined; }',
|
|
79
|
-
errors: [{ messageId: 'noOptionalUndefined' }],
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
code: 'function foo(bar?: string | undefined) {}',
|
|
83
|
-
errors: [{ messageId: 'noOptionalUndefined' }],
|
|
84
|
-
},
|
|
85
|
-
],
|
|
86
|
-
});
|
package/src/eslint/rules.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ambient typing for the custom ESLint rule modules. Each `../rules/*.js`
|
|
3
|
-
* file default-exports a one-rule plugin object: `{ rules: { '<name>': rule } }`.
|
|
4
|
-
*
|
|
5
|
-
* They are authored as plain ESM JS — the canonical ESLint plugin format — so
|
|
6
|
-
* the apps that adopt this package keep loading byte-identical rule logic. They
|
|
7
|
-
* are typed loosely here (and via `allowJs: false`, TS uses THIS declaration
|
|
8
|
-
* rather than re-inferring the JS) so the strict `Rule.RuleModule` shape is
|
|
9
|
-
* applied uniformly across all 17 rules.
|
|
10
|
-
*/
|
|
11
|
-
declare module '*.js' {
|
|
12
|
-
import type { Rule } from 'eslint';
|
|
13
|
-
|
|
14
|
-
const plugin: { rules: Record<string, Rule.RuleModule> };
|
|
15
|
-
export default plugin;
|
|
16
|
-
}
|
package/src/eslint/types.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { Rule, Linter } from 'eslint';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* A single custom ESLint rule implementation (the object passed to ESLint's
|
|
5
|
-
* `RuleTester`). The rule `.mjs` files export `{ rules: { '<name>': rule } }`.
|
|
6
|
-
*/
|
|
7
|
-
export type CustomRule = Rule.RuleModule;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* The shape each rule `.mjs` module default-exports: a one-rule plugin object.
|
|
11
|
-
*/
|
|
12
|
-
export interface SingleRulePlugin {
|
|
13
|
-
rules: Record<string, CustomRule>;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* An ESLint flat-config plugin object: a name + the merged rule map.
|
|
18
|
-
*/
|
|
19
|
-
export interface FlatConfigPlugin {
|
|
20
|
-
meta: { name: string; version: string };
|
|
21
|
-
rules: Record<string, CustomRule>;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* A flat-config block (the entries of an `eslint.config.mjs` array).
|
|
26
|
-
*/
|
|
27
|
-
export type FlatConfig = Linter.FlatConfig;
|