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-code-in-comments

See original GitHub issue

While developing, I frequently try different solutions, and end up with commented-out code, which I occasionally even commit. I’d like for ESLint to warn me about this.

How to detect code

A line of code ends with one of the following characters: {}; .

  • Advantages: Simple.
  • Disadvantages: Would miss something like //console.log('test'), and while testing code ignoring the semicolon is probably common.

An alternative would be to somehow detect valid JS, but that seems unnecessarily complex.

Reporting

Adjacent comments should generate only a single error. You can view the following as a single comment block.

// console.log(1);
// console.log(2);
// console.log(3);

Options

Inline documentation can sometimes contain code, so we need a way to allow some comments, perhaps in comments starting with /**.

Suggested default:

[2, {isCodeRegExp: /[\{\};](\n|$)/, allowRegExp: /^\*/}]

(The options will be transformed into regexps when strings are given.)

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
tmsdnlcommented, Nov 19, 2015
0reactions
ilyavolodincommented, Nov 19, 2015

I saw that plugin a while back, and it basically runs every comment through espree. If it gets valid AST - it’s commented out code. Problem is, you might have commented out just a few statements, for example, just a case block inside a switch which will not parse properly, but it is still a commented out code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SEC Proposed Rules
SEC Proposed Rules · Regulation NMS: Minimum Pricing Increments, Access Fees, and Transparency of Better Priced Orders · File No: S7-30-22 · Comments...
Read more >
Proposed Rules - GovInfo
This proposed rule, if finalized, would harmonize certain sections of FDA's regulations on human subject protection and institutional review ...
Read more >
Coding Guidelines - PLCopen
proposal how these rules can be used. ... Guideline: In the released versions of programs there should be no code in comments, even...
Read more >
Trade Regulation Rule on Commercial Surveillance and Data ...
The Federal Trade Commission (``FTC'') is publishing this advance notice of proposed rulemaking (``ANPR'') to request public comment on the ...
Read more >
Applying maintainability guidelines within Flutter Applications
Code duplication violates Visser's 3rd maintainability rule, ... plan. In a semi-structured interview, questions are planned but not ...
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 Hashnode Post

No results found