Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const str1 = `Hello world`;
const text = 'hello';
const wrapped = `${text}`;
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused variable wrapped.

Suggested change
const wrapped = `${text}`;

Copilot uses AI. Check for mistakes.

export {};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ arguments: --type-aware --silent
working directory: fixtures/tsgolint
----------

Found 0 warnings and 50 errors.
Found 0 warnings and 51 errors.
Finished in <variable>ms on 45 files using 1 threads.
----------
CLI result: LintFoundErrors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ working directory: fixtures/tsgolint
3 | }
`----

x typescript-eslint(no-unnecessary-template-expression): Template literal expression is unnecessary and can be simplified.
,-[no-unnecessary-template-expression.ts:2:18]
1 | const text = 'hello';
2 | const wrapped = `${text}`;
: ^^^^^^^
3 |
`----

x typescript-eslint(no-unnecessary-type-arguments): This is the default value for this type parameter, so it can be omitted.
,-[no-unnecessary-type-arguments.ts:4:25]
3 | }
Expand Down Expand Up @@ -388,7 +396,7 @@ working directory: fixtures/tsgolint
: ^^^^^^^^
`----

Found 0 warnings and 50 errors.
Found 0 warnings and 51 errors.
Finished in <variable>ms on 45 files using 1 threads.
----------
CLI result: LintFoundErrors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,57 @@ pub struct NoUnnecessaryTemplateExpression;
declare_oxc_lint!(
/// ### What it does
///
/// This rule disallows unnecessary template literals.
/// Disallows unnecessary template expressions (interpolations) that can be simplified.
///
/// ### Why is this bad?
///
/// Template literals should only be used when they are needed for string interpolation or multi-line strings. Using template literals when a simple string would suffice adds unnecessary complexity.
/// Template literals with substitution expressions that are unnecessary add complexity
/// without providing any benefit. Static string literal expressions or expressions that
/// are already strings can be simplified.
///
/// Note: This rule does not flag template literals without substitution expressions.
/// For example, `` `hello` `` is allowed even though it could be written as `'hello'`.
///
/// ### Examples
///
/// Examples of **incorrect** code for this rule:
/// ```ts
/// const str1 = `Hello world`;
/// // Static values can be incorporated into the surrounding template
/// const ab1 = `${'a'}${'b'}`;
/// const ab2 = `a${'b'}`;
///
/// const str2 = `42`;
/// const stringWithNumber = `${'1 + 1 = '}${2}`;
/// const stringWithBoolean = `${'true is '}${true}`;
///
/// const str3 = `true`;
/// // Expressions that are already strings can be rewritten without a template
/// const text = 'a';
/// const wrappedText = `${text}`;
///
/// // Template with only literal expressions
/// const str4 = `${'Hello'} ${'world'}`;
/// declare const intersectionWithString: string & { _brand: 'test-brand' };
/// const wrappedIntersection = `${intersectionWithString}`;
/// ```
///
/// Examples of **correct** code for this rule:
/// ```ts
/// const str1 = 'Hello world';
/// // Static values incorporated into the template
/// const ab1 = `ab`;
///
/// const str2 = '42';
/// // Template with non-trivial interpolation
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "correct" example on line 48 shows const greeting = Hello ${name}!; which is described as "Template with non-trivial interpolation". However, this example could be misleading because according to the rule's purpose, wrapping a simple string variable in a template literal is unnecessary. The reason this is considered "correct" is because it has additional static content ("Hello " and "!") around the variable, making the template literal necessary for string composition. Consider clarifying the comment to say "Template with interpolation and static content" to better distinguish it from the incorrect example of just wrapping a variable.

Suggested change
/// // Template with non-trivial interpolation
/// // Template with interpolation and static content

Copilot uses AI. Check for mistakes.
/// const name = 'world';
/// const greeting = `Hello ${name}!`;
///
/// const str3 = 'true';
/// // Template with expression
/// const result = `Result: ${1 + 2}`;
///
/// // Template with variable interpolation
/// const name = 'world';
/// const str4 = `Hello ${name}`;
/// // Simple strings don't need templates
/// const text = 'a';
/// const wrappedText = text;
///
/// // Multi-line string
/// // Multi-line strings are fine
/// const multiline = `
/// Hello
/// world
/// `;
///
/// // Template with expression
/// const str5 = `Result: ${1 + 2}`;
/// ```
NoUnnecessaryTemplateExpression(tsgolint),
typescript,
Expand Down
Loading