Skip to content

Commit 5cd37fa

Browse files
committed
Fix unicorn/prefer-string-raw lint issues
1 parent 1328cc2 commit 5cd37fa

12 files changed

+35
-35
lines changed

lib/rules/attribute-hyphenation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ module.exports = {
5151
allOf: [
5252
{ type: 'string' },
5353
{ not: { type: 'string', pattern: ':exit$' } },
54-
{ not: { type: 'string', pattern: '^\\s*$' } }
54+
{ not: { type: 'string', pattern: String.raw`^\s*$` } }
5555
]
5656
},
5757
uniqueItems: true,

lib/rules/html-indent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ module.exports = {
6262
allOf: [
6363
{ type: 'string' },
6464
{ not: { type: 'string', pattern: ':exit$' } },
65-
{ not: { type: 'string', pattern: '^\\s*$' } }
65+
{ not: { type: 'string', pattern: String.raw`^\s*$` } }
6666
]
6767
},
6868
uniqueItems: true,

lib/rules/no-restricted-custom-event.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ module.exports = {
155155
sourceCode.text[nameWithLoc.range[0]]
156156
}${JSON.stringify(option.suggest)
157157
.slice(1, -1)
158-
.replace(/'/gu, "\\'")}${
158+
.replace(/'/gu, String.raw`\'`)}${
159159
sourceCode.text[nameWithLoc.range[1] - 1]
160160
}`
161161
)

lib/rules/no-undef-properties.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ module.exports = {
106106
/** @param {RuleContext} context */
107107
create(context) {
108108
const options = context.options[0] || {}
109-
const ignores = /** @type {string[]} */ (options.ignores || ['/^\\$/']).map(
110-
toRegExp
111-
)
109+
const ignores = /** @type {string[]} */ (
110+
options.ignores || [String.raw`/^\$/`]
111+
).map(toRegExp)
112112
const propertyReferenceExtractor = definePropertyReferenceExtractor(context)
113113
const programNode = context.getSourceCode().ast
114114

lib/rules/script-indent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module.exports = {
3232
allOf: [
3333
{ type: 'string' },
3434
{ not: { type: 'string', pattern: ':exit$' } },
35-
{ not: { type: 'string', pattern: '^\\s*$' } }
35+
{ not: { type: 'string', pattern: String.raw`^\s*$` } }
3636
]
3737
},
3838
uniqueItems: true,

lib/rules/v-on-event-hyphenation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module.exports = {
3030
allOf: [
3131
{ type: 'string' },
3232
{ not: { type: 'string', pattern: ':exit$' } },
33-
{ not: { type: 'string', pattern: '^\\s*$' } }
33+
{ not: { type: 'string', pattern: String.raw`^\s*$` } }
3434
]
3535
},
3636
uniqueItems: true,

lib/utils/regexp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const RE_REGEXP_STR = /^\/(.+)\/(.*)$/u
1212
*/
1313
function escape(string) {
1414
return string && RE_HAS_REGEXP_CHAR.test(string)
15-
? string.replace(RE_REGEXP_CHAR, '\\$&')
15+
? string.replace(RE_REGEXP_CHAR, String.raw`\$&`)
1616
: string
1717
}
1818

tests/lib/rules/html-comment-indent.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,7 @@ tester.run('html-comment-indent', rule, {
246246
endColumn: 11
247247
},
248248
{
249-
message:
250-
'Expected base point indentation of 10 spaces, but found " \\t".',
249+
message: String.raw`Expected base point indentation of 10 spaces, but found " \t".`,
251250
line: 7,
252251
column: 1,
253252
endLine: 7,
@@ -452,8 +451,7 @@ tester.run('html-comment-indent', rule, {
452451
endColumn: 14
453452
},
454453
{
455-
message:
456-
'Expected base point indentation of 12 spaces, but found " \\t".',
454+
message: String.raw`Expected base point indentation of 12 spaces, but found " \t".`,
457455
line: 12,
458456
column: 1,
459457
endLine: 12,
@@ -671,13 +669,11 @@ comment -->
671669
`,
672670
errors: [
673671
{
674-
message:
675-
'Expected base point indentation of " \\t \\t \\t ", but found 7 spaces.',
672+
message: String.raw`Expected base point indentation of " \t \t \t ", but found 7 spaces.`,
676673
line: 4
677674
},
678675
{
679-
message:
680-
'Expected base point indentation of " \\t \\t \\t ", but found 7 spaces.',
676+
message: String.raw`Expected base point indentation of " \t \t \t ", but found 7 spaces.`,
681677
line: 5
682678
}
683679
]

tests/lib/rules/html-indent.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ tester.run(
471471
`,
472472
errors: [
473473
{
474-
message: 'Expected " " character, but found "\\t" character.',
474+
message: String.raw`Expected " " character, but found "\t" character.`,
475475
line: 3
476476
}
477477
]
@@ -495,7 +495,7 @@ tester.run(
495495
options: ['tab'],
496496
errors: [
497497
{
498-
message: 'Expected "\\t" character, but found " " character.',
498+
message: String.raw`Expected "\t" character, but found " " character.`,
499499
line: 3
500500
}
501501
]
@@ -931,7 +931,7 @@ tester.run(
931931
options: ['tab', { ignores: ['VAttribute'] }],
932932
errors: [
933933
{
934-
message: 'Expected "\\t" character, but found " " character.',
934+
message: String.raw`Expected "\t" character, but found " " character.`,
935935
line: 2
936936
}
937937
]

tests/lib/rules/no-undef-components.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ tester.run('no-undef-components', rule, {
104104
`,
105105
options: [
106106
{
107-
ignorePatterns: ['custom(\\-\\w+)+']
107+
ignorePatterns: [String.raw`custom(\-\w+)+`]
108108
}
109109
]
110110
},
@@ -170,7 +170,7 @@ tester.run('no-undef-components', rule, {
170170
`,
171171
options: [
172172
{
173-
ignorePatterns: ['custom(\\-\\w+)+']
173+
ignorePatterns: [String.raw`custom(\-\w+)+`]
174174
}
175175
]
176176
},
@@ -185,7 +185,7 @@ tester.run('no-undef-components', rule, {
185185
`,
186186
options: [
187187
{
188-
ignorePatterns: ['custom(\\-\\w+)+']
188+
ignorePatterns: [String.raw`custom(\-\w+)+`]
189189
}
190190
]
191191
},
@@ -200,7 +200,7 @@ tester.run('no-undef-components', rule, {
200200
`,
201201
options: [
202202
{
203-
ignorePatterns: ['custom(\\-\\w+)+']
203+
ignorePatterns: [String.raw`custom(\-\w+)+`]
204204
}
205205
]
206206
},
@@ -215,7 +215,7 @@ tester.run('no-undef-components', rule, {
215215
`,
216216
options: [
217217
{
218-
ignorePatterns: ['Custom(\\w+)+']
218+
ignorePatterns: [String.raw`Custom(\w+)+`]
219219
}
220220
]
221221
},
@@ -230,7 +230,7 @@ tester.run('no-undef-components', rule, {
230230
`,
231231
options: [
232232
{
233-
ignorePatterns: ['Custom(\\w+)+']
233+
ignorePatterns: [String.raw`Custom(\w+)+`]
234234
}
235235
]
236236
},
@@ -245,7 +245,7 @@ tester.run('no-undef-components', rule, {
245245
`,
246246
options: [
247247
{
248-
ignorePatterns: ['Custom(\\w+)+']
248+
ignorePatterns: [String.raw`Custom(\w+)+`]
249249
}
250250
]
251251
},
@@ -261,7 +261,11 @@ tester.run('no-undef-components', rule, {
261261
`,
262262
options: [
263263
{
264-
ignorePatterns: ['Custom(\\w+)+', 'Warm(\\w+)+', 'InfoBtn(\\w+)+']
264+
ignorePatterns: [
265+
String.raw`Custom(\w+)+`,
266+
String.raw`Warm(\w+)+`,
267+
String.raw`InfoBtn(\w+)+`
268+
]
265269
}
266270
]
267271
},
@@ -849,7 +853,7 @@ tester.run('no-undef-components', rule, {
849853
`,
850854
options: [
851855
{
852-
ignorePatterns: ['custom(\\-\\w+)+']
856+
ignorePatterns: [String.raw`custom(\-\w+)+`]
853857
}
854858
],
855859
errors: [
@@ -888,7 +892,7 @@ tester.run('no-undef-components', rule, {
888892
`,
889893
options: [
890894
{
891-
ignorePatterns: ['custom(\\-\\w+)+']
895+
ignorePatterns: [String.raw`custom(\-\w+)+`]
892896
}
893897
],
894898
errors: [

tests/lib/rules/script-indent.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ tester.run(
263263
`,
264264
errors: [
265265
{
266-
message: 'Expected " " character, but found "\\t" character.',
266+
message: String.raw`Expected " " character, but found "\t" character.`,
267267
line: 3
268268
}
269269
]
@@ -289,11 +289,11 @@ tester.run(
289289
options: ['tab'],
290290
errors: [
291291
{
292-
message: 'Expected "\\t" character, but found " " character.',
292+
message: String.raw`Expected "\t" character, but found " " character.`,
293293
line: 3
294294
},
295295
{
296-
message: 'Expected "\\t" character, but found " " character.',
296+
message: String.raw`Expected "\t" character, but found " " character.`,
297297
line: 4
298298
}
299299
]

tools/update-docs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ class DocFile {
8888
? meta.docs.description
8989
: this.content.match(/^description: (.*)$/m)[1]
9090
const escapedDescription = description
91-
.replace(/\*/g, '\\*')
92-
.replace(/_/g, '\\_')
91+
.replace(/\*/g, String.raw`\*`)
92+
.replace(/_/g, String.raw`\_`)
9393
const title = `# ${ruleId}\n\n> ${escapedDescription}`
9494
const notes = []
9595

0 commit comments

Comments
 (0)