Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor options #235

Merged
merged 20 commits into from Mar 8, 2021
Merged

Refactor options #235

merged 20 commits into from Mar 8, 2021

Commits on Mar 7, 2021

  1. Copy the full SHA
    cfc42ad View commit details
    Browse the repository at this point in the history
  2. Collect external option interfaces in src/options.ts: SchemaOptions, …

    …CreateNodeOptions, ToJSOptions
    eemeli committed Mar 7, 2021
    Copy the full SHA
    ebd65fe View commit details
    Browse the repository at this point in the history
  3. Drop the keepCstNodes and keepNodeTypes options

    BREAKING CHANGE: The earlier parser change has meant that information is
    retained differently during composition. Effectively, the values of
    these options are no longer used, so they should be explicitly dropped
    from the options interfaces to make that clear. The behaviour now is as
    if `{ keepCstNodes: false, keepNodeTypes: true }` is always set.
    
    This may require some API changes for CST users, as errors also no
    longer provide a reference to the source CST node, just the original
    line position. To match an error to a node, you should search for a node
    that includes the error position in its range.
    
    To discard node type information from the tree, use a visitor:
    
        import { isNode, parseDocument, visit } from 'yaml'
    
        const doc = parseDocument('{ foo: "bar" }')
        visit(doc, (key, node) => {
          if (isNode(node)) delete node.type
        })
    
        String(doc) === 'foo: bar\n'
    eemeli committed Mar 7, 2021
    Copy the full SHA
    3a984de View commit details
    Browse the repository at this point in the history
  4. Copy the full SHA
    44d3593 View commit details
    Browse the repository at this point in the history
  5. Use type rather than interface for options

    This is a workaround for microsoft/TypeScript#15300
    eemeli committed Mar 7, 2021
    Copy the full SHA
    b64bc4d View commit details
    Browse the repository at this point in the history
  6. Drop mapAsMap from DocumentOptions

    BREAKING CHANGE: The option now needs to be given to the document's
    toJS() method, rather than being also available on the document
    constructor and in YAML.defaultOptions. The behaviour of parse() is
    unaffected.
    
    ```diff
     import { parseDocument } from 'yaml'
    
    -const doc = parseDocument('foo: bar', { mapAsMap: true })
    -const js = doc.toJS()
    +const doc = parseDocument('foo: bar')
    +const js = doc.toJS({ mapAsMap: true })
    ```
    eemeli committed Mar 7, 2021
    Copy the full SHA
    dfcc35b View commit details
    Browse the repository at this point in the history
  7. Move maxAliasCount from DocumentOptions to ToJSOptions

    BREAKING CHANGE: The option now needs to be given to the document's
    toJS() method, rather than being also available on the document
    constructor and in YAML.defaultOptions. The behaviour of parse() is
    unaffected.
    
    ```diff
     import { parseDocument } from 'yaml'
    
    -const doc = parseDocument('foo: bar', { maxAliasCount: -1 })
    -const js = doc.toJS()
    +const doc = parseDocument('foo: bar')
    +const js = doc.toJS({ maxAliasCount: -1 })
    ```
    eemeli committed Mar 7, 2021
    Copy the full SHA
    d16d170 View commit details
    Browse the repository at this point in the history
  8. Drop indent, indentSeq & simpleKeys from DocumentOptions

    BREAKING CHANGE: These options now need to be given to the document's
    toString() method, rather than being also available on the document
    constructor and in YAML.defaultOptions. The behaviour of stringify()
    is unaffected.
    
    ```diff
     import { parseDocument } from 'yaml'
    
    -const doc = parseDocument('foo: bar', { indent: 4, indentSeq: false })
    -const str = doc.toString()
    +const doc = parseDocument('foo: bar')
    +const str = doc.toString({ indent: 4, indentSeq: false })
    ```
    eemeli committed Mar 7, 2021
    Copy the full SHA
    09a2175 View commit details
    Browse the repository at this point in the history
  9. Refactor doc.setSchema(); drop Document.defaults

    BREAKING CHANGE: The new API of doc.setSchema(), now requiring an
    explicit version as well as supporting all Schema options. This is
    required to reduce the dependency on a mutating doc.options object.
    
    -doc.setSchema('json')
    +doc.setSchema('1.2', { schema: 'json' })
    
    -doc.options.merge = false
    -doc.setSchema('1.1')
    +doc.setSchema('1.1', { merge: false })
    
    As a side effect of these changes, the Document.defaults object is
    removed, along with the doc.getDefaults() method. The version-specific
    schema options now need to be set explicitly in function arguments.
    eemeli committed Mar 7, 2021
    Copy the full SHA
    b76e620 View commit details
    Browse the repository at this point in the history
  10. Move BigInt option from scalarOptions to ParseOptions

    BREAKING CHANGE: Rather than setting `YAML.scalarOptions.int.asBigInt`,
    users should use the `intAsBigInt` option given to parse functions and
    constructors.
    eemeli committed Mar 7, 2021
    Copy the full SHA
    fbe193e View commit details
    Browse the repository at this point in the history
  11. Move falseStr, nullStr & trueStr options from scalarOptions to ParseO…

    …ptions
    
    BREAKING CHANGE: Rather than setting these via `scalarOptions.bool`
    and `scalarOptions.null`, users should pass them as options given
    to the stringify() function and the doc.toString() method.
    eemeli committed Mar 7, 2021
    Copy the full SHA
    37e6688 View commit details
    Browse the repository at this point in the history
  12. Copy the full SHA
    bd3bec5 View commit details
    Browse the repository at this point in the history
  13. Move lineWidth & minContentWidth options from scalarOptions to ParseO…

    …ptions
    
    BREAKING CHANGE: Rather than setting these via `scalarOptions.str.fold`,
    users should pass them as options given to the stringify() function and
    the doc.toString() method.
    eemeli committed Mar 7, 2021
    Copy the full SHA
    3ccdb13 View commit details
    Browse the repository at this point in the history
  14. Drop special options for !!binary

    BREAKING CHANGE: The line width now follows the general `lineWidth`
    value and takes indent level into account. `!!binary` nodes that do
    not explicitly declare a `type` will use `BLOCK_LITERAL`. To set the
    type of such nodes, use a visitor:
    
        import { visit } from 'yaml'
    
        visit(doc, {
          Scalar(key, value) {
            if (value.tag === 'tag:yaml.org,2002:binary')
              value.type = 'QUOTE_DOUBLE'
          }
        })
    eemeli committed Mar 7, 2021
    Copy the full SHA
    5f1df49 View commit details
    Browse the repository at this point in the history
  15. Move double-quoted string options from scalarOptions to ParseOptions

    The options are also renamed:
    - doubleQuoted.jsonEncoding -> doubleQuotedAsJSON
    - doubleQuoted.minMultiLineLength -> doubleQuotedMinMultiLineLength
    
    BREAKING CHANGE: Rather than setting these via
    `scalarOptions.str.doubleQuoted`, users should pass them as options
    given to the stringify() function and the doc.toString() method.
    eemeli committed Mar 7, 2021
    Copy the full SHA
    21d4060 View commit details
    Browse the repository at this point in the history
  16. Move remaining string options from scalarOptions to ParseOptions

    The `defaultKeyType` option now accepts (and defaults to) `null`, with
    which value the `defaultStringType` also controls implicit key types.
    
    Some of the options are renamed:
    - defaultType -> defaultStringType
    - defaultKeyType -> defaultKeyType (unchanged)
    - defaultQuoteSingle -> singleQuote
    
    BREAKING CHANGE: Rather than setting these via `scalarOptions.str`,
    users should pass them as options given to the stringify() function
    and the doc.toString() method.
    eemeli committed Mar 7, 2021
    Copy the full SHA
    67de2e1 View commit details
    Browse the repository at this point in the history
  17. Copy the full SHA
    f281157 View commit details
    Browse the repository at this point in the history
  18. Cleanup: Drop scalarOptions (now empty) & options from tag interface

    Additionally, un-document the YAML.defaultOptions export.
    
    BREAKING CHANGE: These are no longer used, as their functionality has
    been moved to ParseOptions and ToStringOptions.
    eemeli committed Mar 7, 2021
    Copy the full SHA
    24383fc View commit details
    Browse the repository at this point in the history
  19. Copy the full SHA
    4e8d437 View commit details
    Browse the repository at this point in the history
  20. Replace doc.directivesEndMarker with doc.directives.marker & directiv…

    …es option
    
    As cleanup, also remove the now-obsolete doc.version value
    
    BREAKING CHANGE: To now detect if a parsed document included an explicit
    doc-start marker, use `doc.directives.marker === true`. To include the
    marker when stringifying, either set that value to true, or use
    `doc.toString({ directives: true )`. To explicitly leave out directives
    and the doc-start marker from the output, use
    `doc.toString({ directives: false )`.
    eemeli committed Mar 7, 2021
    Copy the full SHA
    7f76212 View commit details
    Browse the repository at this point in the history