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.

Idea: extend capability of `extract-sequence-expressions` or applicable rule

See original GitHub issue

One class of sequence expressions missed by the extract-sequence-expressions rule (or some other rule for this purpose) is when the sequence statements are tucked into an "if expression’. For example:

let a = true;

if(console.log('one'), console.log('two'), a) {
  console.log('three')
}

This is equivalent and more clearly written as:

let a = true;

console.log('one');
console.log('two');

if (a) {
  console.log('three')
}

Javascript returns the last expression in the sequence for evaluation in the “if expression”.

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
eprestoncommented, Dec 30, 2022

It works well.

I’m going to write out some detailed bits so we have a good record of test overage, environment, versions.

Tested Versions

module version
putout “28.3.0”
@putout/plugin-extract-sequence-expressions “3.5.0”
@putout/plugin-logical-expressions “1.2.0”

Test Project Metrics

language files code comment blank total
JavaScript 283 50,763 2,617 6,566 59,946

Test Detection

94 errors in 50 files

Test Detail

Test 1:

  • It hoists the sequence expressions found in 'if statements" correctly
  • this is the simple case found above

Test 2:

  • When it is proceeded by a single line, left associating control statement with an optional BodyBlock
  • It creates a BodyBlock if required, then hoists the sequence statements above leaving the condition
  • preserves execution order and practical outcomes
  • exposes the actual execution of the code by the runtime while improving readability

“For Statement” example for clarity:

for (let n = 0; n < t.length; n++)
  if (((i = '(' + e + ': ' + t[n] + ')'), window.matchMedia(i).matches)) return t[n];

Is transformed into the more readable equivalent:

for (let n = 0; n < t.length; n++) {
  i = '(' + e + ': ' + t[n] + ')';
  if (window.matchMedia(i).matches) return t[n];
}
1reaction
coderaisercommented, Dec 28, 2022

I’d be excited to see if we can hoist out these sequence expressions. Helpful if someone puts a comma in the wrong place creating a sequence expression when they mean to combine a condition into a larger expression for the control block. It would be neat to hit save and see the statement get ejected above on its own line.

Landed in @putout/plugin-extract-sequence-expressions@3.5.0 🎉. Is it works for you?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Extract method | IntelliJ IDEA Documentation - JetBrains
The Extract Method refactoring lets you take a code fragment that can be grouped, move it into a separated method, and replace the...
Read more >
FIE2: a program for the extraction of genomic DNA sequences ...
FIE2 (5′ end Information Extraction v2) is a web-based program for easy identification and extraction of nucleotide sequence around the start of genes ......
Read more >
Keyword Extraction: A Guide to Finding Keywords in Text
Keyword extraction simplifies the task of finding relevant words and phrases within unstructured text. This includes emails, social media posts, chat ...
Read more >
A survey of best practices for RNA-seq data analysis
RNA-sequencing (RNA-seq) has a wide variety of applications, but no single analysis pipeline can be used in all cases.
Read more >
Using RegEx (Regular Expression Extractor) with JMeter
Another use case is saving the extracted information to a variable, so it can be used later on in the performance test, for...
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