Commit 60404418 authored by Mike Greiling's avatar Mike Greiling

Merge branch 'justin_ho-fix-no-else-return' into 'master'

Fix no-else-return eslint rule

See merge request gitlab-org/gitlab!30454
parents 632ce4dd 9c96399c
...@@ -22,17 +22,17 @@ rules: ...@@ -22,17 +22,17 @@ rules:
- allow: - allow:
- __ - __
- _links - _links
# Disabled for now, to make the airbnb-base 12.1.0 -> 13.1.0 update smoother
no-else-return:
- error
- allowElseIf: true
import/no-unresolved: import/no-unresolved:
- error - error
- ignore: - ignore:
# https://gitlab.com/gitlab-org/gitlab/issues/38226 # https://gitlab.com/gitlab-org/gitlab/issues/38226
- '^ee_component/' - '^ee_component/'
import/no-useless-path-segments: off
import/order: off import/order: off
# Disabled for now, to make the airbnb-base 12.1.0 -> 13.1.0 update smoother
no-else-return:
- error
- allowElseIf: true
import/no-useless-path-segments: off
lines-between-class-members: off lines-between-class-members: off
# Disabled for now, to make the plugin-vue 4.5 -> 5.0 update smoother # Disabled for now, to make the plugin-vue 4.5 -> 5.0 update smoother
vue/no-confusing-v-for-v-if: error vue/no-confusing-v-for-v-if: error
......
/* eslint-disable func-names, no-else-return, consistent-return, one-var, no-return-assign */ /* eslint-disable func-names, consistent-return, one-var, no-return-assign */
import $ from 'jquery'; import $ from 'jquery';
...@@ -201,9 +201,8 @@ export default class ImageFile { ...@@ -201,9 +201,8 @@ export default class ImageFile {
if (domImg) { if (domImg) {
if (domImg.complete) { if (domImg.complete) {
return callback.call(this, domImg.naturalWidth, domImg.naturalHeight); return callback.call(this, domImg.naturalWidth, domImg.naturalHeight);
} else {
return img.on('load', () => callback.call(this, domImg.naturalWidth, domImg.naturalHeight));
} }
return img.on('load', () => callback.call(this, domImg.naturalWidth, domImg.naturalHeight));
} }
} }
} }
/* eslint-disable func-names, no-else-return */ /* eslint-disable func-names */
import $ from 'jquery'; import $ from 'jquery';
import { __ } from './locale'; import { __ } from './locale';
...@@ -52,9 +52,8 @@ export default function initCompareAutocomplete(limitTo = null, clickHandler = ( ...@@ -52,9 +52,8 @@ export default function initCompareAutocomplete(limitTo = null, clickHandler = (
return $('<li />') return $('<li />')
.addClass('dropdown-header') .addClass('dropdown-header')
.text(ref.header); .text(ref.header);
} else {
return $('<li />').append(link);
} }
return $('<li />').append(link);
}, },
id(obj, $el) { id(obj, $el) {
return $el.attr('data-ref'); return $el.attr('data-ref');
......
/* eslint-disable no-else-return, no-lonely-if */
/* global CommentsStore */ /* global CommentsStore */
import $ from 'jquery'; import $ from 'jquery';
...@@ -22,27 +21,19 @@ const CommentAndResolveBtn = Vue.extend({ ...@@ -22,27 +21,19 @@ const CommentAndResolveBtn = Vue.extend({
showButton() { showButton() {
if (this.discussion) { if (this.discussion) {
return this.discussion.isResolvable(); return this.discussion.isResolvable();
} else {
return false;
} }
return false;
}, },
isDiscussionResolved() { isDiscussionResolved() {
return this.discussion.isResolved(); return this.discussion.isResolved();
}, },
buttonText() { buttonText() {
if (this.isDiscussionResolved) { if (this.textareaIsEmpty) {
if (this.textareaIsEmpty) { return this.isDiscussionResolved ? __('Unresolve thread') : __('Resolve thread');
return __('Unresolve thread');
} else {
return __('Comment & unresolve thread');
}
} else {
if (this.textareaIsEmpty) {
return __('Resolve thread');
} else {
return __('Comment & resolve thread');
}
} }
return this.isDiscussionResolved
? __('Comment & unresolve thread')
: __('Comment & resolve thread');
}, },
}, },
created() { created() {
......
/* eslint-disable func-names, no-else-return, guard-for-in, no-restricted-syntax, no-lonely-if, no-continue */ /* eslint-disable func-names, guard-for-in, no-restricted-syntax, no-lonely-if, no-continue */
/* global CommentsStore */ /* global CommentsStore */
import $ from 'jquery'; import $ from 'jquery';
...@@ -25,9 +25,8 @@ const JumpToDiscussion = Vue.extend({ ...@@ -25,9 +25,8 @@ const JumpToDiscussion = Vue.extend({
buttonText() { buttonText() {
if (this.discussionId) { if (this.discussionId) {
return __('Jump to next unresolved thread'); return __('Jump to next unresolved thread');
} else {
return __('Jump to first unresolved thread');
} }
return __('Jump to first unresolved thread');
}, },
allResolved() { allResolved() {
return this.unresolvedDiscussionCount === 0; return this.unresolvedDiscussionCount === 0;
...@@ -36,12 +35,10 @@ const JumpToDiscussion = Vue.extend({ ...@@ -36,12 +35,10 @@ const JumpToDiscussion = Vue.extend({
if (this.discussionId) { if (this.discussionId) {
if (this.unresolvedDiscussionCount > 1) { if (this.unresolvedDiscussionCount > 1) {
return true; return true;
} else {
return this.discussionId !== this.lastResolvedId;
} }
} else { return this.discussionId !== this.lastResolvedId;
return this.unresolvedDiscussionCount >= 1;
} }
return this.unresolvedDiscussionCount >= 1;
}, },
lastResolvedId() { lastResolvedId() {
let lastId; let lastId;
......
/* eslint-disable no-useless-return, func-names, no-underscore-dangle, no-new, consistent-return, no-shadow, no-param-reassign, no-lonely-if, no-else-return, dot-notation, no-empty */ /* eslint-disable no-useless-return, func-names, no-underscore-dangle, no-new, consistent-return, no-shadow, no-param-reassign, no-lonely-if, dot-notation, no-empty */
/* global Issuable */ /* global Issuable */
/* global ListLabel */ /* global ListLabel */
...@@ -311,9 +311,8 @@ export default class LabelsSelect { ...@@ -311,9 +311,8 @@ export default class LabelsSelect {
firstLabel: selectedLabels[0], firstLabel: selectedLabels[0],
labelCount: selectedLabels.length - 1, labelCount: selectedLabels.length - 1,
}); });
} else {
return defaultLabel;
} }
return defaultLabel;
}, },
fieldName: $dropdown.data('fieldName'), fieldName: $dropdown.data('fieldName'),
id(label) { id(label) {
...@@ -325,9 +324,8 @@ export default class LabelsSelect { ...@@ -325,9 +324,8 @@ export default class LabelsSelect {
if ($dropdown.hasClass('js-filter-submit') && label.isAny == null) { if ($dropdown.hasClass('js-filter-submit') && label.isAny == null) {
return label.title; return label.title;
} else {
return label.id;
} }
return label.id;
}, },
hidden() { hidden() {
const page = $('body').attr('data-page'); const page = $('body').attr('data-page');
......
/* eslint-disable func-names, no-param-reassign, operator-assignment, no-else-return, consistent-return */ /* eslint-disable func-names, no-param-reassign, operator-assignment, consistent-return */
import $ from 'jquery'; import $ from 'jquery';
import { insertText } from '~/lib/utils/common_utils'; import { insertText } from '~/lib/utils/common_utils';
...@@ -217,9 +217,8 @@ export function insertMarkdownText({ ...@@ -217,9 +217,8 @@ export function insertMarkdownText({
} }
if (val.indexOf(tag) === 0) { if (val.indexOf(tag) === 0) {
return String(val.replace(tag, '')); return String(val.replace(tag, ''));
} else {
return String(tag) + val;
} }
return String(tag) + val;
}) })
.join('\n'); .join('\n');
} }
......
/* eslint-disable func-names, no-underscore-dangle, no-param-reassign, consistent-return, no-else-return */ /* eslint-disable func-names, no-underscore-dangle, no-param-reassign, consistent-return */
import $ from 'jquery'; import $ from 'jquery';
...@@ -128,9 +128,8 @@ LineHighlighter.prototype.hashToRange = function(hash) { ...@@ -128,9 +128,8 @@ LineHighlighter.prototype.hashToRange = function(hash) {
const first = parseInt(matches[1], 10); const first = parseInt(matches[1], 10);
const last = matches[2] ? parseInt(matches[2], 10) : null; const last = matches[2] ? parseInt(matches[2], 10) : null;
return [first, last]; return [first, last];
} else {
return [null, null];
} }
return [null, null];
}; };
// Highlight a single line // Highlight a single line
...@@ -153,9 +152,8 @@ LineHighlighter.prototype.highlightRange = function(range) { ...@@ -153,9 +152,8 @@ LineHighlighter.prototype.highlightRange = function(range) {
} }
return results; return results;
} else {
return this.highlightLine(range[0]);
} }
return this.highlightLine(range[0]);
}; };
// Set the URL hash string // Set the URL hash string
......
/* eslint-disable one-var, no-else-return, no-self-compare, consistent-return, no-param-reassign, no-shadow */ /* eslint-disable one-var, no-self-compare, consistent-return, no-param-reassign, no-shadow */
/* global Issuable */ /* global Issuable */
/* global ListMilestone */ /* global ListMilestone */
...@@ -123,9 +123,8 @@ export default class MilestoneSelect { ...@@ -123,9 +123,8 @@ export default class MilestoneSelect {
toggleLabel: (selected, el) => { toggleLabel: (selected, el) => {
if (selected && 'id' in selected && $(el).hasClass('is-active')) { if (selected && 'id' in selected && $(el).hasClass('is-active')) {
return selected.title; return selected.title;
} else {
return defaultLabel;
} }
return defaultLabel;
}, },
defaultLabel, defaultLabel,
fieldName: $dropdown.data('fieldName'), fieldName: $dropdown.data('fieldName'),
...@@ -133,9 +132,8 @@ export default class MilestoneSelect { ...@@ -133,9 +132,8 @@ export default class MilestoneSelect {
id: milestone => { id: milestone => {
if (!useId && !$dropdown.is('.js-issuable-form-dropdown')) { if (!useId && !$dropdown.is('.js-issuable-form-dropdown')) {
return milestone.name; return milestone.name;
} else {
return milestone.id;
} }
return milestone.id;
}, },
hidden: () => { hidden: () => {
$selectBox.hide(); $selectBox.hide();
...@@ -244,13 +242,12 @@ export default class MilestoneSelect { ...@@ -244,13 +242,12 @@ export default class MilestoneSelect {
) )
.find('span') .find('span')
.text(data.milestone.title); .text(data.milestone.title);
} else {
$value.html(milestoneLinkNoneTemplate);
return $sidebarCollapsedValue
.attr('data-original-title', __('Milestone'))
.find('span')
.text(__('None'));
} }
$value.html(milestoneLinkNoneTemplate);
return $sidebarCollapsedValue
.attr('data-original-title', __('Milestone'))
.find('span')
.text(__('None'));
}) })
.catch(() => { .catch(() => {
// eslint-disable-next-line no-jquery/no-fade // eslint-disable-next-line no-jquery/no-fade
......
/* eslint-disable no-else-return */
import $ from 'jquery'; import $ from 'jquery';
import '~/gl_dropdown'; import '~/gl_dropdown';
import Api from './api'; import Api from './api';
...@@ -23,9 +21,8 @@ export default class NamespaceSelect { ...@@ -23,9 +21,8 @@ export default class NamespaceSelect {
toggleLabel(selected) { toggleLabel(selected) {
if (selected.id == null) { if (selected.id == null) {
return selected.text; return selected.text;
} else {
return `${selected.kind}: ${selected.full_path}`;
} }
return `${selected.kind}: ${selected.full_path}`;
}, },
data(term, dataCallback) { data(term, dataCallback) {
return Api.namespaces(term, namespaces => { return Api.namespaces(term, namespaces => {
...@@ -43,9 +40,8 @@ export default class NamespaceSelect { ...@@ -43,9 +40,8 @@ export default class NamespaceSelect {
text(namespace) { text(namespace) {
if (namespace.id == null) { if (namespace.id == null) {
return namespace.text; return namespace.text;
} else {
return `${namespace.kind}: ${namespace.full_path}`;
} }
return `${namespace.kind}: ${namespace.full_path}`;
}, },
renderRow: this.renderRow, renderRow: this.renderRow,
clicked(options) { clicked(options) {
......
/* eslint-disable func-names, consistent-return, no-return-assign, no-else-return, @gitlab/require-i18n-strings */ /* eslint-disable func-names, consistent-return, no-return-assign, @gitlab/require-i18n-strings */
import $ from 'jquery'; import $ from 'jquery';
import RefSelectDropdown from './ref_select_dropdown'; import RefSelectDropdown from './ref_select_dropdown';
...@@ -76,9 +76,8 @@ export default class NewBranchForm { ...@@ -76,9 +76,8 @@ export default class NewBranchForm {
const matched = this.name.val().match(restriction.pattern); const matched = this.name.val().match(restriction.pattern);
if (matched) { if (matched) {
return errors.concat(formatter(matched.reduce(unique, []), restriction)); return errors.concat(formatter(matched.reduce(unique, []), restriction));
} else {
return errors;
} }
return errors;
}; };
const errors = this.restrictions.reduce(validator, []); const errors = this.restrictions.reduce(validator, []);
if (errors.length > 0) { if (errors.length > 0) {
......
/* eslint-disable no-restricted-properties, babel/camelcase, /* eslint-disable no-restricted-properties, babel/camelcase,
no-unused-expressions, default-case, no-unused-expressions, default-case,
consistent-return, no-alert, no-param-reassign, no-else-return, consistent-return, no-alert, no-param-reassign,
no-shadow, no-useless-escape, no-shadow, no-useless-escape,
class-methods-use-this */ class-methods-use-this */
...@@ -1123,10 +1123,9 @@ export default class Notes { ...@@ -1123,10 +1123,9 @@ export default class Notes {
if (row.is('.js-temp-notes-holder')) { if (row.is('.js-temp-notes-holder')) {
// remove temporary row for diff lines // remove temporary row for diff lines
return row.remove(); return row.remove();
} else {
// only remove the form
return form.remove();
} }
// only remove the form
return form.remove();
} }
cancelDiscussionForm(e) { cancelDiscussionForm(e) {
......
/* eslint-disable func-names, no-else-return */ /* eslint-disable func-names */
import $ from 'jquery'; import $ from 'jquery';
import Api from './api'; import Api from './api';
...@@ -74,18 +74,17 @@ const projectSelect = () => { ...@@ -74,18 +74,17 @@ const projectSelect = () => {
}, },
projectsCallback, projectsCallback,
); );
} else {
return Api.projects(
query.term,
{
order_by: this.orderBy,
with_issues_enabled: this.withIssuesEnabled,
with_merge_requests_enabled: this.withMergeRequestsEnabled,
membership: !this.allProjects,
},
projectsCallback,
);
} }
return Api.projects(
query.term,
{
order_by: this.orderBy,
with_issues_enabled: this.withIssuesEnabled,
with_merge_requests_enabled: this.withMergeRequestsEnabled,
membership: !this.allProjects,
},
projectsCallback,
);
}, },
id(project) { id(project) {
if (simpleFilter) return project.id; if (simpleFilter) return project.id;
......
/* eslint-disable consistent-return, no-else-return */ /* eslint-disable consistent-return */
import $ from 'jquery'; import $ from 'jquery';
...@@ -16,11 +16,10 @@ export default function syntaxHighlight(el) { ...@@ -16,11 +16,10 @@ export default function syntaxHighlight(el) {
if ($(el).hasClass('js-syntax-highlight')) { if ($(el).hasClass('js-syntax-highlight')) {
// Given the element itself, apply highlighting // Given the element itself, apply highlighting
return $(el).addClass(gon.user_color_scheme); return $(el).addClass(gon.user_color_scheme);
} else { }
// Given a parent element, recurse to any of its applicable children // Given a parent element, recurse to any of its applicable children
const $children = $(el).find('.js-syntax-highlight'); const $children = $(el).find('.js-syntax-highlight');
if ($children.length) { if ($children.length) {
return syntaxHighlight($children); return syntaxHighlight($children);
}
} }
} }
/* eslint-disable func-names, consistent-return, one-var, no-else-return, class-methods-use-this */ /* eslint-disable func-names, consistent-return, one-var, class-methods-use-this */
import $ from 'jquery'; import $ from 'jquery';
import { visitUrl } from './lib/utils/url_utility'; import { visitUrl } from './lib/utils/url_utility';
...@@ -15,9 +15,8 @@ export default class TreeView { ...@@ -15,9 +15,8 @@ export default class TreeView {
if (e.metaKey || e.which === 2) { if (e.metaKey || e.which === 2) {
e.preventDefault(); e.preventDefault();
return window.open(path, '_blank'); return window.open(path, '_blank');
} else {
return visitUrl(path);
} }
return visitUrl(path);
} }
}); });
// Show the "Loading commit data" for only the first element // Show the "Loading commit data" for only the first element
......
/* eslint-disable func-names, prefer-rest-params, consistent-return, no-shadow, no-else-return, no-self-compare, no-unused-expressions, yoda, prefer-spread, babel/camelcase, no-param-reassign */ /* eslint-disable func-names, prefer-rest-params, consistent-return, no-shadow, no-self-compare, no-unused-expressions, yoda, prefer-spread, babel/camelcase, no-param-reassign */
/* global Issuable */ /* global Issuable */
/* global emitSidebarEvent */ /* global emitSidebarEvent */
...@@ -148,12 +148,11 @@ function UsersSelect(currentUser, els, options = {}) { ...@@ -148,12 +148,11 @@ function UsersSelect(currentUser, els, options = {}) {
name: selectedUser.name, name: selectedUser.name,
length: otherSelected.length, length: otherSelected.length,
}); });
} else {
return sprintf(s__('UsersSelect|%{name} + %{length} more'), {
name: firstUser.name,
length: selectedUsers.length - 1,
});
} }
return sprintf(s__('UsersSelect|%{name} + %{length} more'), {
name: firstUser.name,
length: selectedUsers.length - 1,
});
}; };
$('.assign-to-me-link').on('click', e => { $('.assign-to-me-link').on('click', e => {
...@@ -375,13 +374,11 @@ function UsersSelect(currentUser, els, options = {}) { ...@@ -375,13 +374,11 @@ function UsersSelect(currentUser, els, options = {}) {
$dropdown.find('.dropdown-toggle-text').removeClass('is-default'); $dropdown.find('.dropdown-toggle-text').removeClass('is-default');
if (selected.text) { if (selected.text) {
return selected.text; return selected.text;
} else {
return selected.name;
} }
} else { return selected.name;
$dropdown.find('.dropdown-toggle-text').addClass('is-default');
return defaultLabel;
} }
$dropdown.find('.dropdown-toggle-text').addClass('is-default');
return defaultLabel;
}, },
defaultLabel, defaultLabel,
hidden() { hidden() {
......
/* eslint-disable no-shadow, no-else-return */ /* eslint-disable no-shadow */
import $ from 'jquery'; import $ from 'jquery';
import '~/gl_dropdown'; import '~/gl_dropdown';
...@@ -33,9 +33,8 @@ function WeightSelect(els, options = {}) { ...@@ -33,9 +33,8 @@ function WeightSelect(els, options = {}) {
id(obj, el) { id(obj, el) {
if ($(el).data('none') == null) { if ($(el).data('none') == null) {
return $(el).data('id'); return $(el).data('id');
} else {
return '';
} }
return '';
}, },
clicked(glDropdownEvt) { clicked(glDropdownEvt) {
const { e } = glDropdownEvt; const { e } = glDropdownEvt;
......
/* eslint-disable no-else-return, dot-notation, no-return-assign, no-new, no-underscore-dangle */ /* eslint-disable dot-notation, no-return-assign, no-new, no-underscore-dangle */
import $ from 'jquery'; import $ from 'jquery';
import LineHighlighter from '~/line_highlighter'; import LineHighlighter from '~/line_highlighter';
...@@ -8,10 +8,9 @@ describe('LineHighlighter', function() { ...@@ -8,10 +8,9 @@ describe('LineHighlighter', function() {
const clickLine = function(number, eventData = {}) { const clickLine = function(number, eventData = {}) {
if ($.isEmptyObject(eventData)) { if ($.isEmptyObject(eventData)) {
return $(`#L${number}`).click(); return $(`#L${number}`).click();
} else {
const e = $.Event('click', eventData);
return $(`#L${number}`).trigger(e);
} }
const e = $.Event('click', eventData);
return $(`#L${number}`).trigger(e);
}; };
beforeEach(function() { beforeEach(function() {
loadFixtures('static/line_highlighter.html'); loadFixtures('static/line_highlighter.html');
......
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