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

What is the annotation to hide warning from unreachable code? #4113

Closed
juj opened this issue Aug 29, 2023 · 5 comments
Closed

What is the annotation to hide warning from unreachable code? #4113

juj opened this issue Aug 29, 2023 · 5 comments

Comments

@juj
Copy link

juj commented Aug 29, 2023

It looks like the documentation page does not document the mechanism to mute a warning that stems from unreachable code?

I am getting

building:ERROR: C:/Users/jukkaj/AppData/Local/Temp/emscripten_temp_ey7njtln/hello_world.js:18416:51: WARNING - [JSC_UNREACHABLE_CODE] unreachable code
  18416|       if (GL.currentContext.version >= 2 && false) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.

where the unreachable code is intentional. I would like to annotate the whole function to not warn about this, but the doc page https://github.com/google/closure-compiler/wiki/Warnings does not have any mention about "unreachable".

Is this a case of documentation missing a spot, or is this feature missing?

@juj
Copy link
Author

juj commented Aug 29, 2023

I see there is this in code:

https://github.com/google/closure-compiler/blob/43850b5db8bd10fcea312a174e469da6343110a4/src/com/google/javascript/jscomp/CheckUnreachableCode.java#L32C1-L34

  static final DiagnosticType UNREACHABLE_CODE = DiagnosticType.warning(
      "JSC_UNREACHABLE_CODE", "unreachable code");

and running node cli.js --help gives

Available Error Groups: accessControls, checkPrototypalTypes,
    checkRegExp, checkTypes, checkVars, conformanceViolations, const,
    constantProperty, deprecated, deprecatedAnnotations, duplicateMessage,
    es5Strict, externsValidation, functionParams, globalThis, invalidCasts,
    lintVarDeclarations, misplacedTypeAnnotation, missingOverride,
    missingPolyfill, missingProperties, missingProvide, missingRequire,
    missingReturn, missingSourcesWarnings, moduleLoad, moduleImport,
    msgDescriptions, nonStandardJsDocs, partialAlias, polymer,
    reportUnknownTypes, strictCheckTypes, strictMissingProperties,
    strictModuleDepCheck, strictPrimitiveOperators, suspiciousCode,
    typeInvalidation, undefinedVars, underscore, unknownDefines,
    unusedLocalVariables, unusedPrivateMembers, uselessCode,
    untranspilableFeatures,visibility

but I don't know how to translate that code JSC_UNREACHABLE_CODE into the correct error group? Maybe that is supposed to be uselessCode?

@lauraharker
Copy link
Contributor

@juj
Copy link
Author

juj commented Aug 29, 2023

Great, thanks! Btw, I wonder if it might make sense to directly print it in the warning/error that appears, like GCC and Clang do?

E.g. currently the warning prints WARNING - [JSC_UNREACHABLE_CODE] unreachable code.

Why not print WARNING - [uselessCode] unreachable code?

@juj
Copy link
Author

juj commented Aug 29, 2023

Or alternatively, would it be possible to support @suppress{JSC_UNREACHABLE_CODE} in addition to @suppress{uselessCode}?

The two different warning code namespaces makes me confused, wondering why both need to exist, and why I as user need to know to map between the two. Would seem to be easier to just present and use one code namespace?

@lauraharker
Copy link
Contributor

I agree it's confusing. We talked as a team earlier this year about both possibilities you've suggested but I don't see that we ever filed an issue to track it, so created #4114.

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

No branches or pull requests

2 participants