Skip to content

init created empty .all-contributorsrc #359

@schweden1997

Description

@schweden1997

Describe the bug
When I use yarn all-contributors init a .all-contributorsrc is created but it contains just an undefined in line 1.
When trying to add a contributor the json-fixer fails, since json cannot contain just an undefined.
When manually creating a .all-contributorsrc and using all-contributors add the command deletes everything in the .all-contributorsrc and adds an undefined.

To Reproduce
Steps to reproduce the behavior:

  1. yarn init -y
  2. yarn add -D all-contributors-cli
  3. git init
  4. yarn all-contributors init (.all-contributorsrc is created, but undefined)
  5. yarn all-contributors add schweden1997 doc,code (this errors)
There's still an error!
There's still an error!
There's still an error!
Error: Expected "[", "false", "null", "true", "{", number, or string but "u" found.
    at doubleCheck (/Users/marcodegaetano/Developer/oss/test-ac/.yarn/cache/json-fixer-npm-1.6.15-ae75b6da33-ae805d5155.zip/node_modules/json-fixer/index.js:29:11)
    at fixJson (/Users/marcodegaetano/Developer/oss/test-ac/.yarn/cache/json-fixer-npm-1.6.15-ae75b6da33-ae805d5155.zip/node_modules/json-fixer/index.js:103:10)
    at doubleCheck (/Users/marcodegaetano/Developer/oss/test-ac/.yarn/cache/json-fixer-npm-1.6.15-ae75b6da33-ae805d5155.zip/node_modules/json-fixer/index.js:27:44)
    at fixJson (/Users/marcodegaetano/Developer/oss/test-ac/.yarn/cache/json-fixer-npm-1.6.15-ae75b6da33-ae805d5155.zip/node_modules/json-fixer/index.js:103:10)
    at doubleCheck (/Users/marcodegaetano/Developer/oss/test-ac/.yarn/cache/json-fixer-npm-1.6.15-ae75b6da33-ae805d5155.zip/node_modules/json-fixer/index.js:27:44)
    at fixJson (/Users/marcodegaetano/Developer/oss/test-ac/.yarn/cache/json-fixer-npm-1.6.15-ae75b6da33-ae805d5155.zip/node_modules/json-fixer/index.js:103:10)
    at doubleCheck (/Users/marcodegaetano/Developer/oss/test-ac/.yarn/cache/json-fixer-npm-1.6.15-ae75b6da33-ae805d5155.zip/node_modules/json-fixer/index.js:27:44)
    at fixJson (/Users/marcodegaetano/Developer/oss/test-ac/.yarn/cache/json-fixer-npm-1.6.15-ae75b6da33-ae805d5155.zip/node_modules/json-fixer/index.js:103:10)
    at doubleCheck (/Users/marcodegaetano/Developer/oss/test-ac/.yarn/cache/json-fixer-npm-1.6.15-ae75b6da33-ae805d5155.zip/node_modules/json-fixer/index.js:27:44)
    at fixJson (/Users/marcodegaetano/Developer/oss/test-ac/.yarn/cache/json-fixer-npm-1.6.15-ae75b6da33-ae805d5155.zip/node_modules/json-fixer/index.js:103:10)

Expected behavior
init command should create correct .all-contributorsrc

Additional context
node -v v20.3.1
node -v v16.20.1 (both tested)
yarn -v 3.6.1
yarn -v 1.22.19 (both tested)
all-contributors -v 6.26.0

Solution
Error seems to occur from:

return pify(fs.writeFile)(configPath, `${formatConfig(content)}\n`)

formatConfig() requires 2 arguments. The first is configPath, second is content. Here the content is passed as the configPath.
Changing this to:

return pify(fs.writeFile)(configPath, `${formatConfig(configPath, content)}\n`);

resolves the issue.

Same thing applied to this:

fs.writeFileSync(configPath, formatConfig(config))

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions