Repository: azat-io/eslint-plugin-perfectionist (ts)

Issue:
Bug: `natural` sort ignores `order`
### Describe the bug

Please see the self-explicit code example below.

### Code example

Configuration:
```ts
{
  type: 'natural',
  order: 'desc'
}
```

Code:
```ts
interface Test {
    a
    b
}
```

No error is reported.

### ESLint version

8.57.0

### ESLint Plugin Perfectionist version

4.1.2

### Additional comments

_No response_

### Validations

- [X] Read the [docs](https://perfectionist.dev).
- [X] Check that there isn't [already an issue](https://github.com/azat-io/eslint-plugin-perfectionist/issues) that reports the same bug to avoid creating a duplicate.

Pull request description:
fix: fixes `natural` sort ignoring `order`
Fixes #405.

### Description

One line fix.

The issue comes from the fact that the sort order is provided to the `natural-orderby` library, while an additional sort by order is done at the end, cancelling it.

https://github.com/azat-io/eslint-plugin-perfectionist/blob/eed1b809a954778baed8117abd72efcd39c9c0c8/utils/compare.ts#L60-L63

https://github.com/azat-io/eslint-plugin-perfectionist/blob/eed1b809a954778baed8117abd72efcd39c9c0c8/utils/compare.ts#L46

https://github.com/azat-io/eslint-plugin-perfectionist/blob/eed1b809a954778baed8117abd72efcd39c9c0c8/utils/compare.ts#L97

The PR also adds some simple additional unit tests for the `compare` function to prevent potential regressions in the future.

### What is the purpose of this pull request?
- [x] Bug fix


Patch:
diff --git a/utils/compare.ts b/utils/compare.ts
index cade523..38dcf0c 100644
--- a/utils/compare.ts
+++ b/utils/compare.ts
@@ -59,7 +59,6 @@ export let compare = <T extends SortingNode>(
   } else if (options.type === 'natural') {
     let naturalCompare = createNaturalCompare({
       locale: options.locales.toString(),
-      order: options.order,
     })
     let formatString = getFormatStringFunction(
       options.ignoreCase,


Test patch:
diff --git a/test/compare.test.ts b/test/compare.test.ts
new file mode 100644
index 0000000..245118a
--- /dev/null
+++ b/test/compare.test.ts
@@ -0,0 +1,140 @@
+import { describe, expect, it } from 'vitest'
+
+import type { SortingNode } from '../typings'
+
+import { compare } from '../utils/compare'
+
+describe('compare', () => {
+  describe('alphabetical', () => {
+    let compareOptions = {
+      specialCharacters: 'keep',
+      type: 'alphabetical',
+      ignoreCase: false,
+      locales: 'en-US',
+      order: 'asc',
+    } as const
+
+    it('sorts by order asc', () => {
+      expect(
+        compare(
+          createTestNode({ name: 'b' }),
+          createTestNode({ name: 'a' }),
+          compareOptions,
+        ),
+      ).toBe(1)
+    })
+
+    it('sorts by order desc', () => {
+      expect(
+        compare(createTestNode({ name: 'a' }), createTestNode({ name: 'b' }), {
+          ...compareOptions,
+          order: 'desc',
+        }),
+      ).toBe(1)
+    })
+
+    it('sorts ignoring case', () => {
+      expect(
+        compare(
+          createTestNode({ name: 'aB' }),
+          createTestNode({ name: 'Ab' }),
+          {
+            ...compareOptions,
+            ignoreCase: true,
+          },
+        ),
+      ).toBe(0)
+    })
+
+    it('sorts while trimming special characters', () => {
+      expect(
+        compare(createTestNode({ name: '_a' }), createTestNode({ name: 'a' }), {
+          ...compareOptions,
+          specialCharacters: 'trim',
+        }),
+      ).toBe(0)
+    })
+
+    it('sorts while removing special characters', () => {
+      expect(
+        compare(
+          createTestNode({ name: 'ab' }),
+          createTestNode({ name: 'a_b' }),
+          {
+            ...compareOptions,
+            specialCharacters: 'remove',
+          },
+        ),
+      ).toBe(0)
+    })
+  })
+
+  describe('natural', () => {
+    let compareOptions = {
+      specialCharacters: 'keep',
+      ignoreCase: false,
+      locales: 'en-US',
+      type: 'natural',
+      order: 'asc',
+    } as const
+
+    it('sorts by order asc', () => {
+      expect(
+        compare(
+          createTestNode({ name: 'b' }),
+          createTestNode({ name: 'a' }),
+          compareOptions,
+        ),
+      ).toBe(1)
+    })
+
+    it('sorts by order desc', () => {
+      expect(
+        compare(createTestNode({ name: 'a' }), createTestNode({ name: 'b' }), {
+          ...compareOptions,
+          order: 'desc',
+        }),
+      ).toBe(1)
+    })
+
+    it('sorts ignoring case', () => {
+      expect(
+        compare(
+          createTestNode({ name: 'aB' }),
+          createTestNode({ name: 'Ab' }),
+          {
+            ...compareOptions,
+            ignoreCase: true,
+          },
+        ),
+      ).toBe(0)
+    })
+
+    it('sorts while trimming special characters', () => {
+      expect(
+        compare(createTestNode({ name: '_a' }), createTestNode({ name: 'a' }), {
+          ...compareOptions,
+          specialCharacters: 'trim',
+        }),
+      ).toBe(0)
+    })
+
+    it('sorts while removing special characters', () => {
+      expect(
+        compare(
+          createTestNode({ name: 'ab' }),
+          createTestNode({ name: 'a_b' }),
+          {
+            ...compareOptions,
+            specialCharacters: 'remove',
+          },
+        ),
+      ).toBe(0)
+    })
+  })
+
+  let createTestNode = ({ name }: { name: string }): SortingNode =>
+    ({
+      name,
+    }) as SortingNode
+})