:mega: Help Wanted - Looking for Maintainer: https://github.com/Glavin001/atom-beautify/issues/2572 | :lipstick: Universal beautification package for Atom editor (:warning: Currently migrating to https://github.com/Unibeautify/ and have very limited bandwidth for Atom-Beautify Issues. Thank you for your patience and understanding :heart: )
iSort breaks with supplied parameters if the input file is not part of an existing atom project (e.g. if a standalone python file is edited with atom). Specifically, iSort will throw the error: "Error: arguments passed in without any paths or content."
the function atom?.project.relativizePath(filePath) returns an array that has the project path at array[0] and the relativized file-path at array[1] if the file is part of a project, otherwise array[0] is null (see this issue). Therefore, if the file is not part of a project, then projectPath in the above code will equal null, and the -sp (settings path) parameter will not have an argument, resulting in the erroneous behavior.
Suggested fix
(Worked for me, anyway)
Replace the above code with:
if options.sort_imports
filePath = context.filePath
console.log(filePath)
projectPath = atom?.project.relativizePath(filePath)[0]
if projectPath
@exe("isort").run(["-sp", projectPath, tempFile])
else
@exe("isort").run([tempFile])
which forgoes the -sp parameter when the file is not part of a project (projectPath == null) and it is therefore unnecessary.
Steps to Reproduce
Edit a python file without adding it to a project
Tick the "Sort imports" setting in Atom Beautify > Python
Run command Atom Beautify: Beautify Editor
Receive error described above
Checklist
I have:
[x] Tried uninstalling and reinstalling Atom Beautify to ensure it installed properly
[x] Reloaded (or restarted) Atom to ensure it is not a caching issue
[ ] Filled out the Input, Expected, and Actual sections above or have edited/removed them in a way that fully describes the issue.
[ ] Generated debugging information by executing Atom Beautify: Help Debug Editor command in Atom and added link for debug.md Gist to this issue
(I have not performed these last two actions as I have discovered the cause of the bug, but neither have I submitted a pull request as this bug may repeat in other beautifiers that make use of atom?.project.relativizePath() and the team may have a more appropriate fix in mind).
Description
iSort breaks with supplied parameters if the input file is not part of an existing atom project (e.g. if a standalone python file is edited with atom). Specifically, iSort will throw the error: "Error: arguments passed in without any paths or content."
Why this happens
The following code snippet comes from lines 57-60 in atom-beautify/src/beautifiers/autopep8.coffee
the function
atom?.project.relativizePath(filePath)
returns an array that has the project path at array[0] and the relativized file-path at array[1] if the file is part of a project, otherwise array[0] is null (see this issue). Therefore, if the file is not part of a project, thenprojectPath
in the above code will equal null, and the-sp
(settings path) parameter will not have an argument, resulting in the erroneous behavior.Suggested fix
(Worked for me, anyway) Replace the above code with:
which forgoes the
-sp
parameter when the file is not part of a project (projectPath == null
) and it is therefore unnecessary.Steps to Reproduce
Atom Beautify: Beautify Editor
Checklist
I have:
Atom Beautify: Help Debug Editor
command in Atom and added link fordebug.md
Gist to this issue(I have not performed these last two actions as I have discovered the cause of the bug, but neither have I submitted a pull request as this bug may repeat in other beautifiers that make use of
atom?.project.relativizePath()
and the team may have a more appropriate fix in mind).