Commit a6788c1a authored by Kushal Pandya's avatar Kushal Pandya

Run through Prettier and remove ESLint disables

Formats the file to match Prettier rules
Removes all blacklisted ESLint rules
parent 02ccbb0a
/* eslint-disable no-new, no-unused-vars, consistent-return, no-else-return */
/* global GitLab */
import $ from 'jquery'; import $ from 'jquery';
import Pikaday from 'pikaday'; import Pikaday from 'pikaday';
import Autosave from './autosave'; import Autosave from './autosave';
...@@ -19,9 +16,11 @@ export default class IssuableForm { ...@@ -19,9 +16,11 @@ export default class IssuableForm {
this.handleSubmit = this.handleSubmit.bind(this); this.handleSubmit = this.handleSubmit.bind(this);
this.wipRegex = /^\s*(\[WIP\]\s*|WIP:\s*|WIP\s+)+\s*/i; this.wipRegex = /^\s*(\[WIP\]\s*|WIP:\s*|WIP\s+)+\s*/i;
new GfmAutoComplete(gl.GfmAutoComplete && gl.GfmAutoComplete.dataSources).setup(); this.gfmAutoComplete = new GfmAutoComplete(
new UsersSelect(); gl.GfmAutoComplete && gl.GfmAutoComplete.dataSources,
new ZenMode(); ).setup();
this.usersSelect = new UsersSelect();
this.zenMode = new ZenMode();
this.titleField = this.form.find('input[name*="[title]"]'); this.titleField = this.form.find('input[name*="[title]"]');
this.descriptionField = this.form.find('textarea[name*="[description]"]'); this.descriptionField = this.form.find('textarea[name*="[description]"]');
...@@ -57,8 +56,16 @@ export default class IssuableForm { ...@@ -57,8 +56,16 @@ export default class IssuableForm {
} }
initAutosave() { initAutosave() {
new Autosave(this.titleField, [document.location.pathname, document.location.search, 'title']); this.autosave = new Autosave(this.titleField, [
return new Autosave(this.descriptionField, [document.location.pathname, document.location.search, 'description']); document.location.pathname,
document.location.search,
'title',
]);
return new Autosave(this.descriptionField, [
document.location.pathname,
document.location.search,
'description',
]);
} }
handleSubmit() { handleSubmit() {
...@@ -74,7 +81,7 @@ export default class IssuableForm { ...@@ -74,7 +81,7 @@ export default class IssuableForm {
this.$wipExplanation = this.form.find('.js-wip-explanation'); this.$wipExplanation = this.form.find('.js-wip-explanation');
this.$noWipExplanation = this.form.find('.js-no-wip-explanation'); this.$noWipExplanation = this.form.find('.js-no-wip-explanation');
if (!(this.$wipExplanation.length && this.$noWipExplanation.length)) { if (!(this.$wipExplanation.length && this.$noWipExplanation.length)) {
return; return undefined;
} }
this.form.on('click', '.js-toggle-wip', this.toggleWip); this.form.on('click', '.js-toggle-wip', this.toggleWip);
this.titleField.on('keyup blur', this.renderWipExplanation); this.titleField.on('keyup blur', this.renderWipExplanation);
...@@ -89,11 +96,10 @@ export default class IssuableForm { ...@@ -89,11 +96,10 @@ export default class IssuableForm {
if (this.workInProgress()) { if (this.workInProgress()) {
this.$wipExplanation.show(); this.$wipExplanation.show();
return this.$noWipExplanation.hide(); return this.$noWipExplanation.hide();
} else { }
this.$wipExplanation.hide(); this.$wipExplanation.hide();
return this.$noWipExplanation.show(); return this.$noWipExplanation.show();
} }
}
toggleWip(event) { toggleWip(event) {
event.preventDefault(); event.preventDefault();
...@@ -110,7 +116,7 @@ export default class IssuableForm { ...@@ -110,7 +116,7 @@ export default class IssuableForm {
} }
addWip() { addWip() {
this.titleField.val(`WIP: ${(this.titleField.val())}`); this.titleField.val(`WIP: ${this.titleField.val()}`);
} }
initTargetBranchDropdown() { initTargetBranchDropdown() {
......
...@@ -79,7 +79,8 @@ let timeagoInstance; ...@@ -79,7 +79,8 @@ let timeagoInstance;
*/ */
export const getTimeago = () => { export const getTimeago = () => {
if (!timeagoInstance) { if (!timeagoInstance) {
const localeRemaining = (number, index) => [ const localeRemaining = (number, index) =>
[
[s__('Timeago|just now'), s__('Timeago|right now')], [s__('Timeago|just now'), s__('Timeago|right now')],
[s__('Timeago|%s seconds ago'), s__('Timeago|%s seconds remaining')], [s__('Timeago|%s seconds ago'), s__('Timeago|%s seconds remaining')],
[s__('Timeago|1 minute ago'), s__('Timeago|1 minute remaining')], [s__('Timeago|1 minute ago'), s__('Timeago|1 minute remaining')],
...@@ -96,7 +97,8 @@ export const getTimeago = () => { ...@@ -96,7 +97,8 @@ export const getTimeago = () => {
[s__('Timeago|%s years ago'), s__('Timeago|%s years remaining')], [s__('Timeago|%s years ago'), s__('Timeago|%s years remaining')],
][index]; ][index];
const locale = (number, index) => [ const locale = (number, index) =>
[
[s__('Timeago|just now'), s__('Timeago|right now')], [s__('Timeago|just now'), s__('Timeago|right now')],
[s__('Timeago|%s seconds ago'), s__('Timeago|in %s seconds')], [s__('Timeago|%s seconds ago'), s__('Timeago|in %s seconds')],
[s__('Timeago|1 minute ago'), s__('Timeago|in 1 minute')], [s__('Timeago|1 minute ago'), s__('Timeago|in 1 minute')],
...@@ -119,7 +121,7 @@ export const getTimeago = () => { ...@@ -119,7 +121,7 @@ export const getTimeago = () => {
} }
return timeagoInstance; return timeagoInstance;
} };
/** /**
* For the given element, renders a timeago instance. * For the given element, renders a timeago instance.
...@@ -184,7 +186,7 @@ export const getDayDifference = (a, b) => { ...@@ -184,7 +186,7 @@ export const getDayDifference = (a, b) => {
* @param {Number} seconds * @param {Number} seconds
* @return {String} * @return {String}
*/ */
export const timeIntervalInWords = (intervalInSeconds) => { export const timeIntervalInWords = intervalInSeconds => {
const secondsInteger = parseInt(intervalInSeconds, 10); const secondsInteger = parseInt(intervalInSeconds, 10);
const minutes = Math.floor(secondsInteger / 60); const minutes = Math.floor(secondsInteger / 60);
const seconds = secondsInteger - minutes * 60; const seconds = secondsInteger - minutes * 60;
...@@ -196,7 +198,7 @@ export const timeIntervalInWords = (intervalInSeconds) => { ...@@ -196,7 +198,7 @@ export const timeIntervalInWords = (intervalInSeconds) => {
text = `${seconds} ${pluralize('second', seconds)}`; text = `${seconds} ${pluralize('second', seconds)}`;
} }
return text; return text;
} };
export const dateInWords = (date, abbreviated = false, hideYear = false) => { export const dateInWords = (date, abbreviated = false, hideYear = false) => {
if (!date) return date; if (!date) return date;
...@@ -240,7 +242,7 @@ export const dateInWords = (date, abbreviated = false, hideYear = false) => { ...@@ -240,7 +242,7 @@ export const dateInWords = (date, abbreviated = false, hideYear = false) => {
} }
return `${monthName} ${date.getDate()}, ${year}`; return `${monthName} ${date.getDate()}, ${year}`;
} };
/** /**
* Returns month name based on provided date. * Returns month name based on provided date.
...@@ -447,13 +449,13 @@ export const parseSeconds = (seconds, { daysPerWeek = 5, hoursPerDay = 8 } = {}) ...@@ -447,13 +449,13 @@ export const parseSeconds = (seconds, { daysPerWeek = 5, hoursPerDay = 8 } = {})
return periodCount; return periodCount;
}); });
} };
/** /**
* Accepts a timeObject (see parseSeconds) and returns a condensed string representation of it * Accepts a timeObject (see parseSeconds) and returns a condensed string representation of it
* (e.g. '1w 2d 3h 1m' or '1h 30m'). Zero value units are not included. * (e.g. '1w 2d 3h 1m' or '1h 30m'). Zero value units are not included.
*/ */
export const stringifyTime = (timeObject) => { export const stringifyTime = timeObject => {
const reducedTime = _.reduce( const reducedTime = _.reduce(
timeObject, timeObject,
(memo, unitValue, unitName) => { (memo, unitValue, unitName) => {
...@@ -463,10 +465,11 @@ export const stringifyTime = (timeObject) => { ...@@ -463,10 +465,11 @@ export const stringifyTime = (timeObject) => {
'', '',
).trim(); ).trim();
return reducedTime.length ? reducedTime : '0m'; return reducedTime.length ? reducedTime : '0m';
} };
/** /**
* Accepts a time string of any size (e.g. '1w 2d 3h 5m' or '1w 2d') and returns * Accepts a time string of any size (e.g. '1w 2d 3h 5m' or '1w 2d') and returns
* the first non-zero unit/value pair. * the first non-zero unit/value pair.
*/ */
export const abbreviateTime = (timeStr) => timeStr.split(' ').filter(unitStr => unitStr.charAt(0) !== '0')[0]; export const abbreviateTime = timeStr =>
timeStr.split(' ').filter(unitStr => unitStr.charAt(0) !== '0')[0];
<script> <script>
import { __, sprintf } from '~/locale'; import { __, sprintf } from '~/locale';
import { abbreviateTime } from '~/lib/utils/datetime_utility'; import { abbreviateTime } from '~/lib/utils/datetime_utility';
import icon from '~/vue_shared/components/icon.vue'; import icon from '~/vue_shared/components/icon.vue';
import tooltip from '~/vue_shared/directives/tooltip'; import tooltip from '~/vue_shared/directives/tooltip';
export default { export default {
name: 'TimeTrackingCollapsedState', name: 'TimeTrackingCollapsedState',
components: { components: {
icon, icon,
...@@ -94,7 +94,7 @@ ...@@ -94,7 +94,7 @@
title = __('Time spent'); title = __('Time spent');
} }
return sprintf('%{title}: %{text}', ({ title, text: this.text })); return sprintf('%{title}: %{text}', { title, text: this.text });
}, },
tooltipText() { tooltipText() {
return this.showNoTimeTrackingState ? __('Time tracking') : this.timeTrackedTooltipText; return this.showNoTimeTrackingState ? __('Time tracking') : this.timeTrackedTooltipText;
...@@ -105,7 +105,7 @@ ...@@ -105,7 +105,7 @@
return abbreviateTime(timeStr); return abbreviateTime(timeStr);
}, },
}, },
}; };
</script> </script>
<template> <template>
......
...@@ -225,7 +225,7 @@ describe('prettyTime methods', () => { ...@@ -225,7 +225,7 @@ describe('prettyTime methods', () => {
expect(obj.hours).toBe(hours); expect(obj.hours).toBe(hours);
expect(obj.days).toBe(days); expect(obj.days).toBe(days);
expect(obj.weeks).toBe(weeks); expect(obj.weeks).toBe(weeks);
} };
describe('parseSeconds', () => { describe('parseSeconds', () => {
it('should correctly parse a negative value', () => { it('should correctly parse a negative value', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment