ci: Ensure that eslint runs on all frontend code (no-changelog) (#4602)
* ensure that eslint runs on all frontend code * remove tslint from `design-system` * enable prettier and eslint-prettier for `design-system` * Delete tslint.json * use a single editorconfig for the repo * enable prettier for all code in `design-system` * more linting fixes on design-system * ignore coverage for git and prettier * lintfix on editor-ui
This commit is contained in:
committed by
GitHub
parent
d96d6f11db
commit
13659d036f
@@ -1,12 +1,11 @@
|
||||
|
||||
import { IValidator, RuleGroup } from "../../types";
|
||||
import { IValidator, RuleGroup, Validatable } from '../../types';
|
||||
|
||||
export const emailRegex =
|
||||
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
||||
|
||||
export const VALIDATORS: { [key: string]: IValidator | RuleGroup } = {
|
||||
REQUIRED: {
|
||||
validate: (value: string | number | boolean | null | undefined) => {
|
||||
validate: (value: Validatable) => {
|
||||
if (typeof value === 'string' && !!value.trim()) {
|
||||
return false;
|
||||
}
|
||||
@@ -21,7 +20,7 @@ export const VALIDATORS: { [key: string]: IValidator | RuleGroup } = {
|
||||
},
|
||||
},
|
||||
MIN_LENGTH: {
|
||||
validate: (value: string | number | boolean | null | undefined, config: { minimum: number }) => {
|
||||
validate: (value: Validatable, config: { minimum: number }) => {
|
||||
if (typeof value === 'string' && value.length < config.minimum) {
|
||||
return {
|
||||
messageKey: 'formInput.validator.minCharactersRequired',
|
||||
@@ -33,7 +32,7 @@ export const VALIDATORS: { [key: string]: IValidator | RuleGroup } = {
|
||||
},
|
||||
},
|
||||
MAX_LENGTH: {
|
||||
validate: (value: string | number | boolean | null | undefined, config: { maximum: number }) => {
|
||||
validate: (value: Validatable, config: { maximum: number }) => {
|
||||
if (typeof value === 'string' && value.length > config.maximum) {
|
||||
return {
|
||||
messageKey: 'formInput.validator.maxCharactersRequired',
|
||||
@@ -45,12 +44,12 @@ export const VALIDATORS: { [key: string]: IValidator | RuleGroup } = {
|
||||
},
|
||||
},
|
||||
CONTAINS_NUMBER: {
|
||||
validate: (value: string | number | boolean | null | undefined, config: { minimum: number }) => {
|
||||
validate: (value: Validatable, config: { minimum: number }) => {
|
||||
if (typeof value !== 'string') {
|
||||
return false;
|
||||
}
|
||||
|
||||
const numberCount = (value.match(/\d/g) || []).length;
|
||||
const numberCount = (value.match(/\d/g) ?? []).length;
|
||||
if (numberCount < config.minimum) {
|
||||
return {
|
||||
messageKey: 'formInput.validator.numbersRequired',
|
||||
@@ -62,7 +61,7 @@ export const VALIDATORS: { [key: string]: IValidator | RuleGroup } = {
|
||||
},
|
||||
},
|
||||
VALID_EMAIL: {
|
||||
validate: (value: string | number | boolean | null | undefined) => {
|
||||
validate: (value: Validatable) => {
|
||||
if (!emailRegex.test(String(value).trim().toLowerCase())) {
|
||||
return {
|
||||
messageKey: 'formInput.validator.validEmailRequired',
|
||||
@@ -73,12 +72,12 @@ export const VALIDATORS: { [key: string]: IValidator | RuleGroup } = {
|
||||
},
|
||||
},
|
||||
CONTAINS_UPPERCASE: {
|
||||
validate: (value: string | number | boolean | null | undefined, config: { minimum: number }) => {
|
||||
validate: (value: Validatable, config: { minimum: number }) => {
|
||||
if (typeof value !== 'string') {
|
||||
return false;
|
||||
}
|
||||
|
||||
const uppercaseCount = (value.match(/[A-Z]/g) || []).length;
|
||||
const uppercaseCount = (value.match(/[A-Z]/g) ?? []).length;
|
||||
if (uppercaseCount < config.minimum) {
|
||||
return {
|
||||
messageKey: 'formInput.validator.uppercaseCharsRequired',
|
||||
@@ -101,35 +100,30 @@ export const VALIDATORS: { [key: string]: IValidator | RuleGroup } = {
|
||||
messageKey: 'formInput.validator.defaultPasswordRequirements',
|
||||
},
|
||||
},
|
||||
{ name: 'MAX_LENGTH', config: {maximum: 64} },
|
||||
{ name: 'MAX_LENGTH', config: { maximum: 64 } },
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
export const getValidationError = (
|
||||
value: any, // tslint:disable-line:no-any
|
||||
export const getValidationError = <T extends Validatable, C>(
|
||||
value: T,
|
||||
validators: { [key: string]: IValidator | RuleGroup },
|
||||
validator: IValidator | RuleGroup,
|
||||
config?: any, // tslint:disable-line:no-any
|
||||
config?: C,
|
||||
): ReturnType<IValidator['validate']> => {
|
||||
if (validator.hasOwnProperty('rules')) {
|
||||
const rules = (validator as RuleGroup).rules;
|
||||
for (let i = 0; i < rules.length; i++) {
|
||||
if (rules[i].hasOwnProperty('rules')) {
|
||||
const error = getValidationError(
|
||||
value,
|
||||
validators,
|
||||
rules[i] as RuleGroup,
|
||||
config,
|
||||
);
|
||||
const error = getValidationError(value, validators, rules[i] as RuleGroup, config);
|
||||
|
||||
if (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
if (rules[i].hasOwnProperty('name') ) {
|
||||
const rule = rules[i] as {name: string, config?: any}; // tslint:disable-line:no-any
|
||||
if (rules[i].hasOwnProperty('name')) {
|
||||
const rule = rules[i] as { name: string; config?: C };
|
||||
if (!validators[rule.name]) {
|
||||
continue;
|
||||
}
|
||||
@@ -140,17 +134,14 @@ export const getValidationError = (
|
||||
validators[rule.name] as IValidator,
|
||||
rule.config,
|
||||
);
|
||||
if (error && (validator as RuleGroup).defaultError !== undefined) {
|
||||
// @ts-ignore
|
||||
if (error && 'defaultError' in validator && validator.defaultError) {
|
||||
return validator.defaultError;
|
||||
} else if (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (
|
||||
validator.hasOwnProperty('validate')
|
||||
) {
|
||||
} else if (validator.hasOwnProperty('validate')) {
|
||||
return (validator as IValidator).validate(value, config);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user