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

fix(docs): fixup and lint optionals and return values in api.md #1376

Merged
merged 2 commits into from
Mar 18, 2020

Conversation

JoelEinbinder
Copy link
Contributor

@JoelEinbinder JoelEinbinder commented Mar 13, 2020

Currently in our API ? means null, but sometimes it means optional. Linting optional/nulls with this patch is required for #1166 to land nicely.

Previously, return types were not being linted in api.md. This is fixed, along with many broken return types.

This patch considers ? to mean nullable, and has some heuristics to determine optionality. I believe this to be the minimal patch needed to unblock #1166. After it lands, we can consider changing the api docs to hopefully remove some heuristics and strangeness.

firefoxVersion: browserVersions.firefox,
})));
messages.push(...await preprocessor.ensureReleasedAPILinks([readme], VERSION));
// const preprocessor = require('./preprocessor');
Copy link
Member

Choose a reason for hiding this comment

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

What is this about?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

draft, its not done.

Copy link
Contributor

@dgozman dgozman left a comment

Choose a reason for hiding this comment

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

Can we spell out our policy? Something like the following or not?

  • Optional arguments are denoted as [, arg] in the arg list.
  • All incoming object properties are optional by default.
  • All incoming object properties which are required are marked as required.
  • Outgoing object properties can not be optional (only nullable).
  • "?" means nullable, both in incoming and outgoing.

@@ -205,7 +205,7 @@ Indicates that the browser is connected.
- `geolocation` <[Object]>
- `latitude` <[number]> Latitude between -90 and 90.
Copy link
Contributor

Choose a reason for hiding this comment

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

Required here?

docs/api.md Outdated
@@ -3718,7 +3718,7 @@ const { chromium } = require('playwright'); // Or 'firefox' or 'webkit'.

#### browserType.connect(options)
- `options` <[Object]>
- `wsEndpoint` <[string]> A browser websocket endpoint to connect to.
- `wsEndpoint` <[string]> A browser websocket endpoint to connect to. **required**
- `slowMo` <?[number]> Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going on. Defaults to 0.
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove '?' here?

@JoelEinbinder JoelEinbinder force-pushed the fixup_api_optionals branch 3 times, most recently from a340ba7 to 9622d70 Compare March 17, 2020 20:31
@JoelEinbinder JoelEinbinder changed the title fix optionals in api.md fix(docs): fixup and lint optionals and return values in api.md Mar 17, 2020
@JoelEinbinder JoelEinbinder marked this pull request as ready for review March 17, 2020 20:41
docs/api.md Outdated
@@ -1750,7 +1749,7 @@ const [response] = await Promise.all([
Shortcut for [page.mainFrame().waitForNavigation(options)](#framewaitfornavigationoptions).

#### page.waitForRequest(urlOrPredicate[, options])
- `urlOrPredicate` <?[string]|[RegExp]|[Function]> Optional. Request URL string, regex or predicate receiving [Request] object.
- `urlOrPredicate` <[string]|[RegExp]|[Function]> Optional. Request URL string, regex or predicate receiving [Request] object.
Copy link
Contributor

Choose a reason for hiding this comment

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

Reading the implementation, urlOrPredicate is not optional. Let's update the description.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

docs/api.md Outdated
@@ -1766,7 +1765,7 @@ await page.waitForRequest(request => request.url().searchParams.get('foo') === '
```

#### page.waitForResponse(urlOrPredicate[, options])
- `urlOrPredicate` <?[string]|[RegExp]|[Function]> Optional. Request URL string, regex or predicate receiving [Response] object.
- `urlOrPredicate` <[string]|[RegExp]|[Function]> Optional. Request URL string, regex or predicate receiving [Response] object.
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -2931,9 +2930,9 @@ function, it **will not be called**.

#### consoleMessage.location()
- returns: <[Object]>
Copy link
Contributor

Choose a reason for hiding this comment

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

We return an object with optional fields? Let's make them nullable instead.

Copy link
Contributor Author

@JoelEinbinder JoelEinbinder Mar 18, 2020

Choose a reason for hiding this comment

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

These are helpful when JSON stringifying or console logging these objects in node. I'd rather not change implementation in this patch.

- `invalid` <[string]> Whether and in what way this node's value is invalid.
- `orientation` <[string]> Whether the node is oriented horizontally or vertically.
- `children` <[Array]<[Object]>> Child [AXNode]s of this node, if any.
- `value` <[string]|[number]> The current value of the node, if applicable.
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here - make it nullable?

@@ -3905,7 +3904,7 @@ const v8toIstanbul = require('v8-to-istanbul');
#### chromiumCoverage.stopCSSCoverage()
- returns: <[Promise]<[Array]<[Object]>>> Promise that resolves to the array of coverage reports for all stylesheets
- `url` <[string]> StyleSheet URL
- `text` <[string]> StyleSheet content
- `text` <[string]> StyleSheet content, if available.
Copy link
Contributor

Choose a reason for hiding this comment

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

Also here.

@@ -3915,8 +3914,13 @@ const v8toIstanbul = require('v8-to-istanbul');
#### chromiumCoverage.stopJSCoverage()
- returns: <[Promise]<[Array]<[Object]>>> Promise that resolves to the array of coverage reports for all scripts
- `url` <[string]> Script URL
- `source` <[string]> Script content
- `source` <[string]> Script content, if applicable.
Copy link
Contributor

Choose a reason for hiding this comment

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

And here.

@JoelEinbinder JoelEinbinder merged commit b0749e3 into microsoft:master Mar 18, 2020
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

Successfully merging this pull request may close these issues.

3 participants