bazelbuild / bazelbuild/rules_closure

Impossible advice how to suppress error

Open
#229 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
159
Forks
111
PR merge metrics
No merged PRs in 30d

Description

I'm currently in progress of adding "compile time file renaming" to my application which should work similar to `goo.getCssName` (e.g. `my/path/foo.bar` will be replaced with `/static/`).
The best solution would be to write a compiler pass for it, but that may not be too straightforward (I do have an idea how to improve this experience I will share later), so I started by generating a renaming map and doing the lookup at runtime. The code looks similar to this:

```js
const StringConst = goog.require('goog.string.Const');

/** @const {!Object} */
const files = {
'my/path/foo.bar': '/static/'
};

/**
* @param {string} name
* @return {!StringConst}
*/
function file(name) {
if (name in files) {
return StringConst.from(files[name]);
}
return StringConst.from(name);
}
```
When compiling this, I get the following error:
```
ERROR: .../BUILD.bazel:53:1: Compiling 876 JavaScript files to .../application.client_main.js failed (Exit 1).
.../foo.js:45: ERROR - Function argument is not a string literal or a constant assigned from a string literal or a concatenation of these.
return StringConst.from(this.files_[name]);
^
ProTip: "JSC_CONSTANT_NOT_STRING_LITERAL_ERROR" can be added to the `suppress` attribute of:
//rule:name
```
However, if I do add "JSC_CONSTANT_NOT_STRING_LITERAL_ERROR" to the suppress attribute, closure_js_library complains that is does not know this suppress.
```
ERROR: .../BUILD.bazel:13:1: Checking 5 JS files in //rule:name failed (Exit 1).
ERROR: Bad --suppress value: JSC_CONSTANT_NOT_STRING_LITERAL_ERROR
```

I know that the error is there for a very good reason and I also think it may be a good thing that this error is not suppressible (there is a workaround), but I don't think the compiler should give you advice how to suppress this error and then complain that it doesn't know it.

Contributor guide

Open the contributing guide

Research direction

Start with the BUILD.bazel entries and the closure_js_library rule involved in the reported compilation, then trace how the Closure Compiler diagnostic and its ProTip suppress value are passed through. Reproduce the mismatch using the shown StringConst.from lookup and verify that the compiler advice matches the suppress values accepted by the rule, or is removed when suppression is unsupported.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
build-system, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.