Skip to content

Commit

Permalink
Merge pull request jupyter-widgets#2874 from SylvainCorlay/fix-linter…
Browse files Browse the repository at this point in the history
…-warnings

Fix tagsinputs linter warnings
  • Loading branch information
SylvainCorlay authored May 12, 2020
2 parents 3bd7527 + e832ed2 commit efa9e89
Showing 1 changed file with 30 additions and 25 deletions.
55 changes: 30 additions & 25 deletions packages/controls/src/widget_tagsinput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function clamp(value: number, min: number, max: number): number {
/**
* Remove children from an HTMLElement
*/
function removeChildren(el: HTMLElement) {
function removeChildren(el: HTMLElement): void {
while (el.firstChild) {
el.removeChild(el.firstChild);
}
Expand Down Expand Up @@ -92,7 +92,7 @@ abstract class TagsInputBaseView extends DOMWidgetView {
/**
* Called when view is rendered.
*/
render() {
render(): void {
super.render();

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

this.el.onclick = this.focus.bind(this);
this.el.ondrop = (event: DragEvent) => {
this.el.ondrop = (event: DragEvent): void => {
// Put the tag at the end of the list if there is no currently hovered tag
const index =
this.hoveredTagIndex == null ? this.tags.length : this.hoveredTagIndex;
this.ondrop(event, index);
return this.ondrop(event, index);
};
this.el.ondragover = this.ondragover.bind(this);

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

Expand All @@ -168,7 +168,7 @@ abstract class TagsInputBaseView extends DOMWidgetView {
// Drag and drop
tag.draggable = true;
tag.ondragstart = ((index: number, value: any) => {
return (event: DragEvent) => {
return (event: DragEvent): void => {
this.ondragstart(event, index, value, this.model.model_id);
};
})(index, value[index]);
Expand Down Expand Up @@ -202,7 +202,7 @@ abstract class TagsInputBaseView extends DOMWidgetView {
/**
* Update the auto-completion list
*/
updateAutocomplete() {
updateAutocomplete(): void {
removeChildren(this.autocompleteList);

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

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

Expand Down Expand Up @@ -296,15 +296,15 @@ abstract class TagsInputBaseView extends DOMWidgetView {
/**
* Resize the input element
*/
resizeInput() {
resizeInput(): void {
const size = this.taginput.value.length + 1;
this.taginput.setAttribute('size', String(size));
}

/**
* Handle key events on the input element
*/
handleKeyEvent(event: KeyboardEvent) {
handleKeyEvent(event: KeyboardEvent): void {
const valueLength = this.model.get('value').length;

// Do nothing if the user is typing something
Expand Down Expand Up @@ -376,7 +376,12 @@ abstract class TagsInputBaseView extends DOMWidgetView {
/**
* Function that gets called when a tag with a given `value` is being dragged.
*/
ondragstart(event: DragEvent, index: number, tagValue: any, origin: string) {
ondragstart(
event: DragEvent,
index: number,
tagValue: any,
origin: string
): void {
if (event.dataTransfer == null) {
return;
}
Expand All @@ -388,7 +393,7 @@ abstract class TagsInputBaseView extends DOMWidgetView {
/**
* Function that gets called when a tag has been dragged on the tag at the `index` position.
*/
ondrop(event: DragEvent, index: number) {
ondrop(event: DragEvent, index: number): void {
if (event.dataTransfer == null) {
return;
}
Expand Down Expand Up @@ -432,12 +437,12 @@ abstract class TagsInputBaseView extends DOMWidgetView {
this.addTag(index, draggedTagValue);
}

ondragover(event: DragEvent) {
ondragover(event: DragEvent): void {
// This is needed for the drag and drop to work
event.preventDefault();
}

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

ondragend() {
ondragend(): void {
if (this.hoveredTag != null) {
this.hoveredTag.style.marginLeft = '1px';
}
Expand All @@ -458,7 +463,7 @@ abstract class TagsInputBaseView extends DOMWidgetView {
/**
* Select tags from `start` to `start + dx` not included.
*/
select(start: number, dx: number) {
select(start: number, dx: number): void {
const valueLength = this.model.get('value').length;

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

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

value.splice(tagIndex, 1);
Expand All @@ -511,15 +516,15 @@ abstract class TagsInputBaseView extends DOMWidgetView {
/**
* Focus on the input element
*/
focus() {
focus(): void {
this.taginputWrapper.style.display = 'inline-block';
this.taginput.focus();
}

/**
* Lose focus on the input element
*/
loseFocus() {
loseFocus(): void {
if (this.preventLoosingFocus) {
return;
}
Expand All @@ -539,7 +544,7 @@ abstract class TagsInputBaseView extends DOMWidgetView {
* #### Notes
* This is a read-only attribute.
*/
get tagName() {
get tagName(): string {
// We can't make this an attribute with a default value
// since it would be set after it is needed in the
// constructor.
Expand Down Expand Up @@ -624,7 +629,7 @@ export class TagsInputView extends TagsInputBaseView {
/**
* Returns the text that should be displayed in the tag element
*/
getTagText(value: string) {
getTagText(value: string): string {
return value;
}

Expand Down Expand Up @@ -753,7 +758,7 @@ abstract class NumbersInputModel extends TagsInputModel {
}

abstract class NumbersInputView extends TagsInputView {
render() {
render(): void {
// Initialize text formatter
this.model.on('change:format', () => {
this.formatter = d3Format.format(this.model.get('format'));
Expand All @@ -767,7 +772,7 @@ abstract class NumbersInputView extends TagsInputView {
/**
* Returns the text that should be displayed in the tag element
*/
getTagText(value: string) {
getTagText(value: string): string {
return this.formatter(this.parseNumber(value));
}

Expand Down

0 comments on commit efa9e89

Please sign in to comment.