@soubiran/eslint 0.0.0 → 0.8.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/README.md +3 -0
- package/dist/index.d.mts +49 -0
- package/dist/index.mjs +49 -0
- package/package.json +29 -2
package/README.md
ADDED
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
//#region src/server-layering.d.ts
|
|
2
|
+
declare const serverLayeringPlugin: {
|
|
3
|
+
rules: {
|
|
4
|
+
'repositories-only-in-services': {
|
|
5
|
+
meta: {
|
|
6
|
+
type: string;
|
|
7
|
+
docs: {
|
|
8
|
+
description: any;
|
|
9
|
+
};
|
|
10
|
+
schema: never[];
|
|
11
|
+
messages: {
|
|
12
|
+
restricted: any;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
create(context: any): {
|
|
16
|
+
ImportDeclaration?: undefined;
|
|
17
|
+
ExportAllDeclaration?: undefined;
|
|
18
|
+
ExportNamedDeclaration?: undefined;
|
|
19
|
+
} | {
|
|
20
|
+
ImportDeclaration: (node: any) => void;
|
|
21
|
+
ExportAllDeclaration: (node: any) => void;
|
|
22
|
+
ExportNamedDeclaration(node: any): void;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
'services-only-in-controllers': {
|
|
26
|
+
meta: {
|
|
27
|
+
type: string;
|
|
28
|
+
docs: {
|
|
29
|
+
description: any;
|
|
30
|
+
};
|
|
31
|
+
schema: never[];
|
|
32
|
+
messages: {
|
|
33
|
+
restricted: any;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
create(context: any): {
|
|
37
|
+
ImportDeclaration?: undefined;
|
|
38
|
+
ExportAllDeclaration?: undefined;
|
|
39
|
+
ExportNamedDeclaration?: undefined;
|
|
40
|
+
} | {
|
|
41
|
+
ImportDeclaration: (node: any) => void;
|
|
42
|
+
ExportAllDeclaration: (node: any) => void;
|
|
43
|
+
ExportNamedDeclaration(node: any): void;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
//#endregion
|
|
49
|
+
export { serverLayeringPlugin };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
//#region src/server-layering.ts
|
|
2
|
+
function normalizePath(filePath) {
|
|
3
|
+
return filePath.replaceAll("\\", "/");
|
|
4
|
+
}
|
|
5
|
+
function createRestrictedRelativeImportRule({ allowedFile, importPattern, message }) {
|
|
6
|
+
return {
|
|
7
|
+
meta: {
|
|
8
|
+
type: "problem",
|
|
9
|
+
docs: { description: message },
|
|
10
|
+
schema: [],
|
|
11
|
+
messages: { restricted: message }
|
|
12
|
+
},
|
|
13
|
+
create(context) {
|
|
14
|
+
if (allowedFile(normalizePath(context.filename))) return {};
|
|
15
|
+
function check(node) {
|
|
16
|
+
const importSource = node.source?.value;
|
|
17
|
+
if (typeof importSource !== "string") return;
|
|
18
|
+
if (!importPattern.test(importSource.trim())) return;
|
|
19
|
+
context.report({
|
|
20
|
+
node: node.source,
|
|
21
|
+
messageId: "restricted"
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
ImportDeclaration: check,
|
|
26
|
+
ExportAllDeclaration: check,
|
|
27
|
+
ExportNamedDeclaration(node) {
|
|
28
|
+
if (node.source) check(node);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const serverLayeringPlugin = { rules: {
|
|
35
|
+
"repositories-only-in-services": createRestrictedRelativeImportRule({
|
|
36
|
+
allowedFile: (filePath) => filePath.includes("/src/server/services/"),
|
|
37
|
+
importPattern: /^(?:\.{1,2}\/)+repositories\/[^/]+\.repository$/u,
|
|
38
|
+
message: "Repositories can only be imported from services."
|
|
39
|
+
}),
|
|
40
|
+
"services-only-in-controllers": createRestrictedRelativeImportRule({
|
|
41
|
+
allowedFile: (filePath) => {
|
|
42
|
+
return filePath.includes("/src/server/controllers/") || filePath.includes("/src/server/mappers/") || filePath.includes("/src/server/workflows/") || filePath.endsWith("/src/server/index.ts");
|
|
43
|
+
},
|
|
44
|
+
importPattern: /^(?:\.{1,2}\/)+services\/[^/]+\.service$/u,
|
|
45
|
+
message: "Services can only be imported from controllers, mappers, workflows, or the worker entrypoint."
|
|
46
|
+
})
|
|
47
|
+
} };
|
|
48
|
+
//#endregion
|
|
49
|
+
export { serverLayeringPlugin };
|
package/package.json
CHANGED
|
@@ -1,4 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soubiran/eslint",
|
|
3
|
-
"
|
|
4
|
-
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.8.2",
|
|
5
|
+
"author": "Estéban Soubiran <esteban@soubiran.dev>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"funding": "https://github.com/sponsors/Barbapapazes",
|
|
8
|
+
"homepage": "https://github.com/Barbapapazes/.soubiran.dev",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/Barbapapazes/.soubiran.dev"
|
|
12
|
+
},
|
|
13
|
+
"bugs": "https://github.com/Barbapapazes/.soubiran.dev/issues",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.mts",
|
|
17
|
+
"import": "./dist/index.mjs"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"main": "dist/index.mjs",
|
|
21
|
+
"types": "dist/index.d.mts",
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"tsdown": "^0.21.10"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsdown"
|
|
30
|
+
}
|
|
31
|
+
}
|