Skip to content

Commit efa9e89

Browse files
Merge pull request #2874 from SylvainCorlay/fix-linter-warnings
Fix tagsinputs linter warnings
2 parents 3bd7527 + e832ed2 commit efa9e89

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

packages/controls/src/widget_tagsinput.ts

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function clamp(value: number, min: number, max: number): number {
2626
/**
2727
* Remove children from an HTMLElement
2828
*/
29-
function removeChildren(el: HTMLElement) {
29+
function removeChildren(el: HTMLElement): void {
3030
while (el.firstChild) {
3131
el.removeChild(el.firstChild);
3232
}
@@ -92,7 +92,7 @@ abstract class TagsInputBaseView extends DOMWidgetView {
9292
/**
9393
* Called when view is rendered.
9494
*/
95-
render() {
95+
render(): void {
9696
super.render();
9797

9898
this.el.classList.add('jupyter-widgets');
@@ -120,11 +120,11 @@ abstract class TagsInputBaseView extends DOMWidgetView {
120120
this.taginputWrapper.appendChild(this.autocompleteList);
121121

122122
this.el.onclick = this.focus.bind(this);
123-
this.el.ondrop = (event: DragEvent) => {
123+
this.el.ondrop = (event: DragEvent): void => {
124124
// Put the tag at the end of the list if there is no currently hovered tag
125125
const index =
126126
this.hoveredTagIndex == null ? this.tags.length : this.hoveredTagIndex;
127-
this.ondrop(event, index);
127+
return this.ondrop(event, index);
128128
};
129129
this.el.ondragover = this.ondragover.bind(this);
130130

@@ -148,7 +148,7 @@ abstract class TagsInputBaseView extends DOMWidgetView {
148148
* Called when the model is changed. The model may have been
149149
* changed by another view or by a state update from the back-end.
150150
*/
151-
update() {
151+
update(): void {
152152
// Prevent hiding the input element and clearing the selection when updating everything
153153
this.preventLoosingFocus = true;
154154

@@ -168,7 +168,7 @@ abstract class TagsInputBaseView extends DOMWidgetView {
168168
// Drag and drop
169169
tag.draggable = true;
170170
tag.ondragstart = ((index: number, value: any) => {
171-
return (event: DragEvent) => {
171+
return (event: DragEvent): void => {
172172
this.ondragstart(event, index, value, this.model.model_id);
173173
};
174174
})(index, value[index]);
@@ -202,7 +202,7 @@ abstract class TagsInputBaseView extends DOMWidgetView {
202202
/**
203203
* Update the auto-completion list
204204
*/
205-
updateAutocomplete() {
205+
updateAutocomplete(): void {
206206
removeChildren(this.autocompleteList);
207207

208208
const allowedTags = this.model.get('allowed_tags');
@@ -217,7 +217,7 @@ abstract class TagsInputBaseView extends DOMWidgetView {
217217
/**
218218
* Update the tags, called when the selection has changed and we need to update the tags CSS
219219
*/
220-
updateTags() {
220+
updateTags(): void {
221221
const value: Array<any> = this.model.get('value');
222222

223223
for (const idx in this.tags) {
@@ -235,7 +235,7 @@ abstract class TagsInputBaseView extends DOMWidgetView {
235235
/**
236236
* Handle a new value is added from the input element
237237
*/
238-
handleValueAdded(event: Event) {
238+
handleValueAdded(event: Event): void {
239239
const newTagValue = trim(this.taginput.value);
240240
const tagIndex = this.inputIndex;
241241

@@ -296,15 +296,15 @@ abstract class TagsInputBaseView extends DOMWidgetView {
296296
/**
297297
* Resize the input element
298298
*/
299-
resizeInput() {
299+
resizeInput(): void {
300300
const size = this.taginput.value.length + 1;
301301
this.taginput.setAttribute('size', String(size));
302302
}
303303

304304
/**
305305
* Handle key events on the input element
306306
*/
307-
handleKeyEvent(event: KeyboardEvent) {
307+
handleKeyEvent(event: KeyboardEvent): void {
308308
const valueLength = this.model.get('value').length;
309309

310310
// Do nothing if the user is typing something
@@ -376,7 +376,12 @@ abstract class TagsInputBaseView extends DOMWidgetView {
376376
/**
377377
* Function that gets called when a tag with a given `value` is being dragged.
378378
*/
379-
ondragstart(event: DragEvent, index: number, tagValue: any, origin: string) {
379+
ondragstart(
380+
event: DragEvent,
381+
index: number,
382+
tagValue: any,
383+
origin: string
384+
): void {
380385
if (event.dataTransfer == null) {
381386
return;
382387
}
@@ -388,7 +393,7 @@ abstract class TagsInputBaseView extends DOMWidgetView {
388393
/**
389394
* Function that gets called when a tag has been dragged on the tag at the `index` position.
390395
*/
391-
ondrop(event: DragEvent, index: number) {
396+
ondrop(event: DragEvent, index: number): void {
392397
if (event.dataTransfer == null) {
393398
return;
394399
}
@@ -432,12 +437,12 @@ abstract class TagsInputBaseView extends DOMWidgetView {
432437
this.addTag(index, draggedTagValue);
433438
}
434439

435-
ondragover(event: DragEvent) {
440+
ondragover(event: DragEvent): void {
436441
// This is needed for the drag and drop to work
437442
event.preventDefault();
438443
}
439444

440-
ondragenter(event: DragEvent, index: number) {
445+
ondragenter(event: DragEvent, index: number): void {
441446
if (this.hoveredTag != null && this.hoveredTag != this.tags[index]) {
442447
this.hoveredTag.style.marginLeft = '1px';
443448
}
@@ -447,7 +452,7 @@ abstract class TagsInputBaseView extends DOMWidgetView {
447452
this.hoveredTag.style.marginLeft = '30px';
448453
}
449454

450-
ondragend() {
455+
ondragend(): void {
451456
if (this.hoveredTag != null) {
452457
this.hoveredTag.style.marginLeft = '1px';
453458
}
@@ -458,7 +463,7 @@ abstract class TagsInputBaseView extends DOMWidgetView {
458463
/**
459464
* Select tags from `start` to `start + dx` not included.
460465
*/
461-
select(start: number, dx: number) {
466+
select(start: number, dx: number): void {
462467
const valueLength = this.model.get('value').length;
463468

464469
if (!this.selection) {
@@ -471,7 +476,7 @@ abstract class TagsInputBaseView extends DOMWidgetView {
471476
/**
472477
* Remove all the selected tags.
473478
*/
474-
removeSelectedTags() {
479+
removeSelectedTags(): void {
475480
const value: Array<string> = [...this.model.get('value')];
476481
const valueLength = value.length;
477482

@@ -494,7 +499,7 @@ abstract class TagsInputBaseView extends DOMWidgetView {
494499
/**
495500
* Remove a tag given its index in the list
496501
*/
497-
removeTag(tagIndex: number) {
502+
removeTag(tagIndex: number): void {
498503
const value: Array<string> = [...this.model.get('value')];
499504

500505
value.splice(tagIndex, 1);
@@ -511,15 +516,15 @@ abstract class TagsInputBaseView extends DOMWidgetView {
511516
/**
512517
* Focus on the input element
513518
*/
514-
focus() {
519+
focus(): void {
515520
this.taginputWrapper.style.display = 'inline-block';
516521
this.taginput.focus();
517522
}
518523

519524
/**
520525
* Lose focus on the input element
521526
*/
522-
loseFocus() {
527+
loseFocus(): void {
523528
if (this.preventLoosingFocus) {
524529
return;
525530
}
@@ -539,7 +544,7 @@ abstract class TagsInputBaseView extends DOMWidgetView {
539544
* #### Notes
540545
* This is a read-only attribute.
541546
*/
542-
get tagName() {
547+
get tagName(): string {
543548
// We can't make this an attribute with a default value
544549
// since it would be set after it is needed in the
545550
// constructor.
@@ -624,7 +629,7 @@ export class TagsInputView extends TagsInputBaseView {
624629
/**
625630
* Returns the text that should be displayed in the tag element
626631
*/
627-
getTagText(value: string) {
632+
getTagText(value: string): string {
628633
return value;
629634
}
630635

@@ -753,7 +758,7 @@ abstract class NumbersInputModel extends TagsInputModel {
753758
}
754759

755760
abstract class NumbersInputView extends TagsInputView {
756-
render() {
761+
render(): void {
757762
// Initialize text formatter
758763
this.model.on('change:format', () => {
759764
this.formatter = d3Format.format(this.model.get('format'));
@@ -767,7 +772,7 @@ abstract class NumbersInputView extends TagsInputView {
767772
/**
768773
* Returns the text that should be displayed in the tag element
769774
*/
770-
getTagText(value: string) {
775+
getTagText(value: string): string {
771776
return this.formatter(this.parseNumber(value));
772777
}
773778

0 commit comments

Comments
 (0)