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

src,doc: refactor to replace typedefs with usings #910

Conversation

RaisinTen
Copy link
Contributor

No description provided.

@mhdawson
Copy link
Member

What level of compiler support does this syntax require?

@RaisinTen
Copy link
Contributor Author

@mhdawson all compilers support this except except Digital Mars C++.
See row 11 (Template aliases) of: https://en.cppreference.com/w/cpp/compiler_support#cpp11

How do I fix the lint error? Running this doesn't change anything for me locally:

❯ npm run lint:fix

> node-addon-api@3.1.0 lint:fix
> git-clang-format '*.h', '*.cc'

no modified files to format

@mhdawson
Copy link
Member

One more question, is there anything that you can do with a typedef definition that you can't do with the using def ?

@RaisinTen
Copy link
Contributor Author

@mhdawson no there isn't.
I preferred using using here because it can do whatever typedef does + it also allows templates.

@legendecas
Copy link
Member

How do I fix the lint error? Running this doesn't change anything for me locally:

The lint is comparing the local changes with the main branch. Please have a check on your local main branch and dev branch are up to date with the GitHub one.

@RaisinTen
Copy link
Contributor Author

The lint is comparing the local changes with the main branch. Please have a check on your local main branch and dev branch are up to date with the GitHub one.

@legendecas Yes, they are up to date. Turns out, getNativeBinary() of node_modules/clang-format/index.js can't find the clang-format binary on my machine because it's an unsupported architecture I guess (ia32). tools/clang-format.js ends up swallowing the error because it checks for error instead of stderr of the spawned ChildProcess.

I tried to copy and paste the linter error log into a file and git apply it but unfortunately it prints:

error: corrupt patch at line 48

:/

@RaisinTen
Copy link
Contributor Author

PR to fix the error detection: #914

@RaisinTen RaisinTen force-pushed the src,doc/refactor-to-replace-typedefs-with-usings branch from c51c971 to 77083ea Compare March 8, 2021 12:43
@RaisinTen
Copy link
Contributor Author

I could apply the patch from the logs of the failed style check run and now the style check passes too.

However, it seems to have added some more changes than what I intended (like indenting some other parts of the code).
Would it make sense to run clang-format on the full codebase and make a PR to fix the style so that other PRs don't have to make unrelated style changes?

PTAL.

Copy link
Member

@mhdawson mhdawson left a comment

Choose a reason for hiding this comment

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

LGTM

@mhdawson
Copy link
Member

mhdawson commented Mar 9, 2021

@nodejs/node-api let me know if you have any concerns about this one by Friday (or approve), otherwise I'll go ahead and land it.

Copy link
Member

@NickNaso NickNaso left a comment

Choose a reason for hiding this comment

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

Some notes about the reasons that pushed me to approve this PR:

It's possible to define a new name for an existing type with both:

  • typedef (We call this declaration typedef and the resulting name typedef-name)
  • using (We can call this decalration alias desclaration)

The using alternative is more readable because you always have the type name on the left side of the =.

Unlike a typedef an alias declaration can be templated to provide a conveninet name for a family of types. This is available since C++11 and is called alias template.

@mhdawson
Copy link
Member

Need to run on our CI to make sure all the older compilers support using before landing.

@NickNaso
Copy link
Member

NickNaso commented Mar 12, 2021

@mhdawson
Copy link
Member

@NickNaso thanks for running the CIs

The failures on 11 seem unrelated to this PR as you mention, possibly because of something that would have been backported to 10.x but not 11.

Checking the table in https://en.cppreference.com/w/cpp/compiler_support#cpp11 it also seems to confirm that all of the minimum levels for Node.js 10.x support using so I think this is good to land.

mhdawson pushed a commit that referenced this pull request Mar 15, 2021
PR-URL: #910
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: NickNaso <nicoladelgobbo@gmail.com>
@mhdawson
Copy link
Member

Landed as 71494a4

@mhdawson mhdawson closed this Mar 15, 2021
@RaisinTen RaisinTen deleted the src,doc/refactor-to-replace-typedefs-with-usings branch March 16, 2021 16:11
kevindavies8 added a commit to kevindavies8/node-addon-api-Develop that referenced this pull request Aug 24, 2022
PR-URL: nodejs/node-addon-api#910
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: NickNaso <nicoladelgobbo@gmail.com>
Marlyfleitas added a commit to Marlyfleitas/node-api-addon-Development that referenced this pull request Aug 26, 2022
PR-URL: nodejs/node-addon-api#910
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: NickNaso <nicoladelgobbo@gmail.com>
wroy7860 added a commit to wroy7860/addon-api-benchmark-node that referenced this pull request Sep 19, 2022
PR-URL: nodejs/node-addon-api#910
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: NickNaso <nicoladelgobbo@gmail.com>
johnfrench3 pushed a commit to johnfrench3/node-addon-api-git that referenced this pull request Aug 11, 2023
PR-URL: nodejs/node-addon-api#910
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: NickNaso <nicoladelgobbo@gmail.com>
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.

4 participants