-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
[jest-docblock] add strip #4571
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed. If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
packages/jest-docblock/src/index.js
Outdated
export function strip(contents: string) { | ||
const match = contents.match(docblockRe); | ||
const docblockLength = match && match[0] ? match[0].length + 1 : 0; | ||
return contents.substring(docblockLength); |
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.
Could we do:
return match && match[0] ? contents.substring(match[0].length + 1) : contents;
instead?
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.
Good thinking! Better to return contents
than to return contents.substring(0)
Nice! |
Codecov Report
@@ Coverage Diff @@
## master #4571 +/- ##
==========================================
+ Coverage 55.6% 55.61% +0.01%
==========================================
Files 186 186
Lines 6352 6354 +2
Branches 3 3
==========================================
+ Hits 3532 3534 +2
Misses 2819 2819
Partials 1 1
Continue to review full report at Codecov.
|
* [jest-docblock] add strip * add a couple tests * off by one error * improve code as per @cpojers suggestion
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Prettier is implementing a
--insertPragma
flag to insert a@format
pragma to the top of files.During implementation it became apparent that a
stripDocblock
function would be helpful for replacing docblocks. E.g.:This PR introduces a new function,
strip(contents: string)
for returning the whole file except the top docblock.Test Plan
Basic unit tests