Fixed the following code smells:

1. Use concise character class syntax
2. Add a "break" statement or remove this "else" clause.
3. Replace this generic exception class with a more specific one.
4. Use a regular expression literal instead of the 'RegExp' constructor.
5. Use the opposite operator ("not in") instead.
This commit is contained in:
Yogesh Mahajan
2022-09-10 13:48:14 +05:30
committed by Akshay Joshi
parent d967d5046d
commit cbf5886430
13 changed files with 19 additions and 58 deletions

View File

@@ -27,8 +27,7 @@ export function minMaxValidator(label, value, minValue, maxValue) {
export function numberValidator(label, value) {
if((_.isUndefined(value) || _.isNull(value) || String(value) === ''))
return null;
let pattern = new RegExp('^-?[0-9]+(\.?[0-9]*)?$');
if (!pattern.test(value)) {
if (!/^-?[0-9]+(\.?[0-9]*)?$/.test(value)) {
return sprintf(pgAdmin.Browser.messages.MUST_BE_NUM, label);
}
return null;
@@ -38,8 +37,7 @@ export function numberValidator(label, value) {
export function integerValidator(label, value) {
if((_.isUndefined(value) || _.isNull(value) || String(value) === ''))
return null;
let pattern = new RegExp('^-?[0-9]*$');
if (!pattern.test(value)) {
if (!/^-?[0-9]*$/.test(value)) {
return sprintf(pgAdmin.Browser.messages.MUST_BE_INT, label);
}
return null;