@thestartupfactory/eslint-plugin-open-rules
v1.0.19
Published
Custom ESLint rules to enforce specific coding standards and best practices for your project.
Downloads
308
Readme
TSF Open ESLint Rules
Custom ESLint rules to enforce specific coding standards and best practices for your project.
Installation
You can install the package via npm:
npm install @thestartupfactory/eslint-plugin-open-rules --save-dev
or via Yarn:
yarn add @thestartupfactory/eslint-plugin-open-rules --dev
Usage
To use these rules in your project, add the library as a plugin in your ESLint configuration.
Example .eslintrc.js:
module.exports = {
plugins: [
'@thestartupfactory/open-rules'
],
rules: {
'@thestartupfactory/open-rules/switch-exhaustive': 'error',
'@thestartupfactory/open-rules/prisma-explicit-select': 'warn',
'@thestartupfactory/open-rules/prisma-find-many-requires-limit': 'error',
}
};
Or add to your eslint configuration using default rules via:
"plugins": [
"@thestartupfactory/open-rules"
],
"extends": ["plugin:@thestartupfactory/eslint-plugin-open-rules/recommended"],
Configuration
Each rule in this library can be enabled or disabled independently, and configured to either warn or error as per your project’s requirements.
If additional configuration is needed for individual rules, refer to the rule-specific settings in the Rules section below.
Rules
Here’s a brief overview of the rules available in this library:
switch-exhaustive:
Ensures that switch statements include exhaustive cases, with a default case that calls an exhaustivenessCheck function to verify all cases are handled.
switch (value) {
case 'case1':
// handle case
break;
default:
exhaustivenessCheck(value);
}
prisma-explicit-select:
Enforces explicit select statements when using Prisma ORM to ensure only the required fields are fetched from the database.
const user = await prisma.user.findUnique({
where: { id: 1 },
select: { name: true, email: true } // Ensures specific fields are selected
});
prisma-find-many-requires-limit:
Ensures that findMany queries with Prisma ORM include a limit clause to prevent fetching large datasets unintentionally.
const users = await prisma.user.findMany({
where: { active: true },
take: 10 // Limit the results to 10
});