Skip to content

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

Merged
Berkmann18 merged 1 commit into
all-contributors:masterfrom
JoshuaKGoldberg:use-prettier-if-possible
May 28, 2023
Merged

Berkmann18 merged 1 commit into
all-contributors:masterfrom
JoshuaKGoldberg:use-prettier-if-possible

Conversation

@JoshuaKGoldberg

Copy link
Copy Markdown
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
Copy Markdown
Member

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

@allcontributors

Copy link
Copy Markdown
Contributor

@Berkmann18

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

@Berkmann18
Berkmann18 merged commit e0a5312 into all-contributors:master May 28, 2023
@all-contributors-release-bot

Copy link
Copy Markdown
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

dubzzz commented Jul 6, 2023 •

Copy link
Copy Markdown

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.

Comment thread src/util/config-file.js
)
}
return pify(fs.writeFile)(configPath, `${JSON.stringify(content, null, 2)}\n`)
return pify(fs.writeFile)(configPath, `${formatConfig(content)}\n`)

Copy link
Copy Markdown

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
Copy Markdown

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
Copy Markdown

Choose a reason for hiding this comment

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

🌷🌷

dubzzz added a commit to dubzzz/cli that referenced this pull request Jul 6, 2023
The change all-contributors#356 seem to break the formatting of the file .all-contributorsrc. Instead of formatting the content, it formats "undefined".

See:
- all-contributors#356 (comment)
- all-contributors#356 (comment)
@dubzzz dubzzz mentioned this pull request Jul 6, 2023
3 of 4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants