Skip to content

Commit 98acaf8

Browse files
committed
feature: @putout/plugin-react-hook-form: drop support of node < 20
1 parent 4718b72 commit 98acaf8

File tree

16 files changed

+65
-89
lines changed

16 files changed

+65
-89
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as v7ApplyFormState from './v7-apply-form-state/index.js';
2+
import * as v6ApplyClearErrors from './v6-apply-clear-errors/index.js';
3+
import * as v6ConvertAsToRender from './v6-convert-as-to-render/index.js';
4+
import * as v6ConvertFormContextToFormProvider from './v6-convert-form-context-to-form-provider/index.js';
5+
import * as v6ConvertTriggerValidationToTrigger from './v6-convert-trigger-validation-to-trigger/index.js';
6+
import * as v5RemoveValueFromControl from './v5-remove-value-from-control/index.js';
7+
8+
export const rules = {
9+
'v7-apply-form-state': v7ApplyFormState,
10+
'v6-apply-clear-errors': v6ApplyClearErrors,
11+
'v6-convert-as-to-render': v6ConvertAsToRender,
12+
'v6-convert-form-context-to-form-provider': v6ConvertFormContextToFormProvider,
13+
'v6-convert-trigger-validation-to-trigger': v6ConvertTriggerValidationToTrigger,
14+
'v5-remove-value-from-control': v5RemoveValueFromControl,
15+
};

packages/plugin-react-hook-form/lib/react-hook-form.js

-17
This file was deleted.

packages/plugin-react-hook-form/lib/v5-remove-value-from-control/index.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
'use strict';
1+
export const report = () => `Remove 'value property' from 'control' attribute`;
22

3-
module.exports.report = () => `Remove 'value property' from 'control' attribute`;
4-
5-
module.exports.match = () => ({
3+
export const match = () => ({
64
'({value: __a})': (vars, path) => {
75
if (!path.parentPath.parentPath.isJSXExpressionContainer())
86
return false;
@@ -16,6 +14,6 @@ module.exports.match = () => ({
1614
},
1715
});
1816

19-
module.exports.replace = () => ({
17+
export const replace = () => ({
2018
'({value: __a})': '__a',
2119
});

packages/plugin-react-hook-form/lib/v5-remove-value-from-control/index.spec.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as removeValueFromControl from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const removeValueFromControl = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['remove-value-from-control', removeValueFromControl],
97
],
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
'use strict';
1+
import {operator} from 'putout';
22

3-
const {operator} = require('putout');
43
const {rename} = operator;
54

6-
module.exports.report = () => `Use 'clearErrors' instead of 'clearError'`;
5+
export const report = () => `Use 'clearErrors' instead of 'clearError'`;
76

8-
module.exports.fix = (path) => {
7+
export const fix = (path) => {
98
const program = path.scope.getProgramParent().path;
109
rename(program, 'clearError', 'clearErrors');
1110
};
1211

13-
module.exports.include = () => [
12+
export const include = () => [
1413
'clearError(__args)',
1514
];

packages/plugin-react-hook-form/lib/v6-apply-clear-errors/index.spec.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as applyClearErrors from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const applyClearErrors = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['apply-clear-errors', applyClearErrors],
97
],

packages/plugin-react-hook-form/lib/v6-convert-as-to-render/index.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'use strict';
2-
3-
const {types, template} = require('putout');
1+
import {types, template} from 'putout';
42

53
const {
64
JSXExpressionContainer,
@@ -15,9 +13,9 @@ const ARROW = template(`({field}) => {
1513
return (%%expression%%);
1614
}`);
1715

18-
module.exports.report = () => `Use 'render' instead of 'as' in '<Control/>' elements`;
16+
export const report = () => `Use 'render' instead of 'as' in '<Control/>' elements`;
1917

20-
module.exports.match = () => ({
18+
export const match = () => ({
2119
'<Controller __jsx_attributes/>': ({__jsx_attributes}) => {
2220
for (const attr of __jsx_attributes) {
2321
if (isJSXSpreadAttribute(attr))
@@ -31,7 +29,7 @@ module.exports.match = () => ({
3129
},
3230
});
3331

34-
module.exports.replace = () => ({
32+
export const replace = () => ({
3533
[`
3634
<Controller
3735
as={__a}

packages/plugin-react-hook-form/lib/v6-convert-as-to-render/index.spec.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as convertAsToRender from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const convertAsToRender = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['convert-as-to-render', convertAsToRender],
97
],
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
'use strict';
1+
import {operator} from 'putout';
22

3-
const {operator} = require('putout');
43
const {rename} = operator;
54

6-
module.exports.report = () => `Use '<FormProvider/>' instead of '<FormContext/>'`;
5+
export const report = () => `Use '<FormProvider/>' instead of '<FormContext/>'`;
76

8-
module.exports.fix = (path) => {
7+
export const fix = (path) => {
98
rename(path, 'FormContext', 'FormProvider');
109
};
1110

12-
module.exports.include = () => [
11+
export const include = () => [
1312
'<FormContext __jsx_attributes>__jsx_children</FormContext>',
1413
];
1514

16-
module.exports.filter = (path) => path.scope.getAllBindings().FormContext;
15+
export const filter = (path) => path.scope.getAllBindings().FormContext;

packages/plugin-react-hook-form/lib/v6-convert-form-context-to-form-provider/index.spec.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as convert from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const convert = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['v6-convert-form-context-to-form-provider', convert],
97
],
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
'use strict';
1+
import {operator} from 'putout';
22

3-
const {operator} = require('putout');
43
const {rename} = operator;
54

6-
module.exports.report = () => `Use 'trigger()' instead of 'triggerValidation()'`;
5+
export const report = () => `Use 'trigger()' instead of 'triggerValidation()'`;
76

8-
module.exports.fix = (path) => {
7+
export const fix = (path) => {
98
rename(path, 'triggerValidation', 'trigger');
109
};
1110

12-
module.exports.include = () => [
11+
export const include = () => [
1312
'triggerValidation(__args)',
1413
];
1514

16-
module.exports.filter = ({scope}) => {
15+
export const filter = ({scope}) => {
1716
const bindings = scope.getAllBindings();
1817
return bindings.triggerValidation;
1918
};

packages/plugin-react-hook-form/lib/v6-convert-trigger-validation-to-trigger/index.spec.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as convertAsToRender from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const convertAsToRender = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['convert-trigger-validation-to-trigger', convertAsToRender],
97
],

packages/plugin-react-hook-form/lib/v7-apply-form-state/index.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
'use strict';
1+
import {types} from 'putout';
22

3-
const {types} = require('putout');
43
const {
54
objectProperty,
65
isRestElement,
76
objectPattern,
87
} = types;
98

10-
module.exports.report = () => `Use 'formState.errors' instead of 'errors'`;
9+
export const report = () => `Use 'formState.errors' instead of 'errors'`;
1110

1211
const COMPUTED = false;
1312
const SHORTHAND = true;
1413

15-
module.exports.exclude = () => [
14+
export const exclude = () => [
1615
'const __object = formState',
1716
];
1817

19-
module.exports.match = () => ({
18+
export const match = () => ({
2019
'const __object = __a': ({__object}, path) => {
2120
const bindings = path.scope.getAllBindings();
2221

@@ -35,7 +34,7 @@ module.exports.match = () => ({
3534
},
3635
});
3736

38-
module.exports.replace = () => ({
37+
export const replace = () => ({
3938
'const __object = __a': ({__object}, path) => {
4039
for (const property of __object.properties) {
4140
if (isRestElement(property))

packages/plugin-react-hook-form/lib/v7-apply-form-state/index.spec.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as apply from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const apply = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['apply-form-state', apply],
97
],

packages/plugin-react-hook-form/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "@putout/plugin-react-hook-form",
33
"version": "5.0.0",
4-
"type": "commonjs",
4+
"type": "module",
55
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
66
"description": "🐊Putout plugin adds ability to migrate to latest version of React Hook Form",
77
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-react-hook-form#readme",
8-
"main": "lib/react-hook-form.js",
8+
"main": "lib/index.js",
99
"release": false,
1010
"tag": false,
1111
"changelog": false,
@@ -47,7 +47,7 @@
4747
},
4848
"license": "MIT",
4949
"engines": {
50-
"node": ">=18"
50+
"node": ">=20"
5151
},
5252
"publishConfig": {
5353
"access": "public"

packages/plugin-react-hook-form/test/react-hook-form.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as reactHookForm from '../lib/index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const reactHookForm = require('..');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['react-hook-form', reactHookForm],
97
],

0 commit comments

Comments
 (0)