forked from Lex-Studios/Stellar-Spend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.js
More file actions
162 lines (153 loc) · 4.62 KB
/
Copy patheslint.config.js
File metadata and controls
162 lines (153 loc) · 4.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// For more info, see https://github.com/storybookjs/eslint-plugin-storybook#configuration-flat-config-format
import { createRequire } from 'module';
import { fileURLToPath } from 'url';
import { dirname, resolve } from 'path';
import storybook from 'eslint-plugin-storybook';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const require = createRequire(import.meta.url);
const tsParser = require('@typescript-eslint/parser');
const tsPlugin = require('@typescript-eslint/eslint-plugin');
const reactHooksPlugin = require('eslint-plugin-react-hooks');
const reactPlugin = require('eslint-plugin-react');
const nextPlugin = require('@next/eslint-plugin-next');
// ---------------------------------------------------------------------------
// Module boundary helpers
//
// Rule: app/, components/, and hooks/ must only import lib modules via their
// public barrel (e.g. `@/lib/polling`, not `@/lib/polling/backoff`).
// Contracts/ internals must never be imported from TypeScript source.
// ---------------------------------------------------------------------------
/**
* Builds a `no-restricted-imports` patterns entry that forbids deep imports
* into a given lib module (anything beyond the barrel index).
*
* Allowed : import { x } from '@/lib/polling'
* Forbidden: import { x } from '@/lib/polling/backoff'
*/
function deepLibPattern(module) {
return {
group: [`@/lib/${module}/**`],
message: `Import from '@/lib/${module}' barrel instead of a deep path. See docs/code-organization.md.`,
};
}
/** All lib modules that have an enforced public barrel. */
const BOUNDARY_MODULES = [
'api-keys',
'api-versioning',
'cache',
'clients',
'db',
'di',
'events',
'feature-flags',
'geo',
'graphql',
'ledger',
'middleware',
'notifications',
'offramp',
'onramp',
'payroll',
'polling',
'refund',
'repositories',
'security',
'services',
'stellar',
'validators',
'wallets',
'webhook',
];
const BOUNDARY_PATTERNS = [
// Deep lib module imports
...BOUNDARY_MODULES.map(deepLibPattern),
// Contract internals must never be imported from TypeScript
{
group: ['**/contracts/**'],
message:
'Do not import Rust contract internals from TypeScript. Use generated bindings only.',
},
];
export default [
{
ignores: ['.next/**', 'node_modules/**', 'public/sw.js'],
},
{
files: ['**/*.{js,jsx,ts,tsx}'],
languageOptions: {
parser: tsParser,
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
},
},
plugins: {
'@next/next': nextPlugin,
react: reactPlugin,
'react-hooks': reactHooksPlugin,
'@typescript-eslint': tsPlugin,
},
settings: {
react: {
version: 'detect',
},
next: {
rootDir: resolve(__dirname),
},
},
rules: {
...reactPlugin.configs.flat.recommended.rules,
...reactPlugin.configs.flat['jsx-runtime'].rules,
...reactHooksPlugin.configs['recommended-latest'].rules,
...nextPlugin.configs.recommended.rules,
...nextPlugin.configs['core-web-vitals'].rules,
'react/no-unknown-property': 'off',
'react/prop-types': 'off',
'react/no-unescaped-entities': 'off',
'@next/next/no-img-element': 'warn',
'@typescript-eslint/no-explicit-any': 'error',
// Enforce no unused variables project-wide.
// Convention: prefix intentionally-unused params/vars with _ to suppress.
'no-unused-vars': 'off', // disabled in favour of the TS-aware rule below
'@typescript-eslint/no-unused-vars': [
'error',
{
vars: 'all',
args: 'after-used',
argsIgnorePattern: '^_',
caughtErrors: 'all',
caughtErrorsIgnorePattern: '^_',
ignoreRestSiblings: true,
},
],
'no-console': 'warn',
},
},
// ---------------------------------------------------------------------------
// Module boundary enforcement
//
// Applies to the three consumer layers: app, components, hooks.
// Each layer may only import from a lib module's public barrel, never from
// internal sub-paths. This prevents accidental coupling to implementation
// details and keeps the contract layer fully isolated.
// ---------------------------------------------------------------------------
{
files: [
'src/app/**/*.{ts,tsx}',
'src/components/**/*.{ts,tsx}',
'src/hooks/**/*.{ts,tsx}',
],
rules: {
'no-restricted-imports': [
'error',
{
patterns: BOUNDARY_PATTERNS,
},
],
},
},
];