Open Zelman88 opened 6 years ago
Thank you for your debug file.
There appears to be a bug when calling https://github.com/Glavin001/atom-beautify/blob/master/src/beautifiers/beautifier.coffee#L138
###
Find file
###
findFile: (startDir, fileNames) ->
throw new Error "Specify file names to find." unless arguments.length
unless fileNames instanceof Array
fileNames = [fileNames]
startDir = startDir.split(path.sep)
while startDir.length
currentDir = startDir.join(path.sep)
for fileName in fileNames
filePath = path.join(currentDir, fileName)
try
fs.accessSync(filePath, fs.R_OK)
return filePath
startDir.pop()
return null
It is likely one or both of these lines: https://github.com/Glavin001/atom-beautify/blob/master/src/beautifiers/php-cs-fixer.coffee#L61-L65
Investigating your logs closer:
2018-02-16T14:19:22.108Z - error: [beautifiers\index.coffee] TypeError: Cannot read property 'split' of undefined
at PHPCSFixer.module.exports.Beautifier.findFile (file:///C:/Users/adamz/.atom/packages/atom-beautify/src/beautifiers/beautifier.coffee:138:24)
at PHPCSFixer.module.exports.PHPCSFixer.beautify (file:///C:/Users/adamz/.atom/packages/atom-beautify/src/beautifiers/php-cs-fixer.coffee:65:39)
at file:///C:/Users/adamz/.atom/packages/atom-beautify/src/beautifiers/index.coffee:355:28
It is coming from https://github.com/Glavin001/atom-beautify/blob/master/src/beautifiers/php-cs-fixer.coffee#L65
options.cs_fixer_config_file = @findFile(atom.project.getPaths()[0], configFiles)
Specifically
atom.project.getPaths()[0]
Have you opened a project in Atom? I wonder if a workaround is to ensure you have a project folder opened.
Pull Requests welcome to fix this! Please let me know if you need any help making a Pull Request to Atom-Beautify, @Zelman88 . ๐
@Glavin001 I'm using https://atom.io/packages/ftp-remote-edit and not opening any project. Indeed when I open project locally in Atom beautify with php-cs-fixer works both locally and remote. Is there any possibility that it would work without opening project locally? I prefer to work directly on my servers with ftp connection.
also other beautifiers like HTML or CSS don't have this problem - they work with ftp-remote-edit without opening project locally
It is distinctly a bug with PHP-CS-Fixer beautifier integration in Atom-Beautify.
To fix this I recommend making a Pull Request fixing the code here: https://github.com/Glavin001/atom-beautify/blob/master/src/beautifiers/php-cs-fixer.coffee#L63-L65
# Try again to find a config file in the project root
if not options.cs_fixer_config_file
options.cs_fixer_config_file = @findFile(atom.project.getPaths()[0], configFiles)
It could be something like changing to:
if not options.cs_fixer_config_file and atom.project.getPaths()[0]
However, you will need to test this fix for yourself.
cc @szeck87
Same goes for PHPCBF: https://github.com/Glavin001/atom-beautify/blob/master/src/beautifiers/phpcbf.coffee#L45
Changed to this: ``if not options.cs_fixer_config_file and atom.project.getPaths()[0]"
and now it works ๐
Maybe someone more familiar with github could make a Pull Request? I don't have any experience with this.
@Zelman88 : Awesome to hear it is working now for you!
Maybe someone more familiar with github could make a Pull Request? I don't have any experience with this.
I would love to help you become a contributor to this project, especially since you discovered this bug ๐ .
You can use GitHub's file editing interface directly! No need to clone the Git repository. Go to these links:
Make the changes which you found worked for you.
Here are some other quick reads to help you: https://help.github.com/articles/creating-a-pull-request/
It would be wonderful to help you get started contributing on GitHub! Let @szeck87 or I know if you need a hand with anything -- it should not take long ๐ . Thanks in advance!
This issue has been automatically marked as stale because it has not had recent activity. If this is still an issue, please add a comment. It will be closed if no further activity occurs. Thank you for your contributions.
Submitted Glavin001's fix since the issue still exists.
Still facing same issues on fresh Atom with ftp-remote-edit without a local project.
Same error, any php source. Why PR https://github.com/Glavin001/atom-beautify/pull/2313 is ignored?
Same issue still happening. Please include PR #2313 .
Ditto... ftp-remote-edit coughing up the same error still
I am getting the same 'split' error. I tired a new pull and the line updates mentioned above and not luck. Any suggestions?
Same issue here, Tried Glavin001 fix (https://github.com/Glavin001/atom-beautify/issues/2044#issuecomment-366295528) to no avail.
Still seeing this 2018 reported issue. Any progress?
+1 here, same error not fixed :/
+1, same error at ftp-remote-edit
Same error using Atom Beautify on OpenSUSE Tumbleweed with PHP 7.4.3. Not sure what I can do to set-up automatic PHP formatting in Atom.
+1, same error at ftp-remote-edit
Same error here. Just checking out if Atom would help me in php development. Seems not so.
+1, same error on ftp-remote-edit
I have been having this issue for a long time, and still have it in atom 1.4.9 on Debian when not opening a project or project folder.
I fixed it as reported above https://github.com/Glavin001/atom-beautify/issues/2044#issuecomment-366295528
Looking at the stack trace I find the same rows as other users:
Cannot read property 'split' of undefined TypeError: Cannot read property 'split' of undefined at PHPCSFixer.module.exports.Beautifier.findFile (/home/user_name/.atom/packages/atom-beautify/src/beautifiers/beautifier.coffee:138:25) at PHPCSFixer.module.exports.PHPCSFixer.beautify (/home/user_name/.atom/packages/atom-beautify/src/beautifiers/php-cs-fixer.coffee:65:39) [...]
so the problem arises when php-cs-fixer.coffee (line 65) calls the function findFile (located in beautifier.coffee, line 134). This function tries to do the following at line 138:
startDir = startDir.split(path.sep)
so since startDir results as "undefined", I can guess that the row at line 65 in php-cs-fixer.coffee is passing an empty first argument here:
options.cs_fixer_config_file = @findFile(atom.project.getPaths()[0], configFiles)
At this point I tried the fix suggested above and it seems to be working for me:
in /home/user_name/.atom/packages/atom-beautify/src/beautifiers/php-cs-fixer.coffe at line 64:
change this row:
if not options.cs_fixer_config_file
into this:
if not options.cs_fixer_config_file and atom.project.getPaths()[0]
then close and reopen atom if needed.
this seems to be working, I can guess that the reason is that if there is not a cs_fixer_config_file if you do not open a project, but atom can get a path (i didn't check how that works), so the "findFile" function will have a value to give to "startDir" and the "split" function won't fail anymore.
The problem is probably somewhere else to be honest, I don't think this fix should be "permanent", maybe it also depends on local php/atom configurations. As mentioned this does not happen when opening a project in atom.
i change this line at two places
if not options.cs_fixer_config_file
# Find a config file in the working directory if a custom one was not provided
if not options.cs_fixer_config_file and atom.project.getPaths()[0]
options.cs_fixer_config_file = if context? and context.filePath? then @findFile(path.dirname(context.filePath), configFiles
# Try again to find a config file in the project root
if not options.cs_fixer_config_file and atom.project.getPaths()[0]
options.cs_fixer_config_file = @findFile(atom.project.getPaths()[0], configFiles)
I'm still getting this error with remote ftp editing too
I gave up trying to use this.
On Aug 3, 2021, at 4:48 PM, EL-S @.***> wrote:
๏ปฟ I'm still getting this error with remote ftp editing too
โ You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.
i change this line at two places
if not options.cs_fixer_config_file
# Find a config file in the working directory if a custom one was not provided if not options.cs_fixer_config_file and atom.project.getPaths()[0] options.cs_fixer_config_file = if context? and context.filePath? then @findFile(path.dirname(context.filePath), configFiles # Try again to find a config file in the project root if not options.cs_fixer_config_file and atom.project.getPaths()[0] options.cs_fixer_config_file = @findFile(atom.project.getPaths()[0], configFiles)
This fix worked for me
It would be good to put the corrected file because I still can't use it in php
TypeError: Cannot read property 'split' of undefined at PHPCSFixer.module.exports.Beautifier.findFile (file:///C:/Users/Rodrigo Glz/.atom/packages/atom-beautify/src/beautifiers/beautifier.coffee:138:25) at PHPCSFixer.module.exports.PHPCSFixer.beautify (file:///C:/Users/Rodrigo Glz/.atom/packages/atom-beautify/src/beautifiers/php-cs-fixer.coffee:65:39) at file:///C:/Users/Rodrigo Glz/.atom/packages/atom-beautify/src/beautifiers/index.coffee:363:28 at tryCatcher (C:\Users\Rodrigo Glz.atom\packages\atom-beautify\node_modules\bluebird\js\release\util.js:16:23) at Promise._settlePromiseFromHandler (C:\Users\Rodrigo Glz.atom\packages\atom-beautify\node_modules\bluebird\js\release\promise.js:547:31) at Promise._settlePromise (C:\Users\Rodrigo Glz.atom\packages\atom-beautify\node_modules\bluebird\js\release\promise.js:604:18) at Promise._settlePromiseCtx (C:\Users\Rodrigo Glz.atom\packages\atom-beautify\node_modules\bluebird\js\release\promise.js:641:10) at _drainQueueStep (C:\Users\Rodrigo Glz.atom\packages\atom-beautify\node_modules\bluebird\js\release\async.js:97:12) at _drainQueue (C:\Users\Rodrigo Glz.atom\packages\atom-beautify\node_modules\bluebird\js\release\async.js:86:9) at Async._drainQueues (C:\Users\Rodrigo Glz.atom\packages\atom-beautify\node_modules\bluebird\js\release\async.js:102:5) at Async.drainQueues (C:\Users\Rodrigo Glz.atom\packages\atom-beautify\node_modules\bluebird\js\release\async.js:15:14)
@Glavin001, I see two pull requests pending since some time now. One implements the fix in the way that was discussed here. Is there a chance that this bug could be fixed with a coming update?
On all my computers I've got a problem with beautifying php files with atom beautify. Both php-cs-fixer and phpcbf give me an error:
Searched this problem on google, but no luck. Anybody had similiar problem?