@putout/plugin-types 1.2.0 → 1.3.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/README.md CHANGED
@@ -19,7 +19,8 @@ npm i putout @putout/plugin-types -D
19
19
  "types/declare": "on",
20
20
  "types/convert-typeof-to-istype": "on",
21
21
  "types/remove-useless-conversion": "on",
22
- "types/remove-double-negations": "on"
22
+ "types/remove-double-negations": "on",
23
+ "types/remove-useless-typeof": "on"
23
24
  }
24
25
  }
25
26
  ```
@@ -89,7 +90,6 @@ if (isBool(a))
89
90
  return x;
90
91
  ```
91
92
 
92
-
93
93
  ### remove-useless-conversion
94
94
 
95
95
  #### ❌ Example of incorrect code
@@ -129,6 +129,24 @@ if (a) {
129
129
  }
130
130
  ```
131
131
 
132
+ ### remove-useless-typeof
133
+
134
+ > The `typeof` operator returns a string indicating the type of the unevaluated operand.
135
+ >
136
+ > (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof)
137
+
138
+ #### ❌ Example of incorrect code
139
+
140
+ ```js
141
+ typeof typeof 'hello';
142
+ ```
143
+
144
+ #### ✅ Example of correct code
145
+
146
+ ```js
147
+ typeof 'hello';
148
+ ```
149
+
132
150
  ## Comparison
133
151
 
134
152
  Linter | Rule | Fix
package/lib/index.js CHANGED
@@ -9,5 +9,6 @@ module.exports.rules = {
9
9
  ...getRule('convert-typeof-to-is-type'),
10
10
  ...getRule('remove-useless-conversion'),
11
11
  ...getRule('remove-double-negations'),
12
+ ...getRule('remove-useless-typeof'),
12
13
  };
13
14
 
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ module.exports.report = () => `Useless typeof should be avoided`;
4
+
5
+ module.exports.replace = () => ({
6
+ 'typeof typeof __a': 'typeof __a',
7
+ });
8
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-types",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin adds ability to transform code related to types assertions",