brandongregoryscott / eslint-plugin-collation

ESLint plugin for making your code easier to read, with autofix and TypeScript support
https://eslint-plugin-collation.brandonscott.me
Apache License 2.0
4 stars 0 forks source link

alphabetize-interfaces should handle TypeIntersections #43

Closed brandongregoryscott closed 2 years ago

brandongregoryscott commented 2 years ago

Splitting this issue off from https://github.com/brandongregoryscott/collation/issues/24#issuecomment-1085268873

Update alphabetize-interfaces to sort interfaces that have TypeIntersections. A test will already be added in this shape:

it("should sort nested types with type unions", async () => {
        // Arrange
        const input = createSourceFile(
            `
                export interface RouteMap extends GenericRouteMap {
                    root: RouteDefinition & {
                        routes: {
                            library: RouteDefinition & {
                                routes: {
                                    files: RouteDefinition;
                                    instruments: RouteDefinition;
                                };
                            };
                            help: RouteDefinition & {
                                routes: {
                                    usage: RouteDefinition;
                                };
                            };
                            login: RouteDefinition;
                            logout: RouteDefinition;
                            register: RouteDefinition;
                            workstation: RouteDefinition & {
                                routes: {
                                    workstation: RouteDefinition;
                                };
                            };
                        };
                    };
                }
            `
        );

        const expected = createSourceFile(
            `
                export interface RouteMap extends GenericRouteMap {
                    root: RouteDefinition & {
                        routes: {
                            library: RouteDefinition & {
                                routes: {
                                    files: RouteDefinition;
                                    instruments: RouteDefinition;
                                };
                            };
                            help: RouteDefinition & {
                                routes: {
                                    usage: RouteDefinition;
                                };
                            };
                            login: RouteDefinition;
                            logout: RouteDefinition;
                            register: RouteDefinition;
                            workstation: RouteDefinition & {
                                routes: {
                                    workstation: RouteDefinition;
                                };
                            };
                        };
                    };
                }
            `
        );

        // Act
        const result = await alphabetizeInterfaces(input);

        // Assert
        expect(result).toHaveErrors();
        expect(result).toMatchSourceFile(expected);
        await result.file.save();
    });