Skip to content

Commit b346981

Browse files
committed
feature: @putout/plugin-convert-object-entries-to-object-keys: add
1 parent 2a3bd76 commit b346981

File tree

17 files changed

+223
-3
lines changed

17 files changed

+223
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,6 +2167,7 @@ It has a lot of plugins divided by groups:
21672167
| [`@putout/plugin-convert-assignment-to-arrow-function`](/packages/plugin-convert-assignment-to-arrow-function#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-convert-assignment-to-arrow-function.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-convert-assignment-to-arrow-function) |
21682168
| [`@putout/plugin-convert-const-to-let`](/packages/plugin-convert-const-to-let#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-convert-const-to-let.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-convert-const-to-let) |
21692169
| [`@putout/plugin-convert-object-entries-to-array-entries`](/packages/plugin-convert-object-entries-to-array-entries#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-convert-object-entries-to-array-entries.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-convert-object-entries-to-array-entries) |
2170+
| [`@putout/plugin-convert-object-entries-to-object-keys`](/packages/plugin-convert-object-entries-to-object-keys#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-convert-object-entries-to-object-keys.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-convert-object-entries-to-object-keys) |
21702171

21712172
### Removers
21722173

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules
2+
*.swp
3+
yarn-error.log
4+
5+
coverage
6+
.idea
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import {run} from 'madrun';
2+
3+
export default {
4+
'test': () => `tape 'test/*.js'`,
5+
'watch:test': async () => `nodemon -w lib -w test -x "${await run('test')}"`,
6+
'lint': () => `putout .`,
7+
'fresh:lint': () => run('lint', '--fresh'),
8+
'lint:fresh': () => run('lint', '--fresh'),
9+
'fix:lint': () => run('lint', '--fix'),
10+
'coverage': async () => `c8 ${await run('test')}`,
11+
'report': () => 'c8 report --reporter=lcov',
12+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.*
2+
test
3+
yarn-error.log
4+
5+
coverage
6+
*.config.*
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"check-coverage": true,
3+
"all": true,
4+
"exclude": [
5+
"**/*.spec.*",
6+
"**/fixture",
7+
"test",
8+
".*.*",
9+
"**/*.config.*"
10+
],
11+
"branches": 100,
12+
"lines": 100,
13+
"functions": 100,
14+
"statements": 100
15+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"match": {
3+
"*.md": {
4+
"convert-object-entries-to-object-keys": "off"
5+
}
6+
}
7+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) coderaiser
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# @putout/plugin-convert-object-entries-to-object-keys [![NPM version][NPMIMGURL]][NPMURL]
2+
3+
[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-convert-object-entries-to-object-keys.svg?style=flat&longCache=true
4+
[NPMURL]: https://npmjs.org/package/@putout/plugin-convert-object-entreis-to-object-keys "npm"
5+
6+
> The `Object.keys()` static method returns an array of a given object's own enumerable string-keyed property key-value pairs.
7+
>
8+
> (c) [`Object.keys()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys)
9+
10+
> The `Object.entries()` static method returns an array of a given object's own enumerable string-keyed property key-value pairs.
11+
>
12+
> (c) [`Object.entries()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
13+
14+
🐊[**Putout**](https://github.com/coderaiser/putout) plugin adds ability to convert `Object.entries()` to `Object.keys()`
15+
16+
Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/f902e1f52d551545cede97db4cfba345/dbae8bfd2c4b0b4ec9612e2002a87c2a5961204d).
17+
18+
## Install
19+
20+
```
21+
npm i @putout/plugin-convert-object-entries-to-object-keys -D
22+
```
23+
24+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/82cf60991515c274d0ba08f2ca36e9e6/bf3021f992f596d4316469c062cafd257c44c487).
25+
26+
## Rule
27+
28+
```json
29+
{
30+
"rules": {
31+
"convert-object-entries-to-object-keys": "on"
32+
}
33+
}
34+
```
35+
36+
## ❌ Example of incorrect code
37+
38+
```js
39+
for (const [name] of Object.entries(tokens)) {
40+
console.log(name);
41+
}
42+
```
43+
44+
## ✅ Example of correct code
45+
46+
```js
47+
for (const name of Object.keys(tokens)) {
48+
console.log(name);
49+
}
50+
```
51+
52+
## License
53+
54+
MIT
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import {safeAlign} from 'eslint-plugin-putout';
2+
3+
export default safeAlign;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const report = () => `Use 'Object.keys()' instead of 'Object.enries()'`;
2+
3+
export const replace = () => ({
4+
'for (const [__a] of Object.entries(__b)) __body': 'for (const __a of Object.keys(__b)) __body',
5+
'for (const [__a] of entries(__b)) __body': 'for (const __a of keys(__b)) __body',
6+
});

0 commit comments

Comments
 (0)