Skip to content

Commit

Permalink
build: update eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
WikiRik committed Jan 7, 2022
1 parent f055c11 commit f048a4c
Show file tree
Hide file tree
Showing 32 changed files with 150 additions and 149 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": "airbnb-base",
"parser": "babel-eslint",
"parser": "@babel/eslint-parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,18 @@ jobs:
uses: codecov/codecov-action@v1
with:
file: ./coverage/cobertura-coverage.xml
lint:
runs-on: ubuntu-20.04
name: Run lint on Node.js 14
steps:
- name: Setup Node.js 14
uses: actions/setup-node@v2-beta
with:
node-version: 14
check-latest: true
- name: Checkout repository
uses: actions/checkout@v2
- name: Install dependencies
run: npm install
- name: Run lint
run: npm run lint
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@
"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"@babel/eslint-parser": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/register": "^7.0.0",
"babel-eslint": "^10.0.1",
"babel-plugin-add-module-exports": "^1.0.0",
"eslint": "^4.19.1",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-plugin-import": "^2.11.0",
"eslint": "^8.0.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.0.0",
"mocha": "^6.2.3",
"npm-run-all": "^4.1.5",
"nyc": "^14.1.0",
Expand All @@ -65,7 +65,7 @@
"build:es": "babel src -d es --env-name=es",
"build:node": "babel src -d .",
"build": "run-p build:*",
"pretest": "npm run build && npm run lint",
"pretest": "npm run build",
"test": "nyc --reporter=cobertura --reporter=text-summary mocha --require @babel/register --reporter dot"
},
"engines": {
Expand Down
3 changes: 2 additions & 1 deletion src/lib/alpha.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const alpha = {
'uk-UA': /^[А-ЩЬЮЯЄIЇҐі]+$/i,
'vi-VN': /^[A-ZÀÁẠẢÃÂẦẤẬẨẪĂẰẮẶẲẴĐÈÉẸẺẼÊỀẾỆỂỄÌÍỊỈĨÒÓỌỎÕÔỒỐỘỔỖƠỜỚỢỞỠÙÚỤỦŨƯỪỨỰỬỮỲÝỴỶỸ]+$/i,
'ku-IQ': /^[ئابپتجچحخدرڕزژسشعغفڤقکگلڵمنوۆھەیێيطؤثآإأكضصةظذ]+$/i,
// eslint-disable-next-line no-misleading-character-class
ar: /^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/,
he: /^[א-ת]+$/,
fa: /^['آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی']+$/i,
Expand Down Expand Up @@ -63,6 +64,7 @@ export const alphanumeric = {
'uk-UA': /^[0-9А-ЩЬЮЯЄIЇҐі]+$/i,
'ku-IQ': /^[٠١٢٣٤٥٦٧٨٩0-9ئابپتجچحخدرڕزژسشعغفڤقکگلڵمنوۆھەیێيطؤثآإأكضصةظذ]+$/i,
'vi-VN': /^[0-9A-ZÀÁẠẢÃÂẦẤẬẨẪĂẰẮẶẲẴĐÈÉẸẺẼÊỀẾỆỂỄÌÍỊỈĨÒÓỌỎÕÔỒỐỘỔỖƠỜỚỢỞỠÙÚỤỦŨƯỪỨỰỬỮỲÝỴỶỸ]+$/i,
// eslint-disable-next-line no-misleading-character-class
ar: /^[٠١٢٣٤٥٦٧٨٩0-9ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/,
he: /^[0-9א-ת]+$/,
fa: /^['0-9آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی۱۲۳۴۵۶۷۸۹۰']+$/i,
Expand All @@ -74,7 +76,6 @@ export const decimal = {
ar: '٫',
};


export const englishLocales = ['AU', 'GB', 'HK', 'IN', 'NZ', 'ZA', 'ZM'];

for (let locale, i = 0; i < englishLocales.length; i++) {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/isBase64.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function isBase64(str, options) {
}

const firstPaddingChar = str.indexOf('=');
return firstPaddingChar === -1 ||
firstPaddingChar === len - 1 ||
(firstPaddingChar === len - 2 && str[len - 1] === '=');
return firstPaddingChar === -1
|| firstPaddingChar === len - 1
|| (firstPaddingChar === len - 2 && str[len - 1] === '=');
}
4 changes: 1 addition & 3 deletions src/lib/isCurrency.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ function currencyRegex(options) {
let decimal_digits = `\\d{${options.digits_after_decimal[0]}}`;
options.digits_after_decimal.forEach((digit, index) => { if (index !== 0) decimal_digits = `${decimal_digits}|\\d{${digit}}`; });

const symbol =
`(${options.symbol.replace(/\W/, m => `\\${m}`)})${(options.require_symbol ? '' : '?')}`,
const symbol = `(${options.symbol.replace(/\W/, (m) => `\\${m}`)})${(options.require_symbol ? '' : '?')}`,
negative = '-?',
whole_dollar_amount_without_sep = '[1-9]\\d*',
whole_dollar_amount_with_sep = `[1-9]\\d{0,2}(\\${options.thousands_separator}\\d{3})*`,
Expand Down Expand Up @@ -53,7 +52,6 @@ function currencyRegex(options) {
return new RegExp(`^(?!-? )(?=.*\\d)${pattern}$`);
}


const default_currency_options = {
symbol: '$',
require_symbol: false,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/isDataURI.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export default function isDataURI(str) {
}
for (let i = 0; i < attributes.length; i++) {
if (
!(i === attributes.length - 1 && attributes[i].toLowerCase() === 'base64') &&
!validAttribute.test(attributes[i])
!(i === attributes.length - 1 && attributes[i].toLowerCase() === 'base64')
&& !validAttribute.test(attributes[i])
) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/isDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ export default function isDate(input, options) {
}
if (typeof input === 'string' && isValidFormat(options.format)) {
const formatDelimiter = options.delimiters
.find(delimiter => options.format.indexOf(delimiter) !== -1);
.find((delimiter) => options.format.indexOf(delimiter) !== -1);
const dateDelimiter = options.strictMode
? formatDelimiter
: options.delimiters.find(delimiter => input.indexOf(delimiter) !== -1);
: options.delimiters.find((delimiter) => input.indexOf(delimiter) !== -1);
const dateAndFormat = zip(
input.split(dateDelimiter),
options.format.toLowerCase().split(formatDelimiter)
Expand Down
1 change: 0 additions & 1 deletion src/lib/isEAN.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const LENGTH_EAN_8 = 8;
const LENGTH_EAN_14 = 14;
const validEanRegex = /^(\d{8}|\d{13}|\d{14})$/;


/**
* Get position weight given:
* EAN length and digit index/position
Expand Down
18 changes: 8 additions & 10 deletions src/lib/isEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ function validateDisplayName(display_name) {
}

// the quotes in display name must start with character symbol \
const all_start_with_back_slash =
display_name_without_quotes.split('"').length === display_name_without_quotes.split('\\"').length;
const all_start_with_back_slash = display_name_without_quotes.split('"').length === display_name_without_quotes.split('\\"').length;
if (!all_start_with_back_slash) {
return false;
}
Expand All @@ -58,7 +57,6 @@ function validateDisplayName(display_name) {
return true;
}


export default function isEmail(str, options) {
assertString(str);
options = merge(options, default_email_options);
Expand Down Expand Up @@ -128,8 +126,8 @@ export default function isEmail(str, options) {
}

if (options.ignore_max_length === false && (
!isByteLength(user, { max: 64 }) ||
!isByteLength(domain, { max: 254 }))
!isByteLength(user, { max: 64 })
|| !isByteLength(domain, { max: 254 }))
) {
return false;
}
Expand All @@ -154,13 +152,13 @@ export default function isEmail(str, options) {

if (user[0] === '"') {
user = user.slice(1, user.length - 1);
return options.allow_utf8_local_part ?
quotedEmailUserUtf8.test(user) :
quotedEmailUser.test(user);
return options.allow_utf8_local_part
? quotedEmailUserUtf8.test(user)
: quotedEmailUser.test(user);
}

const pattern = options.allow_utf8_local_part ?
emailUserUtf8Part : emailUserPart;
const pattern = options.allow_utf8_local_part
? emailUserUtf8Part : emailUserPart;

const user_parts = user.split('.');
for (let i = 0; i < user_parts.length; i++) {
Expand Down
10 changes: 5 additions & 5 deletions src/lib/isFloat.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ export default function isFloat(str, options) {
return false;
}
const value = parseFloat(str.replace(',', '.'));
return float.test(str) &&
(!options.hasOwnProperty('min') || value >= options.min) &&
(!options.hasOwnProperty('max') || value <= options.max) &&
(!options.hasOwnProperty('lt') || value < options.lt) &&
(!options.hasOwnProperty('gt') || value > options.gt);
return float.test(str)
&& (!options.hasOwnProperty('min') || value >= options.min)
&& (!options.hasOwnProperty('max') || value <= options.max)
&& (!options.hasOwnProperty('lt') || value < options.lt)
&& (!options.hasOwnProperty('gt') || value > options.gt);
}

export const locales = Object.keys(decimal);
2 changes: 0 additions & 2 deletions src/lib/isHSL.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import assertString from './util/assertString';


const hslComma = /^hsla?\(((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn)?(,(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}(,((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?))?\)$/i;
const hslSpace = /^hsla?\(((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn)?(\s(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s?(\/\s((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s?)?\)$/i;


export default function isHSL(str) {
assertString(str);

Expand Down
6 changes: 3 additions & 3 deletions src/lib/isIBAN.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ function hasValidIbanFormat(str) {
const strippedStr = str.replace(/[\s\-]+/gi, '').toUpperCase();
const isoCountryCode = strippedStr.slice(0, 2).toUpperCase();

return (isoCountryCode in ibanRegexThroughCountryCode) &&
ibanRegexThroughCountryCode[isoCountryCode].test(strippedStr);
return (isoCountryCode in ibanRegexThroughCountryCode)
&& ibanRegexThroughCountryCode[isoCountryCode].test(strippedStr);
}

/**
Expand All @@ -122,7 +122,7 @@ function hasValidIbanFormat(str) {
function hasValidIbanChecksum(str) {
const strippedStr = str.replace(/[^A-Z0-9]+/gi, '').toUpperCase(); // Keep only digits and A-Z latin alphabetic
const rearranged = strippedStr.slice(4) + strippedStr.slice(0, 4);
const alphaCapsReplacedWithDigits = rearranged.replace(/[A-Z]/g, char => char.charCodeAt(0) - 55);
const alphaCapsReplacedWithDigits = rearranged.replace(/[A-Z]/g, (char) => char.charCodeAt(0) - 55);

const remainder = alphaCapsReplacedWithDigits.match(/\d{1,7}/g)
.reduce((acc, value) => Number(acc + value) % 97, '');
Expand Down
3 changes: 0 additions & 3 deletions src/lib/isIMEI.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import assertString from './util/assertString';


let imeiRegexWithoutHypens = /^[0-9]{15}$/;
let imeiRegexWithHypens = /^\d{2}-\d{6}-\d{6}-\d{1}$/;


export default function isIMEI(str, options) {
assertString(str);
options = options || {};
Expand All @@ -17,7 +15,6 @@ export default function isIMEI(str, options) {
imeiRegex = imeiRegexWithHypens;
}


if (!imeiRegex.test(str)) {
return false;
}
Expand Down
20 changes: 10 additions & 10 deletions src/lib/isIP.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ const IPv4AddressFormat = `(${IPv4SegmentFormat}[.]){3}${IPv4SegmentFormat}`;
const IPv4AddressRegExp = new RegExp(`^${IPv4AddressFormat}$`);

const IPv6SegmentFormat = '(?:[0-9a-fA-F]{1,4})';
const IPv6AddressRegExp = new RegExp('^(' +
`(?:${IPv6SegmentFormat}:){7}(?:${IPv6SegmentFormat}|:)|` +
`(?:${IPv6SegmentFormat}:){6}(?:${IPv4AddressFormat}|:${IPv6SegmentFormat}|:)|` +
`(?:${IPv6SegmentFormat}:){5}(?::${IPv4AddressFormat}|(:${IPv6SegmentFormat}){1,2}|:)|` +
`(?:${IPv6SegmentFormat}:){4}(?:(:${IPv6SegmentFormat}){0,1}:${IPv4AddressFormat}|(:${IPv6SegmentFormat}){1,3}|:)|` +
`(?:${IPv6SegmentFormat}:){3}(?:(:${IPv6SegmentFormat}){0,2}:${IPv4AddressFormat}|(:${IPv6SegmentFormat}){1,4}|:)|` +
`(?:${IPv6SegmentFormat}:){2}(?:(:${IPv6SegmentFormat}){0,3}:${IPv4AddressFormat}|(:${IPv6SegmentFormat}){1,5}|:)|` +
`(?:${IPv6SegmentFormat}:){1}(?:(:${IPv6SegmentFormat}){0,4}:${IPv4AddressFormat}|(:${IPv6SegmentFormat}){1,6}|:)|` +
`(?::((?::${IPv6SegmentFormat}){0,5}:${IPv4AddressFormat}|(?::${IPv6SegmentFormat}){1,7}|:))` +
')(%[0-9a-zA-Z-.:]{1,})?$');
const IPv6AddressRegExp = new RegExp('^('
+ `(?:${IPv6SegmentFormat}:){7}(?:${IPv6SegmentFormat}|:)|`
+ `(?:${IPv6SegmentFormat}:){6}(?:${IPv4AddressFormat}|:${IPv6SegmentFormat}|:)|`
+ `(?:${IPv6SegmentFormat}:){5}(?::${IPv4AddressFormat}|(:${IPv6SegmentFormat}){1,2}|:)|`
+ `(?:${IPv6SegmentFormat}:){4}(?:(:${IPv6SegmentFormat}){0,1}:${IPv4AddressFormat}|(:${IPv6SegmentFormat}){1,3}|:)|`
+ `(?:${IPv6SegmentFormat}:){3}(?:(:${IPv6SegmentFormat}){0,2}:${IPv4AddressFormat}|(:${IPv6SegmentFormat}){1,4}|:)|`
+ `(?:${IPv6SegmentFormat}:){2}(?:(:${IPv6SegmentFormat}){0,3}:${IPv4AddressFormat}|(:${IPv6SegmentFormat}){1,5}|:)|`
+ `(?:${IPv6SegmentFormat}:){1}(?:(:${IPv6SegmentFormat}){0,4}:${IPv4AddressFormat}|(:${IPv6SegmentFormat}){1,6}|:)|`
+ `(?::((?::${IPv6SegmentFormat}){0,5}:${IPv4AddressFormat}|(?::${IPv6SegmentFormat}){1,7}|:))`
+ ')(%[0-9a-zA-Z-.:]{1,})?$');

export default function isIP(str, version = '') {
assertString(str);
Expand Down
18 changes: 9 additions & 9 deletions src/lib/isIdentityCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const validators = {

if (str != null && str.length === 11 && isInt(str, { allow_leading_zeroes: true })) {
const digits = str.split('').slice(0, -1);
const sum = digits.reduce((acc, digit, index) =>
acc + (Number(digit) * weightOfDigits[index + 1]), 0);
// eslint-disable-next-line max-len
const sum = digits.reduce((acc, digit, index) => acc + (Number(digit) * weightOfDigits[index + 1]), 0);

const modulo = sum % 10;
const lastDigit = Number(str.charAt(str.length - 1));
Expand Down Expand Up @@ -59,7 +59,7 @@ const validators = {
}

// validate the control digit
const number = sanitized.slice(0, -1).replace(/[X,Y,Z]/g, char => charsValue[char]);
const number = sanitized.slice(0, -1).replace(/[X,Y,Z]/g, (char) => charsValue[char]);

return sanitized.endsWith(controlDigits[number % 23]);
},
Expand Down Expand Up @@ -185,7 +185,7 @@ const validators = {
const new_nic = /^[1-9]\d{11}$/i;

if (str.length === 10 && old_nic.test(str)) return true;
else if (str.length === 12 && new_nic.test(str)) return true;
if (str.length === 12 && new_nic.test(str)) return true;
return false;
},
'he-IL': (str) => {
Expand Down Expand Up @@ -277,7 +277,7 @@ const validators = {

const parityBit = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];

const checkAddressCode = addressCode => provincesAndCities.includes(addressCode);
const checkAddressCode = (addressCode) => provincesAndCities.includes(addressCode);

const checkBirthDayCode = (birDayCode) => {
const yyyy = parseInt(birDayCode.substring(0, 4), 10);
Expand All @@ -287,7 +287,7 @@ const validators = {
if (xdata > new Date()) {
return false;
// eslint-disable-next-line max-len
} else if ((xdata.getFullYear() === yyyy) && (xdata.getMonth() === mm - 1) && (xdata.getDate() === dd)) {
} if ((xdata.getFullYear() === yyyy) && (xdata.getMonth() === mm - 1) && (xdata.getDate() === dd)) {
return true;
}
return false;
Expand All @@ -305,8 +305,8 @@ const validators = {
return parityBit[mod];
};

const checkParityBit = idCardNo => getParityBit(idCardNo) === idCardNo.charAt(17).toUpperCase();

// eslint-disable-next-line max-len
const checkParityBit = (idCardNo) => getParityBit(idCardNo) === idCardNo.charAt(17).toUpperCase();

const check15IdCardNo = (idCardNo) => {
let check = /^[1-9]\d{7}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}$/.test(idCardNo);
Expand Down Expand Up @@ -396,7 +396,7 @@ export default function isIdentityCard(str, locale) {
assertString(str);
if (locale in validators) {
return validators[locale](str);
} else if (locale === 'any') {
} if (locale === 'any') {
for (const key in validators) {
// https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
// istanbul ignore else
Expand Down
4 changes: 2 additions & 2 deletions src/lib/isIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export default function isIn(str, options) {
}
}
return array.indexOf(str) >= 0;
} else if (typeof options === 'object') {
} if (typeof options === 'object') {
return options.hasOwnProperty(str);
} else if (options && typeof options.indexOf === 'function') {
} if (options && typeof options.indexOf === 'function') {
return options.indexOf(str) >= 0;
}
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/isInt.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export default function isInt(str, options) {
// Get the regex to use for testing, based on whether
// leading zeroes are allowed or not.
let regex = (
options.hasOwnProperty('allow_leading_zeroes') && !options.allow_leading_zeroes ?
int : intLeadingZeroes
options.hasOwnProperty('allow_leading_zeroes') && !options.allow_leading_zeroes
? int : intLeadingZeroes
);

// Check min/max/lt/gt
Expand Down

0 comments on commit f048a4c

Please sign in to comment.