Skip to content

Commit b7d991e

Browse files
committed
Reduce linting complexity
1 parent 72a9d18 commit b7d991e

File tree

8 files changed

+40
-31
lines changed

8 files changed

+40
-31
lines changed

.eslintrc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"extends": "takiyon-react",
33
"env": {
4-
"browser": true,
54
"node": true
65
},
76
"settings": {
@@ -10,9 +9,5 @@
109
"config": "webpack.test.config.js"
1110
}
1211
}
13-
},
14-
"rules": {
15-
"react/destructuring-assignment": "off",
16-
"react/jsx-sort-props": "off"
1712
}
1813
}

examples/.eslintrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
{
2+
"env": {
3+
"browser": true,
4+
"node": false
5+
},
26
"rules": {
37
"import/no-extraneous-dependencies": ["error", {
48
"devDependencies": true

examples/src/js/ClickableLabelsExample.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ class ClickExample extends React.Component {
124124
<div className="clickable-labels">
125125
<CheckboxTree
126126
checked={checked}
127+
expandOnClick
127128
expanded={expanded}
128129
nodes={nodes}
129-
expandOnClick
130130
onCheck={this.onCheck}
131131
onClick={this.onClick}
132132
onExpand={this.onExpand}

examples/src/js/FilterExample.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,10 @@ class FilterExample extends React.Component {
120120
}
121121

122122
filterTree() {
123+
const { filterText } = this.state;
124+
123125
// Reset nodes back to unfiltered state
124-
if (!this.state.filterText) {
126+
if (!filterText) {
125127
this.setState((prevState) => ({
126128
nodesFiltered: prevState.nodes,
127129
}));

src/js/CheckboxTree.js

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ class CheckboxTree extends React.Component {
109109
this.combineMemorized = memoize((icons1, icons2) => ({ ...icons1, ...icons2 })).bind(this);
110110
}
111111

112-
// eslint-disable-next-line react/sort-comp
113112
static getDerivedStateFromProps(newProps, prevState) {
114113
const { model, prevProps } = prevState;
115114
const { disabled, id, nodes } = newProps;
@@ -138,20 +137,22 @@ class CheckboxTree extends React.Component {
138137

139138
onCheck(nodeInfo) {
140139
const { checkModel, noCascade, onCheck } = this.props;
141-
const model = this.state.model.clone();
142-
const node = model.getNode(nodeInfo.value);
140+
const { model } = this.state;
141+
const newModel = model.clone();
142+
const node = newModel.getNode(nodeInfo.value);
143143

144-
model.toggleChecked(nodeInfo, nodeInfo.checked, checkModel, noCascade);
145-
onCheck(model.serializeList('checked'), { ...node, ...nodeInfo });
144+
newModel.toggleChecked(nodeInfo, nodeInfo.checked, checkModel, noCascade);
145+
onCheck(newModel.serializeList('checked'), { ...node, ...nodeInfo });
146146
}
147147

148148
onExpand(nodeInfo) {
149149
const { onExpand } = this.props;
150-
const model = this.state.model.clone();
151-
const node = model.getNode(nodeInfo.value);
150+
const { model } = this.state;
151+
const newModel = model.clone();
152+
const node = newModel.getNode(nodeInfo.value);
152153

153-
model.toggleNode(nodeInfo.value, 'expanded', nodeInfo.expanded);
154-
onExpand(model.serializeList('expanded'), { ...node, ...nodeInfo });
154+
newModel.toggleNode(nodeInfo.value, 'expanded', nodeInfo.expanded);
155+
onExpand(newModel.serializeList('expanded'), { ...node, ...nodeInfo });
155156
}
156157

157158
onNodeClick(nodeInfo) {
@@ -172,16 +173,18 @@ class CheckboxTree extends React.Component {
172173

173174
expandAllNodes(expand = true) {
174175
const { onExpand } = this.props;
176+
const { model } = this.state;
175177

176178
onExpand(
177-
this.state.model.clone()
179+
model.clone()
178180
.expandAllNodes(expand)
179181
.serializeList('expanded'),
180182
);
181183
}
182184

183185
determineShallowCheckState(node, noCascade) {
184-
const flatNode = this.state.model.getNode(node.value);
186+
const { model } = this.state;
187+
const flatNode = model.getNode(node.value);
185188

186189
if (flatNode.isLeaf || noCascade || node.children.length === 0) {
187190
// Note that an empty parent node tracks its own state
@@ -200,14 +203,18 @@ class CheckboxTree extends React.Component {
200203
}
201204

202205
isEveryChildChecked(node) {
206+
const { model } = this.state;
207+
203208
return node.children.every(
204-
(child) => this.state.model.getNode(child.value).checkState === 1,
209+
(child) => model.getNode(child.value).checkState === 1,
205210
);
206211
}
207212

208213
isSomeChildChecked(node) {
214+
const { model } = this.state;
215+
209216
return node.children.some(
210-
(child) => this.state.model.getNode(child.value).checkState > 0,
217+
(child) => model.getNode(child.value).checkState > 0,
211218
);
212219
}
213220

@@ -258,11 +265,11 @@ class CheckboxTree extends React.Component {
258265
expanded={flatNode.expanded}
259266
icon={node.icon}
260267
icons={this.combineMemorized(defaultIcons, icons)}
268+
isLeaf={flatNode.isLeaf}
269+
isParent={flatNode.isParent}
261270
label={node.label}
262271
lang={lang}
263272
optimisticToggle={optimisticToggle}
264-
isLeaf={flatNode.isLeaf}
265-
isParent={flatNode.isParent}
266273
showCheckbox={showCheckbox}
267274
showNodeIcon={showNodeIcon}
268275
title={showNodeTitle ? node.title || node.label : node.title}

src/js/TreeNode.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,10 @@ class TreeNode extends React.PureComponent {
202202
{clickable ? (
203203
<span
204204
className="rct-node-clickable"
205-
onClick={this.onClick}
206-
onKeyPress={this.onClick}
207205
role="button"
208206
tabIndex={0}
207+
onClick={this.onClick}
208+
onKeyPress={this.onClick}
209209
>
210210
{children}
211211
</span>
@@ -233,8 +233,8 @@ class TreeNode extends React.PureComponent {
233233
disabled={disabled}
234234
id={inputId}
235235
indeterminate={checked === 2}
236-
onClick={this.onCheck}
237236
onChange={() => {}}
237+
onClick={this.onCheck}
238238
/>
239239
<span
240240
aria-checked={checked === 1}
@@ -256,10 +256,10 @@ class TreeNode extends React.PureComponent {
256256
<span
257257
key={1}
258258
className="rct-node-clickable"
259-
onClick={this.onClick}
260-
onKeyPress={this.onClick}
261259
role="link"
262260
tabIndex={0}
261+
onClick={this.onClick}
262+
onKeyPress={this.onClick}
263263
>
264264
{children}
265265
</span>
@@ -290,11 +290,13 @@ class TreeNode extends React.PureComponent {
290290
}
291291

292292
renderChildren() {
293-
if (!this.props.expanded) {
293+
const { children, expanded } = this.props;
294+
295+
if (!expanded) {
294296
return null;
295297
}
296298

297-
return this.props.children;
299+
return children;
298300
}
299301

300302
render() {

test/.eslintrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"mocha": true
44
},
55
"rules": {
6-
"import/no-extraneous-dependencies": ["error", {"devDependencies": ["**/*.js"]}],
76
"react/jsx-props-no-spreading": "off"
87
}
98
}

test/CheckboxTree.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,14 +757,14 @@ describe('<CheckboxTree />', () => {
757757
const makeEmptyParentNode = (checked) => (
758758
mount(
759759
<CheckboxTree
760+
checked={checked}
760761
nodes={[
761762
{
762763
value: 'jupiter',
763764
label: 'Jupiter',
764765
children: [],
765766
},
766767
]}
767-
checked={checked}
768768
onCheck={(node) => {
769769
actualChecked = node;
770770
}}

0 commit comments

Comments
 (0)