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

Enhance the fixer of interface-over-type-literal #4796

Closed
wants to merge 5 commits into from
Closed

Enhance the fixer of interface-over-type-literal #4796

wants to merge 5 commits into from

Conversation

ychen10
Copy link

@ychen10 ychen10 commented Jul 13, 2019

PR checklist

Overview of change:

Added a step in the fixer so that it goes into the members to check if they carry a trailing comma. If they do, replace it with semicolon. The fixed interface now looks like

interface User {
  someData: {
    firstName: string,
    lastName: string,
    registered: boolean,
  };
  location: string;
  quantity: number;
}

instead of

interface User {
  someData: {
    firstName: string,
    lastName: string,
    registered: boolean,
  },
  location: string,
  quantity: number,
}

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

CHANGELOG.md entry:

[enhancement] interface-over-type-literal The fixer now makes sure that the interface uses semicolon to separate individual member declarations.

@palantirtech
Copy link
Member

Thanks for your interest in palantir/tslint, @ychen10! Before we can accept your pull request, you need to sign our contributor license agreement - just visit https://cla.palantir.com/ and follow the instructions. Once you sign, I'll automatically update this pull request.

@ychen10
Copy link
Author

ychen10 commented Jul 13, 2019

Test failing as per #4784

@JoshuaKGoldberg
Copy link
Contributor

Declined per #4795 😢.

In general, until an issue is marked as Status: Accepting PRs, it's better to hold off on writing a PR. You never know when an issue will be declined by some annoying maintainer.

if (members.length !== 0) {
members.forEach(mem => {
const memText: string = mem.getFullText();
if (memText[memText.length - 1] === ",") {
Copy link
Contributor

Choose a reason for hiding this comment

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

If you fork this rule and use it in your own project, you might want to write some test cases around comments and spacing:

type Wat = {
    someMember : string /* gotcha! */,
}

Copy link
Author

Choose a reason for hiding this comment

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

Got it. Thanks!

@JoshuaKGoldberg
Copy link
Contributor

FWIW, you can always fork this rule (copy & paste the .js output into a new file) and use it in your own project instead of the core rule.

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.

Have interface-over-type-literal replace trailing comma delimiters with semicolons
3 participants