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

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

Open
niftylettuce opened this issue Jan 4, 2022 · 4 comments
Labels
help wanted We are looking for community help type: bug Functionality that does not work as intended/expected

Comments

@niftylettuce
Copy link

niftylettuce commented Jan 4, 2022

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

plugin-pug/src/printer.ts

Lines 1456 to 1483 in 9e6620a

// Continue without formatting the content
const warningContext: string[] = [
'[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.'
];
warningContext.push(`\ncode: \`${rawText.trim()}\``);
// TODO: If other token types occur use `if (usedInterpolatedCode)`
warningContext.push(
'\nYou used interpolated code in your pipeless script tag, so you may ignore this warning.'
);
if (types.isNativeError(error)) {
warningContext.push(`\nFound ${parser} ${error.name}: ${error.message}.`);
} else {
logger.debug('typeof error:', typeof error);
warningContext.push(`\nUnexpected error for parser ${parser}.`, error as string);
}
logger.warn(...warningContext);
result = rawText;
}
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
Copy link
Author

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.

@spence-s
Copy link

spence-s commented Jan 4, 2022

@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

@Shinigami92
Copy link
Member

Are you interested in creating a PR?

@Shinigami92 Shinigami92 added help wanted We are looking for community help type: bug Functionality that does not work as intended/expected labels Jan 6, 2022
@shadowgate15
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted We are looking for community help type: bug Functionality that does not work as intended/expected
Projects
None yet
Development

No branches or pull requests

4 participants