Commit dd0ecc8e authored by Lee Tickett's avatar Lee Tickett Committed by Kushal Pandya

Remove var from new_branch_form.js

parent d18625a2
/* eslint-disable func-names, no-var, one-var, consistent-return, no-return-assign, no-shadow, no-else-return, @gitlab/i18n/no-non-i18n-strings */
/* eslint-disable func-names, consistent-return, no-return-assign, no-else-return, @gitlab/i18n/no-non-i18n-strings */
import $ from 'jquery';
import RefSelectDropdown from './ref_select_dropdown';
......@@ -26,23 +26,22 @@ export default class NewBranchForm {
}
setupRestrictions() {
var endsWith, invalid, single, startsWith;
startsWith = {
const startsWith = {
pattern: /^(\/|\.)/g,
prefix: "can't start with",
conjunction: 'or',
};
endsWith = {
const endsWith = {
pattern: /(\/|\.|\.lock)$/g,
prefix: "can't end in",
conjunction: 'or',
};
invalid = {
const invalid = {
pattern: /(\s|~|\^|:|\?|\*|\[|\\|\.\.|@\{|\/{2,}){1}/g,
prefix: "can't contain",
conjunction: ', ',
};
single = {
const single = {
pattern: /^@+$/g,
prefix: "can't be",
conjunction: 'or',
......@@ -51,19 +50,17 @@ export default class NewBranchForm {
}
validate() {
var errorMessage, errors, formatter, unique, validator;
const { indexOf } = [];
this.branchNameError.empty();
unique = function(values, value) {
const unique = function(values, value) {
if (indexOf.call(values, value) === -1) {
values.push(value);
}
return values;
};
formatter = function(values, restriction) {
var formatted;
formatted = values.map(value => {
const formatter = function(values, restriction) {
const formatted = values.map(value => {
switch (false) {
case !/\s/.test(value):
return 'spaces';
......@@ -75,10 +72,9 @@ export default class NewBranchForm {
});
return `${restriction.prefix} ${formatted.join(restriction.conjunction)}`;
};
validator = (function(_this) {
const validator = (function(_this) {
return function(errors, restriction) {
var matched;
matched = _this.name.val().match(restriction.pattern);
const matched = _this.name.val().match(restriction.pattern);
if (matched) {
return errors.concat(formatter(matched.reduce(unique, []), restriction));
} else {
......@@ -86,9 +82,9 @@ export default class NewBranchForm {
}
};
})(this);
errors = this.restrictions.reduce(validator, []);
const errors = this.restrictions.reduce(validator, []);
if (errors.length > 0) {
errorMessage = $('<span/>').text(errors.join(', '));
const errorMessage = $('<span/>').text(errors.join(', '));
return this.branchNameError.append(errorMessage);
}
}
......
---
title: Remove var from new_branch_form.js
merge_request: 20099
author: Lee Tickett
type: other
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