question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rule proposal: `no-useless-interpolation`

See original GitHub issue

Hi there! 👋 First of all, thanks again for this plugin, super helpful, the things available in this plugin.

I wanted to propose a new rule to address a pattern that I have seen from a lot of our students at @upleveled - writing overly complex patterns with unnecessary interpolations in template strings (eg. a single string variable, or a string literal, or multiple string literals).

Fail

const withString = `${str}`;
const withStringLiteral = `${'abc'}`;
const withMultipleStringLiterals = `${'abc'}${'def'}`;

Pass

const withString = str;
const withStringLiteral = 'abc';
const withMultipleStringLiterals = 'abcdef';

Implementation ideas

Looking into the ASTExplorer, I guess the simple version of the first failure case below would be:

  • only 1 element in TemplateLiteral.expressions (an Identifier)
  • only 2 elements in TemplateLiteral.quasis, all empty strings

For the literals, I guess no limit to the quasis, but every element in expressions should be a Literal.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:12
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
fiskercommented, May 11, 2021

The rule could be two parts

  1. forbid string literal as expression.
  2. No expression-only template.

Update:

String concatenation should fobid too

`before${ "head" + expression + "tail" }after`

3reactions
fiskercommented, May 11, 2021

One note, taged templates should not reported.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Proposed rule: Order Competition Rule - SEC.gov
proposed rule would prohibit a restricted competition trading center from internally executing certain orders of individual investors at a ...
Read more >
Spatially adaptive color filter array interpolation for ... - CiteSeerX
ABSTRACT: Conventional single-chip digital cameras use color filter arrays (CFA) to sample different spectral components. Demosaicing algorithms interpolate ...
Read more >
Spatially adaptive color filter array ... - ResearchGate
In this work, we propose to perform the edge-preserving signal correlation based (EP-SCB) interpolation [1] as a second pass to those images ...
Read more >
Kernel Interpolation of High Dimensional Scattered Data - arXiv
The main goal of the current paper is to propose and study a new stochastic framework for kernel interpolation of high dimensional data....
Read more >
Denoising and interpolation of noisy Bayer data ... - NASA/ADS
The aim is to obtain a full-resolution RGB noiseless image. The proposed technique is specifically targeted to filter signal-dependant, e.g. Poissonian, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found