-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
ESLint Plugin: Restrict tolerances as fixable error #13785
Conversation
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.
Code changes generated by the updated rule and its fixer look great.
I'm not familiar with the ESlint API so I might not be the best person to accept this PR. Let me do some more testing locally.
@@ -1,5 +1,5 @@ | |||
/** | |||
* Node dependencies |
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.
There was probably some reason to use Node
keyword but I'm happy to see it merged into External
group 👍
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.
There was probably some reason to use
Node
keyword but I'm happy to see it merged intoExternal
group 👍
I suppose the idea is the imports are from the Node.js API, not any explicit dependency. I could see there being some value in it, but it's not something we either codified or use consistently. Same goes for "Browser dependencies".
As part of this overall effort, I'm fine to make adjustments from what we've standardized. But the important thing is forcing ourselves to have these conversations, rather than let inconsistencies grow via the unwritten conventions of a few people.
diff --git a/packages/block-library/src/audio/icon.js b/packages/block-library/src/audio/icon.js
index 4b871506b..46ea192be 100644
--- a/packages/block-library/src/audio/icon.js
+++ b/packages/block-library/src/audio/icon.js
@@ -1,5 +1,5 @@
/**
- * WordPress dependencies
+ * Internal dependencies
*/
import { Path, SVG } from '@wordpress/components'; I tried the above and noticed that running At the moment the following code passes linter checks: /**
* Internal dependencies
*/
/**
* WordPress dependencies
*/
import { Path, SVG } from '@wordpress/components'; this is the output from the aforementioned call on the diff. |
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.
This looks like a great improvement. I left my comments but I don't find them as blockers but rather a future improvement. Again, it would be great to have another 👀 on the the actual implementation :)
Oh, and there is now merge conflict to be resolved after the name of the test file has changed.
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 tested that ESLint is indeed stricter to report the comment.
The fixer, though, is able to substitute comments with some tolerance in dependencies
(whether it has a final dot or not, and whether the first letter is in uppercase or lowercase) but not in the locality. In any of these cases:
/**
* Wordpress dependencies.
*/
/**
* wordpress dependencies.
*/
/**
* internal dependencies.
*/
/**
* external dependencies.
*/
/**
* node dependencies.
*/
what happens is that a new comment properly formatted is added, but the old is not removed so it ends up as:
/**
* External dependencies
*/
/**
* node dependencies.
*/
Can we add some tolerance to the locality as well as per the examples above? With those implemented, the fixer will be able to actually fix 99% of use cases.
@nosolosw I'm not sure I follow the specific issue. Could you fork the original snippet to demonstrate a full example of problematic code? |
@aduth sure, here it is: https://astexplorer.net/#/gist/4bd0d3532fdc5944fa75ce3913af72cb/a13b33187d0decf2014c7b5ae34b50b85ca5daa6 In that example, changing |
@nosolosw I think the root issue there is capitalization of the first word. A quick test of a substitution to make the pattern case-insensitive seems to work as expected: -const pattern = new RegExp( `^\\*?\\n \\* ${ locality } [dD]ependencies\\.?\\n $` );
+const pattern = new RegExp( `^\\*?\\n \\* ${ locality } dependencies\\.?\\n $`, 'i' ); |
8e8fde2
to
1cf75fa
Compare
* Framework: Resolve dependency grouping inconsistencies * ESLint Plugin: Restrict tolerances as fixable error
* Framework: Resolve dependency grouping inconsistencies * ESLint Plugin: Restrict tolerances as fixable error
Continues #13757
This pull request continues from #13757, eliminating tolerances as described in that pull request:
Note: The tolerances still technically exist in the implementation, but are now used as part of the "fixer" behavior to identify the comment as eligible to have its value be substituted/upgrade using the corrected value.
(See example fixer output)
Testing instructions:
Ensure lint passes:
Optional: Introduce an error case and verify fixer behavior: