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: allow type: unsorted for all remaining rules #468

Merged
merged 27 commits into from
Feb 13, 2025

Conversation

hugop95
Copy link
Contributor

@hugop95 hugop95 commented Feb 11, 2025

Most of the added lines are documentation and tests.

Description

Today, only the following rules support type: unsorted directly in the options object (meaning: outside of customGroups)

  • sort-array-includes
  • sort-sets
  • sort-maps (is supposed to but actually isn't due to its JSON schema, and a test is missing about that)
  • sort-objects
  • sort-interfaces
  • sort-object-types

These rules support this feature because they have a useConfigurationIf option, which synergizes well together.

The problem

The current implementation of type: unsorted is simple, but is lacking as it returns very early. As such,

  • It ignores newlinesBetween.
  • It ignores groups.
  • It ignores dependency order (although this is less of an issue as we don't enforce a specific sort order here).

Users may want to type: unsorted with:

  • newlinesBetween, in order not to enforce sorting order, but to enforce no newline between elements.
  • groups, to enforce grouping, but not enforce any sorting other than required dependency sort.

Making all rules handle type: unsorted also makes the codebase more uniform: it's better if all rules can handle as many things in common as possible!

Proposal

This PR focuses on the following:

  1. Prevents type: unsorted from returning early and ignoring newlinesBetween and groups options.
  2. Enables type: unsorted for all remaining rules that did not support it.

The two implementation commits are:

Commit split

  • Commit 1: Documentation fixes from previous PRs.
  • Commit 2: Fixes sort-maps not handling type: unsorted when it should already be.
  • Commits 3-5: Refactor and adds additional tests to rules already handling type: unsorted.
  • Commit 6: Enables type: unsorted for all remaining rules.
  • Commits 7+: 1 commit per rule
    • Simplifying code if needed.
    • Updating documentation.
    • Adding tests.

Impacted tests

No test was removed or had its content updated.

What is the purpose of this pull request?

  • New Feature

@hugop95 hugop95 changed the title feat: allows type: unsorted for all remaining rules feat: enable type: unsorted for all remaining rules Feb 11, 2025
@hugop95 hugop95 changed the title feat: enable type: unsorted for all remaining rules feat: allow type: unsorted for all remaining rules Feb 11, 2025
@hugop95 hugop95 force-pushed the fix/unsorted branch 6 times, most recently from fc9679b to 53151e7 Compare February 13, 2025 11:03
@hugop95 hugop95 force-pushed the fix/unsorted branch 2 times, most recently from 49451a8 to ab44220 Compare February 13, 2025 11:12
@hugop95 hugop95 marked this pull request as ready for review February 13, 2025 11:18
@azat-io azat-io merged commit f92ab2a into azat-io:main Feb 13, 2025
8 checks passed
@hugop95 hugop95 deleted the fix/unsorted branch February 13, 2025 15:21
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