8000 style(src/*): fixes lint errors in all files · Rookie-M/react-sortablejs@87aa177 · GitHub
[go: up one dir, main page]

Skip to content

Commit 87aa177

Browse files
committed
style(src/*): fixes lint errors in all files
1 parent 7f1984c commit 87aa177

File tree

3 files changed

+43
-28
lines changed

3 files changed

+43
-28
lines changed

src/react-sortable.tsx

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const store: Store = { dragging: null };
3737
export class ReactSortable<T extends ItemInterface> extends Component<
3838
ReactSortableProps<T>
3939
> {
40+
/* eslint-disable-next-line */
4041
static defaultProps: Partial<ReactSortableProps<any>> = {
4142
clone: (item) => item,
4243
};
@@ -56,7 +57,7 @@ export class ReactSortable<T extends ItemInterface> extends Component<
5657

5758
props.setList(newList, this.sortable, store);
5859
invariant(
59-
//@ts-ignore
60+
//@ts-expect-error: Doesn't exist. Will deprecate soon.
6061
!props.plugins,
6162
`
6263
Plugins prop is no longer supported.
@@ -65,13 +66,13 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
6566
`
6667
);
6768
}
68-
componentDidMount() {
69+
componentDidMount(): void {
6970
if (this.ref.current === null) return;
7071
const newOptions = this.makeOptions();
7172
Sortable.create(this.ref.current, newOptions);
7273
}
7374

74-
render() {
75+
render(): JSX.Element {
7576
const { tag, style, className, id } = this.props;
7677
const classicProps = { style, className, id };
7778

@@ -94,17 +95,20 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
9495
dataIdAttr,
9596
selectedClass = "sortable-selected",
9697
chosenClass = "sortable-chosen",
98+
/* eslint-disable */
9799
dragClass = "sortable-drag",
98100
fallbackClass = "sortable-falback",
99101
ghostClass = "sortable-ghost",
100102
swapClass = "sortable-swap-highlight",
103+
/* eslint-enable */
101104
filter = "sortable-filter",
102105
list,
103106
} = this.props;
104107

105108
// if no children, don't do anything.
106109
if (!children || children == null) return null;
107110
const dataid = dataIdAttr || "data-id";
111+
/* eslint-disable-next-line */
108112
return Children.map(children as ReactElement<any>[], (child, index) => {
109113
const item = list[index];
110114
const { className: prevClassName } = child.props;
@@ -137,7 +141,7 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
137141
if (el === null) return null;
138142
const key = Object.keys(el).find((k) => k.includes("Sortable"));
139143
if (!key) return null;
140-
//@ts-ignore - I know what I'm doing.
144+
//@ts-expect-error: fix me.
141145
return el[key] as Sortable;
142146
}
143147

@@ -186,36 +190,39 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
186190
}
187191

188192
/** Prepares a method that will be used in the sortable options to call an `on[Handler]` prop & an `on[Handler]` ReactSortable method. */
189-
prepareOnHandlerPropAndDOM(evtName: HandledMethodNames) {
190-
return (evt: SortableEvent) => {
193+
prepareOnHandlerPropAndDOM(
194+
evtName: HandledMethodNames
195+
): (evt: SortableEvent) => void {
196+
return (evt) => {
191197
// call the component prop
192198
this.callOnHandlerProp(evt, evtName);
193199
// calls state change
194-
//@ts-ignore - until @types multidrag item is in
200+
//@ts-expect-error: until @types multidrag item is in
195201
this[evtName](evt);
196202
};
197203
}
198204

199205
/** Prepares a method that will be used in the sortable options to call an `on[Handler]` prop */
200206
prepareOnHandlerProp(
201207
evtName: Exclude<AllMethodsExceptMove, HandledMethodNames>
202-
) {
203-
return (evt: SortableEvent) => {
208+
): (evt: SortableEvent) => void {
209+
return (evt) => {
204210
// call the component prop
205211
this.callOnHandlerProp(evt, evtName);
206212
};
207213
}
208214

209215
/** Calls the `props.on[Handler]` function */
210-
callOnHandlerProp(evt: SortableEvent, evtName: AllMethodsExceptMove) {
216+
callOnHandlerProp(evt: SortableEvent, evtName: AllMethodsExceptMove): void {
211217
const propEvent = this.props[evtName];
212218
if (propEvent) propEvent(evt, this.sortable, store);
213219
}
214220

215221
// SORTABLE DOM HANDLING
216222

217-
onAdd(evt: MultiDragEvent) {
223+
onAdd(evt: MultiDragEvent): void {
218224
const { list, setList, clone } = this.props;
225+
/* eslint-disable-next-line */
219226
const otherList = [...store.dragging!.props.list];
220227
const customs = createCustoms(evt, otherList);
221228
removeNodes(customs);
@@ -226,7 +233,7 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
226233
setList(newList, this.sortable, store);
227234
}
228235

229-
onRemove(evt: MultiDragEvent) {
236+
onRemove(evt: MultiDragEvent): void {
230237
const { list, setList } = this.props;
231238
const mode = getMode(evt);
232239
const customs = createCustoms(evt, list);
@@ -248,7 +255,7 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
248255
}));
249256
break;
250257
case "normal":
251-
customClones = customs.map((item, index) => ({
258+
customClones = customs.map((item) => ({
252259
...item,
253260
element: evt.clone,
254261
}));
@@ -266,6 +273,7 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
266273
// replace selected items with cloned items
267274
customs.forEach((curr) => {
268275
const index = curr.oldIndex;
276+
/* eslint-disable-next-line */
269277
const newItem = this.props.clone!(curr.item, evt);
270278
newList.splice(index, 1, newItem);
271279
});
@@ -276,7 +284,7 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
276284
setList(newList, this.sortable, store);
277285
}
278286

279-
onUpdate(evt: MultiDragEvent) {
287+
onUpdate(evt: MultiDragEvent): void {
280288
const { list, setList } = this.props;
281289
const customs = createCustoms(evt, list);
282290
removeNodes(customs);
@@ -285,15 +293,15 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
285293
return setList(newList, this.sortable, store);
286294
}
287295

288-
onStart(evt: SortableEvent) {
296+
onStart(): void {
289297
store.dragging = this;
290298
}
291299

292-
onEnd(evt: SortableEvent) {
300+
onEnd(): void {
293301
store.dragging = null;
294302
}
295303

296-
onChoose(evt: SortableEvent) {
304+
onChoose(evt: SortableEvent): void {
297305
const { list, setList } = this.props;
298306
const newList = list.map((item, index) => {
299307
if (index === evt.oldIndex) {
@@ -307,7 +315,7 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
307315
setList(newList, this.sortable, store);
308316
}
309317

310-
onUnchoose(evt: SortableEvent) {
318+
onUnchoose(evt: SortableEvent): void {
311319
const { list, setList } = this.props;
312320
const newList = list.map((item, index) => {
313321
if (index === evt.oldIndex) {
@@ -321,12 +329,12 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
321329
setList(newList, this.sortable, store);
322330
}
323331

324-
onSpill(evt: SortableEvent) {
332+
onSpill(evt: SortableEvent): void {
325333
const { removeOnSpill, revertOnSpill } = this.props;
326334
if (removeOnSpill && !revertOnSpill) removeNode(evt.item);
327335
}
328336

329-
onSelect(evt: MultiDragEvent) {
337+
onSelect(evt: MultiDragEvent): void {
330338
const { list, setList } = this.props;
331339
const newList = list.map((item) => ({ ...item, selected: false }));
332340
evt.newIndicies.forEach((curr) => {
@@ -343,7 +351,7 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
343351
setList(newList, this.sortable, store);
344352
}
345353

346-
onDeselect(evt: MultiDragEvent) {
354+
onDeselect(evt: MultiDragEvent): void {
347355
const { list, setList } = this.props;
348356
const newList = list.map((item) => ({ ...item, selected: false }));
349357
evt.newIndicies.forEach((curr) => {

src/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface ItemInterface {
1919
chosen?: boolean;
2020
/** When true, it will not be possible to pick this item up in the list. */
2121
filtered?: boolean;
22+
/* eslint-disable-next-line */
2223
[property: string]: any;
2324
}
2425

@@ -41,6 +42,7 @@ export interface ReactSortableProps<T>
4142
* @example
4243
* forwardRef<HTMLElement, YOURPROPS>((props, ref) => <button {...props} ref={ref} />)
4344
*/
45+
/* eslint-disable-next-line */
4446
tag?: ForwardRefExoticComponent<RefAttributes<any>> | keyof ReactHTML;
4547
/**
4648
* If this is provided, the function will replace the clone in place.
@@ -63,6 +65,7 @@ export interface ReactSortableProps<T>
6365
* Mainly used to access `props.list` within another components.
6466
*/
6567
export interface Store {
68+
/* eslint-disable-next-line */
6669
dragging: null | ReactSortable<any>;
6770
}
6871

src/util.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { AllMethodNames, ItemInterface, ReactSortableProps } from "./types";
77
* Removes the `node` from the DOM
88
* @param node
99
*/
10-
export function removeNode(node: HTMLElement):void {
10+
export function removeNode(node: HTMLElement): void {
1111
if (node.parentElement !== null) node.parentElement.removeChild(node);
1212
}
1313

@@ -21,7 +21,7 @@ export function insertNodeAt(
2121
parent: HTMLElement,
2222
newChild: HTMLElement,
2323
index: number
24-
):void {
24+
): void {
2525
const refChild = parent.children[index] || null;
2626
parent.insertBefore(newChild, refChild);
2727
}
@@ -32,16 +32,20 @@ export function insertNodeAt(
3232
// @todo - do I need parenElement?
3333
export function handleDOMChanges<T extends ItemInterface>(
3434
customs: Normalized<T>[]
35-
):void {
35+
): void {
3636
removeNodes(customs);
3737
insertNodes(customs);
3838
}
3939

40-
export function removeNodes<T extends ItemInterface>(customs: Normalized<T>[]):void {
40+
export function removeNodes<T extends ItemInterface>(
41+
customs: Normalized<T>[]
42+
): void {
4143
customs.forEach((curr) => removeNode(curr.element));
4244
}
4345

44-
export function insertNodes<T extends ItemInterface>(customs: Normalized<T>[]) :void{
46+
export function insertNodes<T extends ItemInterface>(
47+
customs: Normalized<T>[]
48+
): void {
4549
customs.forEach((curr) => {
4650
insertNodeAt(curr.parentElement, curr.element, curr.oldIndex);
4751
});
@@ -50,7 +54,7 @@ export function insertNodes<T extends ItemInterface>(customs: Normalized<T>[]) :
5054
export function createCustoms<T extends ItemInterface>(
5155
evt: MultiDragEvent,
5256
list: T[]
53-
):Normalized<T>[] {
57+
): Normalized<T>[] {
5458
const mode = getMode(evt);
5559
const parentElement = { parentElement: evt.from };
5660
let custom = [];
@@ -131,7 +135,7 @@ export function handleStateAdd<T extends ItemInterface>(
131135
return newList;
132136
}
133137

134-
export function getMode(evt: MultiDragEvent):'multidrag'|"swap"|"normal" {
138+
export function getMode(evt: MultiDragEvent): "multidrag" | "swap" | "normal" {
135139
if (evt.oldIndicies && evt.oldIndicies.length > 0) return "multidrag";
136140
if (evt.swapItem) return "swap";
137141
return "normal";

0 commit comments

Comments
 (0)
0