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

feat: use Prettier to write config file, if possible #356

Merged

Conversation

JoshuaKGoldberg
Copy link
Contributor

What: If the user has the prettier package available in their project and has a Prettier config file (e.g. .prettierrc.json), Prettier will be used to write .allcontributorsrc files.

Why: See #347.

How: Adds prettier as an optional dependency. Augments the config writing logic to:

  1. Attempt to require('prettier')
  2. Find the nearest Prettier config for the file with prettier.resolveConfigFile.sync
  3. Use Prettier to format the file with that config
    ...falling back to the traditional JSON.stringify(content, null, 2) if any of that fails.

Checklist:

  • Documentation N/A
  • Tests
  • Ready to be merged
  • Added myself to contributors table N/A

Are optionalDependencies the way to go? I can never keep track of the latest preferences around optionals/peers/etc.

@Berkmann18
Copy link
Member

@all-contributors Please add @JoshuaKGoldberg for ideas and code

@allcontributors
Copy link
Contributor

@Berkmann18

I've put up a pull request to add @JoshuaKGoldberg! 🎉

@Berkmann18 Berkmann18 merged commit e0a5312 into all-contributors:master May 28, 2023
2 checks passed
@all-contributors-release-bot
Copy link
Member

🎉 This PR is included in version 6.26.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@JoshuaKGoldberg JoshuaKGoldberg deleted the use-prettier-if-possible branch May 29, 2023 06:18
@dubzzz
Copy link

dubzzz commented Jul 6, 2023

Not sure it's fully related (I'm still investigating) but when passing from 6.25.0 to 6.26.0 of the project the command all-contributors add username doc,code,test stopped working and fully erased the content of the file .all-contributorsrc. An easy repro is to take https://github.com/dubzzz/fast-check and run yarn contributor:add username doc,code,test on it.


UPDATE 1

No issue with version 6.25.1. Issue starts at 6.26.0.

@@ -43,7 +44,7 @@ function writeConfig(configPath, content) {
`Error! Project files was overridden and is empty in ${configPath}`,
)
}
return pify(fs.writeFile)(configPath, `${JSON.stringify(content, null, 2)}\n`)
return pify(fs.writeFile)(configPath, `${formatConfig(content)}\n`)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that we pass the content as config, no?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we are replacing this code by JSON.stringify(undefined, null, 2)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🌷🌷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants