ESLint plugin to enforce pattern rules in Clean Architecture. Currently enforces that find*
operations are only defined within repository layer files.
npm install --save-dev eslint-plugin-goblock-custom-rules
# or
yarn add -D eslint-plugin-goblock-custom-rules
// eslint.config.js
import repositoryPlugin from "eslint-plugin-goblock-custom-rules";
export default [
{
files: ["src/**/*.ts"],
plugins: {
repository: repositoryPlugin,
},
rules: {
"repository/no-find-outside-repository": "error",
},
},
];
// .eslintrc.js
module.exports = {
plugins: ["eslint-plugin-goblock-custom-rules"],
rules: {
"eslint-plugin-goblock-custom-rules/no-find-outside-repository": "error",
},
};
Ensures that functions starting with find
are only defined within repository files.
// user.repository.ts
export class UserRepository {
async findAll() {
// Allowed in repository files
return this.users.find();
}
}
// user.service.ts
export class UserService {
async findAll() {
// Error: find operations should be in repository layer
return this.users.find();
}
}
// user.controller.ts
export class UserController {
async findById() {
// Error: find operations should be in repository layer
return this.service.findById();
}
}
MIT © goBlockchain