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

mixin arguments can not be formatted #66

Open
ekfuhrmann opened this issue Feb 5, 2020 · 3 comments
Open

mixin arguments can not be formatted #66

ekfuhrmann opened this issue Feb 5, 2020 · 3 comments
Labels
type: enhancement Functionality that enhances existing features

Comments

@ekfuhrmann
Copy link

ekfuhrmann commented Feb 5, 2020

If I have the following formatted code:

+link({
  name: 'Solutions', 
  subnav: {
    sublinks: [
       {name: 'WISP', url: '#', icon:'wisp'},
       {name: 'Fiber', url: '#', icon:'fiber'},
       {name: 'MDU', url: '#', icon:'mdu'},
       {name: 'Voice', url: '#', icon:'voice'},
       {name: 'Cable', url: '#', icon:'cable'},
       {name: 'Enterprise', url: '#', icon:'enterprise'}
    ]
  }
})

It gets formatted to the following:

+link({ name: 'Solutions', subnav: { sublinks: [ {name: 'WISP', url: '#', icon:'wisp'}, {name: 'Fiber', url: '#', icon:'fiber'}, {name: 'MDU', url: '#', icon:'mdu'}, {name: 'Voice', url: '#', icon:'voice'}, {name: 'Cable', url: '#', icon:'cable'}, {name: 'Enterprise', url: '#', icon:'enterprise'} ] }})

Is there any possible way to prevent this reformatting from happening, as it makes parsing the information far more difficult?

@Shinigami92
Copy link
Member

Mh yeah, I knew this would come someday 😌
I definitely have to work on this problem

Could you get around this in the meantime in the following way?

- var nav = {
  name: 'Solutions', 
  subnav: {
    sublinks: [
       {name: 'WISP', url: '#', icon:'wisp'},
       {name: 'Fiber', url: '#', icon:'fiber'},
       {name: 'MDU', url: '#', icon:'mdu'},
       {name: 'Voice', url: '#', icon:'voice'},
       {name: 'Cable', url: '#', icon:'cable'},
       {name: 'Enterprise', url: '#', icon:'enterprise'}
    ]
  }
}
+link(nav)

It's tricky to implement this feature request, because it's multiline-javascript formatting within pug
And I have to take care of the indentation and other things

I may have time at the upcoming weekend

@Shinigami92 Shinigami92 self-assigned this Feb 5, 2020
@Shinigami92 Shinigami92 added the type: enhancement Functionality that enhances existing features label Feb 5, 2020
@ekfuhrmann
Copy link
Author

ekfuhrmann commented Feb 5, 2020

I figured this would be a complicated implementation, so I am totally happy with the - var workaround for the time being.

I wish I could help more with the implementation, but I unfortunately do not have much experience with creating linting rules (I'm guessing it's a fair amount of regex?), but I can certainly help test should you come up with anything.

Thanks for the response!


For anyone looking to use - var, you will need to use the following format for a multi-line var:

- 
  var nav = {
    name: 'Solutions', 
    subnav: {
      sublinks: [
         {name: 'WISP', url: '#', icon:'wisp'},
         {name: 'Fiber', url: '#', icon:'fiber'},
         {name: 'MDU', url: '#', icon:'mdu'},
         {name: 'Voice', url: '#', icon:'voice'},
         {name: 'Cable', url: '#', icon:'cable'},
         {name: 'Enterprise', url: '#', icon:'enterprise'}
      ]
    }
  }
+link(nav)

@Shinigami92
Copy link
Member

Uff... we have a huge problem here :/

plugin-pug/src/printer.ts

Lines 716 to 720 in 34f3a5d

let args: string | null = token.args;
if (args) {
args = args.trim();
args = args.replace(/\s\s+/g, ' ');
result += `(${args})`;

Here we have args and it is just a string
In the string there is a comma separated list of arguments. But I cant split it by , because if one argument in example json contains comma by it self, it breaks.

So I will ask the author of pugjs to change the lexer to output a string[] instead of a string
Same applies also to mixins

So sorry if this could take some time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Functionality that enhances existing features
Projects
None yet
Development

No branches or pull requests

2 participants