-
-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove inline comments during line preprocessing #161
base: master
Are you sure you want to change the base?
Conversation
Co-authored-by: slmg <[email protected]>
Thank you for opening this PR! Could you add a test to validate that the behavior is correct? |
Also fix the handling of lines like " # comment" by trimming before the startsWith("#") check. We can't just map once to the trimmed version, since the filter needs the trim before its check and the map can only trim after splitting on "#".
Good thing you asked for a test case, turns out we missed something (see commit message on 100adc3). Should be good now. |
Sorry for the massive delay on responding to this. Does this handle strings that have the pound sign in them? e.g. |
@@ -15,8 +15,8 @@ export function getIndentation(line: string): string { | |||
*/ | |||
export function preprocessLines(lines: string[]): string[] { | |||
return lines | |||
.map(line => line.trim()) | |||
.filter((line) => !line.startsWith("#")); | |||
.filter((line) => !line.trim().startsWith("#")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't do this unfortunately because it will cut off strings with # in them. See previous discussion here: #144
So we could possibly limit this to only trim comments in the docstring definition since it is less likely to have a string with a # in it than in the body. |
I don't think I realized at the time that hash symbols in strings are possible. I agree with the discussion at #144 that this will be impossible to do exactly right with regex, because it's fundamentally outside of the scope of regular languages. |
Looks like the current implementation only removes lines that start with "#" to filter comments.
As described in issue #160, inline comments are missed. This should resolve issue #160.