@ankhorage/devtools 1.5.1 → 1.5.2
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.
|
@@ -7,10 +7,8 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Every profile includes the shared TypeScript, import, unused-import, Prettier, security, and
|
|
9
9
|
* quality rules. The common quality limits are 50 effective lines per function, 300 effective
|
|
10
|
-
* lines per file, and modified cyclomatic complexity 15.
|
|
11
|
-
*
|
|
12
|
-
* symbols they own. React adds React and Hooks correctness rules; React Native composes the React
|
|
13
|
-
* profile and adds focused React Native rules.
|
|
10
|
+
* lines per file, and modified cyclomatic complexity 15. React adds React and Hooks correctness
|
|
11
|
+
* rules; React Native composes the React profile and adds focused React Native rules.
|
|
14
12
|
*
|
|
15
13
|
* Repository-specific behavior stays additive: `additionalIgnores`, `restrictedImports`, and
|
|
16
14
|
* `overrides` extend the central policy instead of replacing it. Narrow local overrides remain the
|
|
@@ -32,8 +30,6 @@ import securityPlugin from 'eslint-plugin-security';
|
|
|
32
30
|
import simpleImportSort from 'eslint-plugin-simple-import-sort';
|
|
33
31
|
import unusedImports from 'eslint-plugin-unused-imports';
|
|
34
32
|
import tseslint from 'typescript-eslint';
|
|
35
|
-
import { createModuleOwnershipConfig } from './moduleOwnership.js';
|
|
36
|
-
import { resolvePackageEntrypointFiles } from './packageEntrypoints.js';
|
|
37
33
|
import { resolveEslintProfile } from './profile.js';
|
|
38
34
|
export const defaultIgnores = [
|
|
39
35
|
'**/ios/**',
|
|
@@ -56,8 +52,7 @@ export const defaultRestrictedImports = [
|
|
|
56
52
|
export function createConfig(options) {
|
|
57
53
|
const normalized = normalizeOptions(options);
|
|
58
54
|
const profile = resolveEslintProfile(options);
|
|
59
|
-
|
|
60
|
-
return defineConfig({ ignores: [...defaultIgnores, ...normalized.additionalIgnores] }, { ...js.configs.recommended, files: normalized.files }, ...createTypeCheckedConfigs(normalized), createBaseConfig(normalized), createModuleOwnershipConfig(normalized.files, packageEntrypoints), ...createProfileConfigs(profile, normalized.files), ...normalized.overrides, ...(normalized.includePrettier ? [prettierConfig] : []));
|
|
55
|
+
return defineConfig({ ignores: [...defaultIgnores, ...normalized.additionalIgnores] }, { ...js.configs.recommended, files: normalized.files }, ...createTypeCheckedConfigs(normalized), createBaseConfig(normalized), ...createProfileConfigs(profile, normalized.files), ...normalized.overrides, ...(normalized.includePrettier ? [prettierConfig] : []));
|
|
61
56
|
}
|
|
62
57
|
function normalizeOptions(options) {
|
|
63
58
|
return {
|
package/package.json
CHANGED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { basename, normalize } from 'node:path';
|
|
2
|
-
const INDEX_BARREL_FILE = /^index\.(?:ts|tsx|js|jsx|mts|cts|mjs|cjs)$/u;
|
|
3
|
-
function isForwardExport(context, node) {
|
|
4
|
-
const tokens = context.sourceCode.getTokens(node);
|
|
5
|
-
if (tokens.at(0)?.value !== 'export')
|
|
6
|
-
return false;
|
|
7
|
-
return tokens.some((token, index) => token.value === 'from' && tokens.at(index + 1)?.type === 'String');
|
|
8
|
-
}
|
|
9
|
-
function isAllowedForwardExportFile(context) {
|
|
10
|
-
const filename = normalize(context.filename);
|
|
11
|
-
if (INDEX_BARREL_FILE.test(basename(filename)))
|
|
12
|
-
return true;
|
|
13
|
-
return readAllowedFiles(context.options.at(0)).some((file) => normalize(file) === filename);
|
|
14
|
-
}
|
|
15
|
-
function readAllowedFiles(value) {
|
|
16
|
-
if (!isRecord(value))
|
|
17
|
-
return [];
|
|
18
|
-
const { allowedFiles } = value;
|
|
19
|
-
if (!Array.isArray(allowedFiles))
|
|
20
|
-
return [];
|
|
21
|
-
return allowedFiles.filter((file) => typeof file === 'string');
|
|
22
|
-
}
|
|
23
|
-
function isRecord(value) {
|
|
24
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
25
|
-
}
|
|
26
|
-
const noForwardExportsRule = {
|
|
27
|
-
meta: {
|
|
28
|
-
type: 'problem',
|
|
29
|
-
schema: [
|
|
30
|
-
{
|
|
31
|
-
type: 'object',
|
|
32
|
-
properties: {
|
|
33
|
-
allowedFiles: { type: 'array', items: { type: 'string' } },
|
|
34
|
-
},
|
|
35
|
-
additionalProperties: false,
|
|
36
|
-
},
|
|
37
|
-
],
|
|
38
|
-
messages: {
|
|
39
|
-
forwardExport: 'Forward exports are forbidden outside package entrypoints and index barrels. Import directly from the owning module.',
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
create(context) {
|
|
43
|
-
if (isAllowedForwardExportFile(context))
|
|
44
|
-
return {};
|
|
45
|
-
return {
|
|
46
|
-
'Program > *'(node) {
|
|
47
|
-
if (isForwardExport(context, node))
|
|
48
|
-
context.report({ node, messageId: 'forwardExport' });
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
const moduleOwnershipPlugin = {
|
|
54
|
-
rules: { 'no-forward-exports': noForwardExportsRule },
|
|
55
|
-
};
|
|
56
|
-
export function createModuleOwnershipConfig(files, packageEntrypoints = []) {
|
|
57
|
-
return {
|
|
58
|
-
files,
|
|
59
|
-
plugins: { ankhorage: moduleOwnershipPlugin },
|
|
60
|
-
rules: {
|
|
61
|
-
'ankhorage/no-forward-exports': ['error', { allowedFiles: packageEntrypoints }],
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs';
|
|
2
|
-
import { dirname, resolve } from 'node:path';
|
|
3
|
-
import { resolveProjectPackageJsonPath } from './packageJsonPath.js';
|
|
4
|
-
const SOURCE_EXTENSIONS = ['ts', 'tsx', 'js', 'jsx', 'mts', 'cts', 'mjs', 'cjs'];
|
|
5
|
-
const OUTPUT_EXTENSION = /(?:\.d)?\.(?:ts|tsx|js|jsx|mts|cts|mjs|cjs)$/u;
|
|
6
|
-
export function resolvePackageEntrypointFiles(options) {
|
|
7
|
-
const packageJsonPath = resolveProjectPackageJsonPath(options);
|
|
8
|
-
if (packageJsonPath === null)
|
|
9
|
-
return [];
|
|
10
|
-
const packageJson = readPackageJson(packageJsonPath);
|
|
11
|
-
const targets = [
|
|
12
|
-
...collectStringTargets(packageJson.main),
|
|
13
|
-
...collectStringTargets(packageJson.types),
|
|
14
|
-
...collectStringTargets(packageJson.exports),
|
|
15
|
-
];
|
|
16
|
-
return [...new Set(targets.flatMap((target) => toSourceCandidates(target, packageJsonPath)))];
|
|
17
|
-
}
|
|
18
|
-
function readPackageJson(packageJsonPath) {
|
|
19
|
-
const parsed = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
|
|
20
|
-
if (!isRecord(parsed)) {
|
|
21
|
-
throw new Error(`Expected package.json to contain a JSON object: ${packageJsonPath}`);
|
|
22
|
-
}
|
|
23
|
-
return parsed;
|
|
24
|
-
}
|
|
25
|
-
function collectStringTargets(value) {
|
|
26
|
-
if (typeof value === 'string')
|
|
27
|
-
return [value];
|
|
28
|
-
if (Array.isArray(value))
|
|
29
|
-
return value.flatMap(collectStringTargets);
|
|
30
|
-
if (!isRecord(value))
|
|
31
|
-
return [];
|
|
32
|
-
return Object.values(value).flatMap(collectStringTargets);
|
|
33
|
-
}
|
|
34
|
-
function toSourceCandidates(target, packageJsonPath) {
|
|
35
|
-
const normalizedTarget = target.replace(/^\.\//u, '');
|
|
36
|
-
const sourceTarget = normalizedTarget.startsWith('dist/')
|
|
37
|
-
? `src/${normalizedTarget.slice('dist/'.length)}`
|
|
38
|
-
: normalizedTarget;
|
|
39
|
-
if (!sourceTarget.startsWith('src/'))
|
|
40
|
-
return [];
|
|
41
|
-
const sourceBase = sourceTarget.replace(OUTPUT_EXTENSION, '');
|
|
42
|
-
const absoluteBase = resolve(dirname(packageJsonPath), sourceBase);
|
|
43
|
-
return SOURCE_EXTENSIONS.map((extension) => `${absoluteBase}.${extension}`);
|
|
44
|
-
}
|
|
45
|
-
function isRecord(value) {
|
|
46
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
47
|
-
}
|