Skip to content

Commit 0612eb6

Browse files
committed
refactor: move rules to /rules, merge ast.js and react.js
1 parent 8ef178a commit 0612eb6

25 files changed

+275
-282
lines changed

src/index.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
import noEmptyEffect from "./no-empty-effect.js";
2-
import noAdjustStateOnPropChange from "./no-adjust-state-on-prop-change.js";
3-
import noResetAllStateOnPropChange from "./no-reset-all-state-on-prop-change.js";
4-
import noEventHandler from "./no-event-handler.js";
5-
import noPassLiveStateToParent from "./no-pass-live-state-to-parent.js";
6-
import noInitializeState from "./no-initialize-state.js";
7-
import noChainStateUpdates from "./no-chain-state-updates.js";
8-
import noDerivedState from "./no-derived-state.js";
9-
import noPassDataToParent from "./no-pass-data-to-parent.js";
10-
import noManageParent from "./no-manage-parent.js";
1+
import noEmptyEffect from "./rules/no-empty-effect.js";
2+
import noAdjustStateOnPropChange from "./rules/no-adjust-state-on-prop-change.js";
3+
import noResetAllStateOnPropChange from "./rules/no-reset-all-state-on-prop-change.js";
4+
import noEventHandler from "./rules/no-event-handler.js";
5+
import noPassLiveStateToParent from "./rules/no-pass-live-state-to-parent.js";
6+
import noInitializeState from "./rules/no-initialize-state.js";
7+
import noChainStateUpdates from "./rules/no-chain-state-updates.js";
8+
import noDerivedState from "./rules/no-derived-state.js";
9+
import noPassDataToParent from "./rules/no-pass-data-to-parent.js";
10+
import noManageParent from "./rules/no-manage-parent.js";
1111
import globals from "globals";
12-
import "./util/javascript.js";
1312

1413
/**
1514
* @type {import("eslint").ESLint.Plugin}
@@ -68,3 +67,8 @@ Object.assign(plugin.configs, {
6867
});
6968

7069
export default plugin;
70+
71+
// Wraps `Array.every()` to return false for empty arrays.
72+
Array.prototype.notEmptyEvery = function (predicate) {
73+
return this.length > 0 && this.every(predicate);
74+
};

src/no-adjust-state-on-prop-change.js renamed to src/rules/no-adjust-state-on-prop-change.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getCallExpr } from "./util/ast.js";
1+
import { getCallExpr } from "../util/ast.js";
22
import {
33
getEffectDepsRefs,
44
getEffectFnRefs,
@@ -7,7 +7,7 @@ import {
77
isProp,
88
isStateSetter,
99
isUseEffect,
10-
} from "./util/react.js";
10+
} from "../util/ast.js";
1111

1212
/**
1313
* @type {import("eslint").Rule.RuleModule}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getCallExpr } from "./util/ast.js";
1+
import { getCallExpr } from "../util/ast.js";
22
import {
33
getEffectDepsRefs,
44
getEffectFnRefs,
@@ -8,7 +8,7 @@ import {
88
isState,
99
isStateSetter,
1010
isUseEffect,
11-
} from "./util/react.js";
11+
} from "../util/ast.js";
1212

1313
/**
1414
* @type {import("eslint").Rule.RuleModule}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import {
99
hasCleanup,
1010
isUseEffect,
1111
getUpstreamRefs,
12-
} from "./util/react.js";
13-
import { getCallExpr, getDownstreamRefs } from "./util/ast.js";
12+
} from "../util/ast.js";
13+
import { getCallExpr, getDownstreamRefs } from "../util/ast.js";
1414

1515
/**
1616
* @type {import('eslint').Rule.RuleModule}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isUseEffect, getEffectFnRefs } from "./util/react.js";
1+
import { isUseEffect, getEffectFnRefs } from "../util/ast.js";
22

33
/**
44
* @type {import("eslint").Rule.RuleModule}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import {
33
getEffectDepsRefs,
44
hasCleanup,
55
isUseEffect,
6-
} from "./util/react.js";
7-
import { findDownstreamNodes, getDownstreamRefs } from "./util/ast.js";
8-
import { isState } from "./util/react.js";
6+
} from "../util/ast.js";
7+
import { findDownstreamNodes, getDownstreamRefs } from "../util/ast.js";
8+
import { isState } from "../util/ast.js";
99

1010
/**
1111
* @type {import("eslint").Rule.RuleModule}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { getCallExpr } from "./util/ast.js";
1+
import { getCallExpr } from "../util/ast.js";
22
import {
33
getEffectDepsRefs,
44
getEffectFnRefs,
55
getUseStateNode,
66
isImmediateCall,
77
isStateSetter,
88
isUseEffect,
9-
} from "./util/react.js";
9+
} from "../util/ast.js";
1010

1111
/**
1212
* @type {import("eslint").Rule.RuleModule}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import {
22
getEffectFnRefs,
33
getEffectDepsRefs,
44
isUseEffect,
5-
} from "./util/react.js";
6-
import { isProp } from "./util/react.js";
5+
} from "../util/ast.js";
6+
import { isProp } from "../util/ast.js";
77

88
/**
99
* @type {import("eslint").Rule.RuleModule}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import {
77
isProp,
88
hasCleanup,
99
isUseEffect,
10-
} from "./util/react.js";
11-
import { getCallExpr, getDownstreamRefs } from "./util/ast.js";
10+
} from "../util/ast.js";
11+
import { getCallExpr, getDownstreamRefs } from "../util/ast.js";
1212

1313
/**
1414
* @type {import("eslint").Rule.RuleModule}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import {
55
isPropCallback,
66
isState,
77
isUseEffect,
8-
} from "./util/react.js";
9-
import { getCallExpr, getDownstreamRefs } from "./util/ast.js";
8+
} from "../util/ast.js";
9+
import { getCallExpr, getDownstreamRefs } from "../util/ast.js";
1010

1111
/**
1212
* @type {import("eslint").Rule.RuleModule}

0 commit comments

Comments
 (0)