Glavin001 / atom-beautify

: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: )
http://unibeautify.com/
MIT License
1.5k stars 453 forks source link

PHPCBF appears to not run from project folder #2173

Closed chuhta closed 6 years ago

chuhta commented 6 years ago

Description

PHPCBF does not work with relative paths in the ruleset.xml file. It seems like from the debugging I have done that the PHPCBF process is being run from the package folder instead of from the project folder, meaning that relative paths in the ruleset break.

Input Before Beautification

This is what the ruleset looks like:

<?xml version="1.0"?>
<!DOCTYPE ruleset>
<ruleset name="Sample Standard">
    <config name="installed_paths" value="config/Standards" />

Expected Output

The code should be beautified with no errors in the console.

Actual Output

Steps to Reproduce

  1. Add the following settings to atom-beautify.
    executables:
      phpcbf:
        path: "/home/sampleUser/project/vendor/bin/phpcbf"
    general:
      loggerLevel: "verbose"
    php:
      default_beautifier: "PHPCBF"
      phpcbf_version: 3
      standard: "/home/sampleUser/project/config/ruleset.xml
  1. Create a project with a PHPCS ruleset.
  2. Add a custom sniff locally to the project. You can copy a sniff from any PHPCS library and save it to mimic this.
  3. Point the ruleset to the folder containing the sniff. This should be the relative path from the project root.
  4. Run command Atom Beautify: Beautify Language Php.
  5. The beautify seems to have succeeded, but nothing changed.
  6. Open the Developer console (Ctrl+Shift+I).
  7. The error previously described prints out.

Debug

Gist: https://gist.github.com/chuhta/7e780bb9cea466be4413a51a2c0f07f3

Making the following changes to these files resolved the problem of the package not running.

src/beautifiers/phpcbf.coffee

# Lines 89-101
        phpcbf.run([
          "--no-patch" unless isVersion3
          "--standard=#{options.standard}" if options.standard
          tempFile
          ], {
+            cwd: atom.project.relativizePath(standardFile)[0],
            ignoreReturnCode: true
            onStdin: (stdin) ->
              stdin.end()
          })
          .then(=>
            @readFile(tempFile)
          )

src/beautifiers/beautifier.coffee

# Lines 152-158
      .then(([exeName, args, env, exePath]) =>
        @debug('exePath:', exePath)
        @debug('env:', env)
        @debug('PATH:', env.PATH)
        @debug('args', args)
-        args = this.relativizePaths(args)
        @debug('relativized args', args)

src/logger.coffee

No changes actually made in this file, but it appears interactions with it are not as would be expected. The error mentioned above does not appear until I turn the logging up to at least "debug", even though it is clearly an error that is blocking atom-beautifier from working.

Checklist

I have:

ghost commented 6 years ago

Please follow the issue template provided. More specifically, update the original comment for this issue by adding a link to the required debug.md gist which includes debugging information that answers our most commonly asked questions. Thank you.

chuhta commented 6 years ago

I fixed the issue, but the label doesn't appear to be getting removed by the bot.

probot-no-response[bot] commented 6 years ago

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.