Update
This commit is contained in:
9
src/rules/index.ts
Normal file
9
src/rules/index.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import type { Rule } from 'eslint';
|
||||
|
||||
import noImportDot from "./no-import-dot";
|
||||
import requireNodePrefix from "./require-node-prefix"
|
||||
|
||||
export const rules: Record<string, Rule.RuleModule> = {
|
||||
"no-import-dot": noImportDot,
|
||||
"require-node-prefix": requireNodePrefix
|
||||
};
|
@ -1,32 +0,0 @@
|
||||
import type { Rule } from "eslint";
|
||||
|
||||
const rule: Rule.RuleModule = {
|
||||
meta: {
|
||||
type: "problem",
|
||||
docs: {
|
||||
description: "Disallow direct usage of `new PrismaClient()`",
|
||||
category: "Best Practices",
|
||||
recommended: true,
|
||||
},
|
||||
},
|
||||
create(context) {
|
||||
// Check if the file is the target file where the import is allowed
|
||||
if (context.filename.endsWith("src/utils/db.ts")) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return {
|
||||
NewExpression(node) {
|
||||
if (node.callee.type === "Identifier" && node.callee.name === "PrismaClient") {
|
||||
context.report({
|
||||
node,
|
||||
message:
|
||||
"Avoid direct usage of `new PrismaClient()`. Import from `src/utils/db.ts` instead.",
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
export default rule;
|
@ -1,33 +0,0 @@
|
||||
import type { Rule } from "eslint";
|
||||
|
||||
const rule: Rule.RuleModule = {
|
||||
meta: {
|
||||
type: "problem",
|
||||
docs: {
|
||||
description: "Disallow importing webcrypto from node:crypto and crypto modules",
|
||||
category: "Best Practices",
|
||||
recommended: true,
|
||||
},
|
||||
schema: [],
|
||||
},
|
||||
create: context => ({
|
||||
ImportDeclaration(node) {
|
||||
const importedSource = node.source.value as string;
|
||||
const importedSpecifier = node.specifiers[0];
|
||||
|
||||
if (
|
||||
(importedSource === "crypto" || importedSource === "node:crypto") &&
|
||||
importedSpecifier.type === "ImportSpecifier" &&
|
||||
importedSpecifier.local.name === "webcrypto"
|
||||
) {
|
||||
context.report({
|
||||
node: importedSpecifier,
|
||||
message:
|
||||
"Do not import 'webcrypto' from 'crypto' or 'node:crypto'. Use the global variable 'crypto' instead.",
|
||||
});
|
||||
}
|
||||
},
|
||||
}),
|
||||
};
|
||||
|
||||
export default rule;
|
Reference in New Issue
Block a user