rokucommunity / bslint

A linter for BrightScript and BrighterScript.
MIT License
27 stars 14 forks source link

No rule for commented out code #88

Open charlie-abbott-deltatre opened 1 year ago

charlie-abbott-deltatre commented 1 year ago

There is currently no rule for catching commented out code, single or multiple line that is not a todo-pattern or noop comment.

TwitchBronBron commented 1 year ago

I like this one! It should be fairly easy to implement. There are two AST nodes, CommentStatement and CommentExpression that you'd look for in the walker, then we'd just need to define how you configure this in the bslint.json.

charlie-abbott-deltatre commented 1 year ago

Some other things to consider with this change would be to define other allowed comments, like:

'bs:disable-line '#region and '#endregion

etc

TwitchBronBron commented 1 year ago

How would you handle comments like this?

sub main()
    ' get from the registry
    username = getFromRegistry()
    ' print it
    print username
end sub
charlie-abbott-deltatre commented 1 year ago

For devs that would like to use this feature, they would need to update those comments to work with the todo-pattern.

Also with use of todo-pattern comments like this, over multiple lines:

'NOTE: some comment
'            over 2
'            or more lines

Maybe fun.

TwitchBronBron commented 1 year ago

eslint has an alternative approach, where they actually try to parse the comments, and only show errors for code that will parse without error.

https://github.com/cartant/eslint-plugin-etc/blob/main/docs/rules/no-commented-out-code.md

It's worth at least considering. The eslint approach would cause some unparseable commented-out-code to get missed, but might be way nicer for devs to not have to rewrite every single one of their comments to prefix with 'NOTE:'