prettier / vim-prettier Goto Github PK
View Code? Open in Web Editor NEWA Vim plugin for Prettier
License: MIT License
A Vim plugin for Prettier
License: MIT License
Prettier cli works from windows console, but :Prettier
does not.
vim-prettier 0.2.3
I have the following JSON:
{
"URL": { "demoVisualization_comment": "Additional parameters are included: ?tempUnit=F&edgeHost=<ip_or_host_name_of_this_machine>", "securityCertificate": "downloads/test.zip" }
}
If I simply run :Prettier
, I get this correct output:
{
"URL": {
"demoVisualization_comment":
"Additional parameters are included: ?tempUnit=F&edgeHost=<ip_or_host_name_of_this_machine>",
"securityCertificate": "downloads/test.zip"
}
}
But, if I visually select just this line:
"URL": { "demoVisualization_comment": "Additional parameters are included: ?tempUnit=F&edgeHost=<ip_or_host_name_of_this_machine>", "securityCertificate": "downloads/test.zip" }
And run: :'<,'>Prettier
, I get an error:
demoConfig.json|1 col 8| SyntaxError: Unexpected token
Prettier version:
$ npm i -g prettier
[email protected] C:\...\npm\node_modules\prettier
$ node --version
v4.2.1
Note, it is a bit inconsistent.
If I had more lines, sometimes it formats them correctly. I was pruning my JSON lines to try to find a small reproducible example.
Hi,
I've just setup again my vim/prettier/eslint setup and I noticed that when I use prettier with this plugin it adds (at least) 3 now unknown options to the prettier cli. I'm unsure if those options are just deprecated or replaced upstream as I didn't found anything in the changelogs. But it seems to work to just drop those options.
Heres what I did:
node-6.9.5
locally with package.json
(npm install
)<leader>p
(or by calling the Commands directly, I tried both actually)Ignored unknown option: --config-precedence
Ignored unknown option: --no-editorconfig
Ignored unknown option: --loglevel
at the top.
Probably from a race condition where saving then immediately switching to a different buffer, the buffer switched to is overwritten with the contents from the previous buffer.
We should add support for prettier 1.8
This line is being prepended to my *.css files when formatting with vim-prettier:
--parser
with value postcss
is deprecated. Prettier now treats it as: --parser=css
.
I am using prettier version 1.7.1.
vim-prettier 0.2.3
I have installed and using it now, thank you for the plugin.
doc\prettier.txt makes no mention on how to ask for help or support on the plugin.
No website given or email address supplied.
The only way I found this website was opening the changelog.md.
Most plugin authors put headers at the top of each of the files with something like this:
" vim-prettier.vim - A vim plugin wrapper for prettier
" ---------------------------------------------------------------
" Version: 0.2.3
" Author: Whatever <you.want at gmail dot com>
" Last Modified: 2017 Aug 13
" Created: 2017-05-24
" Homepage: http://www.vim.org/scripts/script.php?script_id=5572
" Contributors: Blah...
" Blah
"
" Help: :h vim-prettier.txt
This helps people find support as well as when I prune files from my plugins directory (if the filename wasn't obvious) I know which plugin it was for.
And of course doc\vim-prettier.txt should have similar information or a section for getting help / support / kudos and so on.
HI! Thanks so much for all your work on prettier
and vim-prettier
. It was exactly what I was looking for after having used gofmt
.
I'm super curious - on the readme, you say that you differ from Prettier intentionally. Would love to better understand the reasoning as I'm currently trying to configure it to act the same as Prettier. Thanks!
We should include the MIT license on the plugin
We should start including a CHANGELOG file in order to better track release updates
Hello there!
For unknown reason prettier cannot style css files (there is no any problem with javascript by the way).
Example of css file:
/* @format */
body {
dislay:none ;
opacity: .75;
}
My environment:
:PrettierCli
nothing:PrettierCliPath
prettier:PrettierCliVersion
1.8.0:PrettierVersion
0.2.4:version
NVIM v0.2.0
Build type: RelWithDebInfo
Compilation: /usr/bin/x86_64-linux-gnu-gcc -g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -DDISABLE_LOG -Wdate-time -D_FORTIFY_SOURCE
=2 -Wconversion -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O2 -g -DDISABLE_LOG -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wvla -fstack-protector-strong -fdiag
nostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -I/build/neovim-LpFVCC/neovim-0.2.0/build/config -I/build/neovim-LpFVCC/neovim-0.2.0/src -I/usr/include -I/usr/include -I/u
sr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/build/neovim-LpFVCC/neovim-0.2.0/build/src/nvim/auto -I/build/neovim-LpFVCC/neovim-0.2.0/build/include
Compiled by [email protected]
Optional features included (+) or not (-): +acl +iconv +jemalloc +tui
For differences from Vim, see :help vim-differences
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/usr/share/nvim"
The default setting:
" none|es5|all
g:prettier#config#trailing_comma = 'all'
is causing IE 10 and 11 to trigger an error on JS files.
Perhaps this settings should be set to "none" by default?
Thanks for writing the plugin. Keen to start using it but I've just had a very confusing 30 mins whilst I tried to figure out why vim-prettier seemed to be ignoring my prettier project config file.
I feel that the README indicates that prettier defaults to 'prefer-file'. But in order to get that behaviour when using typescript I have to delete these lines:
vim-prettier/ftplugin/typescript.vim
Lines 1 to 4 in 3cde181
Though I've used vim for a long time, I'm one of those that has never really learnt even the basics of vim script so I'm not sure how to override that setting myself.
Hope this is a reasonable concern to raise. I'm sure I could work around it if I knew more about vim but it seems confusing behaviour to start with. Maybe I'm missing something basic. It wouldn't be the first time I've missed something in the docs.
Thanks for the project though :)
We should allow the user to be able to specify the prettier cli bin path on their .vimrc
file
This would solve problems like the following:
Is there a way to override and specify a specific path for prettier to vim-prettier? (I cannot update the version of prettier in a project i'm working on)
Prettier 1.5 has been release highlights are:
We should be able now include JSON and GraphQL support
Enabling support for GraphQL would be similar to #17
Plug 'prettier/vim-prettier', {
\ 'do': 'npm install',
\ 'for': ['javascript', 'typescript', 'css', 'less', 'scss', 'json', 'graphql'] }
let g:prettier#autoformat = 0
autocmd BufWritePre *.js,*.json,*.css,*.scss,*.less,*.graphql Prettier
let g:prettier#config#semi = 'false'
let g:prettier#config#trailing_comma = 'none'
Hi,
I've been using this config for some times and now in a fresh install it's printing semicolons. Did I missed something or something changed?
Vim 8.0 (MS-Windows 64-bit GUI version with OLE support)
Plug 'mitermayer/vim-prettier', {
\ 'do': 'yarn install',
\ 'for': ['javascript', 'typescript', 'css', 'less', 'scss'] }
" Disable auto formatting of files that have @format tag
let g:prettier#autoformat = 0
" max line lengh that prettier will wrap on
let g:prettier#config#print_width = 80
" number of spaces per indentation level
let g:prettier#config#tab_width = 4
" use tabs over spaces
let g:prettier#config#use_tabs = 'false'
" print semicolons
let g:prettier#config#semi = 'true'
" single quotes over double quotes
let g:prettier#config#single_quote = 'true'
nnoremap <silent><c-f> :Prettier<CR>
origin code
function aLongLongLongFunction(barbarbar, foofoofoo, boobooboo, barbarbar, balabalabala) {
console.log('lalalala');
}
after prettier
function aLongLongLongFunction(
barbarbar,
foofoofoo,
boobooboo,
barbarbar,
balabalabala, // add an extra comma here
) {
console.log('lalalala');
}
In this file
import React from 'react'
import { Route, IndexRoute } from 'react-router/es'
import Root from './modules/Root'
import Page from './modules/Page'
function errorLoading(err) {
console.error('Dynamic page loading failed', err)
}
function loadRoute(cb) {
return module => cb(null, module.default)
}
/*
* @param {Redux Store}
*/
export default () =>
<Route component={Page}>
<Route path="/" component={Root}>
<Route
path="/info(/:category)"
getComponent={(location, cb) => {
import(
/* webpackChunkName : "info" */
'./modules/info/containers/Layout')
.then(loadRoute(cb))
.catch(errorLoading)
}}
/>
</Route>
</Route>
Problem is in comment /* webpackChunkName : "info" */
. From console.it works.
When I save a file ignored by a .prettierignore file, then its contents is deleted.
Hi guys, first of all thank you for your time and effort, I really appreciate it :)
Is it possible to auto format files, on save, without the need to add the "@Format" tag?
I'd like to use it both. If there are an option to specify which tool to be used?
Will keep this as a holding issue to keep track to upgrading to prettier 1.6
prettier
custom configAt the moment vim-prettier has been developed with vim8+ in mind. We should however be more clear about it on our README and make sure we can identify what is our minimum supported vim version.
We should also investigate what is required to guarantee backwards support with older vim versions.
To prevent a script from being loaded and reloaded and reloaded, Vim files add (*.vim) typically add the following to the top of them:
if exists('g:loaded_vim_prettier') || &cp
finish
endif
let g:loaded_vim_prettier = 0.2.3
That way they get loaded once and only once. Once the functions and initialization is complete, there is no need to re-source this file.
I get this error one every save
This is the configuration in my vimrc file:
let g:prettier#config#print_width = 120
let g:prettier#config#bracket_spacing = 'false'
let g:prettier#quickfix_enabled = 1
let g:prettier#autoformat = 0
autocmd BufWritePre .js,.jsx,.mjs,.ts,.tsx,.css,.less,.scss,.json,.graphql Prettier
At the moment if we have an invalid file like this we are still overwriting the buffer with the prettier error output.
// @format
const foo x= (a, b) => {};
becomes
stdin: SyntaxError: Unexpected identifier (2:10)
1 | // @format
> 2 | const foo x= (a, b) => {};
| ^
3 |
Expected behaviour:
Not overwrite buffer and display an error message
Hi! There is a --prose-wrap
option for markdown files since 1.8.2 and was hoping we could configure this option through the plugin's config. Thanks! (If you are open to a PR for it please let me know)
I've just installed the package and whilst calling :Prettier works fine, :PrettierAsync appears to do absolutely nothing.
As far as I can tell, this is caused by the fact that Vim's job_start function is attempting to call the prettier executable directly, which causes the job to fail immediately (job_status returns 'fail') without ever calling the error callback. The correctly working :Prettier goes via a system() call which executes the command via the shell rather than a direct call.
If I prepend 'cmd.exe /C' to the command passed to job_start, it works just fine.
I will put in a fix and create a pull request when I get the chance but I can't guarantee it will be pretty.
Can this be configured to use https://github.com/prettier/prettier-eslint-cli? We have some eslint rules that are incompatible with prettier that work great with the alternate CLI. It's also a great tool as we try to migrate to prettier without completely turning off eslint
I would like to enable trailing commas. Instead of the formatter changing my code from:
Promise.all([
sendToAlphaBroker(firstHalfOfByteChunks, file),
sendToBetaBroker(lastHalfOfByteChunks, file),
]).then(() => {
console.log("Upload complete!");
});
to
Promise.all([
sendToAlphaBroker(firstHalfOfByteChunks, file),
sendToBetaBroker(lastHalfOfByteChunks, file)
]).then(() => {
console.log("Upload complete!");
});
I added this line: let g:prettier#config#trailing_comma = 'all'
to my vimrc file but it doesn't seem to be working?
When prettier fails to execute we should populate the vim quickfix with parsing errors, this behaviour should also be user configurable.
Prettier 1.5.3 does not accept --single-quote false
as a way to using double quotes. This means that g:prettier#config#single_quote = 'false'
doesn't work. I have to use this, which is icky: g:prettier#config#single_quote = '--no-single-quote'
.
When executing :Prettier
it prepends Ignored unknown option: --config-precedence
in buffer
I'm using vim-prettier 0.2.4
with global prettier version 1.7.4
I believe it's related to #53
We should bump our internal plugin prettier dependencie version
We should allow partial formatting upon visual selection. It should also work on both Async and Sync modes.
Can this detect configuration for prettier in package.json
?
// ...
"xo": {
"extends": "prettier",
"plugins": ["babel", "prettier"],
"rules": {
"prettier/prettier": [ // <---------- HERE
"error",
{
"singleQuote": true,
"bracketSpacing": true,
"trailingComma": "none"
}
],
"max-len": ["error", {"code": 80, "ignoreUrls": true}]
},
Its not great having to wait a long time when saving a big file. We should have prettier running async
After I run :Prettier
, and then press <C-o>
to navigate to the last position of cursor, it always point to the beginning of the file. It's annoying. Please fix this.
By allowing the extra comma to be auto added will create an invalid json file
This is an invalid json:
{
"foo": "bar",
}
should be:
{
"foo": "bar"
}
We should make sure that json parsing settings make sure to not include auto adding comma settings
Boolean params for the cli are somehow expected to be 'false' and 'true'.
Prettier uses following logic for resolving config:
The configuration file will be resolved starting from the location of the file being formatted, and searching up the file tree until a config file is (or isn't) found.
Plugin should resolve config of each file using command prettier --find-config-path ./my/file.js
This causes issues when I use following project structure:
|- node_modules/
| |- prettier/
|- packageA/
| |- src/
| | |- index.js
| |- prettier.config.js
|- packageB/
| |- src/
| | |- index.js
| |- prettier.config.js
Plugin doesn't use configs from corresponding directories and formats both files packageA/src/index.js
and packageB/src/index.js
with default config.
We should provide some basic filetype detection but also keeping compatible with other plugins.
This for example would enable to correctly identify graphql, typescript, less, scss etc.. without having to rely on the filetype being implemented by other plugins.
we should be able to leverage from vim did_filetype()
function that will allow us to conditionally set a filetype if no other plugin has done so.
We currently support vim8 async formatting by using its jobs API. However neovim job/channel API is not the same as vim8.
In order to provide a better experience for neovim users we should also support neovim job/channel API.
The option to use single quote is not working.
I have the following in my vimrc:
let g:prettier#config#single_quote = 'true'
Current using Prettier version is 1.9.1.
In
function! s:Get_Exec(...) abort`
let l:rootDir = a:0 > 0 ? a:1 : 0
let l:exec = 0
if rootDir
should check for directory since vim string comparison is always 0, intead it should be:
function! s:Get_Exec(...) abort`
let l:rootDir = a:0 > 0 ? a:1 : 0
let l:exec = 0
if isdirectory(rootDir)
It formats nicely but removes indentation from first line of visual selection.
I suppose it would be more reasonable to just keep the current indentation
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.