Skip to content

Commit 6e7cc8d

Browse files
committed
fix: nullish init (#12)
VariableDeclarator.init will be null if this declarator isn't initialized. In particular, if the declarator hasn't been assigned by any value, the property init will be null. Thus, the pattern like const a will be failed. We fix the issue by using ES6 optional chaining. fix #11
1 parent 6537877 commit 6e7cc8d

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

lib/rules/destructuring-formstate.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ module.exports = {
4242

4343
function check(node) {
4444
if (
45-
node.init.type === "CallExpression" &&
46-
node.init.callee.name === "useForm"
45+
node.init?.type === "CallExpression" &&
46+
node.init?.callee.name === "useForm"
4747
) {
4848
const formStateProperty = node.id.properties.find(
4949
(p) => p.key.name === "formState"
@@ -52,8 +52,8 @@ module.exports = {
5252
if (formStateProperty?.value.type !== "Identifier") return;
5353
checkIsAccessFormStateProperties(formStateProperty.value.name);
5454
} else if (
55-
node.init.type === "CallExpression" &&
56-
node.init.callee.name === "useFormState" &&
55+
node.init?.type === "CallExpression" &&
56+
node.init?.callee.name === "useFormState" &&
5757
node.id.type === "Identifier"
5858
) {
5959
checkIsAccessFormStateProperties(node.id.name);

lib/rules/no-access-control.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ module.exports = {
2929

3030
function check(node) {
3131
if (
32-
node.init.type === "CallExpression" &&
33-
node.init.callee.name === "useForm"
32+
node.init?.type === "CallExpression" &&
33+
node.init?.callee.name === "useForm"
3434
) {
3535
const controlProperty = node.id.properties.find(
3636
(p) => p.key.name === "control"

lib/rules/no-nested-object-setvalue.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ module.exports = {
4242

4343
function check(node) {
4444
if (
45-
node.init.type === "CallExpression" &&
46-
node.init.callee.name === "useForm"
45+
node.init?.type === "CallExpression" &&
46+
node.init?.callee.name === "useForm"
4747
) {
4848
const setValueProperty = node.id.properties.find(
4949
(p) => p.key.name === "setValue"

0 commit comments

Comments
 (0)