eslint-plugin-th-rules
v3.6.1
Published
A List of custom ESLint rules created by Tomer Horowitz
Maintainers
Readme
eslint-plugin-th-rules
A set of custom ESLint rules designed to improve code quality, enforce consistency, and introduce development conventions across TypeScript, React, and JavaScript projects.
This plugin provides:
- Custom rules unique to this repository
- Recommended flat configs that bundle th-rules with popular third-party plugins
- Advanced composable config layers for consumers who want fine-grained control
Installation
npm install --save-dev eslint-plugin-th-rulesor
yarn add -D eslint-plugin-th-rulesThis plugin requires ESLint Flat Config (ESLint 8.21+).
Usage
The plugin exposes three public recommended configurations.
These are the presets most users should consume.
Recommended (Full Opinionated)
Includes:
- All th-rules
- External plugins (lodash, n, sonarjs, security)
- Opinionated rule settings for externals
// eslint.config.js
import thRules from "eslint-plugin-th-rules";
export default [
...thRules.configs.recommended
];Recommended + TypeScript
Recommended plus full strict/stylistic TypeScript configurations.
import thRules from "eslint-plugin-th-rules";
export default [
...thRules.configs.recommendedTypescript
];Recommended + React
Recommended plus:
- eslint-plugin-react
- eslint-plugin-react-hooks
- JSX Runtime rules
import thRules from "eslint-plugin-th-rules";
export default [
...thRules.configs.recommendedReact
];Recommended + TypeScript + React
Recommended plus TypeScript and React extensions.
import thRules from "eslint-plugin-th-rules";
export default [
...thRules.configs.recommendedTypescriptReact
];Advanced Composition (Optional)
If you want total control, you may import internal composition layers.
These layers are intentionally not included in configs, because they are not presets but building blocks.
import {
coreBase,
externalsBase,
externalsOpinionated,
coreTypescript,
coreReact
} from "eslint-plugin-th-rules";Only use th-rules
export default [
...coreBase
];Add external plugins (unstyled)
export default [
...coreBase,
...externalsBase
];Add external plugins + th-rules opinions
export default [
...coreBase,
...externalsBase,
...externalsOpinionated
];Add TypeScript or React extensions
export default [
...coreBase,
...externalsBase,
...externalsOpinionated,
...coreTypescript,
...coreReact
];Auto-Generated Rule Documentation
The following section is generated via eslint-doc-generator.
Do not edit below this line.
Rules
💼 Configurations enabled in.
✅ Set in the recommended configuration.
⚛️ Set in the recommendedReact configuration.
🟦 Set in the recommendedTypescript configuration.
🎲 Set in the recommendedTypescriptReact configuration.
🔧 Automatically fixable by the --fix CLI option.
| Name | Description | 💼 | 🔧 | | :--------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------- | :- | | no-boolean-coercion | Disallow Boolean(value) or !!value. Enforce explicit checks: !.isNil(value) for scalars and !.isEmpty(value) for strings, arrays, and objects. If the value is already boolean, remove coercion. | ✅ ⚛️ 🟦 🎲 | 🔧 | | no-comments | Disallow comments except for specified allowed patterns. | ✅ ⚛️ 🟦 🎲 | 🔧 | | no-default-export | Convert unnamed default exports to named default exports based on the file name. | ✅ ⚛️ 🟦 🎲 | 🔧 | | no-destructuring | Disallow destructuring that does not meet certain conditions. | ✅ ⚛️ 🟦 🎲 | | | no-explicit-nil-compare | Disallow direct comparisons to null or undefined. Use _.isNull(x) / _.isUndefined(x) instead. | ✅ ⚛️ 🟦 🎲 | 🔧 | | no-isnil-isempty-on-boolean | Disallow _.isNil(...) / _.isEmpty(...) when the argument type is boolean or a union containing boolean (e.g., boolean | undefined, boolean | X). | ✅ ⚛️ 🟦 🎲 | | | prefer-explicit-nil-check | Disallow implicit truthy/falsy checks in boolean-test positions. Prefer explicit _.isNil(value) or _.isEmpty(value) (depending on the value type). | ✅ ⚛️ 🟦 🎲 | 🔧 | | prefer-is-empty | Require _.isEmpty instead of length comparisons or boolean checks on .length. | ✅ ⚛️ 🟦 🎲 | 🔧 | | prefer-lodash-iteratee-shorthand | Prefer Lodash iteratee shorthands. Example: _.find(collection, (x) => x.Y === z) -> _.find(collection, {Y: z}). Also prefers property shorthands like _.map(collection, (x) => _.get(x, path)) -> _.map(collection, path). | ✅ ⚛️ 🟦 🎲 | 🔧 | | schemas-in-schemas-file | Require Zod schema declarations to be placed in a .schemas.ts file. | ✅ ⚛️ 🟦 🎲 | | | top-level-functions | Require all top-level functions to be named regular functions. | ✅ ⚛️ 🟦 🎲 | 🔧 | | types-in-dts | Require TypeScript type declarations (type/interface/enum) to be placed in .d.ts files. | ✅ ⚛️ 🟦 🎲 | |
License
MIT
