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

BREAKING(yaml): rename StringifyOptions.noRefs to StringifyOptions.useAnchors #5288

Merged
merged 6 commits into from
Jul 5, 2024

Conversation

iuioiua
Copy link
Collaborator

@iuioiua iuioiua commented Jul 4, 2024

What's changed

The ParseOptions.noRefs option has been renamed to ParseOptions.useAnchors. As a result, the polarity of the option has been swapped. In other words, true behavior has been changed to false behavior, and visa-versa. This only affects users who currently use ParseOptions.noRefs.

Motivation

This change makes the option far easier to understand by avoiding a negative-tensed name.

Migration guide

Use ParseOptions.useAnchors instead of ParseOptions.noRefs and swap the polarity of the option.

import { parse } from "@std/yaml/parse";

const yamlString = `fruits:
  - Apple
  - Banana
  - Cherry`;

- parse(yamlString, { noRefs: false });
+ parse(yamlString, { useAnchors: true });

Related

Closes #5124

@iuioiua iuioiua requested a review from kt3k as a code owner July 4, 2024 00:20
@github-actions github-actions bot added the yaml label Jul 4, 2024
Copy link

codecov bot commented Jul 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.80%. Comparing base (fcc59f2) to head (b5ce607).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5288   +/-   ##
=======================================
  Coverage   95.80%   95.80%           
=======================================
  Files         458      458           
  Lines       37852    37852           
  Branches     5562     5562           
=======================================
  Hits        36264    36264           
  Misses       1548     1548           
  Partials       40       40           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kt3k
Copy link
Member

kt3k commented Jul 4, 2024

I tested noRefs option, but it doesn't seem working in std/yaml.

import { stringify } from "./yaml/mod.ts";
import * as yaml from "npm:js-yaml";

const a = {
  foo: {
    foo: {
      foo: {
      },
    },
  },
};
console.log(stringify([a, a], { noRefs: false }));
console.log(stringify([a, a], { noRefs: true }));
console.log(yaml.dump([a, a], { noRefs: false }));
console.log(yaml.dump([a, a], { noRefs: true }));

This prints:

- foo:
    foo:
      foo: {}
- foo:
    foo:
      foo: {}

- foo:
    foo:
      foo: {}
- foo:
    foo:
      foo: {}

- &ref_0
  foo:
    foo:
      foo: {}
- *ref_0

- foo:
    foo:
      foo: {}
- foo:
    foo:
      foo: {}

I suggest we should rather remove this option. What do you think?

(In my opinion, reference (alias) is not well understood feature of yaml. I think people would want to avoid them by default. The current behavior doesn't create reference (alias), and it is probably aligned to most users' expectation.)

@iuioiua
Copy link
Collaborator Author

iuioiua commented Jul 4, 2024

Oh, yes, let's remove then.

@iuioiua iuioiua closed this Jul 4, 2024
@iuioiua iuioiua deleted the yaml-StringifyOptions.createRefs branch July 4, 2024 05:20
@kt3k
Copy link
Member

kt3k commented Jul 4, 2024

Ah, wait. The feature seems working with 0.224.3, but it's gone in 1.0.0-rc.1. It seems to get broken somewhere between 0.224.3 - 1.0.0-rc.1

@kt3k kt3k restored the yaml-StringifyOptions.createRefs branch July 4, 2024 05:31
@kt3k kt3k reopened this Jul 4, 2024
@kt3k
Copy link
Member

kt3k commented Jul 4, 2024

How about useAnchors instead? 'reference' is not an official yaml term for it. Also 'create' sounds a bit strange to me. It reduces the duplicate occurrence of the same objects, instead of creating something

@iuioiua
Copy link
Collaborator Author

iuioiua commented Jul 4, 2024

SGTM

@iuioiua iuioiua changed the title BREAKING(yaml): rename StringifyOptions.noRefs to StringifyOptions.createRefs BREAKING(yaml): rename StringifyOptions.noRefs to StringifyOptions. useAnchors Jul 5, 2024
@iuioiua iuioiua changed the title BREAKING(yaml): rename StringifyOptions.noRefs to StringifyOptions. useAnchors BREAKING(yaml): rename StringifyOptions.noRefs to StringifyOptions.useAnchors Jul 5, 2024
Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@iuioiua iuioiua merged commit b927e8c into main Jul 5, 2024
13 checks passed
@iuioiua iuioiua deleted the yaml-StringifyOptions.createRefs branch July 5, 2024 05:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

yaml: Rename negative property names in options
2 participants