Commit a9bec233 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'remove_var_from_new_branch_Form_js' into 'master'

Remove var from new_branch_form.js

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