estools / escodegen

ECMAScript code generator
BSD 2-Clause "Simplified" License
2.64k stars 334 forks source link

make array generation configurable (fixes #260) #442

Open d-rk opened 3 years ago

d-rk commented 3 years ago

Hey,

this PR makes the array generation configurable (fixes #260). it introduces three new configuration parameters:

format: {
  arrays: {
    # after 'maxElementsPerLine' elements a newline will be inserted
    maxElementsPerLine: 1,

    # if the line would exceed `maxLineWidth`, a newline is inserted before the element
    maxLineWidth: 80

    # if an array does not fit into a single line, but the first element should directly follow
    # the opening bracket of the array without linebreak, set this to true
    multilineArrayStartsInline: false,
  }
}

The chosen defaults will only change the generation of arrays (compared to current master branch) if maxLineWidth is exceeded.