Skip to content

Keep trailing-comma for var function#13402

Merged
sosukesuzuki merged 4 commits intoprettier:nextfrom
sosukesuzuki:tr-comma
Aug 30, 2022
Merged

Keep trailing-comma for var function#13402
sosukesuzuki merged 4 commits intoprettier:nextfrom
sosukesuzuki:tr-comma

Conversation

@sosukesuzuki
Copy link
Copy Markdown
Contributor

@sosukesuzuki sosukesuzuki commented Aug 30, 2022

Description

Fixes #13202

Checklist

  • I’ve added tests to confirm my change works.
  • (If changing the API or CLI) I’ve documented the changes I’ve made (in the docs/ directory).
  • (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I’ve read the contributing guidelines.

Try the playground for this PR

Comment on lines +920 to +927
const hasComma = () =>
Boolean(
child.source &&
options.originalText
.slice(locStart(child), locStart(node.close))
.trimEnd()
.endsWith(",")
);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ideally we need to use getNextNonSpaceNonCommentCharacterIndexWithStartIndex like this:

                const hasComma = () => {
                  const index =
                    child &&
                    getNextNonSpaceNonCommentCharacterIndexWithStartIndex(
                      options.originalText,
                      locEnd(child)
                    );
                  return index && options.originalText[index] === ",";
                };

But, locEnd for --baz in var(--baz,) returns unexpected value

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Because the location info is like a mess in this parser.

Copy link
Copy Markdown
Member

@fisker fisker Aug 30, 2022

Choose a reason for hiding this comment

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

#13321 is also blocked by this reason.

@sosukesuzuki sosukesuzuki merged commit 40af3ed into prettier:next Aug 30, 2022
@sosukesuzuki sosukesuzuki deleted the tr-comma branch August 30, 2022 15:59
medikoo pushed a commit to medikoo/prettier-elastic that referenced this pull request Jan 31, 2024
* Keep trailing-comma for last el

* Make hasComma function

* Fix tests

* Add changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants