Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Add new
check_source
check to check source code as a string #189Add new
check_source
check to check source code as a string #189Changes from 7 commits
08ebf98
81b1b53
0868950
7fbc051
c74f81f
1928e45
79accdf
f8ca3a5
4d3e1b8
b30462f
baf9f7b
e4dcd70
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Either in this pr or another, this check for the supported check levels is probably something that is repeated. Can we extract this check to another module so we can just do something like this:
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.
If you want to do this in another PR (which I think is fine and keeps this PR's focus singular), can you open an issue and assign to me? I would like to do this if not already done, thanks.
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.
I've thought about that actually, some code is now duplicated three times, which starts to smell like a refactor. I'd be happy to assign this to you, once this gets merged.
Maybe even
If it works well for the other cases.
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.
Pros and cons for sure. There is a cost to drying up code too much. If you have the bandwidth, reading 99 bottles of oop is a good discussion on this.
Passing the type of check (
:check_source
) creates a dependency in that future Util function because it then has to "know" about all of the types of check that exist which perhaps all it really need to know is if the type is one of the standard 4 types.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.
I was just thinking of inserting
:check_source
in the string raised, but I do see your point.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.
String source only? No AST?
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.
Yeah... Originally I had both, so it's not like it's impossible. I removed it because it felt too complex, somehow. And since the AST is built from the string to begin with, it's very simple to use
Code.string_to_quoted
to get the AST.I'm on the fence, so if you think it's better design, I will put it back in. The test I would add would probably be the same as the indentation check, that's the best use I can think of.
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.
I can think of many checks that I would want to do on the AST that current macros do not allow, but you're right, we can just call
Code.string_to_quoted
. As long as it doesn't happen a thousand times in a single analyzer run, there's probably no need to worry about the performance.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.
OK. And if end up using ASTs many times, it won't be difficult to put in back in.
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.
I'm worried that this check is a bit weak. It could be accidentally triggered by something silly in a comment, for example writing
?ü # 252
😁. What if we did the opposite check - ensure that the strings"?ü"
etc are all in the source code? Maybe for all the special values from the exercise, so including a, z, and underscore. I just saw a solution that only used the question mark syntax for the special characters, but not the simple ones.It's not much better, but at least it won't be falsely triggered by comments.
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.
Sounds good, it's a more robust check.
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.
Hard to argue with that code 👍