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

feat: add new rule enforce-line-break #484

Merged
merged 4 commits into from
Jun 29, 2021

Conversation

angelica-bocanegra
Copy link
Contributor

@angelica-bocanegra angelica-bocanegra commented Jun 27, 2021

New rule to enforce line breaks before and after type declarations.

Closes #476

// Error
type A = string;
type B = number;
// Some Comment
type rez = string;

// Fixes to 
type A = string;

type B = number;

// Some Comment
type rez = string;

@gajus

fix (fixer) {
return fixer.insertTextBeforeRange(node.leadingComments[0].range, '\n');
},
message: 'Please enter a line above type declaration',
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the error messages general have the tone of New line required above type declaration. Should we change to like that?

fix (fixer) {
return fixer.insertTextBefore(node, '\n');
},
message: 'Please enter a line above type declaration',
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the message itself be a func that can be reused for both above and below?

const breakLineMessage = (direction) => `Please enter a line ${direction} type declaration`;

return;
}

if (node.loc.start.line !== 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious what does this do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is so you won't get the error 'New line required above type declaration` if the type declaration happens to be on the first line.

Copy link
Contributor

@Brianzchen Brianzchen left a comment

Choose a reason for hiding this comment

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

LGTM

@gajus gajus merged commit 417068c into gajus:master Jun 29, 2021
@gajus
Copy link
Owner

gajus commented Jun 29, 2021

🎉 This PR is included in version 5.8.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@gajus gajus added the released label Jun 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enforce breakline on type definitions
3 participants