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

Add pug aliased options #106

Merged
merged 15 commits into from
Sep 20, 2020
Merged

Add pug aliased options #106

merged 15 commits into from
Sep 20, 2020

Conversation

Shinigami92
Copy link
Member

closes #105

@Shinigami92 Shinigami92 self-assigned this Sep 14, 2020
@Shinigami92 Shinigami92 added framework: Vue Related to the framework Vue type: feature request Functionality that introduces a new feature labels Sep 14, 2020
@SkyaTura
Copy link
Collaborator

Thanks for the fast response

@Shinigami92
Copy link
Member Author

Shinigami92 commented Sep 14, 2020

@SkyaTura Can you provide me a sample vue file for bracketSpacing option that contains js and pug code?

My project is heavily TTD :)

@SkyaTura
Copy link
Collaborator

My pain is actually with singleQuote:

<template lang="pug">
  // intended not to be single quoted
  ComponentBar(
    foo="bar"
    bar="baz"
  )
</template>

<script>
  export default {
    name: 'FooComponent' // intended to be single quote
  }
</script>

@Shinigami92
Copy link
Member Author

Shinigami92 commented Sep 14, 2020

Good that I asked 😁
doesn't work as expected...
Need to work further


OH WOW! I learned an interesting fact about prettier options :D

@SkyaTura
Copy link
Collaborator

OH WOW! I learned an interesting fact about prettier options :D

Could you mind to share what you've learn? I'm curious 😂

@Shinigami92
Copy link
Member Author

@SkyaTura Sure :)

Two things:

  1. If you create aliases like pug* you also have to define the default values for this new option, otherwise it will not be taken at all
  2. It's not really possible to have an option that has a default value of null or undefined when having a value like int
    I'm currently struggling with prettier's default values, my pug* default values and incremental developing without breaking changes

@SkyaTura
Copy link
Collaborator

Isn't possible to get access to the actual config declaration? Before prettier defaults been applied, so that you could check if there are pug* been set?

Or make pug* to be strings, so, if they are set you ignore the prettier's default?

Just wondering here, I don't have any knowledge about prettier plugins yet 😰

@Shinigami92
Copy link
Member Author

Nope, nothing of this is possible :/

@Shinigami92
Copy link
Member Author

Worked on it almost exactly 3 hours 😁
Seems to work

I'm thinking to release a beta 1.6.0-beta.1

And I also need to update changelog

@Shinigami92
Copy link
Member Author

@SkyaTura I released 1.6.0-issue-105.1 for you
Please test the hell out of it 😈

@Shinigami92 Shinigami92 marked this pull request as ready for review September 14, 2020 16:22
@SkyaTura
Copy link
Collaborator

Sure I will

@SkyaTura
Copy link
Collaborator

SkyaTura commented Sep 14, 2020

Edit

TL;DR

It's working perfectly!!! 🎉

For the records

I was rush, and kinda newbie 😅

It was a problem with my package.json, for some reason I don't understand, the project was installing prettier 1.x instead of the latest version (as defined as a dependency of my module).

Simply removing node_modules and package-lock.json, installing again, and everything works fine.


It's ~kinda~ working 😰

I don't know if it's related to this project or I am doing something wrong, but I have this setup:

  • A project where I define my team patterns as a eslint-config
  • I use prettier plugin to load prettier in eslint
  • I use the rules to override prettier's settings

If I run locally, on the module, as a test, it goes well, detect errors and fixes them as well.
If I run remotely, on a project, nothing happens.

The curious thing about it: using @latest works well, using the branch you've created, none of the rules are recognized.

Bonus: this happens both on eslint and vim plugin

So, basically, this is my files:

module/prettier.js

module.exports = {
  extends: ['plugin:prettier/recommended'],
  plugins: ['prettier'],
  rules: {
    'prettier/prettier': [
      'error',
      {
        trailingComma: 'es5',
        printWidth: 80,
        tabWidth: 2,
        semi: false,
        singleQuote: true,
        endOfLine: 'lf',
        plugins: ['@prettier/plugin-pug'],
        pugSingleQuote: false,
        attributeSeparator: 'as-needed',
        closingBracketPosition: 'new-line',
        commentPreserveSpaces: 'trim-all',
      },
      {
        usePrettierrc: false,
      },
    ],
}

project/.eslintrc.js

module.exports = {
  root: true,
  extends: [
    '@myOrg/eslint-config/prettier',
  ],
  ignorePatterns: ['node_modules', 'lib', 'dist', '.thalamus', '.nuxt'],
  rules: {},
}

If this isn't related, sorry :P it wasn't

@Shinigami92
Copy link
Member Author

I need to fix a little thingy, but this will not affect you :)
Just the default assumption of non boolean default values needs to be changed

Cause currently it's not possible to define { "printWidth": xy, "pugPrintWidth": 80 }, this would always take xy for everything

@Shinigami92
Copy link
Member Author

Shinigami92 commented Sep 15, 2020

Dafuq?
Setting "pugSingleQuote": true results in Invalid --pug-single-quote value. Expected null, false or "", but received true. 👀
I thing this is a bug in prettier 😲 referencing prettier/prettier#9204

And I also have a bug when using

{
  "singleQuote": true,
  "pugSingleQuote": false
}

This produces e.g. div(:class="{ "pt-2": !dense }") instead of div(:class="{ 'pt-2': !dense }")

@Shinigami92 Shinigami92 merged commit f69674b into master Sep 20, 2020
@Shinigami92 Shinigami92 deleted the issue-105 branch September 20, 2020 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
framework: Vue Related to the framework Vue type: feature request Functionality that introduces a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New rule names of aliases for prettier defaults
2 participants