Skip to content

Commit bd2cb34

Browse files
committed
refactor(eslint): fix unicorn/prefer-string-replace-all (refs SFKUI-6500)
1 parent 2dca868 commit bd2cb34

File tree

16 files changed

+29
-30
lines changed

16 files changed

+29
-30
lines changed

cypress/assertions/trimmedText.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ chai.Assertion.addMethod("trimmedText", function (expectedString) {
66

77
const actual = $element
88
.text()
9-
.replace(/\r/g, " ")
10-
.replace(/\s+/g, " ")
9+
.replaceAll("\r", " ")
10+
.replaceAll(/\s+/g, " ")
1111
.trim();
1212
this.assert(
1313
actual === expectedString,

eslint.config.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ export default [
150150
"unicorn/prefer-number-properties": "off",
151151
"unicorn/prefer-query-selector": "off",
152152
"unicorn/prefer-set-has": "off",
153-
"unicorn/prefer-string-replace-all": "off",
154153
"unicorn/prefer-string-slice": "off",
155154
"unicorn/prefer-top-level-await": "off",
156155
},

packages/icon-lib-builder/scripts/build.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ async function generateSpritesheetJs(library, data) {
9797
);
9898
spritesheet = spritesheet
9999
/* eslint-disable-next-line sonarjs/slow-regex -- technical debt */
100-
.replace(/.*eslint-disable.*/g, "")
101-
.replace(/PACKAGE/g, JSON.stringify(packageName))
102-
.replace(/LIBRARY/g, JSON.stringify(library))
100+
.replaceAll(/.*eslint-disable.*/g, "")
101+
.replaceAll("PACKAGE", JSON.stringify(packageName))
102+
.replaceAll("LIBRARY", JSON.stringify(library))
103103
.replace(
104104
/IMPORT_SPRITESHEET\(\);.*/,
105105
`const spritesheet = '${data.content}';`,
@@ -109,7 +109,7 @@ async function generateSpritesheetJs(library, data) {
109109
"utf8",
110110
);
111111
/* eslint-disable-next-line sonarjs/slow-regex -- technical debt */
112-
inject = inject.replace(/.*eslint-disable.*/g, "");
112+
inject = inject.replaceAll(/.*eslint-disable.*/g, "");
113113
const content = [spritesheet, inject].join("\n");
114114
const indexJs = path.join(dest, library, "index.js");
115115
const indexDts = path.join(dest, library, "index.d.ts");
@@ -135,9 +135,9 @@ async function generateSpritesheetJsNoInject(library, data) {
135135
);
136136
spritesheet = spritesheet
137137
/* eslint-disable-next-line sonarjs/slow-regex -- technical debt */
138-
.replace(/.*eslint-disable.*/g, "")
139-
.replace(/PACKAGE/g, JSON.stringify(packageName))
140-
.replace(/LIBRARY/g, JSON.stringify(library))
138+
.replaceAll(/.*eslint-disable.*/g, "")
139+
.replaceAll("PACKAGE", JSON.stringify(packageName))
140+
.replaceAll("LIBRARY", JSON.stringify(library))
141141
.replace(
142142
/IMPORT_SPRITESHEET\(\);.*/,
143143
`const spritesheet = '${data.content}';`,
@@ -159,7 +159,7 @@ async function getSpriteSheetdata(directory, files) {
159159
".svg",
160160
)}`;
161161
const name = path.basename(file, ".svg");
162-
const prettyName = capitalize(name.replace(/-/g, " "));
162+
const prettyName = capitalize(name.replaceAll("-", " "));
163163
const svgFile = await fs.readFile(path.join(directory, file), "utf8");
164164
const optimizedSvg = optimize(svgFile, {
165165
plugins: [
@@ -179,9 +179,9 @@ async function getSpriteSheetdata(directory, files) {
179179
});
180180

181181
const symbol = optimizedSvg.data
182-
.replace(/<svg/g, `<symbol id="${id}"`)
183-
.replace(/<\/svg>/g, "</symbol>")
184-
.replace(/ xmlns="[^"]*"/g, "");
182+
.replaceAll("<svg", `<symbol id="${id}"`)
183+
.replaceAll("</svg>", "</symbol>")
184+
.replaceAll(/ xmlns="[^"]*"/g, "");
185185

186186
content += symbol;
187187
icons.push({

packages/icon-lib-builder/scripts/common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export function capitalize(s) {
66
}
77

88
export function camelCase(string) {
9-
return string.replace(/-([a-z])/gi, function (all, letter) {
9+
return string.replaceAll(/-([a-z])/gi, function (all, letter) {
1010
return letter.toUpperCase();
1111
});
1212
}

packages/logic/src/converters/BankAccountNumberConverter/bankAccountNumberConverter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function parseBankAccountNumber(
2121
}
2222

2323
// remove hyphen, blank space, period, comma
24-
const trimmedValue = value.replace(BANK_ACCOUNT_NUMBER_TRIM_REGEXP, "");
24+
const trimmedValue = value.replaceAll(BANK_ACCOUNT_NUMBER_TRIM_REGEXP, "");
2525

2626
return BANK_ACCOUNT_NUMBER_REGEXP.test(trimmedValue)
2727
? trimmedValue

packages/logic/src/converters/PlusgiroConverter/plusgiroConverter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ export function parsePlusgiro(value: string): PlusgiroString | undefined {
2727
* If the number of digits is odd then the first pair in the string can be a single digit.
2828
* If the number of characters is 9, there will be a space after the first 3 characters.
2929
*/
30-
value = value.replace(/ /g, "");
31-
value = value.replace(/\D/g, "");
30+
value = value.replaceAll(" ", "");
31+
value = value.replaceAll(/\D/g, "");
3232

3333
if (
3434
!PLUSGIRO_REGEXP.test(value) ||
35-
!testLuhnChecksum(value.replace(/\D/g, ""))
35+
!testLuhnChecksum(value.replaceAll(/\D/g, ""))
3636
) {
3737
return undefined;
3838
}

packages/logic/src/services/TranslationService/DefaultTranslationProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class DefaultTranslationProvider implements TranslationProviderInterface
4141
defaultValue: string,
4242
args: Record<string, unknown>,
4343
): string {
44-
return defaultValue.replace(
44+
return defaultValue.replaceAll(
4545
/* eslint-disable-next-line sonarjs/slow-regex -- technical debt */
4646
/{{\s*(\S+)\s*}}/g,
4747
(match, key: string) => {

packages/logic/src/text/strip-whitespace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
* @returns Text with whitespace stripped.
77
*/
88
export function stripWhitespace(text: string): string {
9-
return text.replace(/\s+/g, "");
9+
return text.replaceAll(/\s+/g, "");
1010
}

packages/logic/src/utils/PersonnummerUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ import { testLuhnChecksum } from "./test-luhn-checksum";
44
* @public
55
*/
66
export function validChecksum(value: string): boolean {
7-
const yymmddxxxx = value.slice(2).replace(/-/g, "");
7+
const yymmddxxxx = value.slice(2).replaceAll("-", "");
88
return testLuhnChecksum(yymmddxxxx);
99
}

packages/test-utils/src/matchers/to-have-focus.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ expect.addSnapshotSerializer({
1717
},
1818
serialize(value: string) {
1919
/* eslint-disable-next-line no-control-regex -- expected to replace control regex */
20-
return value.replace(/\u001B\[[\d;]*m/g, "");
20+
return value.replaceAll(/\u001B\[[\d;]*m/g, "");
2121
},
2222
});
2323

0 commit comments

Comments
 (0)