@ankhorage/devtools 1.4.1 → 1.5.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.
@@ -1,9 +1,9 @@
1
- import tseslint from 'typescript-eslint';
1
+ import type { Linter } from 'eslint';
2
2
  import type { DevtoolsConfigOptions } from './types.js';
3
3
  export declare const defaultIgnores: readonly ["**/ios/**", "**/android/**", "**/dist/**", "**/build/**", "**/.expo/**", "**/.next/**", "**/node_modules/**", "**/*.d.ts", "**/templates/**", "**/files/**"];
4
4
  export declare const defaultRestrictedImports: readonly [{
5
5
  readonly name: "react-native-reanimated-dnd";
6
6
  readonly message: "Forbidden in Ankhorage packages. Use '@ankhorage/react-native-reanimated-dnd-web' directly.";
7
7
  }];
8
- export declare function createConfig(options: DevtoolsConfigOptions): ReturnType<typeof tseslint.config>;
8
+ export declare function createConfig(options: DevtoolsConfigOptions): Linter.Config[];
9
9
  export type { DevtoolsConfigOptions, DevtoolsEslintProfile, FlatConfigItem, ResolvedDevtoolsEslintProfile, RestrictedImport, } from './types.js';
@@ -4,13 +4,13 @@
4
4
  * The default `profile: 'auto'` reads the nearest `package.json` from `tsconfigRootDir` and uses
5
5
  * `@ankhorage/utility/project` to select overlapping project traits. React Native and Expo select
6
6
  * the `react-native` profile, React and Next.js select `react`, and other projects use `base`.
7
- * Consumers can explicitly select `base`, `react`, or `react-native` when automatic detection is
8
- * not appropriate.
9
7
  *
10
8
  * Every profile includes the shared TypeScript, import, unused-import, Prettier, security, and
11
9
  * quality rules. The common quality limits are 50 effective lines per function, 300 effective
12
- * lines per file, and modified cyclomatic complexity 15. React adds React and Hooks correctness
13
- * rules; React Native composes the React profile and adds focused React Native rules.
10
+ * lines per file, and modified cyclomatic complexity 15. Forward exports are forbidden outside
11
+ * explicit `index.*` barrels so implementation files export only symbols they own. React adds
12
+ * React and Hooks correctness rules; React Native composes the React profile and adds focused
13
+ * React Native rules.
14
14
  *
15
15
  * Repository-specific behavior stays additive: `additionalIgnores`, `restrictedImports`, and
16
16
  * `overrides` extend the central policy instead of replacing it. Narrow local overrides remain the
@@ -21,6 +21,7 @@
21
21
  */
22
22
  import { fixupPluginRules } from '@eslint/compat';
23
23
  import js from '@eslint/js';
24
+ import { defineConfig } from 'eslint/config';
24
25
  import prettierConfig from 'eslint-config-prettier';
25
26
  import importPlugin from 'eslint-plugin-import';
26
27
  import prettierPlugin from 'eslint-plugin-prettier';
@@ -31,6 +32,7 @@ import securityPlugin from 'eslint-plugin-security';
31
32
  import simpleImportSort from 'eslint-plugin-simple-import-sort';
32
33
  import unusedImports from 'eslint-plugin-unused-imports';
33
34
  import tseslint from 'typescript-eslint';
35
+ import { createModuleOwnershipConfig } from './moduleOwnership.js';
34
36
  import { resolveEslintProfile } from './profile.js';
35
37
  export const defaultIgnores = [
36
38
  '**/ios/**',
@@ -53,7 +55,7 @@ export const defaultRestrictedImports = [
53
55
  export function createConfig(options) {
54
56
  const normalized = normalizeOptions(options);
55
57
  const profile = resolveEslintProfile(options);
56
- return tseslint.config({ ignores: [...defaultIgnores, ...normalized.additionalIgnores] }, { ...js.configs.recommended, files: normalized.files }, ...createTypeCheckedConfigs(normalized), createBaseConfig(normalized), ...createProfileConfigs(profile, normalized.files), ...normalized.overrides, ...(normalized.includePrettier ? [prettierConfig] : []));
58
+ return defineConfig({ ignores: [...defaultIgnores, ...normalized.additionalIgnores] }, { ...js.configs.recommended, files: normalized.files }, ...createTypeCheckedConfigs(normalized), createBaseConfig(normalized), createModuleOwnershipConfig(normalized.files), ...createProfileConfigs(profile, normalized.files), ...normalized.overrides, ...(normalized.includePrettier ? [prettierConfig] : []));
57
59
  }
58
60
  function normalizeOptions(options) {
59
61
  return {
@@ -161,7 +163,10 @@ function createProfileConfigs(profile, files) {
161
163
  function createReactConfig(files) {
162
164
  return {
163
165
  files,
164
- plugins: { react: reactPlugin, 'react-hooks': reactHooksPlugin },
166
+ plugins: {
167
+ react: reactPlugin,
168
+ 'react-hooks': fixupPluginRules({ rules: reactHooksPlugin.rules }),
169
+ },
165
170
  settings: { react: { version: 'detect' } },
166
171
  rules: {
167
172
  'react/no-danger': 'error',
@@ -0,0 +1,2 @@
1
+ import type { FlatConfigItem } from './types.js';
2
+ export declare function createModuleOwnershipConfig(files: string[]): FlatConfigItem;
@@ -0,0 +1,46 @@
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
+ }
@@ -1,6 +1,5 @@
1
- import type tseslint from 'typescript-eslint';
2
- type FlatConfig = ReturnType<typeof tseslint.config>;
3
- export type FlatConfigItem = FlatConfig[number];
1
+ import type { Linter } from 'eslint';
2
+ export type FlatConfigItem = Linter.Config;
4
3
  export interface RestrictedImport {
5
4
  readonly name: string;
6
5
  readonly message: string;
@@ -19,4 +18,3 @@ export interface DevtoolsConfigOptions {
19
18
  readonly overrides?: FlatConfigItem[];
20
19
  readonly includePrettier?: boolean;
21
20
  }
22
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ankhorage/devtools",
3
- "version": "1.4.1",
3
+ "version": "1.5.0",
4
4
  "description": "Shared development tools and repository standards for Ankhorage",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/ankhorage/devtools#readme",