Skip to content

Commit d4bccaa

Browse files
committed
feature: @putout/plugin-convert-object-keys-to-object-entries: add
1 parent 32f8844 commit d4bccaa

16 files changed

+238
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,6 +2168,7 @@ It has a lot of plugins divided by groups:
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) |
21702170
| [`@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) |
2171+
| [`@putout/plugin-convert-object-keys-to-object-entries`](/packages/plugin-convert-object-keys-to-object-entries#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-convert-object-keys-to-object-entries.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-convert-object-keys-to-object-entries) |
21712172

21722173
### Removers
21732174

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-keys-to-object-entries": "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: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# @putout/plugin-convert-object-keys-to-object-entries [![NPM version][NPMIMGURL]][NPMURL]
2+
3+
[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-convert-object-keys-to-object-entries.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+
## Install
17+
18+
```
19+
npm i @putout/plugin-convert-object-keys-to-object-entries -D
20+
```
21+
22+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/c0d9b423faead0875f65ea662a42288a/241ecc8b1418ccf174a84e2785def0fd02f28620).
23+
24+
## Rule
25+
26+
```json
27+
{
28+
"rules": {
29+
"convert-object-keys-to-object-entries": "on"
30+
}
31+
}
32+
```
33+
34+
## ❌ Example of incorrect code
35+
36+
```js
37+
for (const [key, value] of Object.keys(tokens)) {
38+
console.log(key, value);
39+
}
40+
41+
for (const [key, value] of keys(tokens)) {
42+
console.log(key, value);
43+
}
44+
```
45+
46+
## ✅ Example of correct code
47+
48+
```js
49+
for (const [key, value] of Object.entries(tokens)) {
50+
console.log(key, value);
51+
}
52+
53+
for (const [key, value] of Object.entries(tokens)) {
54+
console.log(key, value);
55+
}
56+
```
57+
58+
## License
59+
60+
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.entries()' instead of 'Object.keys()'`;
2+
3+
export const replace = () => ({
4+
'for (const [__a, __b] of Object.keys(__c)) __body': 'for (const [__a, __b] of Object.entries(__c)) __body',
5+
'for (const [__a, __b] of keys(__c)) __body': 'for (const [__a, __b] of entries(__c)) __body',
6+
});

0 commit comments

Comments
 (0)