Repository navigation
Expand file tree
/
Copy patheslint.config.mjs
More file actions
100 lines (98 loc) · 3.76 KB
/
Copy patheslint.config.mjs
File metadata and controls
100 lines (98 loc) · 3.76 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
// @ts-check
import eslint from '@eslint/js';
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
import globals from 'globals';
import tseslint from 'typescript-eslint';
// Nest's Logger prints through its own ConsoleLogger until main.ts installs the app logger, and passes
// metadata objects on as the context name; createLogger() applies LOG_LEVEL, LOG_FORMAT, redaction and
// the request id everywhere. Shared with the controller block below, because a later block's
// no-restricted-syntax replaces this one's options instead of merging with them.
const NO_NEST_LOGGER = {
selector: "NewExpression[callee.name='Logger']",
message: 'Use createLogger() from common/services/logger.service instead of new Logger().',
};
export default tseslint.config(
{
ignores: ['eslint.config.mjs'],
},
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
eslintPluginPrettierRecommended,
{
languageOptions: {
globals: {
...globals.node,
...globals.jest,
},
sourceType: 'commonjs',
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
{
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-floating-promises': 'warn',
'@typescript-eslint/no-unsafe-argument': 'warn',
"prettier/prettier": ["error", { endOfLine: "auto" }],
},
},
{
files: ['src/**/*.ts'],
ignores: ['**/*.spec.ts'],
rules: {
'no-restricted-syntax': ['error', NO_NEST_LOGGER],
},
},
{
// Architecture guard: HTTP controllers must go through a per-capability service and
// never reach for the raw WhatsApp engine. This keeps the "session not started" guard,
// error mapping, and business rules behind the service boundary instead of leaking into
// controllers. `.getEngine(` (not `.getEngines()`), the EngineRegistry accessors, and the
// `IWhatsAppEngine` type are banned.
files: ['**/*.controller.ts'],
rules: {
'no-restricted-syntax': [
'error',
NO_NEST_LOGGER,
{
selector: "CallExpression[callee.property.name='getEngine']",
message:
'Controllers must not call getEngine(). Add a method to the capability service (e.g. GroupService) and call that instead.',
},
{
// EngineRegistry.require()/get() resolve a live engine, so reaching for either from a
// controller bypasses the capability service exactly as getEngine() used to. Matches
// `this.engines.require(...)` (a MemberExpression callee object) as well as a bare
// `engines.require(...)`.
selector:
"CallExpression[callee.property.name=/^(require|get)$/]:has(MemberExpression[property.name='engines'])",
message:
'Controllers must not resolve an engine from EngineRegistry. Add a method to the capability service and call that instead.',
},
],
'no-restricted-imports': [
'error',
{
patterns: [
{
// Only the engine abstraction itself is banned — data shapes (e.g. ChatSummary)
// that happen to live in the same file remain importable by controllers.
group: ['**/engine/interfaces/whatsapp-engine.interface'],
importNames: ['IWhatsAppEngine'],
message:
'Controllers must not import IWhatsAppEngine. Keep engine types behind a capability service.',
},
{
group: ['**/engine/engine-registry.service'],
message:
'Controllers must not import EngineRegistry. Keep engine access behind a capability service.',
},
],
},
],
},
},
);