Skip to content

Commit eb2b18b

Browse files
authored
infra(eslint): enable no-useless-escape eslint rule (#2434)
1 parent c80c035 commit eb2b18b

File tree

11 files changed

+29
-33
lines changed

11 files changed

+29
-33
lines changed

.eslintrc.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ module.exports = defineConfig({
2929
},
3030
plugins: ['@typescript-eslint', 'prettier', 'deprecation', 'jsdoc'],
3131
rules: {
32-
// We may want to use this in the future
33-
'no-useless-escape': 'off',
3432
eqeqeq: ['error', 'always', { null: 'ignore' }],
3533
'no-else-return': 'error',
3634
'prefer-template': 'error',

scripts/generateLocales.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ function updateLocaleFile(filePath: string): void {
240240
if (lstatSync(filePath).isFile()) {
241241
const pathParts = filePath
242242
.substring(pathLocales.length + 1, filePath.length - 3)
243-
.split(/[\\\/]/);
243+
.split(/[\\/]/);
244244
const locale = pathParts[0];
245245
pathParts.splice(0, 1);
246246
updateLocaleFileHook(filePath, locale, pathParts);

src/modules/git/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export class GitModule {
9797
const email = this.faker.internet.email({ firstName, lastName });
9898

9999
// Normalize user according to https://github.com/libgit2/libgit2/issues/5342
100-
user = user.replace(/^[\.,:;"\\']|[\<\>\n]|[\.,:;"\\']$/g, '');
100+
user = user.replace(/^[.,:;"\\']|[<>\n]|[.,:;"\\']$/g, '');
101101

102102
lines.push(
103103
`Author: ${user} <${email}>`,

src/modules/helpers/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ function legacyRegexpStringParse(
9999
string: string = ''
100100
): string {
101101
// Deal with range repeat `{min,max}`
102-
const RANGE_REP_REG = /(.)\{(\d+)\,(\d+)\}/;
102+
const RANGE_REP_REG = /(.)\{(\d+),(\d+)\}/;
103103
const REP_REG = /(.)\{(\d+)\}/;
104-
const RANGE_REG = /\[(\d+)\-(\d+)\]/;
104+
const RANGE_REG = /\[(\d+)-(\d+)\]/;
105105
let min: number;
106106
let max: number;
107107
let tmp: number;
@@ -192,7 +192,7 @@ export class SimpleHelpersModule {
192192
.normalize('NFKD') //for example è decomposes to as e + ̀
193193
.replace(/[\u0300-\u036f]/g, '') // removes combining marks
194194
.replace(/ /g, '-') // replaces spaces with hyphens
195-
.replace(/[^\w\.\-]+/g, ''); // removes all non-word characters except for dots and hyphens
195+
.replace(/[^\w.-]+/g, ''); // removes all non-word characters except for dots and hyphens
196196
}
197197

198198
/**
@@ -416,7 +416,7 @@ export class SimpleHelpersModule {
416416

417417
// Deal with single wildcards
418418
const SINGLE_CHAR_REG =
419-
/([.A-Za-z0-9])(?:\{(\d+)(?:\,(\d+)|)\}|(\?|\*|\+))(?![^[]*]|[^{]*})/;
419+
/([.A-Za-z0-9])(?:\{(\d+)(?:,(\d+)|)\}|(\?|\*|\+))(?![^[]*]|[^{]*})/;
420420
let token = pattern.match(SINGLE_CHAR_REG);
421421
while (token != null) {
422422
const quantifierMin: string = token[2];
@@ -439,7 +439,7 @@ export class SimpleHelpersModule {
439439

440440
const SINGLE_RANGE_REG = /(\d-\d|\w-\w|\d|\w|[-!@#$&()`.+,/"])/;
441441
const RANGE_ALPHANUMEMRIC_REG =
442-
/\[(\^|)(-|)(.+?)\](?:\{(\d+)(?:\,(\d+)|)\}|(\?|\*|\+)|)/;
442+
/\[(\^|)(-|)(.+?)\](?:\{(\d+)(?:,(\d+)|)\}|(\?|\*|\+)|)/;
443443
// Deal with character classes with quantifiers `[a-z0-9]{min[, max]}`
444444
token = pattern.match(RANGE_ALPHANUMEMRIC_REG);
445445
while (token != null) {
@@ -548,7 +548,7 @@ export class SimpleHelpersModule {
548548
token = pattern.match(RANGE_ALPHANUMEMRIC_REG);
549549
}
550550

551-
const RANGE_REP_REG = /(.)\{(\d+)\,(\d+)\}/;
551+
const RANGE_REP_REG = /(.)\{(\d+),(\d+)\}/;
552552
// Deal with quantifier ranges `{min,max}`
553553
token = pattern.match(RANGE_REP_REG);
554554
while (token != null) {

src/modules/internet/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ export class InternetModule {
265265
let localPart: string = this.userName({ firstName, lastName });
266266
// Strip any special characters from the local part of the email address
267267
// This could happen if invalid chars are passed in manually in the firstName/lastName
268-
localPart = localPart.replace(/[^A-Za-z0-9._+\-]+/g, '');
268+
localPart = localPart.replace(/[^A-Za-z0-9._+-]+/g, '');
269269

270270
// The local part of an email address is limited to 64 chars per RFC 3696
271271
// We limit to 50 chars to be more realistic

test/modules/commerce.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ describe('commerce', () => {
110110
expect(
111111
amount,
112112
'The expected match should not include a currency symbol'
113-
).toMatch(/^[0-9\.]+$/);
113+
).toMatch(/^[0-9.]+$/);
114114
});
115115

116116
it('should handle negative amounts, but return 0', () => {

test/modules/finance.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ describe('finance', () => {
279279
expect(
280280
amount,
281281
'The expected match should not include a currency symbol'
282-
).toMatch(/^[0-9\.]+$/);
282+
).toMatch(/^[0-9.]+$/);
283283
});
284284

285285
it('should handle negative amounts', () => {
@@ -456,7 +456,7 @@ describe('finance', () => {
456456
it('should return a correct credit card number when issuer provided', () => {
457457
//TODO: implement checks for each format with regexp
458458
const visa = faker.finance.creditCardNumber('visa');
459-
expect(visa).toMatch(/^4(([0-9]){12}|([0-9]){3}(\-([0-9]){4}){3})$/);
459+
expect(visa).toMatch(/^4(([0-9]){12}|([0-9]){3}(-([0-9]){4}){3})$/);
460460
expect(visa).toSatisfy(luhnCheck);
461461

462462
const mastercard = faker.finance.creditCardNumber('mastercard');
@@ -490,7 +490,7 @@ describe('finance', () => {
490490

491491
it('should return custom formatted strings', () => {
492492
let number = faker.finance.creditCardNumber('###-###-##L');
493-
expect(number).toMatch(/^\d{3}\-\d{3}\-\d{3}$/);
493+
expect(number).toMatch(/^\d{3}-\d{3}-\d{3}$/);
494494
expect(number).toSatisfy(luhnCheck);
495495

496496
number = faker.finance.creditCardNumber('234[5-9]#{999}L');

test/modules/helpers.spec.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ describe('helpers', () => {
563563
'6453-####-####-####-###L'
564564
);
565565
expect(number).toMatch(
566-
/^6453\-([0-9]){4}\-([0-9]){4}\-([0-9]){4}\-([0-9]){4}$/
566+
/^6453-([0-9]){4}-([0-9]){4}-([0-9]){4}-([0-9]){4}$/
567567
);
568568
expect(number).toSatisfy(luhnCheck);
569569
});
@@ -574,7 +574,7 @@ describe('helpers', () => {
574574
'*'
575575
);
576576
expect(number).toMatch(
577-
/^6453\-([0-9]){4}\-([0-9]){4}\-([0-9]){4}\-([0-9]){4}$/
577+
/^6453-([0-9]){4}-([0-9]){4}-([0-9]){4}-([0-9]){4}$/
578578
);
579579
expect(number).toSatisfy(luhnCheck);
580580
});
@@ -585,14 +585,14 @@ describe('helpers', () => {
585585
'*'
586586
);
587587
expect(number).toMatch(
588-
/^6453\-([0-9]){4}\-([0-9]){4}\-([0-9]){4}\-([0-9]){4}$/
588+
/^6453-([0-9]){4}-([0-9]){4}-([0-9]){4}-([0-9]){4}$/
589589
);
590590
expect(number).toSatisfy(luhnCheck);
591591
number = faker.helpers.replaceCreditCardSymbols(
592592
'645[5-9]-#{4,6}-#{1,2}-#{4,6}-#{3}L'
593593
);
594594
expect(number).toMatch(
595-
/^645[5-9]\-([0-9]){4,6}\-([0-9]){1,2}\-([0-9]){4,6}\-([0-9]){4}$/
595+
/^645[5-9]-([0-9]){4,6}-([0-9]){1,2}-([0-9]){4,6}-([0-9]){4}$/
596596
);
597597
expect(number).toSatisfy(luhnCheck);
598598
});
@@ -607,14 +607,14 @@ describe('helpers', () => {
607607
const string = faker.helpers.regexpStyleStringParse('#{5,10}');
608608
expect(string.length).toBeLessThanOrEqual(10);
609609
expect(string.length).toBeGreaterThanOrEqual(5);
610-
expect(string).toMatch(/^\#{5,10}$/);
610+
expect(string).toMatch(/^#{5,10}$/);
611611
});
612612

613613
it('flips the range when min > max', () => {
614614
const string = faker.helpers.regexpStyleStringParse('#{10,5}');
615615
expect(string.length).toBeLessThanOrEqual(10);
616616
expect(string.length).toBeGreaterThanOrEqual(5);
617-
expect(string).toMatch(/^\#{5,10}$/);
617+
expect(string).toMatch(/^#{5,10}$/);
618618
});
619619

620620
it('repeats string {n} number of times', () => {
@@ -638,9 +638,7 @@ describe('helpers', () => {
638638
const string = faker.helpers.regexpStyleStringParse(
639639
'Test#{5}%{2,5}Testing**[1-5]**{10}END'
640640
);
641-
expect(string).toMatch(
642-
/^Test\#{5}%{2,5}Testing\*\*[1-5]\*\*{10}END$/
643-
);
641+
expect(string).toMatch(/^Test#{5}%{2,5}Testing\*\*[1-5]\*\*{10}END$/);
644642
});
645643
});
646644

@@ -649,7 +647,7 @@ describe('helpers', () => {
649647
const string = faker.helpers.fromRegExp(/#{5,10}/);
650648
expect(string.length).toBeLessThanOrEqual(10);
651649
expect(string.length).toBeGreaterThanOrEqual(5);
652-
expect(string).toMatch(/^\#{5,10}$/);
650+
expect(string).toMatch(/^#{5,10}$/);
653651
});
654652

655653
it('repeats string {n} number of times', () => {
@@ -667,7 +665,7 @@ describe('helpers', () => {
667665
const string = faker.helpers.fromRegExp(
668666
'Test#{5}%{2,5}Testing*[1-5]{10}END'
669667
);
670-
expect(string).toMatch(/^Test\#{5}%{2,5}Testing*[1-5]{10}END$/);
668+
expect(string).toMatch(/^Test#{5}%{2,5}Testing*[1-5]{10}END$/);
671669
});
672670

673671
it('throws error when min > max outside set', () => {
@@ -1176,7 +1174,7 @@ describe('helpers', () => {
11761174
'lName',
11771175
'domain',
11781176
]); // third argument is provider, or domain for email
1179-
expect(result).toMatch(/\@domain/);
1177+
expect(result).toMatch(/@domain/);
11801178
});
11811179

11821180
it('should be possible to limit unique call by maxTime in ms', () => {

test/modules/image.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ describe('image', () => {
410410

411411
expect(avatarUrl).toBeTypeOf('string');
412412
expect(avatarUrl).toMatch(
413-
/^https:\/\/cloudflare\-ipfs\.com\/ipfs\/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye\/avatar\/\d{1,4}\.jpg$/
413+
/^https:\/\/cloudflare-ipfs\.com\/ipfs\/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye\/avatar\/\d{1,4}\.jpg$/
414414
);
415415
});
416416
});
@@ -463,7 +463,7 @@ describe('image', () => {
463463

464464
expect(imageUrl).toBeTypeOf('string');
465465
expect(imageUrl).toMatch(
466-
/^https\:\/\/loremflickr\.com\/\d+\/\d+\?lock=\d+$/
466+
/^https:\/\/loremflickr\.com\/\d+\/\d+\?lock=\d+$/
467467
);
468468
});
469469
});
@@ -474,7 +474,7 @@ describe('image', () => {
474474

475475
expect(imageUrl).toBeTypeOf('string');
476476
expect(imageUrl).toMatch(
477-
/^https\:\/\/picsum\.photos\/seed\/[0-9a-zA-Z]+\/\d+\/\d+$/
477+
/^https:\/\/picsum\.photos\/seed\/[0-9a-zA-Z]+\/\d+\/\d+$/
478478
);
479479
});
480480
});
@@ -485,7 +485,7 @@ describe('image', () => {
485485

486486
expect(imageUrl).toBeTypeOf('string');
487487
expect(imageUrl).toMatch(
488-
/^https\:\/\/via\.placeholder\.com\/\d+x\d+\/[0-9a-fA-F]{6}\/[0-9a-fA-F]{6}\.[a-z]{3,4}\?text=.+$/
488+
/^https:\/\/via\.placeholder\.com\/\d+x\d+\/[0-9a-fA-F]{6}\/[0-9a-fA-F]{6}\.[a-z]{3,4}\?text=.+$/
489489
);
490490
});
491491
});

test/modules/internet.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ describe('internet', () => {
649649
expect(ua).toBeTypeOf('string');
650650
expect(ua.length).toBeGreaterThanOrEqual(1);
651651
expect(ua).toMatch(
652-
/^(([^\d]+\/[\dA-Za-z\.]+(\s\(.*\)))|([^\d]+\/[\dA-Za-z\.]+(\s\(.*\)*))(\s[^\d]+\/[\dA-Za-z\.]+(\s\(.*\)*))*)$/
652+
/^(([^\d]+\/[\dA-Za-z.]+(\s\(.*\)))|([^\d]+\/[\dA-Za-z.]+(\s\(.*\)*))(\s[^\d]+\/[\dA-Za-z.]+(\s\(.*\)*))*)$/
653653
);
654654
});
655655
});

test/scripts/apidoc/verify-jsdoc-tags.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ describe('verify JSDoc tags', () => {
118118

119119
const path = resolvePathToMethodFile(moduleName, methodName);
120120
const imports = [
121-
...new Set(examples.match(/(?<!\.)faker[^\.]*(?=\.)/g)),
121+
...new Set(examples.match(/(?<!\.)faker[^.]*(?=\.)/g)),
122122
];
123123
writeFileSync(
124124
path,

0 commit comments

Comments
 (0)