@ankhorage/devtools 1.5.0 → 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.
- package/dist/tools/eslint/index.js +3 -6
- package/dist/tools/eslint/packageJsonPath.d.ts +2 -0
- package/dist/tools/eslint/packageJsonPath.js +17 -0
- package/dist/tools/eslint/profile.js +8 -31
- package/package.json +1 -1
- package/dist/tools/eslint/moduleOwnership.d.ts +0 -2
- package/dist/tools/eslint/moduleOwnership.js +0 -46
|
@@ -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
|
-
* React and Hooks correctness rules; React Native composes the React profile and adds focused
|
|
13
|
-
* 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,7 +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
33
|
import { resolveEslintProfile } from './profile.js';
|
|
37
34
|
export const defaultIgnores = [
|
|
38
35
|
'**/ios/**',
|
|
@@ -55,7 +52,7 @@ export const defaultRestrictedImports = [
|
|
|
55
52
|
export function createConfig(options) {
|
|
56
53
|
const normalized = normalizeOptions(options);
|
|
57
54
|
const profile = resolveEslintProfile(options);
|
|
58
|
-
return defineConfig({ ignores: [...defaultIgnores, ...normalized.additionalIgnores] }, { ...js.configs.recommended, files: normalized.files }, ...createTypeCheckedConfigs(normalized), createBaseConfig(normalized),
|
|
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] : []));
|
|
59
56
|
}
|
|
60
57
|
function normalizeOptions(options) {
|
|
61
58
|
return {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { dirname, resolve } from 'node:path';
|
|
3
|
+
export function resolveProjectPackageJsonPath(options) {
|
|
4
|
+
if (options.packageJsonPath !== undefined) {
|
|
5
|
+
return resolve(options.tsconfigRootDir, options.packageJsonPath);
|
|
6
|
+
}
|
|
7
|
+
let directory = resolve(options.tsconfigRootDir);
|
|
8
|
+
for (;;) {
|
|
9
|
+
const candidate = resolve(directory, 'package.json');
|
|
10
|
+
if (existsSync(candidate))
|
|
11
|
+
return candidate;
|
|
12
|
+
const parent = dirname(directory);
|
|
13
|
+
if (parent === directory)
|
|
14
|
+
return null;
|
|
15
|
+
directory = parent;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -1,42 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { dirname, resolve } from 'node:path';
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
3
2
|
import { detectProject, } from '@ankhorage/utility/project';
|
|
3
|
+
import { resolveProjectPackageJsonPath } from './packageJsonPath.js';
|
|
4
4
|
export function resolveEslintProfile(options) {
|
|
5
5
|
const requestedProfile = options.profile ?? 'auto';
|
|
6
|
-
if (requestedProfile !== 'auto')
|
|
6
|
+
if (requestedProfile !== 'auto')
|
|
7
7
|
return requestedProfile;
|
|
8
|
-
}
|
|
9
8
|
const packageJsonPath = resolveProjectPackageJsonPath(options);
|
|
10
9
|
const input = packageJsonPath === null ? {} : readDetectionInput(packageJsonPath);
|
|
11
10
|
return resolveEslintProfileFromDetectionInput('auto', input);
|
|
12
11
|
}
|
|
13
12
|
export function resolveEslintProfileFromDetectionInput(requestedProfile, input) {
|
|
14
|
-
if (requestedProfile !== 'auto')
|
|
13
|
+
if (requestedProfile !== 'auto')
|
|
15
14
|
return requestedProfile;
|
|
16
|
-
}
|
|
17
15
|
const { traits } = detectProject(input);
|
|
18
|
-
if (traits.has('react-native') || traits.has('expo'))
|
|
16
|
+
if (traits.has('react-native') || traits.has('expo'))
|
|
19
17
|
return 'react-native';
|
|
20
|
-
}
|
|
21
18
|
return traits.has('react') ? 'react' : 'base';
|
|
22
19
|
}
|
|
23
|
-
function resolveProjectPackageJsonPath(options) {
|
|
24
|
-
if (options.packageJsonPath !== undefined) {
|
|
25
|
-
return resolve(options.tsconfigRootDir, options.packageJsonPath);
|
|
26
|
-
}
|
|
27
|
-
let directory = resolve(options.tsconfigRootDir);
|
|
28
|
-
for (;;) {
|
|
29
|
-
const candidate = resolve(directory, 'package.json');
|
|
30
|
-
if (existsSync(candidate)) {
|
|
31
|
-
return candidate;
|
|
32
|
-
}
|
|
33
|
-
const parent = dirname(directory);
|
|
34
|
-
if (parent === directory) {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
directory = parent;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
20
|
function readDetectionInput(packageJsonPath) {
|
|
41
21
|
const parsed = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
|
|
42
22
|
if (!isRecord(parsed)) {
|
|
@@ -55,21 +35,18 @@ function optionalDependencyMap(key, value) {
|
|
|
55
35
|
return dependencyMap === undefined ? {} : { [key]: dependencyMap };
|
|
56
36
|
}
|
|
57
37
|
function toDependencyMap(value) {
|
|
58
|
-
if (!isRecord(value))
|
|
38
|
+
if (!isRecord(value))
|
|
59
39
|
return undefined;
|
|
60
|
-
}
|
|
61
40
|
const dependencies = {};
|
|
62
41
|
for (const [name, version] of Object.entries(value)) {
|
|
63
|
-
if (typeof version === 'string')
|
|
42
|
+
if (typeof version === 'string')
|
|
64
43
|
dependencies[name] = version;
|
|
65
|
-
}
|
|
66
44
|
}
|
|
67
45
|
return dependencies;
|
|
68
46
|
}
|
|
69
47
|
function optionalEngines(value) {
|
|
70
|
-
if (!isRecord(value))
|
|
48
|
+
if (!isRecord(value))
|
|
71
49
|
return {};
|
|
72
|
-
}
|
|
73
50
|
const engines = {
|
|
74
51
|
...(typeof value.bun === 'string' ? { bun: value.bun } : {}),
|
|
75
52
|
...(typeof value.node === 'string' ? { node: value.node } : {}),
|
package/package.json
CHANGED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
const INDEX_BARREL_FILES = [
|
|
2
|
-
'**/index.ts',
|
|
3
|
-
'**/index.tsx',
|
|
4
|
-
'**/index.js',
|
|
5
|
-
'**/index.jsx',
|
|
6
|
-
'**/index.mts',
|
|
7
|
-
'**/index.cts',
|
|
8
|
-
'**/index.mjs',
|
|
9
|
-
'**/index.cjs',
|
|
10
|
-
];
|
|
11
|
-
function isForwardExport(context, node) {
|
|
12
|
-
const tokens = context.sourceCode.getTokens(node);
|
|
13
|
-
if (tokens.at(0)?.value !== 'export') {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
return tokens.some((token, index) => token.value === 'from' && tokens.at(index + 1)?.type === 'String');
|
|
17
|
-
}
|
|
18
|
-
const noForwardExportsRule = {
|
|
19
|
-
meta: {
|
|
20
|
-
type: 'problem',
|
|
21
|
-
schema: [],
|
|
22
|
-
messages: {
|
|
23
|
-
forwardExport: 'Forward exports are forbidden outside index barrels. Import directly from the owning module.',
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
create(context) {
|
|
27
|
-
return {
|
|
28
|
-
'Program > *'(node) {
|
|
29
|
-
if (isForwardExport(context, node)) {
|
|
30
|
-
context.report({ node, messageId: 'forwardExport' });
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
const moduleOwnershipPlugin = {
|
|
37
|
-
rules: { 'no-forward-exports': noForwardExportsRule },
|
|
38
|
-
};
|
|
39
|
-
export function createModuleOwnershipConfig(files) {
|
|
40
|
-
return {
|
|
41
|
-
files,
|
|
42
|
-
ignores: [...INDEX_BARREL_FILES],
|
|
43
|
-
plugins: { ankhorage: moduleOwnershipPlugin },
|
|
44
|
-
rules: { 'ankhorage/no-forward-exports': 'error' },
|
|
45
|
-
};
|
|
46
|
-
}
|