Chore: Clean up inline directive parsing #12375
Merged
Conversation
This simply makes the code a bit easier to read by giving a name to `match[1]`.
There are a few thing going on in this function which were getting conflated: 1. Parsing a `directiveType` out of the comment. 2. Ignoring directives that are in line comments but only support block comments. 3. Warning on and ignoring line comments that span multiple lines. Previously these three pieces of functionality were tightly coupled which made the code harder to read. After this change each task is handled independently of the other.
|
LGTM. I agree that this is easier to grok. Thanks! |
|
Looks good, thanks! |
|
I just noticed a way this code could be further cleaned up. I have a commit on another branch here: 6231a5e Given that this PR is already approved, would it be better to update this one or wait for this to merge and open a second one? |
|
@captbaritone I like what you're doing in the latest commit, so personally I would say you could pull that commit into this branch if you like. If you want to make sure that the team still thinks it's good, you could re-request review from the team members who already approved. That said, it's up to you re: how you want to proceed. |
Rather than conditionally set a mutable value and check for it at the end of the switch statement, we can actually just handle it inline by using a fallthrough.
|
Thanks @platinumazure. Updated and new review requested. |
7ffb22f
into
eslint:master
16 checks passed
16 checks passed
continuous-integration (Test on Node.js 12 (Windows))
Test on Node.js 12 (Windows) succeeded
Details
|
LGTM, thanks for contributing! |
This was referenced Nov 9, 2019
This was referenced Mar 26, 2020
This was referenced Apr 3, 2020
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
What is the purpose of this pull request? (put an "X" next to item)
[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[X] Other, please explain:
Clean up somewhat confusing code.
What changes did you make? (Give an overview)
While exploring what would be required to implement RFC #34 I looked into this code and found it more confusing than it needs to be.
This refactor untagles some logic having to do with parsing inline directives
There are a few thing going on in this function which were getting conflated:
directiveTypeout of the comment.Previously these three pieces of functionality were tightly coupled which made the code harder to read. After this change each task is handled independently of the other.
Is there anything you'd like reviewers to focus on?
GitHub makes this diff look more significant than it really is. The change actually consists of a few small changes:
if(lineCommentSupported)nor theelse if (comment.type === "Block")case and thus fall through without ever getting adirectiveTypeassigned.directiveTypeforeslint-disable-next-lineandeslint-disable-linethe same way we handle all other directives.The content of all pre-existing case statements have not actually changed.