Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: all-contributors/cli
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v6.25.1
Choose a base ref
...
head repository: all-contributors/cli
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v6.26.0
Choose a head ref
  • 2 commits
  • 7 files changed
  • 3 contributors

Commits on May 19, 2023

  1. docs: add dwmkerr as a contributor for bug, test, and code (#353)

    * docs: update README.md [skip ci]
    
    * docs: update .all-contributorsrc [skip ci]
    
    ---------
    
    Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
    Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com>
    allcontributors[bot] and gr2m authored May 19, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    45787a7 View commit details

Commits on May 28, 2023

  1. Partially verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    We cannot verify signatures from co-authors, and some of the co-authors attributed to this commit require their commits to be signed.
    Copy the full SHA
    e0a5312 View commit details
Showing with 77 additions and 2 deletions.
  1. +11 −0 .all-contributorsrc
  2. +1 −0 README.md
  3. +3 −0 package.json
  4. +3 −0 src/util/__tests__/__stubs__/.prettierrc.json
  5. +35 −0 src/util/__tests__/formatting.js
  6. +3 −2 src/util/config-file.js
  7. +21 −0 src/util/formatting.js
11 changes: 11 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
@@ -635,6 +635,17 @@
"contributions": [
"code"
]
},
{
"login": "dwmkerr",
"name": "Dave Kerr",
"avatar_url": "https://avatars.githubusercontent.com/u/1926984?v=4",
"profile": "http://www.dwmkerr.com",
"contributions": [
"bug",
"test",
"code"
]
}
],
"skipCi": true
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -169,6 +169,7 @@ Thanks goes to these wonderful people
<td align="center" valign="top" width="16.66%"><a href="https://www.lieret.net"><img src="https://avatars.githubusercontent.com/u/13602468?v=4?s=100" width="100px;" alt="Kilian Lieret"/><br /><sub><b>Kilian Lieret</b></sub></a><br /><a href="https://github.com/all-contributors/cli/issues?q=author%3Aklieret" title="Bug reports">🐛</a></td>
<td align="center" valign="top" width="16.66%"><a href="https://github.com/KnorpelSenf"><img src="https://avatars.githubusercontent.com/u/12952387?v=4?s=100" width="100px;" alt="KnorpelSenf"/><br /><sub><b>KnorpelSenf</b></sub></a><br /><a href="https://github.com/all-contributors/cli/issues?q=author%3AKnorpelSenf" title="Bug reports">🐛</a></td>
<td align="center" valign="top" width="16.66%"><a href="https://rea9lizer.carrd.co"><img src="https://avatars.githubusercontent.com/u/68494132?v=4?s=100" width="100px;" alt="QriLa &#124; Hyeon Gu"/><br /><sub><b>QriLa &#124; Hyeon Gu</b></sub></a><br /><a href="https://github.com/all-contributors/cli/commits?author=qyurila" title="Code">💻</a></td>
<td align="center" valign="top" width="16.66%"><a href="http://www.dwmkerr.com"><img src="https://avatars.githubusercontent.com/u/1926984?v=4?s=100" width="100px;" alt="Dave Kerr"/><br /><sub><b>Dave Kerr</b></sub></a><br /><a href="https://github.com/all-contributors/cli/issues?q=author%3Adwmkerr" title="Bug reports">🐛</a> <a href="https://github.com/all-contributors/cli/commits?author=dwmkerr" title="Tests">⚠️</a> <a href="https://github.com/all-contributors/cli/commits?author=dwmkerr" title="Code">💻</a></td>
</tr>
</tbody>
<tfoot>
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -61,6 +61,9 @@
"nock": "^12.0.0",
"semantic-release": "^17.0.8"
},
"optionalDependencies": {
"prettier": "^2"
},
"eslintIgnore": [
"node_modules",
"coverage",
3 changes: 3 additions & 0 deletions src/util/__tests__/__stubs__/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"useTabs": true
}
35 changes: 35 additions & 0 deletions src/util/__tests__/formatting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import path from 'path'
import formatting from '../formatting'

const content = {contributors: [{id: 'abc123'}]}

const absentFile = '/!@#*&^DefinitelyDoesNotExistAllContributorsCLI$!@#'
const absentConfigFileExpected = `{
"contributors": [
{
"id": "abc123"
}
]
}`

const presentFile = path.join(__dirname, '__stubs__', 'file.json')
const presentConfigFileExpected = `{
"contributors": [
{
"id": "abc123"
}
]
}
`

test('falls back to JSON.stringify when the configPath cannot resolve to a config', () => {
expect(formatting.formatConfig(absentFile, content)).toBe(
absentConfigFileExpected,
)
})

test('uses Prettier when the configPath can resolve to a config', () => {
expect(formatting.formatConfig(presentFile, content)).toBe(
presentConfigFileExpected,
)
})
5 changes: 3 additions & 2 deletions src/util/config-file.js
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ const fs = require('fs')
const pify = require('pify')
const _ = require('lodash/fp')
const jf = require('json-fixer')
const {formatConfig} = require('./formatting')

function readConfig(configPath) {
try {
@@ -14,7 +15,7 @@ function readConfig(configPath) {
}
if (changed) {
//Updates the file with fixes
fs.writeFileSync(configPath, JSON.stringify(config, null, 2))
fs.writeFileSync(configPath, formatConfig(config))
}
return config
} catch (error) {
@@ -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`)
}

function writeContributors(configPath, contributors) {
21 changes: 21 additions & 0 deletions src/util/formatting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function formatConfig(configPath, content) {
const stringified = JSON.stringify(content, null, 2)
try {
const prettier = require('prettier')
const prettierConfig = prettier.resolveConfig.sync(configPath, {
useCache: false,
})

return prettierConfig
? prettier.format(stringified, {...prettierConfig, parser: 'json'})
: stringified
} catch (error) {
// If Prettier can't be required or throws in general,
// assume it's not usable and we should fall back to JSON.stringify
return stringified
}
}

module.exports = {
formatConfig,
}