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

Align front-matter linter with prettier #27828

Merged
merged 1 commit into from
Jul 7, 2023

Conversation

OnkarRuikar
Copy link
Contributor

@OnkarRuikar OnkarRuikar commented Jul 7, 2023

Summary

The front-matter linter and Prettier are correcting each other and are causing some friction.

Problem

Formatters available in YAML space output exactly what is told, so the output remains same no matter the input. But Prettier is an intelligent formatter: it's output changes based on certain conditions.

In following examples YAML parser and Prettier have been told to prefer double quotes to enclose values.

# example 1
title: "TypeError: can't assign to property 'x' on 'y': not an object"

# in this case, both agree on the same thing
title: "TypeError: can't assign to property 'x' on 'y': not an object"

# example 2
title: "TypeError: can't assign to property \"x\" on \"y\": not an object"

# YAML parser yields the same string as output
title: "TypeError: can't assign to property \"x\" on \"y\": not an object"

# Prettier encloses string with double quoted words in single quotes
title: 'TypeError: can''t assign to property "x" on "y": not an object'

Solution

It's easy to simply run YAML formatter's output through Prettier before writing to file, than making the YAML formatter behave like Prettier:

let yml = YAML.dump(fmObject);
yml = await prettier.format(yml, { parser: "yaml" });
// write `yml` to file

Note: apart from above change following changes have been made:

  • updated and added unit tests yarn test:front-matter-linter

  • ran fix:js on all the .js files in the repo to confrom to the new Prettier v3.0.0

  • The *.md files need to be committed before this PR are in Prettier style front-matter #27830

Testing

  • Committed above code changes
  • Commented /files/en-us/web/javascript/**/*.md line in .prettierignore file
  • Ran fix:fm then committed the changes
  • Ran 'fix:md' saw the diff
    Prettier didn't contradict front-matter linter.

@OnkarRuikar OnkarRuikar requested a review from a team as a code owner July 7, 2023 14:34
@OnkarRuikar OnkarRuikar requested review from bsmth and removed request for a team July 7, 2023 14:34
@bsmth
Copy link
Member

bsmth commented Jul 7, 2023

Thanks Onkar 👍 - just confirming I've seen this, I'll try getting to it, but it may not be before Monday if that's okay.

Copy link
Collaborator

@queengooborg queengooborg left a comment

Choose a reason for hiding this comment

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

These changes look good, but the test files seem a little backwards. Since this fixes a pressing issue with formatting though, I'm not going to worry about the tests and get this merged ASAP.

@queengooborg queengooborg merged commit ab66836 into mdn:main Jul 7, 2023
4 of 5 checks passed
@OnkarRuikar OnkarRuikar deleted the update_fm_linter branch July 8, 2023 04:57
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.

None yet

3 participants