Skip to content

Commit

Permalink
Merge pull request #2 from forivall/fix-separators
Browse files Browse the repository at this point in the history
Add tests for the separator special word
  • Loading branch information
joutvhu authored Dec 9, 2024
2 parents 7e3e1d9 + 7817a93 commit 1a74bec
Show file tree
Hide file tree
Showing 14 changed files with 531 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/utils/get-sorted-nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ export const getSortedNodes: GetSortedNodes = (nodes, options) => {

for (const group of importOrder) {
if (group === SEPARATOR_SPECIAL_WORD) {
if (!importOrderSeparation)
if (
finalNodes.length !== 0 &&
finalNodes[finalNodes.length - 1] !== newLineNode
) {
finalNodes.push(newLineNode);
}
continue;
}

Expand Down
366 changes: 366 additions & 0 deletions tests/ImportsManualSeparated/__snapshots__/ppsi.spec.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,366 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`import-export-in-between.ts - typescript-verify: import-export-in-between.ts 1`] = `
import threeLevelRelativePath from "../../../threeLevelRelativePath";
import sameLevelRelativePath from "./sameLevelRelativePath";
import thirdParty from "third-party";
export { random } from './random';
import c from 'c';
import oneLevelRelativePath from "../oneLevelRelativePath";
import otherthing from "@core/otherthing";
import a from 'a';
import twoLevelRelativePath from "../../twoLevelRelativePath";
import component from "@ui/hello";
export default {
title: 'hello',
};
import fourLevelRelativePath from "../../../../fourLevelRelativePath";
import something from "@server/something";
import x from 'x';
function add(a:number,b:number) {
return a + b;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import otherthing from "@core/otherthing";
import something from "@server/something";
import component from "@ui/hello";
import a from "a";
import c from "c";
import thirdParty from "third-party";
import x from "x";
import fourLevelRelativePath from "../../../../fourLevelRelativePath";
import threeLevelRelativePath from "../../../threeLevelRelativePath";
import twoLevelRelativePath from "../../twoLevelRelativePath";
import oneLevelRelativePath from "../oneLevelRelativePath";
import sameLevelRelativePath from "./sameLevelRelativePath";
export { random } from "./random";
export default {
title: "hello",
};
function add(a: number, b: number) {
return a + b;
}
`;

exports[`import-export-only.ts - typescript-verify: import-export-only.ts 1`] = `
import React from 'react';
export const a = 1;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import React from "react";
export const a = 1;
`;

exports[`imports-with-comments.ts - typescript-verify: imports-with-comments.ts 1`] = `
// I am top level comment in this file.
// I am second line of top level comment in this file.
import './commands';
// Comment
// Comment
function add(a:number,b:number) {
return a + b;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// I am top level comment in this file.
// I am second line of top level comment in this file.
import "./commands";
// Comment
// Comment
function add(a: number, b: number) {
return a + b;
}
`;

exports[`imports-with-comments-and-third-party.ts - typescript-verify: imports-with-comments-and-third-party.ts 1`] = `
// I am top level comment in this file.
// I am second line of top level comment in this file.
import './commands';
import React from 'react';
// Comment
// Comment
function add(a:number,b:number) {
return a + b;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// I am top level comment in this file.
// I am second line of top level comment in this file.
import React from "react";
import "./commands";
// Comment
// Comment
function add(a: number, b: number) {
return a + b;
}
`;

exports[`imports-with-comments-on-top.ts - typescript-verify: imports-with-comments-on-top.ts 1`] = `
// I am top level comment in this file.
// I am second line of top level comment in this file.
import z from 'z';
import threeLevelRelativePath from "../../../threeLevelRelativePath";
import sameLevelRelativePath from "./sameLevelRelativePath";
import thirdParty from "third-party";
import oneLevelRelativePath from "../oneLevelRelativePath";
import otherthing from "@core/otherthing";
import abc from "@core/abc";
import twoLevelRelativePath from "../../twoLevelRelativePath";
import component from "@ui/hello";
import fourLevelRelativePath from "../../../../fourLevelRelativePath";
import something from "@server/something";
import xyz from "@ui/xyz";
import qwerty from "@server/qwerty";
function add(a:number,b:number) {
return a + b;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// I am top level comment in this file.
// I am second line of top level comment in this file.
import abc from "@core/abc";
import otherthing from "@core/otherthing";
import qwerty from "@server/qwerty";
import something from "@server/something";
import component from "@ui/hello";
import xyz from "@ui/xyz";
import thirdParty from "third-party";
import z from "z";
import fourLevelRelativePath from "../../../../fourLevelRelativePath";
import threeLevelRelativePath from "../../../threeLevelRelativePath";
import twoLevelRelativePath from "../../twoLevelRelativePath";
import oneLevelRelativePath from "../oneLevelRelativePath";
import sameLevelRelativePath from "./sameLevelRelativePath";
function add(a: number, b: number) {
return a + b;
}
`;

exports[`imports-with-file-level-comments.ts - typescript-verify: imports-with-file-level-comments.ts 1`] = `
//@ts-ignore
// I am file top level comments
import threeLevelRelativePath from "../../../threeLevelRelativePath";
// I am stick to sameLevelRelativePath
import sameLevelRelativePath from "./sameLevelRelativePath";
// I am stick to third party comment
import thirdParty from "third-party";
// leading comment
import {
random // inner comment
} from './random';
// leading comment
export {
random // inner comment
} from './random';
import c from 'c';
import oneLevelRelativePath from "../oneLevelRelativePath";
import otherthing from "@core/otherthing";
import a from 'a';
import twoLevelRelativePath from "../../twoLevelRelativePath";
import component from "@ui/hello";
export default {
title: 'hello',
};
import fourLevelRelativePath from "../../../../fourLevelRelativePath";
import something from "@server/something";
import x from 'x';
// I am function comment
function add(a:number,b:number) {
return a + b; // I am inside function
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//@ts-ignore
// I am file top level comments
import otherthing from "@core/otherthing";
import something from "@server/something";
import component from "@ui/hello";
import a from "a";
import c from "c";
// I am stick to third party comment
import thirdParty from "third-party";
import x from "x";
import fourLevelRelativePath from "../../../../fourLevelRelativePath";
import threeLevelRelativePath from "../../../threeLevelRelativePath";
import twoLevelRelativePath from "../../twoLevelRelativePath";
import oneLevelRelativePath from "../oneLevelRelativePath";
// leading comment
import {
random, // inner comment
} from "./random";
// I am stick to sameLevelRelativePath
import sameLevelRelativePath from "./sameLevelRelativePath";
// leading comment
export {
random, // inner comment
} from "./random";
export default {
title: "hello",
};
// I am function comment
function add(a: number, b: number) {
return a + b; // I am inside function
}
`;

exports[`imports-with-interpreter-directive.ts - typescript-verify: imports-with-interpreter-directive.ts 1`] = `
#!/usr/bin/env node
import otherthing from "@core/otherthing";
import abc from "@core/abc";
import twoLevelRelativePath from "../../twoLevelRelativePath";
import component from "@ui/hello";
import fourLevelRelativePath from "../../../../fourLevelRelativePath";
import something from "@server/something";
import xyz from "@ui/xyz";
import qwerty from "@server/qwerty";
function add(a:number,b:number) {
return a + b;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/usr/bin/env node
import abc from "@core/abc";
import otherthing from "@core/otherthing";
import qwerty from "@server/qwerty";
import something from "@server/something";
import component from "@ui/hello";
import xyz from "@ui/xyz";
import fourLevelRelativePath from "../../../../fourLevelRelativePath";
import twoLevelRelativePath from "../../twoLevelRelativePath";
function add(a: number, b: number) {
return a + b;
}
`;

exports[`imports-without-third-party.ts - typescript-verify: imports-without-third-party.ts 1`] = `
// I am top level comment
import otherthing from "@core/otherthing";
import abc from "@core/abc";
// I am comment
import twoLevelRelativePath from "../../twoLevelRelativePath";
import component from "@ui/hello";
import fourLevelRelativePath from "../../../../fourLevelRelativePath";
import something from "@server/something";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// I am top level comment
import abc from "@core/abc";
import otherthing from "@core/otherthing";
import something from "@server/something";
import component from "@ui/hello";
import fourLevelRelativePath from "../../../../fourLevelRelativePath";
// I am comment
import twoLevelRelativePath from "../../twoLevelRelativePath";
`;

exports[`no-import-export.ts - typescript-verify: no-import-export.ts 1`] = `
function add(a:number,b:number) {
return a + b;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function add(a: number, b: number) {
return a + b;
}
`;

exports[`one-import.ts - typescript-verify: one-import.ts 1`] = `
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************
// Import commands.js using ES2015 syntax:
import './commands';
// Alternatively you can use CommonJS syntax:
// require('./commands')
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************
// Import commands.js using ES2015 syntax:
import "./commands";
// Alternatively you can use CommonJS syntax:
// require('./commands')
`;

exports[`sort-imports-ignored.ts - typescript-verify: sort-imports-ignored.ts 1`] = `
// sort-imports-ignore
import './commands';
import b from 'b';
import a from 'a';
// Comment
function add(a:number,b:number) {
return a + b;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// sort-imports-ignore
import "./commands";
import b from "b";
import a from "a";
// Comment
function add(a: number, b: number) {
return a + b;
}
`;
Loading

0 comments on commit 1a74bec

Please sign in to comment.