Finding unDRY code w/ jsinspect
One of the constants in my software dev career has been a predilection for reducing redundant code as much as feasible. There’s a JSX-fluent CLI tool that been helping me do that at iTRVL.
Runningnpx jsinspect ./packages/agent/src/components/Itinerary/EditItinerary/*Step.js
will give you a set outputs like so:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31./packages/agent/src/components/Itinerary/EditItinerary/FlightStep.js:132,136
<EditableInput
textValue={formatMoney(step.sell, 'USD')}
inputValue={step.sell}
editOnly={true}
inputProps={{ className: classes.editableAlignRight }}
./packages/agent/src/components/Itinerary/EditItinerary/RoadStep.js:136,140
<EditableInput
textValue={formatMoney(step.sell, 'USD')}
inputValue={step.sell}
editOnly={true}
inputProps={{ className: classes.editableAlignRight }}
------------------------------------------------------------
Match - 2 instances
./packages/agent/src/components/Itinerary/EditItinerary/RoadStep.js:94,97
<Paper className="stepLine" elevation={0} style={{ marginLeft: '0px' }}>
<Box className="header">
<Box className="type-icon">
<AirportShuttle />
./packages/agent/src/components/Itinerary/EditItinerary/StayStep.js:284,287
<Paper className="stepLine" elevation={0} style={{ marginLeft: '0px' }}>
<Box className="header">
<Box className="type-icon">
<Tipi />
------------------------------------------------------------
This is especially useful for finding unDRY code in large codebases that you are new to or aren’t wholly familiar with