Rule proposal: no-code-in-comments
See original GitHub issueWhile 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:
- Created 8 years ago
- Comments:7 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
Top Related Hashnode Post
No results found
Top GitHub Comments
Came across a custom rule by @bahmutov: https://github.com/bahmutov/eslint-rules/blob/master/no-commented-out-code.js
Any thoughs?
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 aswitch
which will not parse properly, but it is still a commented out code.