eslint-plugin-th-rules 2.6.1 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [2.7.0](https://github.com/tomerh2001/eslint-plugin-th-rules/compare/v2.6.1...v2.7.0) (2026-01-14)
2
+
3
+
4
+ ### Features
5
+
6
+ * remove prefer-explicit-nil-or-empty-check rule and associated tests ([2aded48](https://github.com/tomerh2001/eslint-plugin-th-rules/commit/2aded48d6f7df8d205cf7817afe3c0fdca39601c))
7
+
1
8
  ## [2.6.1](https://github.com/tomerh2001/eslint-plugin-th-rules/compare/v2.6.0...v2.6.1) (2026-01-14)
2
9
 
3
10
 
package/README.md CHANGED
@@ -11,24 +11,22 @@ This repository contains custom ESLint rules to enhance code quality and consist
11
11
  <!-- begin auto-generated rules list -->
12
12
 
13
13
  💼 Configurations enabled in.\
14
- 🚫 Configurations disabled in.\
15
14
  ✅ Set in the `recommended` configuration.\
16
15
  ⚛️ Set in the `recommended-react` configuration.\
17
16
  🟦 Set in the `recommended-typescript` configuration.\
18
17
  🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).\
19
18
  💡 Manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).
20
19
 
21
- | Name                               | Description | 💼 | 🚫 | 🔧 | 💡 |
22
- | :------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------- | :------ | :- | :- | :- |
23
- | [no-boolean-coercion](docs/rules/no-boolean-coercion.md) | Disallow Boolean(value) or !!value. Enforce _.isNil(value) for scalar values and _.isEmpty(value) for strings, arrays, and objects. | ✅ ⚛️ 🟦 | | | 💡 |
24
- | [no-comments](docs/rules/no-comments.md) | Disallow comments except for specified allowed patterns. | ✅ ⚛️ 🟦 | | 🔧 | |
25
- | [no-default-export](docs/rules/no-default-export.md) | Convert unnamed default exports to named default exports based on the file name. | ✅ ⚛️ 🟦 | | 🔧 | |
26
- | [no-destructuring](docs/rules/no-destructuring.md) | Disallow destructuring that does not meet certain conditions | ✅ ⚛️ 🟦 | | | |
27
- | [prefer-explicit-nil-or-empty-check](docs/rules/prefer-explicit-nil-or-empty-check.md) | Disallow implicit truthy/falsy checks on non-boolean values; require _.isNil or _.isEmpty | | 🟦 | | 💡 |
28
- | [prefer-is-empty](docs/rules/prefer-is-empty.md) | Require _.isEmpty instead of length comparisons | ✅ ⚛️ 🟦 | | | 💡 |
29
- | [schemas-in-schemas-file](docs/rules/schemas-in-schemas-file.md) | Require Zod schema declarations to be placed in a .schemas.ts file | ✅ ⚛️ 🟦 | | | |
30
- | [top-level-functions](docs/rules/top-level-functions.md) | Require all top-level functions to be named/regular functions. | ✅ ⚛️ 🟦 | | 🔧 | |
31
- | [types-in-dts](docs/rules/types-in-dts.md) | Require TypeScript type declarations (type/interface/enum) to be placed in .d.ts files | ✅ ⚛️ 🟦 | | | |
20
+ | Name                    | Description | 💼 | 🔧 | 💡 |
21
+ | :--------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------- | :------ | :- | :- |
22
+ | [no-boolean-coercion](docs/rules/no-boolean-coercion.md) | Disallow Boolean(value) or !!value. Enforce _.isNil(value) for scalar values and _.isEmpty(value) for strings, arrays, and objects. | ✅ ⚛️ 🟦 | | 💡 |
23
+ | [no-comments](docs/rules/no-comments.md) | Disallow comments except for specified allowed patterns. | ✅ ⚛️ 🟦 | 🔧 | |
24
+ | [no-default-export](docs/rules/no-default-export.md) | Convert unnamed default exports to named default exports based on the file name. | ✅ ⚛️ 🟦 | 🔧 | |
25
+ | [no-destructuring](docs/rules/no-destructuring.md) | Disallow destructuring that does not meet certain conditions | ✅ ⚛️ 🟦 | | |
26
+ | [prefer-is-empty](docs/rules/prefer-is-empty.md) | Require _.isEmpty instead of length comparisons | ⚛️ 🟦 | | 💡 |
27
+ | [schemas-in-schemas-file](docs/rules/schemas-in-schemas-file.md) | Require Zod schema declarations to be placed in a .schemas.ts file | ✅ ⚛️ 🟦 | | |
28
+ | [top-level-functions](docs/rules/top-level-functions.md) | Require all top-level functions to be named/regular functions. | ✅ ⚛️ 🟦 | 🔧 | |
29
+ | [types-in-dts](docs/rules/types-in-dts.md) | Require TypeScript type declarations (type/interface/enum) to be placed in .d.ts files | ✅ ⚛️ 🟦 | | |
32
30
 
33
31
  <!-- end auto-generated rules list -->
34
32
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-th-rules",
3
- "version": "2.6.1",
3
+ "version": "2.7.0",
4
4
  "description": "A List of custom ESLint rules created by Tomer Horowitz",
5
5
  "keywords": [
6
6
  "eslint",
package/src/index.js CHANGED
@@ -67,7 +67,6 @@ const baseRecommended = {
67
67
  'th-rules/types-in-dts': 'error',
68
68
  'th-rules/no-boolean-coercion': 'error',
69
69
  'th-rules/prefer-is-empty': 'error',
70
- 'th-rules/prefer-explicit-nil-or-empty-check': 'off',
71
70
  'unicorn/filename-case': 'off',
72
71
  'unicorn/no-array-callback-reference': 'off',
73
72
  'import/extensions': 'off',
@@ -1,9 +0,0 @@
1
- # th-rules/prefer-explicit-nil-or-empty-check
2
-
3
- 📝 Disallow implicit truthy/falsy checks on non-boolean values; require _.isNil or _.isEmpty.
4
-
5
- 🚫 This rule is _disabled_ in the 🟦 `recommended-typescript` config.
6
-
7
- 💡 This rule is manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).
8
-
9
- <!-- end auto-generated rule header -->
@@ -1,102 +0,0 @@
1
- const meta = {
2
- type: 'problem',
3
- docs: {
4
- description:
5
- 'Disallow implicit truthy/falsy checks on non-boolean values; require _.isNil or _.isEmpty',
6
- category: 'Best Practices',
7
- recommended: true,
8
- url: 'https://github.com/tomerh2001/eslint-plugin-th-rules/blob/main/docs/rules/prefer-explicit-nil-or-empty-check.md',
9
- },
10
- hasSuggestions: true,
11
- schema: [],
12
- };
13
-
14
- function create(context) {
15
- const sourceCode = context.getSourceCode();
16
-
17
- function isBooleanLiteral(node) {
18
- return node.type === 'Literal' && typeof node.value === 'boolean';
19
- }
20
-
21
- function isUnaryNot(node) {
22
- return node.type === 'UnaryExpression' && node.operator === '!';
23
- }
24
-
25
- function isImplicitTruthyTarget(node) {
26
- return (
27
- node.type === 'Identifier'
28
- || node.type === 'MemberExpression'
29
- );
30
- }
31
-
32
- function report(node, testedNode, negated) {
33
- const text = sourceCode.getText(testedNode);
34
-
35
- const isNilExpr = negated
36
- ? `!_.isNil(${text})`
37
- : `_.isNil(${text})`;
38
-
39
- const isEmptyExpr = negated
40
- ? `!_.isEmpty(${text})`
41
- : `_.isEmpty(${text})`;
42
-
43
- context.report({
44
- node,
45
- message:
46
- 'Implicit truthy/falsy check on a non-boolean value is not allowed; use explicit _.isNil or _.isEmpty checks',
47
- suggest: [
48
- {
49
- desc: `Replace with ${isNilExpr}`,
50
- fix: fixer => fixer.replaceText(node, isNilExpr),
51
- },
52
- {
53
- desc: `Replace with ${isEmptyExpr}`,
54
- fix: fixer => fixer.replaceText(node, isEmptyExpr),
55
- },
56
- ],
57
- });
58
- }
59
-
60
- function checkTestExpression(node) {
61
- // If (dataObject)
62
- if (isImplicitTruthyTarget(node)) {
63
- report(node, node, true);
64
- return;
65
- }
66
-
67
- // If (!dataObject)
68
- if (
69
- isUnaryNot(node)
70
- && isImplicitTruthyTarget(node.argument)
71
- && !isBooleanLiteral(node.argument)
72
- ) {
73
- report(node, node.argument, false);
74
- }
75
- }
76
-
77
- return {
78
- IfStatement(node) {
79
- checkTestExpression(node.test);
80
- },
81
-
82
- WhileStatement(node) {
83
- checkTestExpression(node.test);
84
- },
85
-
86
- DoWhileStatement(node) {
87
- checkTestExpression(node.test);
88
- },
89
-
90
- ConditionalExpression(node) {
91
- checkTestExpression(node.test);
92
- },
93
-
94
- LogicalExpression(node) {
95
- if (node.operator === '&&' || node.operator === '||') {
96
- checkTestExpression(node.left);
97
- }
98
- },
99
- };
100
- }
101
-
102
- module.exports = {meta, create};
@@ -1,113 +0,0 @@
1
- const {RuleTester} = require('@typescript-eslint/rule-tester');
2
- const rule = require('../src/rules/prefer-explicit-nil-or-empty-check');
3
-
4
- const ruleTester = new RuleTester({
5
- languageOptions: {
6
- ecmaVersion: 2020,
7
- sourceType: 'module',
8
- },
9
- });
10
-
11
- ruleTester.run('prefer-explicit-nil-or-empty-check', rule, {
12
- valid: [
13
- // Explicit checks – allowed
14
- 'if (_.isNil(value)) {}',
15
- 'if (!_.isNil(value)) {}',
16
- 'if (_.isEmpty(list)) {}',
17
- 'if (!_.isEmpty(list)) {}',
18
-
19
- // Explicit comparisons – allowed
20
- 'if (value != null) {}',
21
- 'if (list.length > 0) {}',
22
-
23
- // Boolean values – allowed
24
- 'if (true) {}',
25
- 'if (false) {}',
26
-
27
- // Non-control-flow usage – allowed
28
- 'value;',
29
- 'doSomething(value);',
30
- ],
31
-
32
- invalid: [
33
- {
34
- code: 'if (dataObject) {}',
35
- errors: [
36
- {
37
- message:
38
- 'Implicit truthy/falsy check on a non-boolean value is not allowed; use explicit _.isNil or _.isEmpty checks',
39
- suggestions: [
40
- {
41
- desc: 'Replace with !_.isNil(dataObject)',
42
- output: 'if (!_.isNil(dataObject)) {}',
43
- },
44
- {
45
- desc: 'Replace with !_.isEmpty(dataObject)',
46
- output: 'if (!_.isEmpty(dataObject)) {}',
47
- },
48
- ],
49
- },
50
- ],
51
- },
52
-
53
- {
54
- code: 'if (!dataObject) {}',
55
- errors: [
56
- {
57
- message:
58
- 'Implicit truthy/falsy check on a non-boolean value is not allowed; use explicit _.isNil or _.isEmpty checks',
59
- suggestions: [
60
- {
61
- desc: 'Replace with _.isNil(dataObject)',
62
- output: 'if (_.isNil(dataObject)) {}',
63
- },
64
- {
65
- desc: 'Replace with _.isEmpty(dataObject)',
66
- output: 'if (_.isEmpty(dataObject)) {}',
67
- },
68
- ],
69
- },
70
- ],
71
- },
72
-
73
- {
74
- code: 'while (items) {}',
75
- errors: [
76
- {
77
- message:
78
- 'Implicit truthy/falsy check on a non-boolean value is not allowed; use explicit _.isNil or _.isEmpty checks',
79
- suggestions: [
80
- {
81
- desc: 'Replace with !_.isNil(items)',
82
- output: 'while (!_.isNil(items)) {}',
83
- },
84
- {
85
- desc: 'Replace with !_.isEmpty(items)',
86
- output: 'while (!_.isEmpty(items)) {}',
87
- },
88
- ],
89
- },
90
- ],
91
- },
92
-
93
- {
94
- code: 'data && doSomething();',
95
- errors: [
96
- {
97
- message:
98
- 'Implicit truthy/falsy check on a non-boolean value is not allowed; use explicit _.isNil or _.isEmpty checks',
99
- suggestions: [
100
- {
101
- desc: 'Replace with !_.isNil(data)',
102
- output: '!_.isNil(data) && doSomething();',
103
- },
104
- {
105
- desc: 'Replace with !_.isEmpty(data)',
106
- output: '!_.isEmpty(data) && doSomething();',
107
- },
108
- ],
109
- },
110
- ],
111
- },
112
- ],
113
- });