Skip to content

Commit cedb0aa

Browse files
committed
feature: @putout/plugin-socket-io: add
1 parent 4297d70 commit cedb0aa

22 files changed

+270
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2310,6 +2310,7 @@ Next packages not bundled with 🐊**Putout** but can be installed separately.
23102310
| [`@putout/plugin-convert-throw`](/packages/plugin-convert-throw#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-convert-throw.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-convert-throw) |
23112311
| [`@putout/plugin-printer`](/packages/plugin-printer#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-printer.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-printer) |
23122312
| [`@putout/plugin-minify`](/packages/plugin-minify#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-minify.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-minify) |
2313+
| [`@putout/plugin-socket-io`](/packages/plugin-socket-io#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-socket-io.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-socket-io) |
23132314

23142315
## 🦚 Formatters
23152316

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 'lib/**/*.spec.js' '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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.*
2+
test
3+
*.spec.js
4+
fixture
5+
yarn-error.log
6+
7+
coverage
8+
*.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+
}

packages/plugin-socket-io/LICENSE

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: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# @putout/plugin-socket-io [![NPM version][NPMIMGURL]][NPMURL]
2+
3+
[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-socket-io-hooks.svg?style=flat&longCache=true
4+
[NPMURL]: https://npmjs.org/package/@putout/plugin-socket-io-hooks "npm"
5+
6+
> The library for web and native user interfaces
7+
>
8+
> (c) [socket-io.dev](https://socket-io.dev)
9+
10+
🐊[**Putout**](https://github.com/coderaiser/putout) plugin helps to migrate to new version of [socket.io](https://socket.io/). *Not bundled*.
11+
12+
## Install
13+
14+
```
15+
npm i putout @putout/plugin-socket-io-hooks -D
16+
```
17+
18+
Add `.putout.json` with:
19+
20+
```json
21+
{
22+
"plugins": ["socket-io"]
23+
}
24+
```
25+
26+
## Rules
27+
28+
-[convert-io-listen-to-new-server](#convert-io-listen-to-new-server);
29+
-[declare](#declare);
30+
31+
## Config
32+
33+
```json
34+
{
35+
"rules": {
36+
"socket-io/convert-io-listen-to-new-server": "on",
37+
"socket-io/declare": "on"
38+
}
39+
}
40+
```
41+
42+
## declare
43+
44+
```diff
45+
+import {Server} from 'socket.io';
46+
new Server(server);
47+
```
48+
49+
## convert-io-listen-to-new-server
50+
51+
ESM has no `listen` exported, only `Server`. So it is better to change it to simplify migration.
52+
Check out in 🐊[Putout Editor](https://putout.cloudcmd.io/#/gist/5348f80f9fea90155ca3a91a56bad498/7fd768e92dd2effd40cd7c1491bdbfc2cd5bff5c).
53+
54+
### ❌ Example of incorrect code
55+
56+
```
57+
io.listen(server);
58+
```
59+
60+
### ✅ Example of correct code
61+
62+
```js
63+
new Server(server);
64+
```
65+
66+
## License
67+
68+
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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import io from 'socket.io';
2+
3+
new Server(server);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import io from 'socket.io'
2+
3+
io.listen(server);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const report = () => `Use 'new Server(server)' instead of 'io.listen(server)'`;
2+
3+
export const replace = () => ({
4+
'io.listen(__a)': 'new Server(__a)',
5+
});

0 commit comments

Comments
 (0)