website refactor
This commit is contained in:
13
adapters/.eslintrc.json
Normal file
13
adapters/.eslintrc.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"extends": [
|
||||
"../.eslintrc.json",
|
||||
"plugin:gridpilot-adapters-rules/recommended"
|
||||
],
|
||||
"plugins": [
|
||||
"gridpilot-adapters-rules"
|
||||
],
|
||||
"rules": {
|
||||
"gridpilot-adapters-rules/no-index-files": "error",
|
||||
"gridpilot-adapters-rules/adapter-naming": "error"
|
||||
}
|
||||
}
|
||||
37
adapters/eslint-rules/adapter-naming.js
Normal file
37
adapters/eslint-rules/adapter-naming.js
Normal file
@@ -0,0 +1,37 @@
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: 'problem',
|
||||
docs: {
|
||||
description: 'Enforce adapter naming conventions',
|
||||
category: 'Architecture',
|
||||
recommended: true,
|
||||
},
|
||||
fixable: null,
|
||||
schema: [],
|
||||
messages: {
|
||||
invalidNaming: 'Adapter classes should end with "Adapter", "Repository", "Service", or "Entity". Found: {{name}}',
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
return {
|
||||
ClassDeclaration(node) {
|
||||
const filename = context.getFilename();
|
||||
if (!filename.includes('adapters/')) return;
|
||||
|
||||
const name = node.id.name;
|
||||
const isValidName = /(.+)(Adapter|Repository|Service|Entity|Mapper|Schema|Guard|Module|Controller)$/.test(name);
|
||||
|
||||
if (!isValidName) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'invalidNaming',
|
||||
data: {
|
||||
name,
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
18
adapters/eslint-rules/index.js
Normal file
18
adapters/eslint-rules/index.js
Normal file
@@ -0,0 +1,18 @@
|
||||
const noIndexFiles = require('./no-index-files');
|
||||
const adapterNaming = require('./adapter-naming');
|
||||
|
||||
module.exports = {
|
||||
rules: {
|
||||
'no-index-files': noIndexFiles,
|
||||
'adapter-naming': adapterNaming,
|
||||
},
|
||||
configs: {
|
||||
recommended: {
|
||||
plugins: ['gridpilot-adapters-rules'],
|
||||
rules: {
|
||||
'gridpilot-adapters-rules/no-index-files': 'error',
|
||||
'gridpilot-adapters-rules/adapter-naming': 'error',
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
35
adapters/eslint-rules/no-index-files.js
Normal file
35
adapters/eslint-rules/no-index-files.js
Normal file
@@ -0,0 +1,35 @@
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: 'problem',
|
||||
docs: {
|
||||
description: 'Ban index.ts files in Adapters - use explicit imports instead',
|
||||
category: 'Best Practices',
|
||||
recommended: true,
|
||||
},
|
||||
fixable: null,
|
||||
schema: [],
|
||||
messages: {
|
||||
indexFile: 'Index files are banned in adapters. 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 = [
|
||||
'adapters/index.ts',
|
||||
];
|
||||
|
||||
if (isIndexFile && !allowedPaths.some(path => filename.endsWith(path))) {
|
||||
context.report({
|
||||
node: null,
|
||||
loc: { line: 1, column: 0 },
|
||||
messageId: 'indexFile',
|
||||
});
|
||||
}
|
||||
|
||||
return {};
|
||||
},
|
||||
};
|
||||
8
adapters/eslint-rules/package.json
Normal file
8
adapters/eslint-rules/package.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "eslint-plugin-gridpilot-adapters-rules",
|
||||
"version": "0.1.0",
|
||||
"main": "index.js",
|
||||
"peerDependencies": {
|
||||
"eslint": ">=8.0.0"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user