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

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

Merged
merged 10 commits into from
Oct 5, 2019
Merged

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

merged 10 commits into from
Oct 5, 2019

Conversation

NaridaL
Copy link
Contributor

@NaridaL NaridaL commented Jun 21, 2018

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

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

@NaridaL
Copy link
Contributor Author

NaridaL commented Jun 26, 2018

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

@NaridaL
Copy link
Contributor Author

NaridaL commented Jun 26, 2018

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
Copy link
Contributor Author

NaridaL commented Jun 26, 2018

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?

@@ -165,6 +165,8 @@ export interface ReplacementJson {
innerText: string;
}
export class Replacement {
constructor(readonly start: number, readonly length: number, readonly text: string) {}

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
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
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.

src/rules/memberOrderingRule.ts Show resolved Hide resolved
tslint.json Outdated
"static-before-instance",
"variables-before-functions"
],
"member-ordering": [true, { "order": "fields-first" }],

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?

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
Copy link
Contributor Author

NaridaL commented Jun 26, 2018

@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

@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
Copy link
Contributor Author

NaridaL commented Jun 26, 2018 via email

@giladgray
Copy link

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

@NaridaL
Copy link
Contributor Author

NaridaL commented Jun 27, 2018

@giladgray All rules?

I was thinking something like

image

@giladgray
Copy link

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
Copy link
Contributor Author

NaridaL commented Jun 27, 2018

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.

@NaridaL
Copy link
Contributor Author

NaridaL commented Jul 5, 2018

Failing tests are due to latest commit on master.

@maiis
Copy link

maiis commented Jul 18, 2018

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

@NaridaL
Copy link
Contributor Author

NaridaL commented Aug 24, 2018

rebased onto master

@ericanderson
Copy link
Member

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

@JoshuaKGoldberg
Copy link
Contributor

Removing the breaking change label per #4811!

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

@JoshuaKGoldberg JoshuaKGoldberg left a comment

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
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