prettier/plugin-python

TypeError: locStart is not a function

jleclanche opened this issue · 6 comments

I tried playing with this but got the following stack trace. Reduced repro steps below:

$ mkdir pr; cd pr
$ yarn add --dev --exact prettier @prettier/plugin-python
$ echo '#!/usr/bin/env python' > foo.py
$ yarn run prettier --write foo.py

yarn run v1.5.1
warning package.json: No license field
$ /home/adys/pr/node_modules/.bin/prettier --write foo.py
foo.py
[error] foo.py: TypeError: locStart is not a function
[error]     at comments.forEach (/home/adys/pr/node_modules/prettier/bin-prettier.js:8108:33)
[error]     at Array.forEach (<anonymous>)
[error]     at Object.attach (/home/adys/pr/node_modules/prettier/bin-prettier.js:8094:12)
[error]     at attachComments (/home/adys/pr/node_modules/prettier/bin-prettier.js:32467:14)
[error]     at formatWithCursor (/home/adys/pr/node_modules/prettier/bin-prettier.js:32553:23)
[error]     at Object.formatWithCursor (/home/adys/pr/node_modules/prettier/bin-prettier.js:32835:12)
[error]     at format$1 (/home/adys/pr/node_modules/prettier/bin-prettier.js:38985:21)
[error]     at eachFilename (/home/adys/pr/node_modules/prettier/bin-prettier.js:39208:16)
[error]     at filePaths.forEach.filePath (/home/adys/pr/node_modules/prettier/bin-prettier.js:39150:7)
[error]     at Array.forEach (<anonymous>)
[error]     at eachFilename (/home/adys/pr/node_modules/prettier/bin-prettier.js:39149:15)
[error]     at Object.formatFiles (/home/adys/pr/node_modules/prettier/bin-prettier.js:39166:3)
[error]     at Object.run (/home/adys/pr/node_modules/prettier/bin-prettier.js:39789:14)
[error]     at Object.<anonymous> (/home/adys/pr/node_modules/prettier/bin-prettier.js:39804:5)
[error]     at Module._compile (module.js:649:30)
[error]     at Object.Module._extensions..js (module.js:660:10)
[error]     at Module.load (module.js:561:32)
[error]     at tryModuleLoad (module.js:501:12)
[error]     at Function.Module._load (module.js:493:3)
[error]     at Function.Module.runMain (module.js:690:10)
[error]     at startup (bootstrap_node.js:194:16)
[error]     at bootstrap_node.js:666:3
error An unexpected error occurred: "Command failed.
Exit code: 2
Command: sh
Arguments: -c /home/adys/pr/node_modules/.bin/prettier --write foo.py
Directory: /home/adys/pr
Output:
".
info If you think this is a bug, please open a bug report with the information provided in "/home/adys/pr/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

yarn-error.log

Ah, the error goes away when using git, nvm.

However, if the file only contains #!/usr/bin/env python, I get another error which looks legitimate:

$ /home/adys/pr/node_modules/.bin/prettier --write foo.py
foo.py
[error] foo.py: Error: Comment "#!/usr/bin/env python" was not printed. Please report this error!
[error]     at astComments.forEach.comment (/home/adys/pr/node_modules/prettier/bin-prettier.js:32494:13)
[error]     at Array.forEach (<anonymous>)
[error]     at ensureAllCommentsPrinted (/home/adys/pr/node_modules/prettier/bin-prettier.js:32492:15)
[error]     at formatWithCursor (/home/adys/pr/node_modules/prettier/bin-prettier.js:32562:3)
[error]     at Object.formatWithCursor (/home/adys/pr/node_modules/prettier/bin-prettier.js:32835:12)
[error]     at format$1 (/home/adys/pr/node_modules/prettier/bin-prettier.js:38985:21)
[error]     at eachFilename (/home/adys/pr/node_modules/prettier/bin-prettier.js:39208:16)
[error]     at filePaths.forEach.filePath (/home/adys/pr/node_modules/prettier/bin-prettier.js:39150:7)
[error]     at Array.forEach (<anonymous>)
[error]     at eachFilename (/home/adys/pr/node_modules/prettier/bin-prettier.js:39149:15)
[error]     at Object.formatFiles (/home/adys/pr/node_modules/prettier/bin-prettier.js:39166:3)
[error]     at Object.run (/home/adys/pr/node_modules/prettier/bin-prettier.js:39789:14)
[error]     at Object.<anonymous> (/home/adys/pr/node_modules/prettier/bin-prettier.js:39804:5)
[error]     at Module._compile (module.js:649:30)
[error]     at Object.Module._extensions..js (module.js:660:10)
[error]     at Module.load (module.js:561:32)
[error]     at tryModuleLoad (module.js:501:12)
[error]     at Function.Module._load (module.js:493:3)
[error]     at Function.Module.runMain (module.js:690:10)
[error]     at startup (bootstrap_node.js:194:16)
[error]     at bootstrap_node.js:666:3
error An unexpected error occurred: "Command failed.

And that's #69. Closing.

j-f1 commented

I think we should still look into your original issue — as useful as it is, we shouldn’t be requiring our users to use Git.

I just assumed it was an issue fixed in master and a release isn't out yet. Feel free to reopen though.

I think it's fair to change the README to use git while this is still in early dev.

I see the same error, even with a fresh git clone.

> ../plugin-python/node_modules/.bin/prettier "**/*.py"
[error] api/.tox/py27/bin/activate_this.py: TypeError: locStart is not a function
[error]     at getSortedChildNodes (/usr/local/google/home/melchang/plugin-python/node_modules/prettier/src/main/comments.js:32:11)
[error]     at childNodes.forEach.childNode (/usr/local/google/home/melchang/plugin-python/node_modules/prettier/src/main/comments.js:72:5)
[error]     at Array.forEach (<anonymous>)
[error]     at getSortedChildNodes (/usr/local/google/home/melchang/plugin-python/node_modules/prettier/src/main/comments.js:71:14)
[error]     at childNodes.forEach.childNode (/usr/local/google/home/melchang/plugin-python/node_modules/prettier/src/main/comments.js:72:5)
[error]     at Array.forEach (<anonymous>)
[error]     at getSortedChildNodes (/usr/local/google/home/melchang/plugin-python/node_modules/prettier/src/main/comments.js:71:14)
[error]     at decorateComment (/usr/local/google/home/melchang/plugin-python/node_modules/prettier/src/main/comments.js:84:22)
[error]     at comments.forEach (/usr/local/google/home/melchang/plugin-python/node_modules/prettier/src/main/comments.js:182:5)
[error]     at Array.forEach (<anonymous>)
[error]     at Object.attach (/usr/local/google/home/melchang/plugin-python/node_modules/prettier/src/main/comments.js:176:12)
[error]     at attachComments (/usr/local/google/home/melchang/plugin-python/node_modules/prettier/index.js:34:14)
[error]     at formatWithCursor (/usr/local/google/home/melchang/plugin-python/node_modules/prettier/index.js:120:23)
[error]     at Object.formatWithCursor (/usr/local/google/home/melchang/plugin-python/node_modules/prettier/index.js:402:12)
[error]     at format (/usr/local/google/home/melchang/plugin-python/node_modules/prettier/src/cli/util.js:157:19)
[error]     at eachFilename (/usr/local/google/home/melchang/plugin-python/node_modules/prettier/src/cli/util.js:380:16)
[error]     at filePaths.forEach.filePath (/usr/local/google/home/melchang/plugin-python/node_modules/prettier/src/cli/util.js:322:7)
[error]     at Array.forEach (<anonymous>)
[error]     at eachFilename (/usr/local/google/home/melchang/plugin-python/node_modules/prettier/src/cli/util.js:321:15)
[error]     at Object.formatFiles (/usr/local/google/home/melchang/plugin-python/node_modules/prettier/src/cli/util.js:338:3)
[error]     at Object.run (/usr/local/google/home/melchang/plugin-python/node_modules/prettier/src/cli/index.js:60:12)
[error]     at Object.<anonymous> (/usr/local/google/home/melchang/plugin-python/node_modules/prettier/bin/prettier.js:5:23)