🚧 Work in Progress! 🚧
Please note that this plugin is currently in alpha stage and still under active development. We encourage everyone to try it and give feedback, but we don't recommend it for production use yet.
Prettier is an opinionated code formatter. It enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary.
This plugin adds support for the QML language to Prettier.
yarn:
yarn add --dev prettier prettie-plugin-qml
# or globally
yarn global add prettier prettie-plugin-qml
npm:
npm install --save-dev prettier prettie-plugin-qml
# or globally
npm install --global prettier prettie-plugin-qml
If you installed prettier as a local dependency, you can add prettier as a script in your package.json
,
"scripts": {
"prettier": "prettier"
}
and then run it via
yarn run prettier path/to/file.qml --write
# or
npm run prettier -- path/to/file.qml --write
If you installed globally, run
prettier path/to/file.qml --write
The official prettier plugin for atom supports plugins.
Regarding plugin support in the official plugin prettier-vscode see this issue.
Alternatively, install Run on Save and add the following section to your settings:
"emeraldwalk.runonsave": {
"commands": [
{
"match": "\\.qml$",
"cmd": "prettier ${file} --write"
}
]
}
Regarding plugin support in the official plugin vim-prettier see this issue.
The linting plugin ALE has built-in support for prettier and its plugins. Just add prettier to your list of fixers. For example:
let g:ale_fixers={
\'javascript': ['prettier'],
\'json': ['prettier'],
\'qml': ['prettier'],
\}
Alternatively, adding the following to .vimrc
will define a custom command :PrettierQml
that runs the plugin while preserving the cursor position and run it on save.
" Prettier for QML
function PrettierQmlCursor()
let save_pos = getpos(".")
%! prettier --stdin --parser=qml
call setpos('.', save_pos)
endfunction
" define custom command
command PrettierQml call PrettierQmlCursor()
" format on save
autocmd BufwritePre *.qml PrettierQml
If you're interested in contributing to the development of Prettier for QML, you can follow the CONTRIBUTING guide from Prettier, as it all applies to this repository too.
To test it out on a QML file:
- Clone this repository.
- Run
yarn
. - Create a file called
test.qml
. - Run
yarn prettier test.qml
to check the output.
Christian Zosel |
Evilebot Tnawi |