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

tools: improve heading type detection in json.js #20074

Closed
wants to merge 2 commits into from
Closed

tools: improve heading type detection in json.js #20074

wants to merge 2 commits into from

Conversation

vsemozhetbyt
Copy link
Contributor

@vsemozhetbyt vsemozhetbyt commented Apr 16, 2018

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

It appears that heading type detection in tools/doc/json.js is not accurate because some RegExps are too narrow and some are too wide. Maybe some mean an older source state.

This is an incomplete list of examples of false-positive and false-negative results:

  • Not detected as constructor signatures (with Constructor: prefix or class parent object):
new assert.AssertionError(options)
new crypto.Certificate()
Constructor: new inspector.Session()
new net.Server([options][, connectionListener])
new net.Socket([options])
Constructor: new stream.Writable([options])
new stream.Readable([options])
new stream.Duplex(options)
new stream.Transform([options])
new tls.TLSSocket(socket[, options])
Constructor: new URL(input[, base])
Constructor: new URLSearchParams()
Constructor: new URLSearchParams(string)
Constructor: new URLSearchParams(obj)
Constructor: new URLSearchParams(iterable)
Constructor: new vm.Module(code[, options])
new vm.Script(code, options)
  • Not detected as methods signatures (with more than one ancestor):
fs.realpath.native(path[, options], callback)
fs.realpathSync.native(path[, options])
require.resolve.paths(request)
punycode.ucs2.decode(string)
punycode.ucs2.encode(codePoints)
util.types.isAnyArrayBuffer(value)
util.types.isArgumentsObject(value)
util.types.isArrayBuffer(value)
  • Wrongly detected as method signatures:
DEP0022: os.tmpDir()
DEP0023: os.getNetworkInterfaces()
DEP0026: util.print()
DEP0079: Custom inspection function on Objects via .inspect()
  • Not detected as properties (with more than one ancestor):
buffer.constants.MAX_LENGTH
buffer.constants.MAX_STRING_LENGTH
util.inspect.custom
util.inspect.defaultOptions
util.promisify.custom
  • Wrongly detected as properties:
No `require.extensions`
No `require.cache`
Node.js Crypto Constants
Node.js Error Codes
Native Abstractions for Node.js
V8 Inspector Integration for Node.js
DEP0011: crypto.Credentials
DEP0012: Domain.dispose

I've tried to make RegExp more accurate, but they became more and more complicated, so I've decided to build them from smaller string components so that the final RegExps were more self-explanatory.

@nodejs-github-bot nodejs-github-bot added doc Issues and PRs related to the documentations. tools Issues and PRs related to the tools directory. labels Apr 16, 2018
@vsemozhetbyt

This comment has been minimized.

@vsemozhetbyt
Copy link
Contributor Author

vsemozhetbyt commented Apr 19, 2018

cc @nodejs/documentation PTAL

I understand that this file is rather not very well researched domain, but the change does not require the familiarity with all the md-2-JSON tooling chain: it is just a refactoring of some RegExps that are used to parse well-known heading types in our API docs, so it can be reviewed without any broader context.

@vsemozhetbyt
Copy link
Contributor Author

// To reduse escape slashes in RegExp string components.
const r = String.raw;

const eventPrefix = r`^Event:\s+`;
Copy link
Member

Choose a reason for hiding this comment

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

Any reason for \s? I mean, can there be tabs or new lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I do not think there can be. Do you mean it would be better to use '^Event: +'?

Copy link
Member

Choose a reason for hiding this comment

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

Yes.

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 in the fixup commit.


// To include constructs like `readable\[Symbol.asyncIterator\]()`
// or `readable.\_read(size)` (with Markdown escapes).
const simpleId = r`(?:(?:\\?_)+|\b)\w+\b`;
Copy link
Member

Choose a reason for hiding this comment

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

Why is (?:\\?_) repeated? Is something like _\__\_ possible?

Copy link
Contributor Author

@vsemozhetbyt vsemozhetbyt Apr 22, 2018

Choose a reason for hiding this comment

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

We have __filename and __dirname, so I've thought this was possible.

const classMethodPrefix = r`^Class Method:\s+`;
const maybeClassPropertyPrefix = r`(?:Class Property:\s+)?`;

const maybeQuote = '[\'"]?';
Copy link
Member

Choose a reason for hiding this comment

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

Use ` to avoid escaping?

Copy link
Contributor Author

@vsemozhetbyt vsemozhetbyt Apr 22, 2018

Choose a reason for hiding this comment

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

I've tried, but ESLint throws. It seems this rule does not suffice for this:

'quotes': ['error', 'single', { avoidEscape: true }],

We need "allowTemplateLiterals": true and maybe I will file a PR with this very case if this is landed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And I thought such PR would be a small one) #20214

@vsemozhetbyt
Copy link
Contributor Author

Copy link
Member

@lpinca lpinca left a comment

Choose a reason for hiding this comment

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

SGTM

@vsemozhetbyt
Copy link
Contributor Author

@lpinca Thank you a lot for the review.

I will land soon if there are no objections from anybody as I think we may get no more reviews for this.

@lpinca
Copy link
Member

lpinca commented Apr 22, 2018

I really appreciate all the work you are doing with the docs.

@vsemozhetbyt
Copy link
Contributor Author

Landed in 7fcb52c
Thank you!

vsemozhetbyt added a commit that referenced this pull request Apr 22, 2018
@vsemozhetbyt vsemozhetbyt deleted the doc-tools-fix-json-types branch April 22, 2018 15:11
jasnell pushed a commit that referenced this pull request Apr 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. tools Issues and PRs related to the tools directory.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants