eslint rules
This commit is contained in:
@@ -57,7 +57,8 @@
|
||||
"gridpilot-rules/filename-matches-export": "off",
|
||||
"gridpilot-rules/single-export-per-file": "off",
|
||||
"gridpilot-rules/view-data-builder-contract": "off",
|
||||
"gridpilot-rules/view-data-builder-implements": "error"
|
||||
"gridpilot-rules/view-data-builder-implements": "error",
|
||||
"gridpilot-rules/view-data-builder-imports": "error"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -47,6 +47,7 @@ const serverActionsReturnResult = require('./server-actions-return-result');
|
||||
const serverActionsInterface = require('./server-actions-interface');
|
||||
const noDisplayObjectsInUi = require('./no-display-objects-in-ui');
|
||||
const viewDataBuilderImplements = require('./view-data-builder-implements');
|
||||
const viewDataBuilderImports = require('./view-data-builder-imports');
|
||||
const viewModelBuilderImplements = require('./view-model-builder-implements');
|
||||
const viewDataImplements = require('./view-data-implements');
|
||||
const viewModelImplements = require('./view-model-implements');
|
||||
@@ -133,6 +134,7 @@ module.exports = {
|
||||
'view-data-location': viewDataLocation,
|
||||
'view-data-builder-contract': viewDataBuilderContract,
|
||||
'view-data-builder-implements': viewDataBuilderImplements,
|
||||
'view-data-builder-imports': viewDataBuilderImports,
|
||||
'view-data-implements': viewDataImplements,
|
||||
|
||||
// View Model Rules
|
||||
@@ -262,6 +264,7 @@ module.exports = {
|
||||
'gridpilot-rules/view-data-location': 'error',
|
||||
'gridpilot-rules/view-data-builder-contract': 'error',
|
||||
'gridpilot-rules/view-data-builder-implements': 'error',
|
||||
'gridpilot-rules/view-data-builder-imports': 'error',
|
||||
'gridpilot-rules/view-data-implements': 'error',
|
||||
|
||||
// View Model
|
||||
|
||||
80
apps/website/eslint-rules/view-data-builder-imports.js
Normal file
80
apps/website/eslint-rules/view-data-builder-imports.js
Normal file
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* ESLint rule to enforce ViewDataBuilder import paths
|
||||
*
|
||||
* ViewDataBuilders in lib/builders/view-data/ must:
|
||||
* 1. Import DTO types from lib/types/generated/
|
||||
* 2. Import ViewData types from lib/view-data/
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: 'problem',
|
||||
docs: {
|
||||
description: 'Enforce ViewDataBuilder import paths',
|
||||
category: 'Builders',
|
||||
recommended: true,
|
||||
},
|
||||
fixable: null,
|
||||
schema: [],
|
||||
messages: {
|
||||
invalidDtoImport: 'ViewDataBuilders must import DTO types from lib/types/generated/, not from {{importPath}}',
|
||||
invalidViewDataImport: 'ViewDataBuilders must import ViewData types from lib/view-data/, not from {{importPath}}',
|
||||
missingDtoImport: 'ViewDataBuilders must import DTO types from lib/types/generated/',
|
||||
missingViewDataImport: 'ViewDataBuilders must import ViewData types from lib/view-data/',
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const filename = context.getFilename();
|
||||
const isInViewDataBuilders = filename.includes('/lib/builders/view-data/');
|
||||
|
||||
if (!isInViewDataBuilders) return {};
|
||||
|
||||
let hasDtoImport = false;
|
||||
let hasViewDataImport = false;
|
||||
let dtoImportPath = null;
|
||||
let viewDataImportPath = null;
|
||||
|
||||
return {
|
||||
ImportDeclaration(node) {
|
||||
const importPath = node.source.value;
|
||||
|
||||
// Check for DTO imports (should be from lib/types/generated/)
|
||||
if (importPath.includes('/lib/types/')) {
|
||||
if (!importPath.includes('/lib/types/generated/')) {
|
||||
dtoImportPath = importPath;
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'invalidDtoImport',
|
||||
data: { importPath },
|
||||
});
|
||||
} else {
|
||||
hasDtoImport = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for ViewData imports (should be from lib/view-data/)
|
||||
if (importPath.includes('/lib/view-data/')) {
|
||||
hasViewDataImport = true;
|
||||
viewDataImportPath = importPath;
|
||||
}
|
||||
},
|
||||
|
||||
'Program:exit'() {
|
||||
if (!hasDtoImport) {
|
||||
context.report({
|
||||
node: context.getSourceCode().ast,
|
||||
messageId: 'missingDtoImport',
|
||||
});
|
||||
}
|
||||
|
||||
if (!hasViewDataImport) {
|
||||
context.report({
|
||||
node: context.getSourceCode().ast,
|
||||
messageId: 'missingViewDataImport',
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user