Skip to content
This repository was archived by the owner on Mar 25, 2021. It is now read-only.

[bugfix] member-ordering includes getters and setters#3984

Merged
adidahiya merged 10 commits into
palantir:masterfrom
NaridaL:fix3965
Oct 5, 2019
Merged

[bugfix] member-ordering includes getters and setters#3984
adidahiya merged 10 commits into
palantir:masterfrom
NaridaL:fix3965

Conversation

@NaridaL

@NaridaL NaridaL commented Jun 21, 2018

Copy link
Copy Markdown
Contributor

PR checklist

Overview of change:

Added categories "-accessor" for getters and setters. Added those categories to the presets. Based on #3935, merge that first.

Is there anything you'd like reviewers to focus on?

CHANGELOG.md entry:

[bugfix] member-ordering includes property accessors (getters and setters).

@giladgray

Copy link
Copy Markdown

@NaridaL I just merged #3935 so go ahead and update this 👍

@NaridaL

NaridaL commented Jun 26, 2018

Copy link
Copy Markdown
Contributor Author

Done. Let's see if the lint still fails...

@NaridaL

NaridaL commented Jun 26, 2018

Copy link
Copy Markdown
Contributor Author

OK, yeah, for some reason running npm i locally resulted in me getting the error too.

ERROR: 193:5  member-ordering  Declaration of public instance method not allowed after declaration of private instance method. Instead, this should come after private instance fields.

The error doesn't make much sense, because tslint's tslint.json is using the old-style option "variables-before-functions", and accessors are neither. This is going to be a breaking change, as I added the accessors to the presets, and if you didn't happen to put them in the same location you're going to get errors now. Therefore I suggest doing what the comment on line 534 suggests and remove the old-style options entirely and update tslint.json.

/**
 * Convert from undocumented old-style options.
 * This is designed to mimic the old behavior and should be removed eventually.
 */

@NaridaL

NaridaL commented Jun 26, 2018

Copy link
Copy Markdown
Contributor Author

OK, I changed tslint's own config to use the current config type.

Can I remove the old-style option parsing entirely or do we need a version which outputs warnings first?

Comment thread src/language/rule/rule.ts Outdated
innerText: string;
}
export class Replacement {
constructor(readonly start: number, readonly length: number, readonly text: string) {}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

why are these constructors moved? i did not expect them to come first.

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.

tslint.json: use preset "fields-first" for member-ordering rule instead of previous old-style config.
This seems to match previous config most closely, requiring only 5 changes.

I can recheck if one of the other presets matches more closely, otherwise, this seems the way to go...

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.

Yeah this preset is the closest.

Comment thread test/rules/member-ordering/alphabetize/test.ts.fix
Comment thread src/rules/memberOrderingRule.ts
Comment thread tslint.json Outdated
"static-before-instance",
"variables-before-functions"
],
"member-ordering": [true, { "order": "fields-first" }],

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

is the old options syntax still supported?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

oh right, you asked. we cannot ship a breaking change. please preserve the old syntax, or we'll have to talk about 6.0

@NaridaL

NaridaL commented Jun 26, 2018

Copy link
Copy Markdown
Contributor Author

@giladgray I've added new categories for accessors. I've added these to the presets. (Currently getters and setters are ignored entirely). Therefore, if a user is using one of the presets, this is going to be a breaking change one way or the other. We might as well add other breaking changes (such as removing old style options).

@giladgray

Copy link
Copy Markdown

@NaridaL there's a big difference between a change in the lint result and an API change in the configuration. changing the configuration is a new API contract and requires user intervention during the upgrade in a way that is not automate-able.

conversely, changing the lint result may have no effect (if it's auto-fixable, which it is in this case), or it fails their build and they can easily update the code accordingly. we do not consider lint style changes to be API breaking.

so adding new categories is not an actual API break: it's actually an enhancement. but changing the config options in a non-backward-compatible way is an API break.

@giladgray giladgray changed the title [bugfix] Fix #3965 getters and setters ignored by member-ordering-rule [bugfix] member-ordering includes getters and setters Jun 26, 2018
@NaridaL

NaridaL commented Jun 26, 2018 via email

Copy link
Copy Markdown
Contributor Author

@giladgray

Copy link
Copy Markdown

no need to add a console warning as this would apply to all rules

@NaridaL

NaridaL commented Jun 27, 2018

Copy link
Copy Markdown
Contributor Author

@giladgray All rules?

I was thinking something like

image

@giladgray

Copy link
Copy Markdown

that is awesome! very clear message with migration steps 👌
however, definitely does not belong in this PR as that looks like a rather complex feature in itself and deserves to be reviewed separately.

don't think we're ready to deprecate old options usage just yet, though i imagine that'll be a flagship feature for 6.0 (that's what i meant by all rules -- migrating to object syntax across the board)

@NaridaL

NaridaL commented Jun 27, 2018

Copy link
Copy Markdown
Contributor Author

The rationale for adding the warning here is that the old style options don't handle accessors correctly and output unhelpful warnings. This rule already handles old style options by converting them to current ones, therefore outputting the above warning doesn't require any logic.

Comment thread src/rules/memberOrderingRule.ts
@NaridaL

NaridaL commented Jul 5, 2018

Copy link
Copy Markdown
Contributor Author

Failing tests are due to latest commit on master.

@maiis

maiis commented Jul 18, 2018

Copy link
Copy Markdown

@NaridaL I think you need to rebase this commit to fix the tests: 29fbace

@NaridaL

NaridaL commented Aug 24, 2018

Copy link
Copy Markdown
Contributor Author

rebased onto master

@ericanderson

Copy link
Copy Markdown
Contributor

I'm marking this as breaking due to the changed meaning of the presets.

@JoshuaKGoldberg

Copy link
Copy Markdown
Contributor

Removing the breaking change label per #4811!

@JoshuaKGoldberg JoshuaKGoldberg self-assigned this Oct 5, 2019
@JoshuaKGoldberg JoshuaKGoldberg removed their assignment Oct 5, 2019

@JoshuaKGoldberg JoshuaKGoldberg left a comment

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.

This LGTM. Will wait for review from @adidahiya for a week or so before merging, just in case.

@adidahiya
adidahiya merged commit df68ccf into palantir:master Oct 5, 2019
@adidahiya

Copy link
Copy Markdown
Contributor

thanks for the PR @NaridaL!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

member-ordering rule, alphabetize not working on getters and setters

6 participants