Skip to content

🏗 Lint: isExperimentOn must be passed an explicit string#16688

Merged
jridgewell merged 2 commits intoampproject:masterfrom
jridgewell:grepable-isExperimentOn
Jul 12, 2018
Merged

🏗 Lint: isExperimentOn must be passed an explicit string#16688
jridgewell merged 2 commits intoampproject:masterfrom
jridgewell:grepable-isExperimentOn

Conversation

@jridgewell
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

@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
Copy Markdown
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');
@jridgewell jridgewell force-pushed the grepable-isExperimentOn branch from 1da1fa8 to b1d401e Compare July 12, 2018 21:39
@codecov-io
Copy link
Copy Markdown

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

None yet

Development

Successfully merging this pull request may close these issues.

7 participants