Skip to content

Commit 2d68909

Browse files
committed
feature: @putout/plugin-react: add
1 parent 5efde65 commit 2d68909

File tree

17 files changed

+396
-1
lines changed

17 files changed

+396
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2196,7 +2196,7 @@ Next packages not bundled with 🐊**Putout** but can be installed separately.
21962196
|--------|-------|
21972197
| [`@putout/plugin-apply-entries`](/packages/plugin-apply-entries#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-apply-entries.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-apply-entries) |
21982198
| [`@putout/plugin-eslint-plugin`](/packages/plugin-eslint-plugin#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-eslint-plugin.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-eslint-plugin) |
2199-
| [`@putout/plugin-react-hooks`](/packages/plugin-react-hooks#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-react-hooks.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-react-hooks) |
2199+
| [`@putout/plugin-react`](/packages/plugin-react#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-react.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-react) |
22002200
| [`@putout/plugin-react-hook-form`](/packages/plugin-react-hook-form#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-react-hook-form.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-react-hook-form) |
22012201
| [`@putout/plugin-nextjs`](/packages/plugin-nextjs#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-nextjs.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-nextjs) |
22022202
| [`@putout/plugin-react-router`](/packages/plugin-react-router#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-react-router.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-react-router) |

packages/plugin-react/.madrun.mjs

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+
};

packages/plugin-react/.npmignore

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.*

packages/plugin-react/.nycrc.json

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-react/.putout.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"match": {
3+
".filesystem.json": {
4+
"eslint/convert-rc-to-flat": "on"
5+
}
6+
}
7+
}

packages/plugin-react/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.

packages/plugin-react/README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# @putout/plugin-react [![NPM version][NPMIMGURL]][NPMURL]
2+
3+
[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-react-hooks.svg?style=flat&longCache=true
4+
[NPMURL]: https://npmjs.org/package/@putout/plugin-react-hooks "npm"
5+
6+
> The library for web and native user interfaces
7+
>
8+
> (c) [react.dev](https://react.dev)
9+
10+
🐊[**Putout**](https://github.com/coderaiser/putout) plugin helps to migrate to new version of React. *Not bundled*.
11+
12+
## Install
13+
14+
```
15+
npm i putout @putout/plugin-react-hooks -D
16+
```
17+
18+
Add `.putout.json` with:
19+
20+
```json
21+
{
22+
"plugins": ["react"]
23+
}
24+
```
25+
26+
## Rules
27+
28+
-[remove-useless-provider](#remove-useless-provider);
29+
30+
## Config
31+
32+
Here is list of rules:
33+
34+
```json
35+
{
36+
"rules": {
37+
"react/remove-useless-provider": "on"
38+
}
39+
}
40+
```
41+
42+
## remove-useless-provider
43+
44+
> In React 19, you can render <Context> as a provider instead of <Context.Provider>:
45+
>
46+
> [react.dev](https://react.dev/blog/2024/04/25/react-19#context-as-a-provider)
47+
48+
Check out in 🐊[Putout Editor](https://putout.cloudcmd.io/#/gist/51f66807ab67704288f2f737c5152e6c/8957e4a4beb17e175bff1b10e455ffda59d7c74a).
49+
50+
### ❌ Example of incorrect code
51+
52+
```jsx
53+
function App() {
54+
const [theme, setTheme] = useState('light');
55+
56+
// ...
57+
return (
58+
<UseTheme.Provider value={theme}>
59+
<Page/>
60+
</UseTheme.Provider>
61+
);
62+
}
63+
```
64+
65+
### ✅ Example of correct code
66+
67+
```jsx
68+
function App() {
69+
const [theme, setTheme] = useState('light');
70+
71+
// ...
72+
return (
73+
<UseTheme value={theme}>
74+
<Page/>
75+
</UseTheme>
76+
);
77+
}
78+
```
79+
80+
## License
81+
82+
MIT
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
const {safeAlign} = require('eslint-plugin-putout/config');
4+
5+
module.exports = safeAlign;

packages/plugin-react/lib/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
const removeUselessProvider = require('./remove-useless-provider');
4+
5+
module.exports.rules = {
6+
'remove-useless-provider': removeUselessProvider,
7+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
function App() {
2+
const [theme, setTheme] = useState('light');
3+
4+
// ...
5+
return (
6+
<UseTheme value={theme}>
7+
<Page/>
8+
</UseTheme>
9+
);
10+
}
11+
12+
function App1() {
13+
const [theme, setTheme] = useState('light');
14+
15+
// ...
16+
return (
17+
<Provider value={theme}>
18+
<Page/>
19+
</Provider>
20+
);
21+
}
22+
23+
function App2() {
24+
const [theme, setTheme] = useState('light');
25+
26+
// ...
27+
return (
28+
<Provider.Hello value={theme}>
29+
<Page/>
30+
</Provider.Hello>
31+
);
32+
}

0 commit comments

Comments
 (0)