OyvindSabo / gremlint

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

Make sure closing parenthesis, commas and punctuation are considered when checking if a line is too long #44

Open OyvindSabo opened 4 years ago

OyvindSabo commented 4 years ago

Currently, for nested steps, lines can sometimes be longer than the specified maximum line length because the function which checks the length does not know how deeply nested the steps are. Furthermore, commas or punctuation at the end of lines are not taken into consideration.

An example where closing parentheses are ignored:

Consider the following query formatted with a max line length of 66:

g.V().hasLabel('person').groupCount().by(values('age').choose(is(lt(28)),constant('young'),choose(is(lt(30)), constant('old'), constant('very old'))))

It is formatted like this (67 characters wide):

g.V().
  hasLabel('person').
  groupCount().
    by(
      values('age').
      choose(
        is(lt(28)),
        constant('young'),
        choose(is(lt(30)), constant('old'), constant('very old'))))

It is expected to be formatted like this:

g.V().
  hasLabel('person').
  groupCount().
    by(
      values('age').
      choose(
        is(lt(28)),
        constant('young'),
        choose(
          is(lt(30)),
          constant('old'),
          constant('very old'))))

A test case for this should be added to gremlint/src/formatQuery/__tests__/maxLineLength.test.ts.

An example where punctuation at the end of the line is ignored:

Consider the following query formatted with a max line length of 45:

g.V().hasLabel('person').where(outE('created').count().is(P.gte(2))).count()

It is formatted like this (46 characters wide):

g.V().
  hasLabel('person').
  where(outE('created').count().is(P.gte(2))).
  count()

It is expected to be formatted like this:

g.V().
  hasLabel('person').
  where(
    outE('created').count().is(P.gte(2))).
  count()

There is currently a commented out test for this in gremlint/src/formatQuery/__tests__/maxLineLength.test.ts which should be uncommented upon completion of this task.

An example where comma at the end of the line is ignored

Consider the following query formatted with a max line length of 22:

g.V().choose(hasLabel('person'), out('created'), identity()).values('name')

It is formatted like this (23 characters wide):

g.V().
  choose(
    hasLabel('person'),
    out('created'),
    identity()).
  values('name')

It is expected to be formatted like this:

g.V().
  choose(
    hasLabel(
      'person'),
    out('created'),
    identity()).
  values('name')

A test case for this should be added to gremlint/src/formatQuery/__tests__/maxLineLength.test.ts.