OyvindSabo / gremlint

Linter/Code formatter for Gremlin
https://gremlint.com
Apache License 2.0
11 stars 6 forks source link

It should not be necessary to pass a config to the formatQuery function #63

Closed OyvindSabo closed 3 years ago

OyvindSabo commented 3 years ago

Consider the following example

import { formatQuery } from 'gremlint';

const unformattedQuery = `g.V().has('person', 'name', 'marko').shortestPath().
with(ShortestPath.target, __.has('name', 'josh')).with(ShortestPath.distance,
'weight')`;

const formattedQuery = formatQuery(unformattedQuery, {
  indentation: 0,
  maxLineLength: 80,
  shouldPlaceDotsAfterLineBreaks: false,
});

console.log(formattedQuery);

Even if we only want the default config, we still need to pass it as an argument. The following will give a TypeScript error:

import { formatQuery } from 'gremlint';

const unformattedQuery = `g.V().has('person', 'name', 'marko').shortestPath().
with(ShortestPath.target, __.has('name', 'josh')).with(ShortestPath.distance,
'weight')`;

const formattedQuery = formatQuery(unformattedQuery, {});

console.log(formattedQuery);

And the following will give a type error:

import { formatQuery } from 'gremlint';

const unformattedQuery = `g.V().has('person', 'name', 'marko').shortestPath().
with(ShortestPath.target, __.has('name', 'josh')).with(ShortestPath.distance,
'weight')`;

const formattedQuery = formatQuery(unformattedQuery);

console.log(formattedQuery);

All of these approaches should be possible.

This was less of a concern when formatQuery was only used by the gremlint.com website, but now that Gremlint is exposed as a library, it should be a bit more developer friendly.