glat / MultiLinter

VisualStudio multiple and customizable linting and formatting made easy
9 stars 4 forks source link

prettier not running #12

Open jgwinner opened 3 years ago

jgwinner commented 3 years ago

Hi

I downloaded the extension, install it, configured it in VStudio to run on save: image

then setup the .multilinterrc.json file as in your example:

{
  "eslint": {
    "enabled": true,
    "additionalArguments": "",
    "fileExtensions": "js"
  }
}

Works great.

Searching linters to be used for file extension ".js"
Linters found to be used for file extension ".js" found: eslint,
Searching linter eslint in local mode
Searching linter eslint in directory "C:\c\cover\workhub"
Linter eslint found in path "C:\c\cover\workhub\node_modules\.bin"

About to lint by:

              Linter: "eslint"
   Current Directory: "C:\c\cover\workhub\"
        Command line: "C:\c\cover\workhub\node_modules\.bin\eslint.cmd"
           Arguments: ""nuxt.config.js" -f json"

I then try prettier, by changing the .multilinterrc.json but it never runs:

Searching linters to be used for file extension ".json"
No linters found to be used for file extension "json"

Odd. My package.json has:

  "devDependencies": {
    "@nuxtjs/eslint-config": "^1.0.1",
    "@nuxtjs/eslint-module": "^1.0.0",
...
    "eslint": "^6.1.0",
    "eslint-config-prettier": "^4.1.0",
    "eslint-plugin-nuxt": ">=0.4.2",
    "eslint-plugin-prettier": "^3.0.1",
    "prettier": "2.3.1"
  },
...

Note that per the docs at: https://prettier.io/docs/en/install.html the command is yarn prettier, so I modified your setup:

{
  "prettier": {
    "enabled": true,
    "additionalArguments": "",
    "fileExtensions": "js",
    "executable": "yarn prettier"
  }
}

Now it thinks prettier is configured, BUT still won't run. Debug output:

Formatter Name = prettier

            Enabled = true
         Executable = "yarn prettier"
          Arguments = "--write "{filePath}""
     StdInArguments = "--stdin-filepath "{filePath}""
AdditionalArguments = ""
   InstallationType = "local"

... snip

Searching formatters to be used for file extension ".js"
Formatters found to be used for file extension ".js" found: prettier,
Searching linter prettier in local mode
Searching linter prettier in directory "C:\c\stuff\mycode"
Searching linter prettier in directory "C:\c\stuff"
Searching linter prettier in directory "C:\c"
Searching linter prettier in directory "C:\"
Linter prettier not found. Check your config.
Loading user defined tool configs...
Loading default tool configs from internal resources...
Default tool configs loaded from internal resources...
Searching config file in directory "C:\c\stuff\mycode"
Searching config file in directory "C:\c\stuff"
Searching config file in directory "C:\c"
Searching config file in directory "C:\"
Searching config file in directory "C:\Users\johng"

eslint works fine.

Any ideas? I'm sure it's some other parameter is different from the seeded setup files and our setup, which I thought was fairly off the shelf. Prettier is mandated by the org.

glat commented 3 years ago

It's because of "yarn prettier" executable. Multilinter searches for a "yarn prettier" executable up to the root. Of course it cannot find such file (which name should be "yarn prettier.exe/cmd/bat" and so it fails. Actually is only supported to launch those externals executable directly, such as prettier.exe/cmd/etc, not by using yarn. Sorry.

jgwinner commented 3 years ago

Prettier isn't a .exe, it's JS, so it has to be run via Node, i.e. npm or yarn. There is a .CMD though, which includes that, so I'm getting closer with this, but {filename} isn't expanding.

That's got to be a bug.

{
  "prettier": {
    "enabled": true,
    "additionalArguments": --write "\"{filePath}\"  ",
    "fileExtensions": "js,vue",
    "executable": "prettier.cmd",
    "StdInArguments": ""
  }
}

gives me this error:

Formatters found to be used for file extension ".vue" found: prettier,

About to format by:

           Formatter: "prettier"
   Current Directory: "C:\c\stuff\"
        Command line: "C:\c\stuff\node_modules\.bin\prettier.cmd"
           Arguments: ""{filePath}" --write"

Error:

[error] No files matching the pattern were found: "{filePath}".

If I include {filename} in the StdInArguments it works fine, but replaces my file with the timing of the results. No other combination of {filename} or \"{filename}\" ever worked. It works fine from the command line.

So, I tried:

  "prettier": {
    "enabled": true,
    "additionalArguments": "--parser vue",
    "fileExtensions": "js,vue",
    "executable": "prettier.cmd",
    "StdInArguments": "\"{filePath}\""
  }
}

This locks up visual studio. Had to kill it with the task manager.

Third (tieth) try is the charm, this works:

{
  "prettier": {
    "enabled": true,
    "additionalArguments": "",
    "fileExtensions": "js,vue",
    "executable": "prettier.cmd",
    "StdInArguments": "--parser vue"
  }
}

Because I am using the 'standard' Prettier with an off the shelf install, I think the above settings should be the default in .MultiLiter, or at least documented.

So, it's now working!

jgwinner commented 3 years ago

Whoops - it broke Javascript

glat commented 3 years ago

So is it working now? Also, because the base config for prettier is:

{ "prettier": { "enabled": false, "additionalArguments": "", "fileExtensions": "", "executable": "prettier.cmd", "arguments": "--write \"{filePath}\"", "stdInArguments": "--stdin-filepath \"{filePath}\"", "installationType": "local", "toolType": "formatter" } }

When you want to add a stdInArgument you should add the string to the string in the base config. So you should write:

{ "prettier": { "enabled": true, "additionalArguments": "", "fileExtensions": "js,vue", "executable": "prettier.cmd", "stdInArguments": "--stdin-filepath \"{filePath}\" --parser vue" } }

But I think you can also use:

{ "prettier": { "enabled": true, "additionalArguments": "--parser vue", "fileExtensions": "js,vue" } }

Let me know.

jgwinner commented 3 years ago

Ok, I'll try those, thanks.

The only problem with "--parser vue" was that it broke Javascript, so I could use a different linter that's supposed to do prettier with .js, as the original problem was that one didn't do .vue files. Your add-in does, and it's about the only one. What was weird, is that prettier didn't seem to do .vue files unless I added the --parser vue.

I'll fiddle with it some more. At least now, between the standard linter and your adding, I can get Nuxt to compile and run! Our project upgraded from a 1.x of Prettier to a 2.3.X, which broke a bunch of stuff.