Skip to content

Commit 243fb5f

Browse files
authored
chore: enable prefer-template (#9544)
* prefer-template * review * cleanup * minor cleanup
1 parent a4acc2b commit 243fb5f

File tree

22 files changed

+62
-73
lines changed

22 files changed

+62
-73
lines changed

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ export default tseslint.config(
223223
'prefer-object-has-own': 'error',
224224
'prefer-object-spread': 'error',
225225
'prefer-rest-params': 'error',
226+
'prefer-template': 'error',
226227
radix: 'error',
227228

228229
//

packages/ast-spec/tests/util/serialize-error.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,13 @@ export function serializeError(error: unknown, contents: string): unknown {
1313
location: { start, end },
1414
} = error;
1515

16-
return (
17-
name +
18-
'\n' +
19-
codeFrameColumns(
20-
contents,
21-
{
22-
start: { line: start.line, column: start.column + 1 },
23-
end: { line: end.line, column: end.column + 1 },
24-
},
25-
{ highlightCode: false, message },
26-
)
27-
);
16+
return `${name}
17+
${codeFrameColumns(
18+
contents,
19+
{
20+
start: { line: start.line, column: start.column + 1 },
21+
end: { line: end.line, column: end.column + 1 },
22+
},
23+
{ highlightCode: false, message },
24+
)}`;
2825
}

packages/ast-spec/tests/util/snapshot-diff.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function snapshotDiff(
5757
throw new Error('Unexpected null when diffing snapshots.');
5858
}
5959

60-
return 'Snapshot Diff:\n' + difference;
60+
return `Snapshot Diff:\n${difference}`;
6161
}
6262

6363
// https://github.com/facebook/jest/blob/a293b75310cfc209713df1d34d243eb258995316/packages/jest-diff/src/constants.ts#L8

packages/eslint-plugin-internal/src/rules/plugin-test-formatting.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function getExpectedIndentForNode(
6363
}
6464
function doIndent(line: string, indent: number): string {
6565
for (let i = 0; i < indent; i += 1) {
66-
line = ' ' + line;
66+
line = ` ${line}`;
6767
}
6868
return line;
6969
}

packages/eslint-plugin/src/rules/consistent-generic-constructors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export default createRule<Options, MessageIds>({
103103
fixer.remove(typeArguments),
104104
fixer.insertTextAfter(
105105
getIDToAttachAnnotation(),
106-
': ' + typeAnnotation,
106+
`: ${typeAnnotation}`,
107107
),
108108
];
109109
},

packages/eslint-plugin/src/rules/no-floating-promises.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,8 @@ export default createRule<Options, MessageId>({
6767
floatingFixAwait: 'Add await operator.',
6868
floatingVoid: messageBaseVoid,
6969
floatingFixVoid: 'Add void operator to ignore.',
70-
floatingUselessRejectionHandler:
71-
messageBase + ' ' + messageRejectionHandler,
72-
floatingUselessRejectionHandlerVoid:
73-
messageBaseVoid + ' ' + messageRejectionHandler,
70+
floatingUselessRejectionHandler: `${messageBase} ${messageRejectionHandler}`,
71+
floatingUselessRejectionHandlerVoid: `${messageBaseVoid} ${messageRejectionHandler}`,
7472
floatingPromiseArray: messagePromiseArray,
7573
floatingPromiseArrayVoid: messagePromiseArrayVoid,
7674
},

packages/eslint-plugin/src/rules/no-unsafe-assignment.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,8 @@ export default createRule({
324324
): Readonly<Record<string, unknown>> | undefined {
325325
if (receiverType) {
326326
return {
327-
sender: '`' + checker.typeToString(senderType) + '`',
328-
receiver: '`' + checker.typeToString(receiverType) + '`',
327+
sender: `\`${checker.typeToString(senderType)}\``,
328+
receiver: `\`${checker.typeToString(receiverType)}\``,
329329
};
330330
}
331331
return {

packages/eslint-plugin/src/rules/prefer-function-type.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,13 @@ export default createRule({
142142
node.type === AST_NODE_TYPES.TSInterfaceDeclaration &&
143143
isParentExported
144144
) {
145-
const commentsText = comments.reduce((text, comment) => {
146-
return (
147-
text +
148-
(comment.type === AST_TOKEN_TYPES.Line
149-
? `//${comment.value}`
150-
: `/*${comment.value}*/`) +
151-
'\n'
152-
);
153-
}, '');
145+
const commentsText = comments
146+
.map(({ type, value }) =>
147+
type === AST_TOKEN_TYPES.Line
148+
? `//${value}\n`
149+
: `/*${value}*/\n`,
150+
)
151+
.join('');
154152
// comments should move before export and not between export and interface declaration
155153
fixes.push(fixer.insertTextBefore(node.parent, commentsText));
156154
} else {

packages/eslint-plugin/src/rules/prefer-optional-chain-utils/analyzeChain.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ function getReportDescriptor(
376376
if (lastOperand.isYoda) {
377377
const unaryOperator =
378378
lastOperand.node.right.type === AST_NODE_TYPES.UnaryExpression
379-
? lastOperand.node.right.operator + ' '
379+
? `${lastOperand.node.right.operator} `
380380
: '';
381381

382382
return {
@@ -386,7 +386,7 @@ function getReportDescriptor(
386386
}
387387
const unaryOperator =
388388
lastOperand.node.left.type === AST_NODE_TYPES.UnaryExpression
389-
? lastOperand.node.left.operator + ' '
389+
? `${lastOperand.node.left.operator} `
390390
: '';
391391
return {
392392
left: unaryOperator + newCode,

packages/eslint-plugin/src/rules/unbound-method.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,7 @@ export default createRule<Options, MessageIds>({
113113
},
114114
messages: {
115115
unbound: BASE_MESSAGE,
116-
unboundWithoutThisAnnotation:
117-
BASE_MESSAGE +
118-
'\n' +
119-
'If your function does not access `this`, you can annotate it with `this: void`, or consider using an arrow function instead.',
116+
unboundWithoutThisAnnotation: `${BASE_MESSAGE}\nIf your function does not access \`this\`, you can annotate it with \`this: void\`, or consider using an arrow function instead.`,
120117
},
121118
schema: [
122119
{

0 commit comments

Comments
 (0)