Skip to content

DrRataplan/prettier-plugin-xquery

Repository files navigation

Prettier for XQuery

NPM version Tests Coverage Status

prettier-plugin-xquery is a prettier plugin for XQuery. prettier is an opinionated code formatter that supports multiple languages and integrates with most editors. The idea is to eliminate discussions of style in code review and allow developers to get back to thinking about code design instead.

Demo

A demo page lives at xquery.elliat.nl.

Getting started

To run prettier with the XQuery plugin, you're going to need node.

If you're using the npm CLI, then add the plugin by:

npm install --save-dev prettier prettier-plugin-xquery

Or if you're using yarn, then add the plugin by:

yarn add --dev prettier prettier-plugin-xquery

The prettier executable is now installed and ready for use:

npx prettier --plugin=prettier-plugin-xquery --write '**/*.xq*'

Add a .prettierrc.js to save the configuration

import prettierPluginXQuery from 'prettier-plugin-xquery';

/**
 * @type {import('prettier').Config}
 */
const config = {
	useTabs: true,
	printWidth: 120,
	plugins: [prettierPluginXQuery],
};

export default config;

Configuration

API Option CLI Option Default Description
printWidth --print-width 80 Same as in Prettier (see prettier docs).
tabWidth --tab-width 2 Same as in Prettier (see prettier docs).
singleQuote --single-quote false Same as in Prettier (see prettier docs).
useTabs --use-tabs false Same as in Prettier (see prettier docs).

Any of these can be added to your existing prettier configuration file. For example:

{
  "tabWidth": 4,
  "plugins": ["prettier-plugin-xquery"]
}

Or, they can be passed to prettier as arguments:

prettier --plugin=prettier-plugin-xquery --tab-width 4 --write '**/*.xq*'

Ignoring

A prettier-ignore comment marks code as ignored for formatting. Like this:

module namespace el = "http://www.elliat.nl";

declare function el:reverse (
  $a as xs:integer,
  $b as xs:integer,
  $c as xs:integer,
  $d as xs:integer
) {
  ($d, $c, $b, $a)
};

(: prettier-ignore :)
declare function el:swap (
  $a as xs:integer, $b as xs:integer,
  $c as xs:integer, $b as xs:integer
) {
  ($b, $a, $d, $c)
};

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/drrataplan/prettier-plugin-xquery.

This plugin is under development, the following features are planned:

  • Extensible parsers, for the different dialects of XQuery, like XQuery Update Facility, the ExistDB update syntax or the customizations in MarkLogic
  • Support for XQuery 4.0
  • General stability. Refer to list of known test failures for a report of current known failing tests.

License

The package is available as open source under the terms of the MIT License.

Credits

This project uses the rex parser generator to parse XQuery.

About

Prettier plugin for XQuery formatting

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •