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

fix: fixes overlapping errors between newlinesBetween and comment-after fixes #441

Merged
merged 11 commits into from
Jan 13, 2025

Conversation

hugop95
Copy link
Contributor

@hugop95 hugop95 commented Jan 10, 2025

Related issue: #11
Related comment: #11 (comment)

Description

Note: good news! I've managed to find a way to fix this without impacting any existing test 🙂

In some specific cases, comments-related fixes and newline fixes may overlap.

Example

type Test = {
  onAdd: () => void;
  title: string; // The fix related to this comment will overlap with newline fixes

  onClick: () => void; 
};
'perfectionist/sort-object-types': [
  'error',
  {
    type: 'natural',
    groups: [
      'property',
      'required-method',
    ],
    newlinesBetween: 'always',
  },
]

Today, both comment/order fixes and newlines fixes are done in the same cycle. The easiest fix is to separate those fixes into a different cycle (see below).

Proposal

The PR includes a refactor part and a simple fix that aims to separate the "comments after" fixes and the newlines fixes. "comments after" fixes are fixes related to comments appearing at the end of lines, after nodes.

State today

  • makeFixes handles:
    • Order-related fixes.
    • Comments after fixes.
  • makeNewlinesFixes handles only newline fixes.

Commits split

The refactor commits (first 5 commits) rename and split existing functions into new functions in order to separate each type of fixes independently.

This allows us in the end to do

  let orderFixes = makeOrderFixes({...})

  let commentAfterFixes = makeCommentAfterFixes({...})
  if (commentAfterFixes.length) {
    return [...orderFixes, ...commentAfterFixes]
  }

  let newlinesFixes = makeNewlinesFixes({...})
  return [...orderFixes, ...newlinesFixes]

What is the purpose of this pull request?

  • Bug fix

@hugop95 hugop95 force-pushed the fix/overlapping-errors branch 3 times, most recently from 9c9e0ea to 96ae400 Compare January 10, 2025 07:59
@hugop95 hugop95 changed the title fix: fixes overlapping errors due to newlinesBetween fix: fixes overlapping errors between to newlinesBetween and order-related fixes Jan 10, 2025
@hugop95 hugop95 changed the title fix: fixes overlapping errors between to newlinesBetween and order-related fixes fix: fixes overlapping errors between newlinesBetween and order-related fixes Jan 10, 2025
@hugop95 hugop95 force-pushed the fix/overlapping-errors branch from 96ae400 to de37084 Compare January 10, 2025 12:26
@hugop95 hugop95 force-pushed the fix/overlapping-errors branch 4 times, most recently from b162c04 to b7a3812 Compare January 10, 2025 18:08
@hugop95 hugop95 changed the title fix: fixes overlapping errors between newlinesBetween and order-related fixes fix: fixes overlapping errors between newlinesBetween and comment-after fixes Jan 10, 2025
@hugop95 hugop95 force-pushed the fix/overlapping-errors branch from b7a3812 to 5200b6d Compare January 12, 2025 09:37
@hugop95 hugop95 force-pushed the fix/overlapping-errors branch from 5200b6d to c8b06e7 Compare January 12, 2025 09:48
@hugop95 hugop95 marked this pull request as ready for review January 12, 2025 09:49
@azat-io
Copy link
Owner

azat-io commented Jan 12, 2025

Looks good. I am a bit confused by the long function names. And I want to take some time to think if it can be made a bit simpler.

@hugop95
Copy link
Contributor Author

hugop95 commented Jan 12, 2025

@azat-io I've simplified things in these two commits:

The remaining fixes functions are

  • makeAllFixes
  • makeNewlinesFixes
  • makeCommentAfterFixes
  • makeOrderFixes

@@ -39,6 +38,7 @@ import { createEslintRule } from '../utils/create-eslint-rule'
import { getLinesBetween } from '../utils/get-lines-between'
import { getGroupNumber } from '../utils/get-group-number'
import { getSourceCode } from '../utils/get-source-code'
import { makeAllFixes } from '../utils/make-all-fixes'
Copy link
Owner

Choose a reason for hiding this comment

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

Why not makeFixes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@azat-io Renamed in ee1f5eb.

@azat-io azat-io merged commit a6e1daf into azat-io:main Jan 13, 2025
8 checks passed
@hugop95 hugop95 deleted the fix/overlapping-errors branch January 13, 2025 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants