eslint-plugin-compact-guards
v0.1.2
Published
ESLint plugin enforcing compact guard clauses: no braces, with the return/throw keyword on the same line as the closing parenthesis of the condition.
Maintainers
Readme
eslint-plugin-compact-guards
An ESLint plugin that enforces compact guard clauses: no braces, with the
return/throw keyword on the same line as the closing parenthesis of the if
condition.
// ✗ before
if (!user) {
return null;
}
// ✓ after
if (!user) return null;Installation
npm install --save-dev eslint-plugin-compact-guardsThis plugin supports ESLint ^8.57.1 || ^9 || ^10 and flat configuration.
Usage (flat config)
// eslint.config.js
import compactGuards from "eslint-plugin-compact-guards";
export default [
compactGuards.configs.recommended,
];Or wire the rule up manually:
import compactGuards from "eslint-plugin-compact-guards";
export default [
{
plugins: { "compact-guards": compactGuards },
rules: {
"compact-guards/compact-guard-clause": "error",
},
},
];Rule
compact-guard-clause— enforce compact guard clauses (fixable).
Development
npm install # install dependencies
npm run build # build ESM + CJS + type declarations with tsup
npm test # run the Vitest suite
npm run lint # lint the source
npm run verify # typecheck + lint + build + test + packed-package smoke testThe full development and release workflow is documented in
CONTRIBUTING.md.
