Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

New: Accessibility Modifiers (fixes #87) #88

Merged
merged 1 commit into from
Sep 21, 2016

Conversation

dannyfritz
Copy link
Contributor

@dannyfritz dannyfritz commented Sep 15, 2016

Issue (#87)

This pull request is about getting the public, protected, and private keywords into the ESLint AST.

The accessibility modifier keywords can appear on ClassProperty and MethodProperty.

http://astexplorer.net/#/FfIL8GurdC

@eslintbot
Copy link

Thanks for the pull request, @dannyfritz! I took a look to make sure it's ready for merging and found some changes are needed:

  • The commit summary needs to begin with a tag (such as Fix: or Update:). Please check out our guide for how to properly format your commit summary and update it on this pull request.
  • Pull requests with code require an issue to be mentioned at the end of the commit summary, such as (fixes #1234). Please update the commit summary with an issue (file a new issue if one doesn't already exist).

Can you please update the pull request to address these?

(More information can be found in our pull request guide.)

@eslintbot
Copy link

LGTM

@eslintbot
Copy link

LGTM

@dannyfritz dannyfritz changed the title 🚧 WIP: Visibility Modifiers (#87) New: Accessibility Modifiers (#87) Sep 17, 2016
@dannyfritz dannyfritz changed the title New: Accessibility Modifiers (#87) New: Accessibility Modifiers Sep 17, 2016
@eslintbot
Copy link

LGTM

@eslintbot
Copy link

LGTM

@eslintbot
Copy link

LGTM

@dannyfritz dannyfritz changed the title New: Accessibility Modifiers New: Accessibility Modifiers (fixes #87) Sep 17, 2016
Copy link
Member

@JamesHenry JamesHenry left a comment

Choose a reason for hiding this comment

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

Thanks a lot for this, Danny! This is really coming together

* Gets a TSNode's accessibility level
* @returns {string} accessibility "public", "protected", or "private"
*/
function getTSNodeAccessibility() {
Copy link
Member

Choose a reason for hiding this comment

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

It's a minor point, but I would usually prefer that TSNode be passed into the helper function so that it is a bit more portable.

I'm sure we'll be refactoring some of this code once the project is a bit more mature and things like this will make that process easier.

protected setBar (bar : string) {
this.bar = bar;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Please add at least one example of methods and properties which have multiple TS modifiers on them:

e.g.

class X {
  public static yo: string = 'Init';
  protected get bye() {
    return 'bye';
  }
}

@@ -420,6 +420,8 @@ module.exports = function(ast, extra) {
return null;
}

var accessibility;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I really don't like this line. I'm going to have it always set the accessibility and just have it default to null instead to clean up code.

@dannyfritz
Copy link
Contributor Author

dannyfritz commented Sep 17, 2016

I'm noticing constructor should default to accessibility: "public" and currently does not.

Also, there is a shorthand in TS for specifying members in the constructor parameters. Are type annotations parsed into the tree yet?

@eslintbot
Copy link

LGTM

Copy link
Contributor Author

@dannyfritz dannyfritz left a comment

Choose a reason for hiding this comment

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

constructor should have an accessibility of "public".

@JamesHenry
Copy link
Member

I'm noticing constructor should default to accessibility: "public" and currently does not

I'm not sure what you mean by this. Can you please point me to an example?

Everything in a TypeScript class is public by default (just like a standard ES2015 class), we will only worry about adding accessibility: "public" in the AST for those nodes which have a PublicKeyword as a modifier.

@JamesHenry
Copy link
Member

Also, there is a shorthand in TS for specifying members in the constructor parameters. Are type annotations parsed into the tree yet?

Yes, we will need to handle this behaviour in a separate PR as it will require some discussion. Thanks for flagging though!

@dannyfritz
Copy link
Contributor Author

Alright, if we're only concerned with explicit accessibility keywords then this should be good.

@JamesHenry
Copy link
Member

RE: The constructor:

Oh, I missed this comment from you:

I really don't like this line. I'm going to have it always set the accessibility and just have it default to null instead to clean up code.

...and I can see you have already updated all the relevant existing ASTs.

@nzakas What do you think about this change?

If we do go with Danny's latest changes which adds "accessibility" to everything, then constructor should probably have it too

@dannyfritz
Copy link
Contributor Author

@JamesHenry #87 (comment)

@JamesHenry
Copy link
Member

Ok great, sorry I missed that discussion earlier in the week as I was travelling

@JamesHenry
Copy link
Member

So, to summarise, I still thinks it makes sense to keep the accessibility value to be null, unless the modifiers are explicitly used. They will only be relevant to specific plugin rules anyway

@JamesHenry
Copy link
Member

This LGTM now!

I'll leave it to @nzakas to merge to double check he is happy with "accessibility" over "visibility".

We usually try and match existing ESTree or Flow constructs wherever possible, but these modifiers do not exist on classes for them yet. I therefore think it makes sense to go with TypeScript's term of "accessibility", as in this PR.

Thanks again, @dannyfritz!

@dannyfritz
Copy link
Contributor Author

I'm going to add accessibility to the constructor too. null still if nothing is specified. Then i think this PR is ready.

@dannyfritz dannyfritz changed the title New: Accessibility Modifiers (fixes #87) WIP: New: Accessibility Modifiers (fixes #87) Sep 18, 2016
@nzakas
Copy link
Member

nzakas commented Sep 19, 2016

So, to summarise, I still thinks it makes sense to keep the accessibility value to be null, unless the modifiers are explicitly used.

Totally agree.

I'll leave it to @nzakas to merge to double check he is happy with "accessibility" over "visibility".

Eh, I don't have the energy to argue this point, so it's fine. :)

@dannyfritz it looks like you're still planning on making changes? Can you let us know when you do?

@eslintbot
Copy link

LGTM

@dannyfritz
Copy link
Contributor Author

Alright. This PR is ready for review.

@dannyfritz dannyfritz changed the title WIP: New: Accessibility Modifiers (fixes #87) New: Accessibility Modifiers (fixes #87) Sep 21, 2016
@JamesHenry JamesHenry merged commit 5dae849 into eslint:master Sep 21, 2016
@JamesHenry
Copy link
Member

Thanks, @dannyfritz! This still LGTM.

@dannyfritz dannyfritz deleted the visibility-modifiers branch October 11, 2016 12:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants