Skip to content
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

Merged
merged 4 commits into from
Sep 30, 2017
Merged

[jest-docblock] add strip #4571

merged 4 commits into from
Sep 30, 2017

Conversation

samouri
Copy link
Contributor

@samouri samouri commented Sep 30, 2017

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.:

const newFileContents = newDocblock + '\n' + stripDocblock(oldFileContents);

This PR introduces a new function, strip(contents: string) for returning the whole file except the top docblock.

Test Plan
Basic unit tests

@facebook-github-bot
Copy link
Contributor

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!

export function strip(contents: string) {
const match = contents.match(docblockRe);
const docblockLength = match && match[0] ? match[0].length + 1 : 0;
return contents.substring(docblockLength);
Copy link
Member

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?

Copy link
Contributor Author

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)

@cpojer
Copy link
Member

cpojer commented Sep 30, 2017

Nice!

@codecov-io
Copy link

codecov-io commented Sep 30, 2017

Codecov Report

Merging #4571 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
packages/jest-docblock/src/index.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 216e8ed...5f52819. Read the comment docs.

@cpojer cpojer merged commit 4a3ab53 into jestjs:master Sep 30, 2017
tabrindle pushed a commit to tabrindle/jest that referenced this pull request Oct 2, 2017
* [jest-docblock] add strip

* add a couple tests

* off by one error

* improve code as per @cpojers suggestion
@github-actions
Copy link

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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
@samouri samouri deleted the add/docblock/strip branch April 14, 2022 19:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants