A List of custom ESLint rules created by Tomer Horowitz
npm install eslint-plugin-th-rulesA 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
---
``bash`
npm install --save-dev eslint-plugin-th-rules`
orbash`
yarn add -D eslint-plugin-th-rules
This plugin requires ESLint Flat Config (ESLint 8.21+).
---
The plugin exposes three public recommended configurations.
These are the presets most users should consume.
Includes:
- All th-rules
- External plugins (lodash, n, sonarjs, security)
- Opinionated rule settings for externals
`js
// eslint.config.js
import thRules from "eslint-plugin-th-rules";
export default [
...thRules.configs.recommended
];
`
Recommended plus full strict/stylistic TypeScript configurations.
`js
import thRules from "eslint-plugin-th-rules";
export default [
...thRules.configs.recommendedTypescript
];
`
Recommended plus:
- eslint-plugin-react
- eslint-plugin-react-hooks
- JSX Runtime rules
`js
import thRules from "eslint-plugin-th-rules";
export default [
...thRules.configs.recommendedReact
];
`
`js
import thRules from "eslint-plugin-th-rules";
export default [
...thRules.configs.recommendedTypescriptReact
];
`
---
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.
`js`
import {
coreBase,
externalsBase,
externalsOpinionated,
coreTypescript,
coreReact
} from "eslint-plugin-th-rules";
`js`
export default [
...coreBase
];
`js`
export default [
...coreBase,
...externalsBase
];
`js`
export default [
...coreBase,
...externalsBase,
...externalsOpinionated
];
`js`
export default [
...coreBase,
...externalsBase,
...externalsOpinionated,
...coreTypescript,
...coreReact
];
---
The following section is generated via eslint-doc-generator.
Do not edit below this line.
πΌ Configurations enabled in.\
β
Set in the recommended configuration.\recommendedReact
βοΈ Set in the configuration.\recommendedTypescript
π¦ Set in the configuration.\recommendedTypescriptReact
π² Set in the configuration.\--fix` CLI option.
π§ Automatically fixable by the
| 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. | β
βοΈ π¦ π² | |
---
MIT