plugin-pug icon indicating copy to clipboard operation
plugin-pug copied to clipboard

Feature Request: Ability to disable warnings via code comments or global config rules

Open niftylettuce opened this issue 4 years ago • 4 comments

Request / Idea

This is a feature request to have the ability to disable warnings via code comments or global config rules.

Right now this section of code https://github.com/prettier/plugin-pug/blob/9e6620a4624261561aa966faaaea657804a74749/src/printer.ts#L1456-L1483 has no way of being disabled from outputting to console.

Similar to being able to ignore automatic formatting, it would be great to have (via comments or config, or both possibly), the ability to ignore warnings.

e.g. https://prettier.github.io/plugin-pug/guide/#usage highlights the ability to write //- prettier-ignore before a block of code to disable prettier from auto-formatting it

Input

❯ npx prettier app/views/layout.pug --write --loglevel error
[PugPrinter:start-pipeless-text]: The following expression could not be formatted correctly. This is likely a syntax error or an issue caused by the missing execution context. If you think this is a bug, please open a bug issue.
code: `window._types = {
  success: "#{ t('Success') }",
  error: "#{ t('Error') }",
  info: "#{ t('Info') }",
  warning: "#{ t('Warning') }",
  question: "#{ t('Question') }"
};
window._messages = !{json(flash(), null, null)};`
You used interpolated code in your pipeless script tag, so you may ignore this warning.
Found babel SyntaxError: Unexpected token, expected "," (8:32)
  6 |   question: "#{ t('Question') }"
  7 | };
> 8 | window._messages = !{json(flash(), null, null)};
    |                                ^
  9 |.

Expected Output

None

Additional Context

There is no ability that I've found so far as to disable warnings, or specific warnings related to specific blocks/lines of code.

cc @spence-s @shadowgate15

niftylettuce avatar Jan 04 '22 19:01 niftylettuce

Actually it appears that if I put a //- prettier-ignore above the block scripts that this code is nested in, it works. Thanks to @spence-s for the tip.

niftylettuce avatar Jan 04 '22 20:01 niftylettuce

@niftylettuce @shadowgate15 although we found a work around - I think this should probably be re-labelled/re-named because it is actually a bug.

//- prettier-ignore
block scripts
  //- flash messaging (with koa-better-flash and sweetalert2)
  script.
    window._types = {
      success: "#{ t('Success') }",
      error: "#{ t('Error') }",
      info: "#{ t('Info') }",
      warning: "#{ t('Warning') }",
      question: "#{ t('Question') }",
    };
    window._messages = !{json(flash(), null, null)};

the line that seems to cause the error is window._messages = !{json(flash(), null, null)}; because I believe that prettier tries to format it as javascript and doesn't properly handle the pug tokens, even though this is completely valid pug.

cc @Shinigami92

spence-s avatar Jan 04 '22 22:01 spence-s

Are you interested in creating a PR?

Shinigami92 avatar Jan 06 '22 19:01 Shinigami92

I'll probably work on it at some point but it might be a bit before I circle around to it.

shadowgate15 avatar Jan 06 '22 19:01 shadowgate15