Skip to content

Commit

Permalink
feat: add prettier-ignore to output (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kent C. Dodds authored Nov 22, 2017
1 parent 482a8ab commit ba248a9
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 77 deletions.
34 changes: 34 additions & 0 deletions src/generate/__tests__/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`replace the content between the ALL-CONTRIBUTORS-LIST tags by a table of contributors 1`] = `
"# project
Description
## Contributors
These people contributed to the project:
<!-- ALL-CONTRIBUTORS-LIST:START -->
<!-- prettier-ignore -->
| Kent C. Dodds is awesome! | Divjot Singh is awesome! | Jeroen Engels is awesome! |
| :---: | :---: | :---: |
<!-- ALL-CONTRIBUTORS-LIST:END -->
Thanks a lot everyone!"
`;

exports[`split contributors into multiples lines when there are too many 1`] = `
"# project
Description
## Contributors
These people contributed to the project:
<!-- ALL-CONTRIBUTORS-LIST:START -->
<!-- prettier-ignore -->
| Kent C. Dodds is awesome! | Kent C. Dodds is awesome! | Kent C. Dodds is awesome! | Kent C. Dodds is awesome! | Kent C. Dodds is awesome! |
| :---: | :---: | :---: | :---: | :---: |
| Kent C. Dodds is awesome! | Kent C. Dodds is awesome! |
<!-- ALL-CONTRIBUTORS-LIST:END -->
Thanks a lot everyone!"
`;
36 changes: 3 additions & 33 deletions src/generate/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,9 @@ test('replace the content between the ALL-CONTRIBUTORS-LIST tags by a table of c
const {kentcdodds, bogas04} = contributors
const {options, jfmengels, content} = fixtures()
const contributorList = [kentcdodds, bogas04, jfmengels]
const expected = [
'# project',
'',
'Description',
'',
'## Contributors',
'These people contributed to the project:',
'<!-- ALL-CONTRIBUTORS-LIST:START -->',
'| Kent C. Dodds is awesome! | Divjot Singh is awesome! | Jeroen Engels is awesome! |',
'| :---: | :---: | :---: |',
'<!-- ALL-CONTRIBUTORS-LIST:END -->',
'',
'Thanks a lot everyone!',
].join('\n')

const result = generate(options, contributorList, content)

expect(result).toBe(expected)
expect(result).toMatchSnapshot()
})

test('split contributors into multiples lines when there are too many', () => {
Expand All @@ -70,25 +55,9 @@ test('split contributors into multiples lines when there are too many', () => {
kentcdodds,
kentcdodds,
]
const expected = [
'# project',
'',
'Description',
'',
'## Contributors',
'These people contributed to the project:',
'<!-- ALL-CONTRIBUTORS-LIST:START -->',
'| Kent C. Dodds is awesome! | Kent C. Dodds is awesome! | Kent C. Dodds is awesome! | Kent C. Dodds is awesome! | Kent C. Dodds is awesome! |',
'| :---: | :---: | :---: | :---: | :---: |',
'| Kent C. Dodds is awesome! | Kent C. Dodds is awesome! |',
'<!-- ALL-CONTRIBUTORS-LIST:END -->',
'',
'Thanks a lot everyone!',
].join('\n')

const result = generate(options, contributorList, content)

expect(result).toBe(expected)
expect(result).toMatchSnapshot()
})

test('not inject anything if there is no tags to inject content in', () => {
Expand Down Expand Up @@ -150,6 +119,7 @@ test('inject nothing if there are no contributors', () => {
'## Contributors',
'These people contributed to the project:',
'<!-- ALL-CONTRIBUTORS-LIST:START -->',
'<!-- prettier-ignore -->',
'<!-- ALL-CONTRIBUTORS-LIST:END -->',
'',
'Thanks a lot everyone!',
Expand Down
11 changes: 6 additions & 5 deletions src/generate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ function injectListBetweenTags(newContent) {
) {
return previousContent
}
return (
previousContent.slice(0, endOfOpeningTagIndex + closingTag.length) +
newContent +
previousContent.slice(startOfClosingTagIndex)
)
return [
previousContent.slice(0, endOfOpeningTagIndex + closingTag.length),
'\n<!-- prettier-ignore -->',
newContent,
previousContent.slice(startOfClosingTagIndex),
].join('')
}
}

Expand Down
41 changes: 41 additions & 0 deletions src/init/__tests__/__snapshots__/add-contributors-list.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`create contributors section if content is empty 1`] = `
"
## Contributors
Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!"
`;

exports[`create contributors section if it is absent 1`] = `
"# project
Description
## Contributors
Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!"
`;

exports[`insert list under contributors section 1`] = `
"# project
Description
## Contributors
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore -->
<!-- ALL-CONTRIBUTORS-LIST:END -->"
`;
40 changes: 3 additions & 37 deletions src/init/__tests__/add-contributors-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,21 @@ test('insert list under contributors section', () => {
'## Contributors',
'',
].join('\n')
const expected = [
'# project',
'',
'Description',
'',
'## Contributors',
'',
'<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --><!-- ALL-CONTRIBUTORS-LIST:END -->',
].join('\n')

const result = addContributorsList(content)

expect(result).toBe(expected)
expect(result).toMatchSnapshot()
})

test('create contributors section if it is absent', () => {
const content = ['# project', '', 'Description'].join('\n')
const expected = [
'# project',
'',
'Description',
'## Contributors',
'',
'Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):',
'',
'<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --><!-- ALL-CONTRIBUTORS-LIST:END -->',
'',
'This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!',
].join('\n')

const result = addContributorsList(content)

expect(result).toBe(expected)
expect(result).toMatchSnapshot()
})

test('create contributors section if content is empty', () => {
const content = ''
const expected = [
'',
'## Contributors',
'',
'Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):',
'',
'<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --><!-- ALL-CONTRIBUTORS-LIST:END -->',
'',
'This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!',
].join('\n')

const result = addContributorsList(content)

expect(result).toBe(expected)
expect(result).toMatchSnapshot()
})
7 changes: 5 additions & 2 deletions src/init/init-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ const badgeContent =
'[![All Contributors](https://img.shields.io/badge/all_contributors-0-orange.svg?style=flat-square)](#contributors)'
const headerContent =
'Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):'
const listContent =
'<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --><!-- ALL-CONTRIBUTORS-LIST:END -->'
const listContent = [
'<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->',
'<!-- prettier-ignore -->',
'<!-- ALL-CONTRIBUTORS-LIST:END -->',
].join('\n')
const footerContent =
'This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!'

Expand Down

0 comments on commit ba248a9

Please sign in to comment.