website refactor
This commit is contained in:
13
core/.eslintrc.json
Normal file
13
core/.eslintrc.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"extends": [
|
||||
"../.eslintrc.json",
|
||||
"plugin:gridpilot-core-rules/recommended"
|
||||
],
|
||||
"plugins": [
|
||||
"gridpilot-core-rules"
|
||||
],
|
||||
"rules": {
|
||||
"gridpilot-core-rules/no-index-files": "error",
|
||||
"gridpilot-core-rules/no-framework-imports": "error"
|
||||
}
|
||||
}
|
||||
37
core/eslint-rules/domain-no-application.js
Normal file
37
core/eslint-rules/domain-no-application.js
Normal file
@@ -0,0 +1,37 @@
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: 'problem',
|
||||
docs: {
|
||||
description: 'Enforce that Core Domain does not depend on Application layer',
|
||||
category: 'Architecture',
|
||||
recommended: true,
|
||||
},
|
||||
fixable: null,
|
||||
schema: [],
|
||||
messages: {
|
||||
forbiddenImport: 'Domain layer should not depend on Application layer. Forbidden import from "{{source}}".',
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const filename = context.getFilename();
|
||||
const isDomainFile = filename.includes('/domain/');
|
||||
|
||||
if (!isDomainFile) return {};
|
||||
|
||||
return {
|
||||
ImportDeclaration(node) {
|
||||
const source = node.source.value;
|
||||
if (source.includes('/application/')) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'forbiddenImport',
|
||||
data: {
|
||||
source,
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
21
core/eslint-rules/index.js
Normal file
21
core/eslint-rules/index.js
Normal file
@@ -0,0 +1,21 @@
|
||||
const noIndexFiles = require('./no-index-files');
|
||||
const noFrameworkImports = require('./no-framework-imports');
|
||||
const domainNoApplication = require('./domain-no-application');
|
||||
|
||||
module.exports = {
|
||||
rules: {
|
||||
'no-index-files': noIndexFiles,
|
||||
'no-framework-imports': noFrameworkImports,
|
||||
'domain-no-application': domainNoApplication,
|
||||
},
|
||||
configs: {
|
||||
recommended: {
|
||||
plugins: ['gridpilot-core-rules'],
|
||||
rules: {
|
||||
'gridpilot-core-rules/no-index-files': 'error',
|
||||
'gridpilot-core-rules/no-framework-imports': 'error',
|
||||
'gridpilot-core-rules/domain-no-application': 'error',
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
39
core/eslint-rules/no-framework-imports.js
Normal file
39
core/eslint-rules/no-framework-imports.js
Normal file
@@ -0,0 +1,39 @@
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: 'problem',
|
||||
docs: {
|
||||
description: 'Ban framework imports in Core',
|
||||
category: 'Architecture',
|
||||
recommended: true,
|
||||
},
|
||||
fixable: null,
|
||||
schema: [],
|
||||
messages: {
|
||||
frameworkImport: 'Core must be framework-free. Forbidden import from "{{source}}".',
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const forbiddenPatterns = [
|
||||
/^@nestjs\//,
|
||||
/^express/,
|
||||
/^react/,
|
||||
/^next\//,
|
||||
];
|
||||
|
||||
return {
|
||||
ImportDeclaration(node) {
|
||||
const source = node.source.value;
|
||||
if (forbiddenPatterns.some(pattern => pattern.test(source))) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'frameworkImport',
|
||||
data: {
|
||||
source,
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
35
core/eslint-rules/no-index-files.js
Normal file
35
core/eslint-rules/no-index-files.js
Normal file
@@ -0,0 +1,35 @@
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: 'problem',
|
||||
docs: {
|
||||
description: 'Ban index.ts files in Core - use explicit imports instead',
|
||||
category: 'Best Practices',
|
||||
recommended: true,
|
||||
},
|
||||
fixable: null,
|
||||
schema: [],
|
||||
messages: {
|
||||
indexFile: 'Index files are banned in core. Use explicit imports. Example: Instead of "import { foo } from "./", use "import { foo } from "./foo".',
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const filename = context.getFilename();
|
||||
const isIndexFile = /(^|\/|\\)index\.ts$/.test(filename);
|
||||
|
||||
// Allow root index.ts if any
|
||||
const allowedPaths = [
|
||||
'core/index.ts',
|
||||
];
|
||||
|
||||
if (isIndexFile && !allowedPaths.some(path => filename.endsWith(path))) {
|
||||
context.report({
|
||||
node: null,
|
||||
loc: { line: 1, column: 0 },
|
||||
messageId: 'indexFile',
|
||||
});
|
||||
}
|
||||
|
||||
return {};
|
||||
},
|
||||
};
|
||||
8
core/eslint-rules/package.json
Normal file
8
core/eslint-rules/package.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "eslint-plugin-gridpilot-core-rules",
|
||||
"version": "0.1.0",
|
||||
"main": "index.js",
|
||||
"peerDependencies": {
|
||||
"eslint": ">=8.0.0"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user