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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃彈 Lint: isExperimentOn must be passed an explicit string #16688

Merged
merged 2 commits into from Jul 12, 2018

Conversation

jridgewell
Copy link
Contributor

The root cause of #16671 (from #16528) is difficutly grepping for used experiment flags.

So, make them very grepable.

// BAD
const EXP = 'experiment-name';
isExperimentOn(win, EXP);

// GOOD
isExperimentOn(win, 'experiment-name');


module.exports = function(context) {
const isExperimentOn = 'CallExpression[callee.name=isExperimentOn]';
const message = 'isExperimentOn must be passed an explicit string';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't message contain instructions for the use of /*OK*/?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link

@dreamofabear dreamofabear left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for improving this.

@lannka
Copy link
Contributor

lannka commented Jul 12, 2018

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');
@codecov-io
Copy link

Codecov Report

Merging #16688 into master will increase coverage by 0.94%.
The diff coverage is 86.66%.

@@            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
Flag Coverage 螖
#integration_tests 34.91% <50%> (+22.28%) 猬嗭笍
#unit_tests 77.19% <86.66%> (+0.01%) 猬嗭笍

Continue to review full report at Codecov.

Legend - Click here to learn more
螖 = absolute <relative> (impact), 酶 = not affected, ? = missing data
Powered by Codecov. Last update 424697f...c480e3d. Read the comment docs.

@jridgewell jridgewell merged commit efdab4d into ampproject:master Jul 12, 2018
@jridgewell jridgewell deleted the grepable-isExperimentOn branch July 12, 2018 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

Successfully merging this pull request may close these issues.

None yet

7 participants