🏗 Lint: isExperimentOn must be passed an explicit string#16688
🏗 Lint: isExperimentOn must be passed an explicit string#16688jridgewell merged 2 commits intoampproject:masterfrom
Conversation
|
|
||
| module.exports = function(context) { | ||
| const isExperimentOn = 'CallExpression[callee.name=isExperimentOn]'; | ||
| const message = 'isExperimentOn must be passed an explicit string'; |
There was a problem hiding this comment.
Shouldn't message contain instructions for the use of /*OK*/?
There was a problem hiding this comment.
The only OK usages are AMP.isExperimentOn and isExperimentOn's own tests, because the caller themselves will have a 'amp-experiment' string passed to it (so it's already grepable).
|
Alternatively, can we extract all experiment names as shared constants to one single file. It shouldn't increase extension sizes (actually maybe even reduce the sizes), as closure compiler would be able to remove the unused ones. Linter rules might still be helpful to make sure all isExperimentOn() is called against a constant variable, but not a raw string. |
The root cause of ampproject#16671 (from ampproject#16528) is difficutly grepping for used experiment flags. So, make them very grepable. ```js // BAD const EXP = 'experiment-name'; isExperimentOn(win, EXP); // GOOD isExperimentOn(win, 'experiment-name');
1da1fa8 to
b1d401e
Compare
Codecov Report
@@ Coverage Diff @@
## master #16688 +/- ##
==========================================
+ Coverage 77.17% 78.12% +0.94%
==========================================
Files 552 553 +1
Lines 40279 40325 +46
==========================================
+ Hits 31087 31504 +417
+ Misses 9192 8821 -371
Continue to review full report at Codecov.
|
The root cause of #16671 (from #16528) is difficutly grepping for used experiment flags.
So, make them very grepable.