From c03b7bfe3b51299c855da4648988bc6df81adb6c Mon Sep 17 00:00:00 2001 From: KLewin23 Date: Sat, 25 Mar 2023 07:04:39 +0000 Subject: [PATCH 01/49] Add sort by length option --- src/index.ts | 11 ++++ src/preprocessors/preprocessor.ts | 2 + src/types.ts | 1 + src/utils/__tests__/get-sorted-nodes.spec.ts | 58 ++++++++++++++++++++ src/utils/get-sorted-nodes-group.ts | 11 +++- src/utils/get-sorted-nodes.ts | 3 +- types/index.d.ts | 18 ++++-- 7 files changed, 97 insertions(+), 7 deletions(-) diff --git a/src/index.ts b/src/index.ts index f60f943d..ea7508a6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -48,6 +48,17 @@ const options = { default: false, description: 'Should specifiers be sorted?', }, + importOrderSortByLength: { + type: 'choice', + category: 'Global', + default: null, + choices: [ + {value: 'asc', description: 'will sort from shortest to longest'}, + {value: 'desc', description: 'will sort from longest to shortest'}, + {value: null, description: 'will disable sorting based on length'} + ], + description: 'Should imports be sorted by their string length' + } }; module.exports = { diff --git a/src/preprocessors/preprocessor.ts b/src/preprocessors/preprocessor.ts index 04f96257..0993020e 100644 --- a/src/preprocessors/preprocessor.ts +++ b/src/preprocessors/preprocessor.ts @@ -15,6 +15,7 @@ export function preprocessor(code: string, options: PrettierOptions) { importOrderSeparation, importOrderGroupNamespaceSpecifiers, importOrderSortSpecifiers, + importOrderSortByLength } = options; const parserOptions: ParserOptions = { @@ -40,6 +41,7 @@ export function preprocessor(code: string, options: PrettierOptions) { importOrderSeparation, importOrderGroupNamespaceSpecifiers, importOrderSortSpecifiers, + importOrderSortByLength }); return getCodeFromAst(allImports, directives, code, interpreter); diff --git a/src/types.ts b/src/types.ts index 89eda919..48502116 100644 --- a/src/types.ts +++ b/src/types.ts @@ -19,5 +19,6 @@ export type GetSortedNodes = ( | 'importOrderSeparation' | 'importOrderGroupNamespaceSpecifiers' | 'importOrderSortSpecifiers' + | 'importOrderSortByLength' >, ) => ImportOrLine[]; diff --git a/src/utils/__tests__/get-sorted-nodes.spec.ts b/src/utils/__tests__/get-sorted-nodes.spec.ts index d488c92a..b8b164a8 100644 --- a/src/utils/__tests__/get-sorted-nodes.spec.ts +++ b/src/utils/__tests__/get-sorted-nodes.spec.ts @@ -28,6 +28,7 @@ test('it returns all sorted nodes', () => { importOrderSeparation: false, importOrderGroupNamespaceSpecifiers: false, importOrderSortSpecifiers: false, + importOrderSortByLength: null }) as ImportDeclaration[]; expect(getSortedNodesNames(sorted)).toEqual([ @@ -72,6 +73,7 @@ test('it returns all sorted nodes case-insensitive', () => { importOrderSeparation: false, importOrderGroupNamespaceSpecifiers: false, importOrderSortSpecifiers: false, + importOrderSortByLength: null }) as ImportDeclaration[]; expect(getSortedNodesNames(sorted)).toEqual([ @@ -116,6 +118,7 @@ test('it returns all sorted nodes with sort order', () => { importOrderSeparation: false, importOrderGroupNamespaceSpecifiers: false, importOrderSortSpecifiers: false, + importOrderSortByLength: null }) as ImportDeclaration[]; expect(getSortedNodesNames(sorted)).toEqual([ @@ -160,6 +163,7 @@ test('it returns all sorted nodes with sort order case-insensitive', () => { importOrderSeparation: false, importOrderGroupNamespaceSpecifiers: false, importOrderSortSpecifiers: false, + importOrderSortByLength: null }) as ImportDeclaration[]; expect(getSortedNodesNames(sorted)).toEqual([ 'c', @@ -203,6 +207,7 @@ test('it returns all sorted import nodes with sorted import specifiers', () => { importOrderSeparation: false, importOrderGroupNamespaceSpecifiers: false, importOrderSortSpecifiers: true, + importOrderSortByLength: null }) as ImportDeclaration[]; expect(getSortedNodesNames(sorted)).toEqual([ 'XY', @@ -246,6 +251,7 @@ test('it returns all sorted import nodes with sorted import specifiers with case importOrderSeparation: false, importOrderGroupNamespaceSpecifiers: false, importOrderSortSpecifiers: true, + importOrderSortByLength: null }) as ImportDeclaration[]; expect(getSortedNodesNames(sorted)).toEqual([ 'c', @@ -289,6 +295,7 @@ test('it returns all sorted nodes with custom third party modules', () => { importOrderCaseInsensitive: true, importOrderGroupNamespaceSpecifiers: false, importOrderSortSpecifiers: false, + importOrderSortByLength: null }) as ImportDeclaration[]; expect(getSortedNodesNames(sorted)).toEqual([ 'a', @@ -313,6 +320,7 @@ test('it returns all sorted nodes with namespace specifiers at the top', () => { importOrderSeparation: false, importOrderGroupNamespaceSpecifiers: true, importOrderSortSpecifiers: false, + importOrderSortByLength: null }) as ImportDeclaration[]; expect(getSortedNodesNames(sorted)).toEqual([ @@ -329,3 +337,53 @@ test('it returns all sorted nodes with namespace specifiers at the top', () => { 'z', ]); }); + +test('it returns all sorted nodes, sorted shortest to longest', () => { + const result = getImportNodes(code) + const sorted = getSortedNodes(result, { + importOrder: [], + importOrderCaseInsensitive: false, + importOrderSeparation: false, + importOrderGroupNamespaceSpecifiers: false, + importOrderSortSpecifiers: false, + importOrderSortByLength: 'asc' + }) as ImportDeclaration[]; + expect(getSortedNodesNames(sorted)).toEqual([ + 'g', + 'z', + 'Ba', + 'BY', + 'Xa', + 'XY', + 'a', + 'x', + 'c', + 'k', + 't', + ]); +}) + +test('it returns all sorted nodes, sorted longest to shortest', () => { + const result = getImportNodes(code) + const sorted = getSortedNodes(result, { + importOrder: [], + importOrderCaseInsensitive: false, + importOrderSeparation: false, + importOrderGroupNamespaceSpecifiers: false, + importOrderSortSpecifiers: false, + importOrderSortByLength: 'desc' + }) as ImportDeclaration[]; + expect(getSortedNodesNames(sorted)).toEqual([ + 't', + 'k', + 'c', + 'a', + 'x', + 'Ba', + 'BY', + 'Xa', + 'XY', + 'g', + 'z' + ]); +}) diff --git a/src/utils/get-sorted-nodes-group.ts b/src/utils/get-sorted-nodes-group.ts index 9c9ae6bd..ab0f254f 100644 --- a/src/utils/get-sorted-nodes-group.ts +++ b/src/utils/get-sorted-nodes-group.ts @@ -4,14 +4,23 @@ import { PrettierOptions } from '../types'; export const getSortedNodesGroup = ( imports: ImportDeclaration[], - options: Pick, + options: Pick, ) => { return imports.sort((a, b) => { + const aLength = (a.end || 0) - (a.start || 0) + const bLength = (b.end || 0) - (b.start || 0) + if (options.importOrderGroupNamespaceSpecifiers) { const diff = namespaceSpecifierSort(a, b); if (diff !== 0) return diff; } + if (options.importOrderSortByLength === 'asc') + return aLength - bLength || a.source.value.localeCompare(b.source.value) + + if (options.importOrderSortByLength === 'desc') + return bLength - aLength || a.source.value.localeCompare(b.source.value) + return naturalSort(a.source.value, b.source.value); }); }; diff --git a/src/utils/get-sorted-nodes.ts b/src/utils/get-sorted-nodes.ts index d2c81278..ca43921a 100644 --- a/src/utils/get-sorted-nodes.ts +++ b/src/utils/get-sorted-nodes.ts @@ -21,7 +21,7 @@ export const getSortedNodes: GetSortedNodes = (nodes, options) => { const { importOrderSeparation, importOrderSortSpecifiers, - importOrderGroupNamespaceSpecifiers, + importOrderGroupNamespaceSpecifiers,importOrderSortByLength } = options; const originalNodes = nodes.map(clone); @@ -58,6 +58,7 @@ export const getSortedNodes: GetSortedNodes = (nodes, options) => { const sortedInsideGroup = getSortedNodesGroup(groupNodes, { importOrderGroupNamespaceSpecifiers, + importOrderSortByLength }); // Sort the import specifiers diff --git a/types/index.d.ts b/types/index.d.ts index 4c5f02f3..37ef2de0 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -47,21 +47,21 @@ export interface PluginConfig { /** * A boolean value to enable case-insensitivity in the sorting algorithm used to order imports within each match group. - * + * * For example, when false (or not specified): - * + * * ```js * import ExampleView from './ExampleView'; * import ExamplesList from './ExamplesList'; * ``` - * + * * compared with `"importOrderCaseInsensitive": true`: - * + * * ```js * import ExamplesList from './ExamplesList'; * import ExampleView from './ExampleView'; * ``` - * + * * @default false */ importOrderCaseInsensitive?: boolean; @@ -92,6 +92,14 @@ used to order imports within each match group. * @default ["typescript", "jsx"] */ importOrderParserPlugins?: ImportOrderParserPlugin[]; + + /** + * A choice value to enable sorting imports within their groups based on their string lengths, the two options being ascending and descending. + * Leaving the value blank or setting it to null will result in length being ignored + * + * @default undefined + */ + importOrderSortByLength?: 'asc' | 'desc' | null } export type PrettierConfig = PluginConfig & Config; From 5706700ae9e45fe66ebf4156ce53c9065cfa0920 Mon Sep 17 00:00:00 2001 From: KLewin23 Date: Sat, 25 Mar 2023 07:39:14 +0000 Subject: [PATCH 02/49] fix types --- src/utils/__tests__/get-all-comments-from-nodes.spec.ts | 1 + src/utils/__tests__/get-code-from-ast.spec.ts | 1 + src/utils/__tests__/remove-nodes-from-original-code.spec.ts | 1 + src/utils/get-sorted-nodes-group.ts | 2 +- 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/utils/__tests__/get-all-comments-from-nodes.spec.ts b/src/utils/__tests__/get-all-comments-from-nodes.spec.ts index ff8f156b..06b2d895 100644 --- a/src/utils/__tests__/get-all-comments-from-nodes.spec.ts +++ b/src/utils/__tests__/get-all-comments-from-nodes.spec.ts @@ -14,6 +14,7 @@ const getSortedImportNodes = (code: string, options?: ParserOptions) => { importOrderSeparation: false, importOrderGroupNamespaceSpecifiers: false, importOrderSortSpecifiers: false, + importOrderSortByLength: null }); }; diff --git a/src/utils/__tests__/get-code-from-ast.spec.ts b/src/utils/__tests__/get-code-from-ast.spec.ts index da58c041..f746ffd4 100644 --- a/src/utils/__tests__/get-code-from-ast.spec.ts +++ b/src/utils/__tests__/get-code-from-ast.spec.ts @@ -25,6 +25,7 @@ import a from 'a'; importOrderSeparation: false, importOrderGroupNamespaceSpecifiers: false, importOrderSortSpecifiers: false, + importOrderSortByLength: null }); const formatted = getCodeFromAst(sortedNodes, [], code, null); expect(format(formatted, { parser: 'babel' })).toEqual( diff --git a/src/utils/__tests__/remove-nodes-from-original-code.spec.ts b/src/utils/__tests__/remove-nodes-from-original-code.spec.ts index f214cf55..90717315 100644 --- a/src/utils/__tests__/remove-nodes-from-original-code.spec.ts +++ b/src/utils/__tests__/remove-nodes-from-original-code.spec.ts @@ -25,6 +25,7 @@ test('it should remove nodes from the original code', () => { importOrderSeparation: false, importOrderGroupNamespaceSpecifiers: false, importOrderSortSpecifiers: false, + importOrderSortByLength: null }); const allCommentsFromImports = getAllCommentsFromNodes(sortedNodes); diff --git a/src/utils/get-sorted-nodes-group.ts b/src/utils/get-sorted-nodes-group.ts index ab0f254f..b5dcc0c7 100644 --- a/src/utils/get-sorted-nodes-group.ts +++ b/src/utils/get-sorted-nodes-group.ts @@ -1,4 +1,4 @@ -import { Import, ImportDeclaration } from '@babel/types'; +import { ImportDeclaration } from '@babel/types'; import { naturalSort } from '../natural-sort'; import { PrettierOptions } from '../types'; From da49f66cd59a7cfc030f319247422d3892ad18e6 Mon Sep 17 00:00:00 2001 From: Kieran Lewin Date: Wed, 15 Nov 2023 14:26:07 +0000 Subject: [PATCH 03/49] Correct default type Co-authored-by: annes <76728727+annesnour03@users.noreply.github.com> --- types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/index.d.ts b/types/index.d.ts index 37ef2de0..21231277 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -97,7 +97,7 @@ used to order imports within each match group. * A choice value to enable sorting imports within their groups based on their string lengths, the two options being ascending and descending. * Leaving the value blank or setting it to null will result in length being ignored * - * @default undefined + * @default null */ importOrderSortByLength?: 'asc' | 'desc' | null } From 15bc4d819a73d93790385303bb185095aec4b75b Mon Sep 17 00:00:00 2001 From: Chason Choate <125305848+chason-choate-trilliant@users.noreply.github.com> Date: Thu, 6 Feb 2025 04:09:08 -0600 Subject: [PATCH 04/49] Yet another feature PR (#339) * Added current-state snapshots Capturing the current state of transformations so we can see how the upcoming changes affect them. * Add `` support When `importOrderSeparation` is enabled, users can further control separation placement with the `` keyword. --- README.md | 3 + src/constants.ts | 3 +- .../get-sorted-nodes-by-import-order.spec.ts | 138 ++++++ src/utils/get-sorted-nodes-by-import-order.ts | 10 +- .../__snapshots__/ppsi.spec.js.snap | 446 ++++++++++++++++++ .../import-export-in-between.ts | 20 + .../import-export-only.ts | 2 + .../import-with-type-imports-together.ts | 6 + .../imports-with-comments-and-third-party.ts | 10 + .../imports-with-comments-on-top.ts | 19 + .../imports-with-comments.ts | 10 + .../imports-with-directives.ts | 30 ++ .../imports-with-file-level-comments.ts | 33 ++ .../imports-with-interpreter-directive.ts | 13 + .../imports-without-third-party.ts | 8 + .../no-import-export.ts | 3 + tests/ImportsSeparatedByUser/one-import.ts | 19 + tests/ImportsSeparatedByUser/ppsi.spec.js | 5 + .../sort-imports-ignored.ts | 11 + 19 files changed, 786 insertions(+), 3 deletions(-) create mode 100644 tests/ImportsSeparatedByUser/__snapshots__/ppsi.spec.js.snap create mode 100644 tests/ImportsSeparatedByUser/import-export-in-between.ts create mode 100644 tests/ImportsSeparatedByUser/import-export-only.ts create mode 100644 tests/ImportsSeparatedByUser/import-with-type-imports-together.ts create mode 100644 tests/ImportsSeparatedByUser/imports-with-comments-and-third-party.ts create mode 100644 tests/ImportsSeparatedByUser/imports-with-comments-on-top.ts create mode 100644 tests/ImportsSeparatedByUser/imports-with-comments.ts create mode 100644 tests/ImportsSeparatedByUser/imports-with-directives.ts create mode 100644 tests/ImportsSeparatedByUser/imports-with-file-level-comments.ts create mode 100644 tests/ImportsSeparatedByUser/imports-with-interpreter-directive.ts create mode 100644 tests/ImportsSeparatedByUser/imports-without-third-party.ts create mode 100644 tests/ImportsSeparatedByUser/no-import-export.ts create mode 100644 tests/ImportsSeparatedByUser/one-import.ts create mode 100644 tests/ImportsSeparatedByUser/ppsi.spec.js create mode 100644 tests/ImportsSeparatedByUser/sort-imports-ignored.ts diff --git a/README.md b/README.md index 9c29388f..d89f3130 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,9 @@ between sorted import declarations group. The separation takes place according t "importOrderSeparation": true, ``` +If this option is enabled and `` is used in the `importOrder` array, the plugin +will ONLY add newlines at those locations and at the end of the imports. + #### `importOrderSortSpecifiers` **type**: `boolean` diff --git a/src/constants.ts b/src/constants.ts index 28c009e7..b348b187 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -20,8 +20,9 @@ export const THIRD_PARTY_MODULES_SPECIAL_WORD = ''; export const THIRD_PARTY_TYPES_SPECIAL_WORD = ''; export const TYPES_SPECIAL_WORD = ''; +export const SEPARATOR_SPECIAL_WORD = ''; -const PRETTIER_PLUGIN_SORT_IMPORTS_NEW_LINE = +export const PRETTIER_PLUGIN_SORT_IMPORTS_NEW_LINE = 'PRETTIER_PLUGIN_SORT_IMPORTS_NEW_LINE'; export const newLineNode = expressionStatement( diff --git a/src/utils/__tests__/get-sorted-nodes-by-import-order.spec.ts b/src/utils/__tests__/get-sorted-nodes-by-import-order.spec.ts index cc861b61..a9cc8f6e 100644 --- a/src/utils/__tests__/get-sorted-nodes-by-import-order.spec.ts +++ b/src/utils/__tests__/get-sorted-nodes-by-import-order.spec.ts @@ -4,6 +4,8 @@ import { getImportNodes } from '../get-import-nodes'; import { getSortedNodes } from '../get-sorted-nodes'; import { getSortedNodesModulesNames } from '../get-sorted-nodes-modules-names'; import { getSortedNodesNames } from '../get-sorted-nodes-names'; +import { PRETTIER_PLUGIN_SORT_IMPORTS_NEW_LINE } from "../../constants" +import { ImportOrLine } from "../../types" const code = `// first comment // second comment @@ -337,3 +339,139 @@ test('it returns all sorted nodes with namespace specifiers at the top', () => { 'z', ]); }); + +test('it returns the default separations if `importOrderSeparation` is false', () => { + const result = getImportNodes(code); + const sorted = getSortedNodes(result, { + importOrder: ['', '^a$', '^t$', '', '^k$', '^B', ''], + importOrderCaseInsensitive: false, + importOrderSeparation: false, + importOrderGroupNamespaceSpecifiers: false, + importOrderSortSpecifiers: false, + importOrderSideEffects: true, + }); + expect(getSeparationData(sorted)).toEqual([ + { type: "ImportDeclaration", value: 'XY' }, + { type: "ImportDeclaration", value: 'Xa' }, + { type: "ImportDeclaration", value: 'c' }, + { type: "ImportDeclaration", value: 'g' }, + { type: "ImportDeclaration", value: 'x' }, + { type: "ImportDeclaration", value: 'z' }, + { type: "ImportDeclaration", value: 'a' }, + { type: "ImportDeclaration", value: 't' }, + { type: "ImportDeclaration", value: 'k' }, + { type: "ImportDeclaration", value: 'BY' }, + { type: "ImportDeclaration", value: 'Ba' }, + { type: "ExpressionStatement", value: undefined }, + ]); +}); + +test('it returns default import module separations', () => { + const result = getImportNodes(code); + const sorted = getSortedNodes(result, { + importOrder: ['^a$', '^t$', '^k$', '^B'], + importOrderCaseInsensitive: false, + importOrderSeparation: true, + importOrderGroupNamespaceSpecifiers: false, + importOrderSortSpecifiers: false, + importOrderSideEffects: true, + }); + expect(getSeparationData(sorted)).toEqual([ + { type: "ImportDeclaration", value: 'XY' }, + { type: "ImportDeclaration", value: 'Xa' }, + { type: "ImportDeclaration", value: 'c' }, + { type: "ImportDeclaration", value: 'g' }, + { type: "ImportDeclaration", value: 'x' }, + { type: "ImportDeclaration", value: 'z' }, + { type: "ExpressionStatement", value: undefined }, + { type: "ImportDeclaration", value: 'a' }, + { type: "ExpressionStatement", value: undefined }, + { type: "ImportDeclaration", value: 't' }, + { type: "ExpressionStatement", value: undefined }, + { type: "ImportDeclaration", value: 'k' }, + { type: "ExpressionStatement", value: undefined }, + { type: "ImportDeclaration", value: 'BY' }, + { type: "ImportDeclaration", value: 'Ba' }, + { type: "ExpressionStatement", value: undefined }, + { type: "ExpressionStatement", value: undefined }, + ]); +}); + +test('it returns targeted import module separations', () => { + const result = getImportNodes(code); + const sorted = getSortedNodes(result, { + importOrder: ['^a$', '', '^t$', '', '^k$', '^B'], + importOrderCaseInsensitive: false, + importOrderSeparation: true, + importOrderGroupNamespaceSpecifiers: false, + importOrderSortSpecifiers: false, + importOrderSideEffects: true, + }); + expect(getSeparationData(sorted)).toEqual([ + { type: "ImportDeclaration", value: 'XY' }, + { type: "ImportDeclaration", value: 'Xa' }, + { type: "ImportDeclaration", value: 'c' }, + { type: "ImportDeclaration", value: 'g' }, + { type: "ImportDeclaration", value: 'x' }, + { type: "ImportDeclaration", value: 'z' }, + { type: "ImportDeclaration", value: 'a' }, + { type: "ExpressionStatement", value: undefined }, + { type: "ImportDeclaration", value: 't' }, + { type: "ExpressionStatement", value: undefined }, + { type: "ImportDeclaration", value: 'k' }, + { type: "ImportDeclaration", value: 'BY' }, + { type: "ImportDeclaration", value: 'Ba' }, + { type: "ExpressionStatement", value: undefined }, + ]); +}); + +test('it never returns a separation at the top of the list (leading separator)', () => { + const result = getImportNodes(` + import './test'; + `.trim()); + const sorted = getSortedNodes(result, { + importOrder: ['', '^[./]'], + importOrderCaseInsensitive: false, + importOrderSeparation: true, + importOrderGroupNamespaceSpecifiers: false, + importOrderSortSpecifiers: false, + importOrderSideEffects: true, + }); + expect(getSeparationData(sorted)).toEqual([ + { type: "ImportDeclaration", value: './test' }, + { type: "ExpressionStatement", value: undefined }, + ]); +}); + +test('it never returns a separation at the top of the list (zero preceding imports)', () => { + const result = getImportNodes(` + import './test'; + `.trim()); + const sorted = getSortedNodes(result, { + importOrder: ['^a.*$', '', '^[./]'], + importOrderCaseInsensitive: false, + importOrderSeparation: true, + importOrderGroupNamespaceSpecifiers: false, + importOrderSortSpecifiers: false, + importOrderSideEffects: true, + }); + expect(getSeparationData(sorted)).toEqual([ + { type: "ImportDeclaration", value: './test' }, + { type: "ExpressionStatement", value: undefined }, + ]); +}); + +// Focuses the nodes solely to the import declarations and the new lines +function getSeparationData(nodes: ImportOrLine[]): { type: "ImportDeclaration" | "ExpressionStatement", value?: string }[] { + return nodes + .filter(node => node.type === "ImportDeclaration" + || ( + node.type === "ExpressionStatement" + && node.expression.type === "StringLiteral" + && node.expression.value === PRETTIER_PLUGIN_SORT_IMPORTS_NEW_LINE + )) + .map(x => ({ + type: x.type, + value: x.type === "ImportDeclaration" ? x.source.value : undefined + })); +} diff --git a/src/utils/get-sorted-nodes-by-import-order.ts b/src/utils/get-sorted-nodes-by-import-order.ts index d8ddd623..5450df7e 100644 --- a/src/utils/get-sorted-nodes-by-import-order.ts +++ b/src/utils/get-sorted-nodes-by-import-order.ts @@ -1,6 +1,6 @@ import { clone } from 'lodash'; -import { THIRD_PARTY_MODULES_SPECIAL_WORD, newLineNode } from '../constants'; +import { THIRD_PARTY_MODULES_SPECIAL_WORD, newLineNode, SEPARATOR_SPECIAL_WORD } from '../constants'; import { naturalSort } from '../natural-sort'; import { GetSortedNodes, ImportGroups, ImportOrLine } from '../types'; import { getImportNodesMatchedGroup } from './get-import-nodes-matched-group'; @@ -51,9 +51,14 @@ export const getSortedNodesByImportOrder: GetSortedNodes = (nodes, options) => { importOrderGroups[matchedGroup].push(node); } + const hasUserProvidedSeparators = options.importOrder.includes(SEPARATOR_SPECIAL_WORD); + let safeToAddNewLine = false; for (const group of importOrder) { const groupNodes = importOrderGroups[group]; + if (importOrderSeparation && group === SEPARATOR_SPECIAL_WORD && safeToAddNewLine) { + finalNodes.push(newLineNode); + } if (groupNodes.length === 0) continue; const sortedInsideGroup = getSortedNodesGroup(groupNodes, { @@ -68,8 +73,9 @@ export const getSortedNodesByImportOrder: GetSortedNodes = (nodes, options) => { } finalNodes.push(...sortedInsideGroup); + safeToAddNewLine = true; - if (importOrderSeparation) { + if (importOrderSeparation && !hasUserProvidedSeparators) { finalNodes.push(newLineNode); } } diff --git a/tests/ImportsSeparatedByUser/__snapshots__/ppsi.spec.js.snap b/tests/ImportsSeparatedByUser/__snapshots__/ppsi.spec.js.snap new file mode 100644 index 00000000..b83765d9 --- /dev/null +++ b/tests/ImportsSeparatedByUser/__snapshots__/ppsi.spec.js.snap @@ -0,0 +1,446 @@ +// 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 a from "a"; +import c from "c"; +import thirdParty from "third-party"; +import x from "x"; +import otherthing from "@core/otherthing"; +import something from "@server/something"; + +import component from "@ui/hello"; +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[`import-with-type-imports-together.ts - typescript-verify: import-with-type-imports-together.ts 1`] = ` +import { foo } from "@server/foo" +import type { Quux } from "./quux" +import { Link } from "@ui/Link" +import type { Bar } from "@server/bar" +import type { LinkProps } from "@ui/Link/LinkProps" +import { baz } from "./baz" +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +import type { Bar } from "@server/bar"; +import { foo } from "@server/foo"; + +import { Link } from "@ui/Link"; +import type { LinkProps } from "@ui/Link/LinkProps"; +import { baz } from "./baz"; +import type { Quux } from "./quux"; + +`; + +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 thirdParty from "third-party"; +import z from "z"; +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 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-directives.ts - typescript-verify: imports-with-directives.ts 1`] = ` +'use strict'; +'use client'; + +// comment after directives +import otherthing from "@core/otherthing"; +import abc from "@core/abc"; + +// Comment + +function add(a:number,b:number) { + return a + b; +} + +function addStrict(a:number,b:number) { + 'use strict'; + return a + b; +} + +'preserve me'; + +const workletAdd = (a:number,b:number) => { + 'worklet'; + return a + b; +} + +(function() { + 'use strict'; + // some iffe example + return true; +})(); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +"use strict"; +"use client"; + +// comment after directives +import abc from "@core/abc"; +import otherthing from "@core/otherthing"; + +// Comment + +function add(a: number, b: number) { + return a + b; +} + +function addStrict(a: number, b: number) { + "use strict"; + return a + b; +} + +("preserve me"); + +const workletAdd = (a: number, b: number) => { + "worklet"; + return a + b; +}; + +(function () { + "use strict"; + // some iffe example + return true; +})(); + +`; + +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 a from "a"; +import c from "c"; +// I am stick to third party comment +import thirdParty from "third-party"; +import x from "x"; +import otherthing from "@core/otherthing"; +import something from "@server/something"; + +import component from "@ui/hello"; +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; +} + +`; diff --git a/tests/ImportsSeparatedByUser/import-export-in-between.ts b/tests/ImportsSeparatedByUser/import-export-in-between.ts new file mode 100644 index 00000000..16bc1d77 --- /dev/null +++ b/tests/ImportsSeparatedByUser/import-export-in-between.ts @@ -0,0 +1,20 @@ +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; +} diff --git a/tests/ImportsSeparatedByUser/import-export-only.ts b/tests/ImportsSeparatedByUser/import-export-only.ts new file mode 100644 index 00000000..44f7eff4 --- /dev/null +++ b/tests/ImportsSeparatedByUser/import-export-only.ts @@ -0,0 +1,2 @@ +import React from 'react'; +export const a = 1; diff --git a/tests/ImportsSeparatedByUser/import-with-type-imports-together.ts b/tests/ImportsSeparatedByUser/import-with-type-imports-together.ts new file mode 100644 index 00000000..b6d28272 --- /dev/null +++ b/tests/ImportsSeparatedByUser/import-with-type-imports-together.ts @@ -0,0 +1,6 @@ +import { foo } from "@server/foo" +import type { Quux } from "./quux" +import { Link } from "@ui/Link" +import type { Bar } from "@server/bar" +import type { LinkProps } from "@ui/Link/LinkProps" +import { baz } from "./baz" diff --git a/tests/ImportsSeparatedByUser/imports-with-comments-and-third-party.ts b/tests/ImportsSeparatedByUser/imports-with-comments-and-third-party.ts new file mode 100644 index 00000000..a9fb311d --- /dev/null +++ b/tests/ImportsSeparatedByUser/imports-with-comments-and-third-party.ts @@ -0,0 +1,10 @@ +// 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; +} diff --git a/tests/ImportsSeparatedByUser/imports-with-comments-on-top.ts b/tests/ImportsSeparatedByUser/imports-with-comments-on-top.ts new file mode 100644 index 00000000..6b08ed06 --- /dev/null +++ b/tests/ImportsSeparatedByUser/imports-with-comments-on-top.ts @@ -0,0 +1,19 @@ +// 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; +} diff --git a/tests/ImportsSeparatedByUser/imports-with-comments.ts b/tests/ImportsSeparatedByUser/imports-with-comments.ts new file mode 100644 index 00000000..67b8e461 --- /dev/null +++ b/tests/ImportsSeparatedByUser/imports-with-comments.ts @@ -0,0 +1,10 @@ +// 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; +} diff --git a/tests/ImportsSeparatedByUser/imports-with-directives.ts b/tests/ImportsSeparatedByUser/imports-with-directives.ts new file mode 100644 index 00000000..221ec608 --- /dev/null +++ b/tests/ImportsSeparatedByUser/imports-with-directives.ts @@ -0,0 +1,30 @@ +'use strict'; +'use client'; + +// comment after directives +import otherthing from "@core/otherthing"; +import abc from "@core/abc"; + +// Comment + +function add(a:number,b:number) { + return a + b; +} + +function addStrict(a:number,b:number) { + 'use strict'; + return a + b; +} + +'preserve me'; + +const workletAdd = (a:number,b:number) => { + 'worklet'; + return a + b; +} + +(function() { + 'use strict'; + // some iffe example + return true; +})(); diff --git a/tests/ImportsSeparatedByUser/imports-with-file-level-comments.ts b/tests/ImportsSeparatedByUser/imports-with-file-level-comments.ts new file mode 100644 index 00000000..8ffcfb5d --- /dev/null +++ b/tests/ImportsSeparatedByUser/imports-with-file-level-comments.ts @@ -0,0 +1,33 @@ +//@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 +} diff --git a/tests/ImportsSeparatedByUser/imports-with-interpreter-directive.ts b/tests/ImportsSeparatedByUser/imports-with-interpreter-directive.ts new file mode 100644 index 00000000..8e7de5f6 --- /dev/null +++ b/tests/ImportsSeparatedByUser/imports-with-interpreter-directive.ts @@ -0,0 +1,13 @@ +#!/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; +} diff --git a/tests/ImportsSeparatedByUser/imports-without-third-party.ts b/tests/ImportsSeparatedByUser/imports-without-third-party.ts new file mode 100644 index 00000000..ef1797a2 --- /dev/null +++ b/tests/ImportsSeparatedByUser/imports-without-third-party.ts @@ -0,0 +1,8 @@ +// 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"; diff --git a/tests/ImportsSeparatedByUser/no-import-export.ts b/tests/ImportsSeparatedByUser/no-import-export.ts new file mode 100644 index 00000000..e8f71db3 --- /dev/null +++ b/tests/ImportsSeparatedByUser/no-import-export.ts @@ -0,0 +1,3 @@ +function add(a:number,b:number) { + return a + b; +} diff --git a/tests/ImportsSeparatedByUser/one-import.ts b/tests/ImportsSeparatedByUser/one-import.ts new file mode 100644 index 00000000..35d75ba6 --- /dev/null +++ b/tests/ImportsSeparatedByUser/one-import.ts @@ -0,0 +1,19 @@ +// 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') diff --git a/tests/ImportsSeparatedByUser/ppsi.spec.js b/tests/ImportsSeparatedByUser/ppsi.spec.js new file mode 100644 index 00000000..3f674010 --- /dev/null +++ b/tests/ImportsSeparatedByUser/ppsi.spec.js @@ -0,0 +1,5 @@ +run_spec(__dirname, ["typescript"], { + importOrder: ['^@core/(.*)$', '^@server/(.*)', '', '^@ui/(.*)$', '^[./]'], + importOrderSeparation: true, + importOrderParserPlugins: ['typescript'] +}); diff --git a/tests/ImportsSeparatedByUser/sort-imports-ignored.ts b/tests/ImportsSeparatedByUser/sort-imports-ignored.ts new file mode 100644 index 00000000..c53ddcf0 --- /dev/null +++ b/tests/ImportsSeparatedByUser/sort-imports-ignored.ts @@ -0,0 +1,11 @@ +// sort-imports-ignore + +import './commands'; +import b from 'b'; +import a from 'a'; + +// Comment + +function add(a:number,b:number) { + return a + b; +} From 22e26b6a1cb173d913593bb208bb398b9e512e6d Mon Sep 17 00:00:00 2001 From: Kieran Date: Thu, 20 Mar 2025 10:36:26 +0000 Subject: [PATCH 05/49] fix tests, update docs --- README.md | 7 +++++++ .../get-import-nodes-matched-group.spec.ts | 2 -- .../get-sorted-nodes-by-import-order.spec.ts | 8 ++++++++ src/utils/__tests__/get-sorted-nodes.spec.ts | 3 +++ src/utils/get-sorted-nodes-by-import-order.ts | 3 ++- src/utils/get-sorted-nodes.ts | 2 +- types/index.d.ts | 13 +++++++++++++ 7 files changed, 34 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9c29388f..081fe185 100644 --- a/README.md +++ b/README.md @@ -198,6 +198,13 @@ with options as a JSON string of the plugin array: importOrderParserPlugins: [] ``` +### `importOrderSortByLength` +**type**: `'asc' | 'desc' | null` +**default value**: `null` + +A choice value to enable sorting imports within their groups based on their string lengths, the two options being ascending and descending. +Leaving the value blank or setting it to null will result in length being ignored + ### `importOrderSideEffects` **type**: `boolean` **default value**: `true` diff --git a/src/utils/__tests__/get-import-nodes-matched-group.spec.ts b/src/utils/__tests__/get-import-nodes-matched-group.spec.ts index b585eb48..11ec6b26 100644 --- a/src/utils/__tests__/get-import-nodes-matched-group.spec.ts +++ b/src/utils/__tests__/get-import-nodes-matched-group.spec.ts @@ -1,5 +1,3 @@ -import { THIRD_PARTY_MODULES_SPECIAL_WORD } from '../../constants'; -import { ImportGroups } from '../../types'; import { getImportNodes } from '../get-import-nodes'; import { getImportNodesMatchedGroup } from '../get-import-nodes-matched-group'; diff --git a/src/utils/__tests__/get-sorted-nodes-by-import-order.spec.ts b/src/utils/__tests__/get-sorted-nodes-by-import-order.spec.ts index cc861b61..5461d80e 100644 --- a/src/utils/__tests__/get-sorted-nodes-by-import-order.spec.ts +++ b/src/utils/__tests__/get-sorted-nodes-by-import-order.spec.ts @@ -28,6 +28,7 @@ test('it returns all sorted nodes', () => { importOrderSeparation: false, importOrderGroupNamespaceSpecifiers: false, importOrderSortSpecifiers: false, + importOrderSortByLength: null, importOrderSideEffects: true, }) as ImportDeclaration[]; @@ -73,6 +74,7 @@ test('it returns all sorted nodes case-insensitive', () => { importOrderSeparation: false, importOrderGroupNamespaceSpecifiers: false, importOrderSortSpecifiers: false, + importOrderSortByLength: null, importOrderSideEffects: true, }) as ImportDeclaration[]; @@ -118,6 +120,7 @@ test('it returns all sorted nodes with sort order', () => { importOrderSeparation: false, importOrderGroupNamespaceSpecifiers: false, importOrderSortSpecifiers: false, + importOrderSortByLength: null, importOrderSideEffects: true, }) as ImportDeclaration[]; @@ -163,6 +166,7 @@ test('it returns all sorted nodes with sort order case-insensitive', () => { importOrderSeparation: false, importOrderGroupNamespaceSpecifiers: false, importOrderSortSpecifiers: false, + importOrderSortByLength: null, importOrderSideEffects: true, }) as ImportDeclaration[]; expect(getSortedNodesNames(sorted)).toEqual([ @@ -207,6 +211,7 @@ test('it returns all sorted import nodes with sorted import specifiers', () => { importOrderSeparation: false, importOrderGroupNamespaceSpecifiers: false, importOrderSortSpecifiers: true, + importOrderSortByLength: null, importOrderSideEffects: true, }) as ImportDeclaration[]; expect(getSortedNodesNames(sorted)).toEqual([ @@ -251,6 +256,7 @@ test('it returns all sorted import nodes with sorted import specifiers with case importOrderSeparation: false, importOrderGroupNamespaceSpecifiers: false, importOrderSortSpecifiers: true, + importOrderSortByLength: null, importOrderSideEffects: true, }) as ImportDeclaration[]; expect(getSortedNodesNames(sorted)).toEqual([ @@ -295,6 +301,7 @@ test('it returns all sorted nodes with custom third party modules', () => { importOrderCaseInsensitive: true, importOrderGroupNamespaceSpecifiers: false, importOrderSortSpecifiers: false, + importOrderSortByLength: null, importOrderSideEffects: true, }) as ImportDeclaration[]; expect(getSortedNodesNames(sorted)).toEqual([ @@ -320,6 +327,7 @@ test('it returns all sorted nodes with namespace specifiers at the top', () => { importOrderSeparation: false, importOrderGroupNamespaceSpecifiers: true, importOrderSortSpecifiers: false, + importOrderSortByLength: null, importOrderSideEffects: true, }) as ImportDeclaration[]; diff --git a/src/utils/__tests__/get-sorted-nodes.spec.ts b/src/utils/__tests__/get-sorted-nodes.spec.ts index 54622a03..ae17f0f6 100644 --- a/src/utils/__tests__/get-sorted-nodes.spec.ts +++ b/src/utils/__tests__/get-sorted-nodes.spec.ts @@ -372,6 +372,7 @@ test('it returns all sorted nodes, sorted shortest to longest', () => { importOrderSeparation: false, importOrderGroupNamespaceSpecifiers: false, importOrderSortSpecifiers: false, + importOrderSideEffects: true, importOrderSortByLength: 'asc' }) as ImportDeclaration[]; expect(getSortedNodesNames(sorted)).toEqual([ @@ -397,6 +398,7 @@ test('it returns all sorted nodes, sorted longest to shortest', () => { importOrderSeparation: false, importOrderGroupNamespaceSpecifiers: false, importOrderSortSpecifiers: false, + importOrderSideEffects: false, importOrderSortByLength: 'desc' }) as ImportDeclaration[]; expect(getSortedNodesNames(sorted)).toEqual([ @@ -425,6 +427,7 @@ test('it returns all sorted nodes with types', () => { importOrderGroupNamespaceSpecifiers: false, importOrderSortSpecifiers: false, importOrderSideEffects: true, + importOrderSortByLength: null, }) as ImportDeclaration[]; expect(getSortedNodesNames(sorted)).toEqual([ diff --git a/src/utils/get-sorted-nodes-by-import-order.ts b/src/utils/get-sorted-nodes-by-import-order.ts index d8ddd623..676a700d 100644 --- a/src/utils/get-sorted-nodes-by-import-order.ts +++ b/src/utils/get-sorted-nodes-by-import-order.ts @@ -17,7 +17,7 @@ import { getSortedNodesGroup } from './get-sorted-nodes-group'; export const getSortedNodesByImportOrder: GetSortedNodes = (nodes, options) => { naturalSort.insensitive = options.importOrderCaseInsensitive; - let { importOrder } = options; + let { importOrder,importOrderSortByLength } = options; const { importOrderSeparation, importOrderSortSpecifiers, @@ -58,6 +58,7 @@ export const getSortedNodesByImportOrder: GetSortedNodes = (nodes, options) => { const sortedInsideGroup = getSortedNodesGroup(groupNodes, { importOrderGroupNamespaceSpecifiers, + importOrderSortByLength }); // Sort the import specifiers diff --git a/src/utils/get-sorted-nodes.ts b/src/utils/get-sorted-nodes.ts index fb85e1b2..4f5440b5 100644 --- a/src/utils/get-sorted-nodes.ts +++ b/src/utils/get-sorted-nodes.ts @@ -21,7 +21,7 @@ import { getSortedNodesByImportOrder } from './get-sorted-nodes-by-import-order' * @param options Options to influence the behavior of the sorting algorithm. */ export const getSortedNodes: GetSortedNodes = (nodes, options) => { - const { importOrderSeparation, importOrderSideEffects, importOrderSortByLength } = + const { importOrderSeparation, importOrderSideEffects } = options; // Split nodes at each boundary between a side-effect node and a diff --git a/types/index.d.ts b/types/index.d.ts index e4507bfb..c132ae54 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -101,6 +101,19 @@ used to order imports within each match group. */ importOrderSortByLength?: 'asc' | 'desc' | null + /** + * By default, the plugin sorts side effect imports like any other imports in the file. + * If you need to keep side effect imports in the same place but sort all other imports around them, + * set this option to false. + * + * ``` + * "importOrderImportAttributesKeyword": 'with', + * ``` + * + * @default true + */ + importOrderSideEffects?: boolean; + /** * The import attributes/assertions syntax to use. "with" for import "..." with { type: "json" }, * "assert" for import "..." assert { type: "json" }, and "with-legacy" for import "..." with type: "json". From 7ef0bb21b9151b9575f302c65ea004abc166e06a Mon Sep 17 00:00:00 2001 From: RyderKishan Date: Thu, 15 May 2025 16:07:39 +0530 Subject: [PATCH 06/49] feat: Import sort order skip files --- package.json | 4 +- src/index.ts | 7 +++ src/preprocessors/preprocessor.ts | 8 +++ src/utils/__tests__/should-skip-file.spec.ts | 61 ++++++++++++++++++++ src/utils/should-skip-file.ts | 30 ++++++++++ tsconfig.json | 2 +- yarn.lock | 12 ++++ 7 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 src/utils/__tests__/should-skip-file.spec.ts create mode 100644 src/utils/should-skip-file.ts diff --git a/package.json b/package.json index 9ba8fac2..4be80a58 100644 --- a/package.json +++ b/package.json @@ -38,13 +38,15 @@ "@babel/traverse": "^7.26.7", "@babel/types": "^7.26.7", "javascript-natural-sort": "^0.7.1", - "lodash": "^4.17.21" + "lodash": "^4.17.21", + "minimatch": "^10.0.1" }, "devDependencies": { "@babel/core": "^7.26.7", "@types/chai": "^5.0.1", "@types/jest": "^29.5.14", "@types/lodash": "^4.17.14", + "@types/minimatch": "^5.1.2", "@types/node": "^22.10.10", "@vue/compiler-sfc": "^3.5.13", "jest": "^29.7.0", diff --git a/src/index.ts b/src/index.ts index 216f609d..691da241 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,6 +12,13 @@ import { createSvelteParsers } from './utils/create-svelte-parsers'; const svelteParsers = createSvelteParsers(); const options: Options = { + importOrderSkipFiles: { + type: 'path', + category: 'Global', + array: true, + default: [{ value: [] }], + description: 'Provide a list of files to skip sorting imports.', + }, importOrder: { type: 'path', category: 'Global', diff --git a/src/preprocessors/preprocessor.ts b/src/preprocessors/preprocessor.ts index 716212ec..0e0a6d01 100644 --- a/src/preprocessors/preprocessor.ts +++ b/src/preprocessors/preprocessor.ts @@ -7,6 +7,7 @@ import { getCodeFromAst } from '../utils/get-code-from-ast'; import { getExperimentalParserPlugins } from '../utils/get-experimental-parser-plugins'; import { getSortedNodes } from '../utils/get-sorted-nodes'; import { isSortImportsIgnored } from '../utils/is-sort-imports-ignored'; +import { shouldSkipFile } from '../utils/should-skip-file'; export function preprocessor(code: string, options: PrettierOptions) { const { @@ -18,8 +19,15 @@ export function preprocessor(code: string, options: PrettierOptions) { importOrderSortSpecifiers, importOrderSideEffects, importOrderImportAttributesKeyword, + importOrderSkipFiles, + filepath, } = options; + // Check if the file should be skipped + if (filepath && shouldSkipFile(filepath, (importOrderSkipFiles || []) as string[])) { + return code; + } + const parserOptions: ParserOptions = { sourceType: 'module', plugins: getExperimentalParserPlugins(importOrderParserPlugins), diff --git a/src/utils/__tests__/should-skip-file.spec.ts b/src/utils/__tests__/should-skip-file.spec.ts new file mode 100644 index 00000000..f6431c43 --- /dev/null +++ b/src/utils/__tests__/should-skip-file.spec.ts @@ -0,0 +1,61 @@ +import { shouldSkipFile } from '../should-skip-file'; + +describe('shouldSkipFile', () => { + it('should return false when skipPatterns is empty', () => { + expect(shouldSkipFile('src/file.ts', [])).toBe(false); + }); + + it('should return false when no patterns match', () => { + const patterns = ['test/*.ts', 'lib/*.js']; + expect(shouldSkipFile('src/file.ts', patterns)).toBe(false); + }); + + it('should return true when file matches a pattern', () => { + const patterns = ['src/*.ts', 'lib/*.js']; + expect(shouldSkipFile('src/file.ts', patterns)).toBe(true); + }); + + it('should handle glob patterns correctly', () => { + const patterns = ['*.test.ts', 'generated/**']; + expect(shouldSkipFile('Button.test.ts', patterns)).toBe(true); + expect(shouldSkipFile('generated/types.ts', patterns)).toBe(true); + expect(shouldSkipFile('src/Button.ts', patterns)).toBe(false); + }); + + it('should match filename-only patterns against basename', () => { + const patterns = ['*.js', 'example.ts']; + expect(shouldSkipFile('/long/path/to/file.js', patterns)).toBe(true); + expect(shouldSkipFile('/different/path/example.ts', patterns)).toBe(true); + expect(shouldSkipFile('/path/to/file.ts', patterns)).toBe(false); + }); + + it('should handle special characters in filenames', () => { + const patterns = ['*.spec.ts', '*test*.js']; + expect(shouldSkipFile('my-component.spec.ts', patterns)).toBe(true); + expect(shouldSkipFile('my.test.js', patterns)).toBe(true); + expect(shouldSkipFile('test.jsx', patterns)).toBe(false); + }); + + it('should handle multiple patterns with mixed path separators', () => { + const patterns = ['src/*.ts', 'test/*.js', '*.test.tsx']; + expect(shouldSkipFile('src/file.ts', patterns)).toBe(true); + expect(shouldSkipFile('test/file.js', patterns)).toBe(true); + expect(shouldSkipFile('component.test.tsx', patterns)).toBe(true); + expect(shouldSkipFile('src/sub/file.ts', patterns)).toBe(false); + }); + + it('should handle exact filename matches', () => { + const patterns = ['example.js', 'tsconfig.json']; + expect(shouldSkipFile('/any/path/example.js', patterns)).toBe(true); + expect(shouldSkipFile('/root/tsconfig.json', patterns)).toBe(true); + expect(shouldSkipFile('/path/to/example.test.js', patterns)).toBe(false); + }); + + it('should handle directory patterns', () => { + const patterns = ['test/**/*.*', 'generated/**/*.*']; + expect(shouldSkipFile('test/file.ts', patterns)).toBe(true); + expect(shouldSkipFile('test/unit/component.js', patterns)).toBe(true); + expect(shouldSkipFile('generated/types.ts', patterns)).toBe(true); + expect(shouldSkipFile('src/components/button.ts', patterns)).toBe(false); + }); +}); \ No newline at end of file diff --git a/src/utils/should-skip-file.ts b/src/utils/should-skip-file.ts new file mode 100644 index 00000000..c52a1f1d --- /dev/null +++ b/src/utils/should-skip-file.ts @@ -0,0 +1,30 @@ +import { minimatch } from 'minimatch'; +import path from 'path'; + +/** + * Checks if the current file path matches any of the patterns in importOrderSkipFiles + * @param filePath The path of the current file being processed + * @param skipPatterns Array of patterns for files to skip + * @returns boolean indicating whether the file should be skipped + */ +export function shouldSkipFile(filepath: string, skipPatterns: string[]): boolean { + if (skipPatterns.length === 0) { + return false; + } + + const normalizedPath = filepath.split(path.sep).join('/'); + const filename = path.basename(filepath); + + return skipPatterns.some(pattern => { + // Normalize pattern to use forward slashes + const normalizedPattern = pattern.split(path.sep).join('/'); + + // If pattern doesn't contain '/', match against filename only + if (!normalizedPattern.includes('/')) { + return minimatch(filename, normalizedPattern, { matchBase: true }); + } + + // Otherwise match against full path + return minimatch(normalizedPath, normalizedPattern); + }); +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 6bc2c975..aee6ddb5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { /* Basic Options */ - "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ + "target": "ES2015", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ // "lib": [], /* Specify library files to be included in the compilation. */ "allowJs": true, /* Allow javascript files to be compiled. */ diff --git a/yarn.lock b/yarn.lock index 135f7dd8..9d6a6b38 100644 --- a/yarn.lock +++ b/yarn.lock @@ -729,6 +729,11 @@ resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.17.14.tgz#bafc053533f4cdc5fcc9635af46a963c1f3deaff" integrity sha512-jsxagdikDiDBeIRaPYtArcT8my4tN1og7MtMRquFT3XNA6axxyHDRUemqDz/taRDdOUn0GnGHRCuff4q48sW9A== +"@types/minimatch@^5.1.2": + version "5.1.2" + resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-5.1.2.tgz#07508b45797cb81ec3f273011b054cd0755eddca" + integrity sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA== + "@types/node@*": version "22.9.1" resolved "https://registry.yarnpkg.com/@types/node/-/node-22.9.1.tgz#bdf91c36e0e7ecfb7257b2d75bf1b206b308ca71" @@ -2016,6 +2021,13 @@ mimic-fn@^2.1.0: resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-2.1.0.tgz#7ed2c2ccccaf84d3ffcb7a69b57711fc2083401b" integrity sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg== +minimatch@^10.0.1: + version "10.0.1" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-10.0.1.tgz#ce0521856b453c86e25f2c4c0d03e6ff7ddc440b" + integrity sha512-ethXTt3SGGR+95gudmqJ1eNhRO7eGEGIgYA9vnPatK4/etz2MEVDno5GMCibdMTuBMyElzIlgxMna3K94XDIDQ== + dependencies: + brace-expansion "^2.0.1" + minimatch@^3.0.4, minimatch@^3.1.1, minimatch@^3.1.2: version "3.1.2" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b" From b39a25f5423a0ae3b9583951befa8f96d03c9df0 Mon Sep 17 00:00:00 2001 From: RyderKishan Date: Thu, 15 May 2025 16:19:56 +0530 Subject: [PATCH 07/49] Downgraded minimatch for node 18 --- package.json | 2 +- yarn.lock | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 4be80a58..ed36bf14 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "@babel/types": "^7.26.7", "javascript-natural-sort": "^0.7.1", "lodash": "^4.17.21", - "minimatch": "^10.0.1" + "minimatch": "^9.0.0" }, "devDependencies": { "@babel/core": "^7.26.7", diff --git a/yarn.lock b/yarn.lock index 9d6a6b38..5b7a2ba3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2021,13 +2021,6 @@ mimic-fn@^2.1.0: resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-2.1.0.tgz#7ed2c2ccccaf84d3ffcb7a69b57711fc2083401b" integrity sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg== -minimatch@^10.0.1: - version "10.0.1" - resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-10.0.1.tgz#ce0521856b453c86e25f2c4c0d03e6ff7ddc440b" - integrity sha512-ethXTt3SGGR+95gudmqJ1eNhRO7eGEGIgYA9vnPatK4/etz2MEVDno5GMCibdMTuBMyElzIlgxMna3K94XDIDQ== - dependencies: - brace-expansion "^2.0.1" - minimatch@^3.0.4, minimatch@^3.1.1, minimatch@^3.1.2: version "3.1.2" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b" @@ -2042,6 +2035,13 @@ minimatch@^5.0.1: dependencies: brace-expansion "^2.0.1" +minimatch@^9.0.0: + version "9.0.5" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-9.0.5.tgz#d74f9dd6b57d83d8e98cfb82133b03978bc929e5" + integrity sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow== + dependencies: + brace-expansion "^2.0.1" + ms@^2.1.3: version "2.1.3" resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" From 716257b5c88406e285b6725823009189bb6b1500 Mon Sep 17 00:00:00 2001 From: RyderKishan Date: Thu, 15 May 2025 16:43:00 +0530 Subject: [PATCH 08/49] Added new types --- src/preprocessors/preprocessor.ts | 1 + src/types.ts | 1 + types/index.d.ts | 12 ++++++++++++ 3 files changed, 14 insertions(+) diff --git a/src/preprocessors/preprocessor.ts b/src/preprocessors/preprocessor.ts index 0e0a6d01..b76fdcba 100644 --- a/src/preprocessors/preprocessor.ts +++ b/src/preprocessors/preprocessor.ts @@ -53,6 +53,7 @@ export function preprocessor(code: string, options: PrettierOptions) { importOrderGroupNamespaceSpecifiers, importOrderSortSpecifiers, importOrderSideEffects, + importOrderSkipFiles, }); return getCodeFromAst(allImports, directives, code, interpreter, { diff --git a/src/types.ts b/src/types.ts index 085c0b15..32db66e9 100644 --- a/src/types.ts +++ b/src/types.ts @@ -20,6 +20,7 @@ export type GetSortedNodes = ( | 'importOrderGroupNamespaceSpecifiers' | 'importOrderSortSpecifiers' | 'importOrderSideEffects' + | 'importOrderSkipFiles' >, ) => ImportOrLine[]; diff --git a/types/index.d.ts b/types/index.d.ts index 46bc56ee..025b74a3 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -105,6 +105,18 @@ used to order imports within each match group. * _Default behavior:_ When not specified, @babel/generator will try to match the style in the input code based on the AST shape. */ importOrderImportAttributesKeyword?: 'assert' | 'with' | 'with-legacy'; + + /** + * An array of glob patterns for files that should be skipped by the import sorting. + * Files matching these patterns will not have their imports sorted. + * + * ``` + * "importOrderSkipFiles": ["*.test.ts", "src/generated/**"] + * ``` + * + * @default [] + */ + importOrderSkipFiles?: string[]; } export type PrettierConfig = PluginConfig & Config; From 0ea752622a17444953968a1664a8d3772490a7e5 Mon Sep 17 00:00:00 2001 From: RyderKishan Date: Thu, 15 May 2025 17:20:21 +0530 Subject: [PATCH 09/49] (fix) Types error --- src/preprocessors/preprocessor.ts | 1 - src/types.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/src/preprocessors/preprocessor.ts b/src/preprocessors/preprocessor.ts index b76fdcba..0e0a6d01 100644 --- a/src/preprocessors/preprocessor.ts +++ b/src/preprocessors/preprocessor.ts @@ -53,7 +53,6 @@ export function preprocessor(code: string, options: PrettierOptions) { importOrderGroupNamespaceSpecifiers, importOrderSortSpecifiers, importOrderSideEffects, - importOrderSkipFiles, }); return getCodeFromAst(allImports, directives, code, interpreter, { diff --git a/src/types.ts b/src/types.ts index 32db66e9..085c0b15 100644 --- a/src/types.ts +++ b/src/types.ts @@ -20,7 +20,6 @@ export type GetSortedNodes = ( | 'importOrderGroupNamespaceSpecifiers' | 'importOrderSortSpecifiers' | 'importOrderSideEffects' - | 'importOrderSkipFiles' >, ) => ImportOrLine[]; From fc4c76110d57b33767b1424cc2848bd7bb1e8d78 Mon Sep 17 00:00:00 2001 From: Robbie Wagner Date: Thu, 26 Jun 2025 12:32:18 -0400 Subject: [PATCH 10/49] Switch to ESM --- jest.config.js | 10 +- package.json | 1 + src/index.ts | 4 +- src/preprocessors/svelte-preprocessor.ts | 7 +- ...e-parsers.ts => create-svelte-parsers.cts} | 0 .../{raw-serializer.js => raw-serializer.cjs} | 0 test-setup/{run_spec.js => run_spec.cjs} | 0 tests/Angular/__snapshots__/ppsi.spec.js.snap | 86 --- tests/Angular/{ppsi.spec.js => ppsi.spec.cjs} | 0 tests/Babel/__snapshots__/ppsi.spec.js.snap | 44 -- tests/Babel/{ppsi.spec.js => ppsi.spec.cjs} | 0 tests/Flow/__snapshots__/ppsi.spec.js.snap | 67 --- tests/Flow/{ppsi.spec.js => ppsi.spec.cjs} | 0 .../__snapshots__/ppsi.spec.js.snap | 102 ---- .../{ppsi.spec.js => ppsi.spec.cjs} | 0 .../__snapshots__/ppsi.spec.js.snap | 414 ------------- .../{ppsi.spec.js => ppsi.spec.cjs} | 0 .../__snapshots__/ppsi.spec.js.snap | 357 ----------- .../{ppsi.spec.js => ppsi.spec.cjs} | 0 .../__snapshots__/ppsi.spec.js.snap | 460 -------------- .../{ppsi.spec.js => ppsi.spec.cjs} | 0 .../__snapshots__/ppsi.spec.js.snap | 376 ------------ .../{ppsi.spec.js => ppsi.spec.cjs} | 0 .../__snapshots__/ppsi.spec.js.snap | 34 -- .../{ppsi.spec.js => ppsi.spec.cjs} | 0 tests/Svelte/__snapshots__/ppsi.spec.js.snap | 564 ------------------ tests/Svelte/{ppsi.spec.js => ppsi.spec.cjs} | 0 .../TSDeclare/__snapshots__/ppsi.spec.js.snap | 32 - .../TSDeclare/{ppsi.spec.js => ppsi.spec.cjs} | 0 .../__snapshots__/ppsi.spec.js.snap | 197 ------ .../{ppsi.spec.js => ppsi.spec.cjs} | 0 tests/Vue/__snapshots__/ppsi.spec.js.snap | 376 ------------ tests/Vue/{ppsi.spec.js => ppsi.spec.cjs} | 0 tsconfig.json | 8 +- 34 files changed, 16 insertions(+), 3123 deletions(-) rename src/utils/{create-svelte-parsers.ts => create-svelte-parsers.cts} (100%) rename test-setup/{raw-serializer.js => raw-serializer.cjs} (100%) rename test-setup/{run_spec.js => run_spec.cjs} (100%) delete mode 100644 tests/Angular/__snapshots__/ppsi.spec.js.snap rename tests/Angular/{ppsi.spec.js => ppsi.spec.cjs} (100%) delete mode 100644 tests/Babel/__snapshots__/ppsi.spec.js.snap rename tests/Babel/{ppsi.spec.js => ppsi.spec.cjs} (100%) delete mode 100644 tests/Flow/__snapshots__/ppsi.spec.js.snap rename tests/Flow/{ppsi.spec.js => ppsi.spec.cjs} (100%) delete mode 100644 tests/ImportPreventSortingSideEffects/__snapshots__/ppsi.spec.js.snap rename tests/ImportPreventSortingSideEffects/{ppsi.spec.js => ppsi.spec.cjs} (100%) delete mode 100644 tests/ImportsNotSeparated/__snapshots__/ppsi.spec.js.snap rename tests/ImportsNotSeparated/{ppsi.spec.js => ppsi.spec.cjs} (100%) delete mode 100644 tests/ImportsNotSeparatedRest/__snapshots__/ppsi.spec.js.snap rename tests/ImportsNotSeparatedRest/{ppsi.spec.js => ppsi.spec.cjs} (100%) delete mode 100644 tests/ImportsSeparated/__snapshots__/ppsi.spec.js.snap rename tests/ImportsSeparated/{ppsi.spec.js => ppsi.spec.cjs} (100%) delete mode 100644 tests/ImportsSeparatedRest/__snapshots__/ppsi.spec.js.snap rename tests/ImportsSeparatedRest/{ppsi.spec.js => ppsi.spec.cjs} (100%) delete mode 100644 tests/ImportsWithAttributesKeyword/__snapshots__/ppsi.spec.js.snap rename tests/ImportsWithAttributesKeyword/{ppsi.spec.js => ppsi.spec.cjs} (100%) delete mode 100644 tests/Svelte/__snapshots__/ppsi.spec.js.snap rename tests/Svelte/{ppsi.spec.js => ppsi.spec.cjs} (100%) delete mode 100644 tests/TSDeclare/__snapshots__/ppsi.spec.js.snap rename tests/TSDeclare/{ppsi.spec.js => ppsi.spec.cjs} (100%) delete mode 100644 tests/Typescript/__snapshots__/ppsi.spec.js.snap rename tests/Typescript/{ppsi.spec.js => ppsi.spec.cjs} (100%) delete mode 100644 tests/Vue/__snapshots__/ppsi.spec.js.snap rename tests/Vue/{ppsi.spec.js => ppsi.spec.cjs} (100%) diff --git a/jest.config.js b/jest.config.js index a2335d3e..15af8821 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,14 +1,12 @@ -'use strict'; - const ENABLE_COVERAGE = false; // !!process.env.CI; -module.exports = { +export default { displayName: 'test', - setupFiles: ['/test-setup/run_spec.js'], - snapshotSerializers: ['/test-setup/raw-serializer.js'], + setupFiles: ['/test-setup/run_spec.cjs'], + snapshotSerializers: ['/test-setup/raw-serializer.cjs'], testRegex: 'ppsi\\.spec\\.js$|__tests__/.*\\.ts$', collectCoverage: ENABLE_COVERAGE, collectCoverageFrom: ['src/**/*.ts', '!/node_modules/'], preset: 'ts-jest', testEnvironment: 'node', -}; +}; \ No newline at end of file diff --git a/package.json b/package.json index 9ba8fac2..ed819244 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "5.2.2", "description": "A prettier plugins to sort imports in provided RegEx order", "main": "lib/src/index.js", + "type": "module", "types": "types/index.d.ts", "repository": { "url": "https://github.com/trivago/prettier-plugin-sort-imports", diff --git a/src/index.ts b/src/index.ts index 216f609d..fb30699d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,7 +7,7 @@ import { defaultPreprocessor } from './preprocessors/default-processor'; import { sveltePreprocessor } from './preprocessors/svelte-preprocessor'; import { vuePreprocessor } from './preprocessors/vue-preprocessor'; import type { Options } from 'prettier'; -import { createSvelteParsers } from './utils/create-svelte-parsers'; +import { createSvelteParsers } from './utils/create-svelte-parsers.cjs'; const svelteParsers = createSvelteParsers(); @@ -67,7 +67,7 @@ const options: Options = { }, }; -module.exports = { +export default { parsers: { babel: { ...babelParsers.babel, diff --git a/src/preprocessors/svelte-preprocessor.ts b/src/preprocessors/svelte-preprocessor.ts index 6d1ab285..160da5cb 100644 --- a/src/preprocessors/svelte-preprocessor.ts +++ b/src/preprocessors/svelte-preprocessor.ts @@ -1,14 +1,17 @@ +import { parse } from 'svelte/compiler'; +import prettierPluginSvelte from 'prettier-plugin-svelte'; + import { PrettierOptions } from '../types'; import { preprocessor } from './preprocessor'; const booleanGuard = (value: T | undefined): value is T => Boolean(value); const sortImports = (code: string, options: PrettierOptions) => { - const { parse } = require('svelte/compiler'); const { instance, module } = parse(code); const sources = [instance, module].filter(booleanGuard); if (!sources.length) return code; return sources.reduce((code, source) => { + // @ts-expect-error TODO const snippet = code.slice(source.content.start, source.content.end); const preprocessed = preprocessor(snippet, options); const result = code.replace(snippet, `\n${preprocessed}\n`); @@ -19,6 +22,6 @@ const sortImports = (code: string, options: PrettierOptions) => { export function sveltePreprocessor(code: string, options: PrettierOptions) { const sorted = sortImports(code, options); - const prettierPluginSvelte = require('prettier-plugin-svelte'); + // @ts-expect-error TODO return prettierPluginSvelte.parsers.svelte.preprocess(sorted, options); } diff --git a/src/utils/create-svelte-parsers.ts b/src/utils/create-svelte-parsers.cts similarity index 100% rename from src/utils/create-svelte-parsers.ts rename to src/utils/create-svelte-parsers.cts diff --git a/test-setup/raw-serializer.js b/test-setup/raw-serializer.cjs similarity index 100% rename from test-setup/raw-serializer.js rename to test-setup/raw-serializer.cjs diff --git a/test-setup/run_spec.js b/test-setup/run_spec.cjs similarity index 100% rename from test-setup/run_spec.js rename to test-setup/run_spec.cjs diff --git a/tests/Angular/__snapshots__/ppsi.spec.js.snap b/tests/Angular/__snapshots__/ppsi.spec.js.snap deleted file mode 100644 index c9357cd7..00000000 --- a/tests/Angular/__snapshots__/ppsi.spec.js.snap +++ /dev/null @@ -1,86 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`imports-with-decorators.js - typescript-verify: imports-with-decorators.js 1`] = ` -import { Body, Controller, HttpService, Logger, Post } from "@core/common"; -import { retry } from "@server/operators"; - -import { DesignTemplate, DesignTextElement } from "@server/design/interfaces"; - -import { RuntimeException } from "@server/core/errors/exceptions/runtime.exception"; -import { TemplateService } from "../service/template.service"; -import { UpdateTextDao } from "./update-text.dao"; -import { TextRender } from "@ui/design/render"; -import { CanvasKitService } from "../../../thrid-party/canvas-kit/canvas-kit.service"; -import { CanvasKit } from "@ui/canvaskit-wasm"; - -@Controller("/design/template") -export class TemplateController { - requestFile: (url) => Promise; - CanvasKit: CanvasKit; - - constructor(private templateService: TemplateService, private _httpService: HttpService, - private _canvaskitService: CanvasKitService) { - - - this.CanvasKit = this._canvaskitService.canvasKit; - this.requestFile = (url) => { - const req = this._httpService - .get(\`http:\${url}\`, { responseType: "arraybuffer" }) - .pipe(retry(3)) - .toPromise(); - return new Promise((resolve, reject) => { - req - .then((resp) => { - resolve(resp.data); - }) - .catch(reject); - }); - }; - } -} -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -import { Body, Controller, HttpService, Logger, Post } from "@core/common"; - -import { RuntimeException } from "@server/core/errors/exceptions/runtime.exception"; -import { DesignTemplate, DesignTextElement } from "@server/design/interfaces"; -import { retry } from "@server/operators"; - -import { CanvasKit } from "@ui/canvaskit-wasm"; -import { TextRender } from "@ui/design/render"; - -import { CanvasKitService } from "../../../thrid-party/canvas-kit/canvas-kit.service"; -import { TemplateService } from "../service/template.service"; -import { UpdateTextDao } from "./update-text.dao"; - -@Controller("/design/template") -export class TemplateController { - requestFile: (url) => Promise; - CanvasKit: CanvasKit; - - constructor( - private templateService: TemplateService, - private _httpService: HttpService, - private _canvaskitService: CanvasKitService, - ) { - this.CanvasKit = this._canvaskitService.canvasKit; - this.requestFile = (url) => { - const req = - this._httpService.get < - ArrayBuffer > - (\`http:\${url}\`, { responseType: "arraybuffer" }) - .pipe(retry(3)) - .toPromise(); - return ( - new Promise() < - ArrayBuffer > - ((resolve, reject) => { - req.then((resp) => { - resolve(resp.data); - }).catch(reject); - }) - ); - }; - } -} - -`; diff --git a/tests/Angular/ppsi.spec.js b/tests/Angular/ppsi.spec.cjs similarity index 100% rename from tests/Angular/ppsi.spec.js rename to tests/Angular/ppsi.spec.cjs diff --git a/tests/Babel/__snapshots__/ppsi.spec.js.snap b/tests/Babel/__snapshots__/ppsi.spec.js.snap deleted file mode 100644 index 84c62858..00000000 --- a/tests/Babel/__snapshots__/ppsi.spec.js.snap +++ /dev/null @@ -1,44 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`imports-with-comments.js - babel-verify: imports-with-comments.js 1`] = ` -// I am 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"; - -function add(a,b) { - return a + b; -} -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -// I am top level comment in this file. -import thirdParty from "third-party"; -import z from "z"; - -import abc from "@core/abc"; -import otherthing from "@core/otherthing"; - -import something from "@server/something"; - -import component from "@ui/hello"; -import xyz from "@ui/xyz"; - -import fourLevelRelativePath from "../../../../fourLevelRelativePath"; -import threeLevelRelativePath from "../../../threeLevelRelativePath"; -import twoLevelRelativePath from "../../twoLevelRelativePath"; -import oneLevelRelativePath from "../oneLevelRelativePath"; -import sameLevelRelativePath from "./sameLevelRelativePath"; - -function add(a, b) { - return a + b; -} - -`; diff --git a/tests/Babel/ppsi.spec.js b/tests/Babel/ppsi.spec.cjs similarity index 100% rename from tests/Babel/ppsi.spec.js rename to tests/Babel/ppsi.spec.cjs diff --git a/tests/Flow/__snapshots__/ppsi.spec.js.snap b/tests/Flow/__snapshots__/ppsi.spec.js.snap deleted file mode 100644 index 0703b7dc..00000000 --- a/tests/Flow/__snapshots__/ppsi.spec.js.snap +++ /dev/null @@ -1,67 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`imports-with-comments.js - flow-verify: imports-with-comments.js 1`] = ` -/** - * @flow - */ - -// I am top level comment in this file. -import { type Something } from './__generated__/'; -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"; - -const handleChange = (value: ?string) => {} - -export type AliasFoo3 = { - givesANum(): number -}; -export function givesAFoo3Obj(): AliasFoo3 { - return { - givesANum(): number { return 42; } - }; -}; -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/** - * @flow - */ -// I am top level comment in this file. -import thirdParty from "third-party"; - -import abc from "@core/abc"; -import otherthing from "@core/otherthing"; - -import something from "@server/something"; - -import component from "@ui/hello"; -import xyz from "@ui/xyz"; - -import fourLevelRelativePath from "../../../../fourLevelRelativePath"; -import threeLevelRelativePath from "../../../threeLevelRelativePath"; -import twoLevelRelativePath from "../../twoLevelRelativePath"; -import oneLevelRelativePath from "../oneLevelRelativePath"; -import { type Something } from "./__generated__/"; -import sameLevelRelativePath from "./sameLevelRelativePath"; - -const handleChange = (value: ?string) => {}; - -export type AliasFoo3 = { - givesANum(): number, -}; -export function givesAFoo3Obj(): AliasFoo3 { - return { - givesANum(): number { - return 42; - }, - }; -} - -`; diff --git a/tests/Flow/ppsi.spec.js b/tests/Flow/ppsi.spec.cjs similarity index 100% rename from tests/Flow/ppsi.spec.js rename to tests/Flow/ppsi.spec.cjs diff --git a/tests/ImportPreventSortingSideEffects/__snapshots__/ppsi.spec.js.snap b/tests/ImportPreventSortingSideEffects/__snapshots__/ppsi.spec.js.snap deleted file mode 100644 index fba106ea..00000000 --- a/tests/ImportPreventSortingSideEffects/__snapshots__/ppsi.spec.js.snap +++ /dev/null @@ -1,102 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`imports-with-side-effect-imports.js - typescript-verify: imports-with-side-effect-imports.js 1`] = ` -// I am top level comment in this file. -import thirdParty0 from "third-party0"; -import something3 from "@core/something3"; -import thirdDisco0 from "third-disco0"; -import otherthing3 from "@core/otherthing3"; - -import "side-effect-z"; - -import anotherSameLevelRelativePath3 from "./anotherSameLevelRelativePath3"; -import something0 from "@core/something0"; -import thirdDisco1 from "third-disco1"; -import otherthing0 from "@core/otherthing0"; -import sameLevelRelativePath3 from "./sameLevelRelativePath3"; -import thirdParty1 from "third-party1"; -import oneLevelRelativePath1 from "../oneLevelRelativePath1"; -import anotherOneLevelRelativePath1 from "../anotherOneLevelRelativePath1"; - -import "side-effect-y3"; -import "side-effect-y1"; -import "side-effect-y2"; - -import oneLevelRelativePath2 from "../oneLevelRelativePath2"; -import anotherOneLevelRelativePath2 from "../anotherOneLevelRelativePath2"; -import something2 from "@core/something2"; -import thirdParty3 from "third-party3"; -import anotherSameLevelRelativePath1 from "./anotherSameLevelRelativePath1"; -import sameLevelRelativePath1 from "./sameLevelRelativePath1"; -import otherthing2 from "@core/otherthing2"; -import thirdDisco3 from "third-disco3"; - -import "side-effect-x"; -import anotherSameLevelRelativePath2 from "./anotherSameLevelRelativePath2"; -import sameLevelRelativePath2 from "./sameLevelRelativePath2"; -import something1 from "@core/something1"; -import oneLevelRelativePath3 from "../oneLevelRelativePath3"; -import anotherOneLevelRelativePath3 from "../anotherOneLevelRelativePath3"; -import otherthing1 from "@core/otherthing1"; -import thirdDisco2 from "third-disco2"; -import thirdParty2 from "third-party2"; - -import { Component } from "@angular/core"; - -function add(a,b) { - return a + b; -}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -// I am top level comment in this file. -import thirdDisco0 from "third-disco0"; -import thirdParty0 from "third-party0"; - -import otherthing3 from "@core/otherthing3"; -import something3 from "@core/something3"; - -import "side-effect-z"; - -import thirdDisco1 from "third-disco1"; -import thirdParty1 from "third-party1"; - -import otherthing0 from "@core/otherthing0"; -import something0 from "@core/something0"; - -import anotherOneLevelRelativePath1 from "../anotherOneLevelRelativePath1"; -import oneLevelRelativePath1 from "../oneLevelRelativePath1"; -import anotherSameLevelRelativePath3 from "./anotherSameLevelRelativePath3"; -import sameLevelRelativePath3 from "./sameLevelRelativePath3"; - -import "side-effect-y3"; -import "side-effect-y1"; -import "side-effect-y2"; - -import thirdDisco3 from "third-disco3"; -import thirdParty3 from "third-party3"; - -import otherthing2 from "@core/otherthing2"; -import something2 from "@core/something2"; - -import anotherOneLevelRelativePath2 from "../anotherOneLevelRelativePath2"; -import oneLevelRelativePath2 from "../oneLevelRelativePath2"; -import anotherSameLevelRelativePath1 from "./anotherSameLevelRelativePath1"; -import sameLevelRelativePath1 from "./sameLevelRelativePath1"; - -import "side-effect-x"; - -import { Component } from "@angular/core"; -import thirdDisco2 from "third-disco2"; -import thirdParty2 from "third-party2"; - -import otherthing1 from "@core/otherthing1"; -import something1 from "@core/something1"; - -import anotherOneLevelRelativePath3 from "../anotherOneLevelRelativePath3"; -import oneLevelRelativePath3 from "../oneLevelRelativePath3"; -import anotherSameLevelRelativePath2 from "./anotherSameLevelRelativePath2"; -import sameLevelRelativePath2 from "./sameLevelRelativePath2"; - -function add(a, b) { - return a + b; -} - -`; diff --git a/tests/ImportPreventSortingSideEffects/ppsi.spec.js b/tests/ImportPreventSortingSideEffects/ppsi.spec.cjs similarity index 100% rename from tests/ImportPreventSortingSideEffects/ppsi.spec.js rename to tests/ImportPreventSortingSideEffects/ppsi.spec.cjs diff --git a/tests/ImportsNotSeparated/__snapshots__/ppsi.spec.js.snap b/tests/ImportsNotSeparated/__snapshots__/ppsi.spec.js.snap deleted file mode 100644 index 79565021..00000000 --- a/tests/ImportsNotSeparated/__snapshots__/ppsi.spec.js.snap +++ /dev/null @@ -1,414 +0,0 @@ -// 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 a from "a"; -import c from "c"; -import thirdParty from "third-party"; -import x from "x"; -import otherthing from "@core/otherthing"; -import something from "@server/something"; -import component from "@ui/hello"; -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 thirdParty from "third-party"; -import z from "z"; -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 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-directives.ts - typescript-verify: imports-with-directives.ts 1`] = ` -'use strict'; -'use client'; -import otherthing from "@core/otherthing"; -import abc from "@core/abc"; -// Comment -function add(a:number,b:number) { - return a + b; -} -function addStrict(a:number,b:number) { - 'use strict'; - return a + b; -} - -'preserve me'; - -const workletAdd = (a:number,b:number) => { - 'worklet'; - return a + b; -} - -(function() { - 'use strict'; - // some iffe example - return true; -})(); -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -"use strict"; -"use client"; - -import abc from "@core/abc"; -import otherthing from "@core/otherthing"; - -// Comment -function add(a: number, b: number) { - return a + b; -} -function addStrict(a: number, b: number) { - "use strict"; - return a + b; -} - -("preserve me"); - -const workletAdd = (a: number, b: number) => { - "worklet"; - return a + b; -}; - -(function () { - "use strict"; - // some iffe example - return true; -})(); - -`; - -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 a from "a"; -import c from "c"; -// I am stick to third party comment -import thirdParty from "third-party"; -import x from "x"; -import otherthing from "@core/otherthing"; -import something from "@server/something"; -import component from "@ui/hello"; -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; -} - -`; diff --git a/tests/ImportsNotSeparated/ppsi.spec.js b/tests/ImportsNotSeparated/ppsi.spec.cjs similarity index 100% rename from tests/ImportsNotSeparated/ppsi.spec.js rename to tests/ImportsNotSeparated/ppsi.spec.cjs diff --git a/tests/ImportsNotSeparatedRest/__snapshots__/ppsi.spec.js.snap b/tests/ImportsNotSeparatedRest/__snapshots__/ppsi.spec.js.snap deleted file mode 100644 index ecc8d513..00000000 --- a/tests/ImportsNotSeparatedRest/__snapshots__/ppsi.spec.js.snap +++ /dev/null @@ -1,357 +0,0 @@ -// 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; -} - -`; diff --git a/tests/ImportsNotSeparatedRest/ppsi.spec.js b/tests/ImportsNotSeparatedRest/ppsi.spec.cjs similarity index 100% rename from tests/ImportsNotSeparatedRest/ppsi.spec.js rename to tests/ImportsNotSeparatedRest/ppsi.spec.cjs diff --git a/tests/ImportsSeparated/__snapshots__/ppsi.spec.js.snap b/tests/ImportsSeparated/__snapshots__/ppsi.spec.js.snap deleted file mode 100644 index bb5d393f..00000000 --- a/tests/ImportsSeparated/__snapshots__/ppsi.spec.js.snap +++ /dev/null @@ -1,460 +0,0 @@ -// 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 a from "a"; -import c from "c"; -import thirdParty from "third-party"; -import x from "x"; - -import otherthing from "@core/otherthing"; - -import something from "@server/something"; - -import component from "@ui/hello"; - -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[`import-with-type-imports-together.ts - typescript-verify: import-with-type-imports-together.ts 1`] = ` -import { foo } from "@server/foo" -import type { Quux } from "./quux" -import { Link } from "@ui/Link" -import type { Bar } from "@server/bar" -import type { LinkProps } from "@ui/Link/LinkProps" -import { baz } from "./baz" -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -import type { Bar } from "@server/bar"; -import { foo } from "@server/foo"; - -import { Link } from "@ui/Link"; -import type { LinkProps } from "@ui/Link/LinkProps"; - -import { baz } from "./baz"; -import type { Quux } from "./quux"; - -`; - -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 thirdParty from "third-party"; -import z from "z"; - -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 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-directives.ts - typescript-verify: imports-with-directives.ts 1`] = ` -'use strict'; -'use client'; - -// comment after directives -import otherthing from "@core/otherthing"; -import abc from "@core/abc"; - -// Comment - -function add(a:number,b:number) { - return a + b; -} - -function addStrict(a:number,b:number) { - 'use strict'; - return a + b; -} - -'preserve me'; - -const workletAdd = (a:number,b:number) => { - 'worklet'; - return a + b; -} - -(function() { - 'use strict'; - // some iffe example - return true; -})(); -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -"use strict"; -"use client"; - -// comment after directives -import abc from "@core/abc"; -import otherthing from "@core/otherthing"; - -// Comment - -function add(a: number, b: number) { - return a + b; -} - -function addStrict(a: number, b: number) { - "use strict"; - return a + b; -} - -("preserve me"); - -const workletAdd = (a: number, b: number) => { - "worklet"; - return a + b; -}; - -(function () { - "use strict"; - // some iffe example - return true; -})(); - -`; - -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 a from "a"; -import c from "c"; -// I am stick to third party comment -import thirdParty from "third-party"; -import x from "x"; - -import otherthing from "@core/otherthing"; - -import something from "@server/something"; - -import component from "@ui/hello"; - -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; -} - -`; diff --git a/tests/ImportsSeparated/ppsi.spec.js b/tests/ImportsSeparated/ppsi.spec.cjs similarity index 100% rename from tests/ImportsSeparated/ppsi.spec.js rename to tests/ImportsSeparated/ppsi.spec.cjs diff --git a/tests/ImportsSeparatedRest/__snapshots__/ppsi.spec.js.snap b/tests/ImportsSeparatedRest/__snapshots__/ppsi.spec.js.snap deleted file mode 100644 index b9a6b680..00000000 --- a/tests/ImportsSeparatedRest/__snapshots__/ppsi.spec.js.snap +++ /dev/null @@ -1,376 +0,0 @@ -// 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; -} - -`; diff --git a/tests/ImportsSeparatedRest/ppsi.spec.js b/tests/ImportsSeparatedRest/ppsi.spec.cjs similarity index 100% rename from tests/ImportsSeparatedRest/ppsi.spec.js rename to tests/ImportsSeparatedRest/ppsi.spec.cjs diff --git a/tests/ImportsWithAttributesKeyword/__snapshots__/ppsi.spec.js.snap b/tests/ImportsWithAttributesKeyword/__snapshots__/ppsi.spec.js.snap deleted file mode 100644 index 7972df24..00000000 --- a/tests/ImportsWithAttributesKeyword/__snapshots__/ppsi.spec.js.snap +++ /dev/null @@ -1,34 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`imports-with-attributes-keyword.ts - typescript-verify: imports-with-attributes-keyword.ts 1`] = ` -// I am top level comment in this file. -import thirdParty0 from "third-party0"; -import something3 from "@core/something3"; -import thirdDisco0 from "third-disco0"; -import otherthing3 from "@core/otherthing3"; -import { a } from "b" with { type: "json" }; - -import anotherSameLevelRelativePath3 from "./anotherSameLevelRelativePath3"; -import something0 from "@core/something0"; - -import { b } from "r" with { type: "json" }; - - -function add(a,b) { - return a + b; -}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -// I am top level comment in this file. -import { a } from "b" with { type: "json" }; -import { b } from "r" with { type: "json" }; -import thirdDisco0 from "third-disco0"; -import thirdParty0 from "third-party0"; -import otherthing3 from "@core/otherthing3"; -import something0 from "@core/something0"; -import something3 from "@core/something3"; -import anotherSameLevelRelativePath3 from "./anotherSameLevelRelativePath3"; - -function add(a, b) { - return a + b; -} - -`; diff --git a/tests/ImportsWithAttributesKeyword/ppsi.spec.js b/tests/ImportsWithAttributesKeyword/ppsi.spec.cjs similarity index 100% rename from tests/ImportsWithAttributesKeyword/ppsi.spec.js rename to tests/ImportsWithAttributesKeyword/ppsi.spec.cjs diff --git a/tests/Svelte/__snapshots__/ppsi.spec.js.snap b/tests/Svelte/__snapshots__/ppsi.spec.js.snap deleted file mode 100644 index 382c31fe..00000000 --- a/tests/Svelte/__snapshots__/ppsi.spec.js.snap +++ /dev/null @@ -1,564 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`module.svelte - svelte-verify: module.svelte 1`] = ` - - -
-
- -
- -
- - -
- -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - -
-
- -
- -
- - -
- - - -`; - -exports[`questionale.svelte - svelte-verify: questionale.svelte 1`] = ` - - -
-
- -
- -
- - -
- -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - -
-
- -
- -
- - -
- - - -`; - -exports[`simple.svelte - svelte-verify: simple.svelte 1`] = ` - - -
-
- -
- -
- - -
- -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - -
-
- -
- -
- - -
- - - -`; - -exports[`ts.svelte - svelte-verify: ts.svelte 1`] = ` - - -
-
- -
- -
- - -
- -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - -
-
- -
- -
- - -
- - - -`; diff --git a/tests/Svelte/ppsi.spec.js b/tests/Svelte/ppsi.spec.cjs similarity index 100% rename from tests/Svelte/ppsi.spec.js rename to tests/Svelte/ppsi.spec.cjs diff --git a/tests/TSDeclare/__snapshots__/ppsi.spec.js.snap b/tests/TSDeclare/__snapshots__/ppsi.spec.js.snap deleted file mode 100644 index 6df2908a..00000000 --- a/tests/TSDeclare/__snapshots__/ppsi.spec.js.snap +++ /dev/null @@ -1,32 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`import-inside-ts-declare.ts - typescript-verify: import-inside-ts-declare.ts 1`] = ` -declare module '*.scss' { - const content: { [className: string]: string }; - export = content; -} - -declare const env: { - [key: string]: string; -}; - -declare module 'path-browserify' { - import * as path from 'path'; - export = path; -} -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -declare module "*.scss" { - const content: { [className: string]: string }; - export = content; -} - -declare const env: { - [key: string]: string; -}; - -declare module "path-browserify" { - import * as path from "path"; - export = path; -} - -`; diff --git a/tests/TSDeclare/ppsi.spec.js b/tests/TSDeclare/ppsi.spec.cjs similarity index 100% rename from tests/TSDeclare/ppsi.spec.js rename to tests/TSDeclare/ppsi.spec.cjs diff --git a/tests/Typescript/__snapshots__/ppsi.spec.js.snap b/tests/Typescript/__snapshots__/ppsi.spec.js.snap deleted file mode 100644 index 4cbc0487..00000000 --- a/tests/Typescript/__snapshots__/ppsi.spec.js.snap +++ /dev/null @@ -1,197 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`imports-with-comments.ts - typescript-verify: imports-with-comments.ts 1`] = ` -import z from 'z'; -import { isEmpty } from "lodash-es"; -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 { Component } from "@angular/core"; - -@Component({ - selector: "app-root", - templateUrl: "./app.component.html", - styleUrls: ["./app.component.css"] -}) -export class AppComponent extends BaseComponent { - title = "ng-prettier"; - - override get text(): string { - return isEmpty(this.title) ? "" : this.title; - } -} -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -import { Component } from "@angular/core"; -import { isEmpty } from "lodash-es"; -import thirdParty from "third-party"; -import z from "z"; - -import abc from "@core/abc"; -import otherthing from "@core/otherthing"; - -import something from "@server/something"; - -import component from "@ui/hello"; -import xyz from "@ui/xyz"; - -import fourLevelRelativePath from "../../../../fourLevelRelativePath"; -import threeLevelRelativePath from "../../../threeLevelRelativePath"; -import twoLevelRelativePath from "../../twoLevelRelativePath"; -import oneLevelRelativePath from "../oneLevelRelativePath"; -import sameLevelRelativePath from "./sameLevelRelativePath"; - -@Component({ - selector: "app-root", - templateUrl: "./app.component.html", - styleUrls: ["./app.component.css"], -}) -export class AppComponent extends BaseComponent { - title = "ng-prettier"; - - override get text(): string { - return isEmpty(this.title) ? "" : this.title; - } -} - -`; - -exports[`imports-with-satisfies.ts - typescript-verify: imports-with-satisfies.ts 1`] = ` -import z from 'z'; -import { isEmpty } from "lodash-es"; -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 { Component } from "@angular/core"; - -const somestring = "something" satisfies string - -const someobj = { hello : "world", world:"hello"} satisfies Record~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -import { Component } from "@angular/core"; -import { isEmpty } from "lodash-es"; -import thirdParty from "third-party"; -import z from "z"; - -import abc from "@core/abc"; -import otherthing from "@core/otherthing"; - -import something from "@server/something"; - -import component from "@ui/hello"; -import xyz from "@ui/xyz"; - -import fourLevelRelativePath from "../../../../fourLevelRelativePath"; -import threeLevelRelativePath from "../../../threeLevelRelativePath"; -import twoLevelRelativePath from "../../twoLevelRelativePath"; -import oneLevelRelativePath from "../oneLevelRelativePath"; -import sameLevelRelativePath from "./sameLevelRelativePath"; - -const somestring = "something" satisfies string; - -const someobj = { hello: "world", world: "hello" } satisfies Record< - string, - string ->; - -`; - -exports[`imports-with-unsorted-modules.ts - typescript-verify: imports-with-unsorted-modules.ts 1`] = ` -import z from 'z'; -import { isEmpty, concat, flatten } from "lodash-es"; -import threeLevelRelativePathA, { nonDefaultModuleC, nonDefaultModuleA, nonDefaultModuleB } from "../../../threeLevelRelativePathA"; -import * as allThreeLevelRelativePathBModules from "../../../threeLevelRelativePathB"; -import threeLevelRelativePathC, { - nonDefaultModuleC as nonConflictingModuleNameC, - nonDefaultModuleA as nonConflictingModuleNameA, - nonDefaultModuleB as nonConflictingModuleNameB, - nonDefaultModuleE, - nonDefaultModuleD -} from "../../../threeLevelRelativePathC"; -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 { Component } from "@angular/core"; - -@Component({ - selector: "app-root", - templateUrl: "./app.component.html", - styleUrls: ["./app.component.css"] -}) -export class AppComponent { - title = "ng-prettier"; - - get text(): string { - return isEmpty(this.title) ? "" : this.title; - } -} -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -import { Component } from "@angular/core"; -import { isEmpty, concat, flatten } from "lodash-es"; -import thirdParty from "third-party"; -import z from "z"; - -import abc from "@core/abc"; -import otherthing from "@core/otherthing"; - -import something from "@server/something"; - -import component from "@ui/hello"; -import xyz from "@ui/xyz"; - -import fourLevelRelativePath from "../../../../fourLevelRelativePath"; -import threeLevelRelativePathA, { - nonDefaultModuleC, - nonDefaultModuleA, - nonDefaultModuleB, -} from "../../../threeLevelRelativePathA"; -import * as allThreeLevelRelativePathBModules from "../../../threeLevelRelativePathB"; -import threeLevelRelativePathC, { - nonDefaultModuleC as nonConflictingModuleNameC, - nonDefaultModuleA as nonConflictingModuleNameA, - nonDefaultModuleB as nonConflictingModuleNameB, - nonDefaultModuleE, - nonDefaultModuleD, -} from "../../../threeLevelRelativePathC"; -import twoLevelRelativePath from "../../twoLevelRelativePath"; -import oneLevelRelativePath from "../oneLevelRelativePath"; -import sameLevelRelativePath from "./sameLevelRelativePath"; - -@Component({ - selector: "app-root", - templateUrl: "./app.component.html", - styleUrls: ["./app.component.css"], -}) -export class AppComponent { - title = "ng-prettier"; - - get text(): string { - return isEmpty(this.title) ? "" : this.title; - } -} - -`; diff --git a/tests/Typescript/ppsi.spec.js b/tests/Typescript/ppsi.spec.cjs similarity index 100% rename from tests/Typescript/ppsi.spec.js rename to tests/Typescript/ppsi.spec.cjs diff --git a/tests/Vue/__snapshots__/ppsi.spec.js.snap b/tests/Vue/__snapshots__/ppsi.spec.js.snap deleted file mode 100644 index afad6e57..00000000 --- a/tests/Vue/__snapshots__/ppsi.spec.js.snap +++ /dev/null @@ -1,376 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`setup.vue - vue-verify: setup.vue 1`] = ` - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - - - -`; - -exports[`setupAndScript.vue - vue-verify: setupAndScript.vue 1`] = ` - - - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - - - - - -`; - -exports[`sfc.vue - vue-verify: sfc.vue 1`] = ` - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - -`; - -exports[`sfcNoScript.vue - vue-verify: sfcNoScript.vue 1`] = ` - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - - - -`; - -exports[`sfcWithSpecialReplacerGroups.vue - vue-verify: sfcWithSpecialReplacerGroups.vue 1`] = ` - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - - -`; - -exports[`ts.vue - vue-verify: ts.vue 1`] = ` - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - -`; - -exports[`tsx.vue - vue-verify: tsx.vue 1`] = ` - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - -`; diff --git a/tests/Vue/ppsi.spec.js b/tests/Vue/ppsi.spec.cjs similarity index 100% rename from tests/Vue/ppsi.spec.js rename to tests/Vue/ppsi.spec.cjs diff --git a/tsconfig.json b/tsconfig.json index 6bc2c975..18184c4b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,10 +1,10 @@ { "compilerOptions": { /* Basic Options */ - "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ + "target": "es2022", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ + "module": "es2022", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ // "lib": [], /* Specify library files to be included in the compilation. */ - "allowJs": true, /* Allow javascript files to be compiled. */ + "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ // "declaration": true, /* Generates corresponding '.d.ts' file. */ @@ -60,5 +60,5 @@ "exclude": [ "node_modules" ], - "include": ["./src/**/*.ts"] + "include": ["./src/**/*.ts", "src/utils/create-svelte-parsers.cts"] } From c68dbfb03f0c392de364f3d14728239620be7435 Mon Sep 17 00:00:00 2001 From: Robbie Wagner Date: Thu, 26 Jun 2025 12:51:23 -0400 Subject: [PATCH 11/49] Ensure all tests are running --- jest.config.js | 2 +- src/index.ts | 2 +- ...e-parsers.cts => create-svelte-parsers.ts} | 0 test-setup/run_spec.cjs | 2 +- .../Angular/__snapshots__/ppsi.spec.cjs.snap | 85 +++ tests/Babel/__snapshots__/ppsi.spec.cjs.snap | 40 ++ tests/Flow/__snapshots__/ppsi.spec.cjs.snap | 64 ++ .../__snapshots__/ppsi.spec.cjs.snap | 95 +++ .../__snapshots__/ppsi.spec.cjs.snap | 407 +++++++++++++ .../__snapshots__/ppsi.spec.cjs.snap | 352 +++++++++++ .../__snapshots__/ppsi.spec.cjs.snap | 434 ++++++++++++++ .../__snapshots__/ppsi.spec.cjs.snap | 352 +++++++++++ .../__snapshots__/ppsi.spec.cjs.snap | 36 ++ tests/Svelte/__snapshots__/ppsi.spec.cjs.snap | 545 ++++++++++++++++++ .../__snapshots__/ppsi.spec.cjs.snap | 32 + .../__snapshots__/ppsi.spec.cjs.snap | 188 ++++++ tests/Vue/__snapshots__/ppsi.spec.cjs.snap | 352 +++++++++++ tsconfig.json | 2 +- 18 files changed, 2986 insertions(+), 4 deletions(-) rename src/utils/{create-svelte-parsers.cts => create-svelte-parsers.ts} (100%) create mode 100644 tests/Angular/__snapshots__/ppsi.spec.cjs.snap create mode 100644 tests/Babel/__snapshots__/ppsi.spec.cjs.snap create mode 100644 tests/Flow/__snapshots__/ppsi.spec.cjs.snap create mode 100644 tests/ImportPreventSortingSideEffects/__snapshots__/ppsi.spec.cjs.snap create mode 100644 tests/ImportsNotSeparated/__snapshots__/ppsi.spec.cjs.snap create mode 100644 tests/ImportsNotSeparatedRest/__snapshots__/ppsi.spec.cjs.snap create mode 100644 tests/ImportsSeparated/__snapshots__/ppsi.spec.cjs.snap create mode 100644 tests/ImportsSeparatedRest/__snapshots__/ppsi.spec.cjs.snap create mode 100644 tests/ImportsWithAttributesKeyword/__snapshots__/ppsi.spec.cjs.snap create mode 100644 tests/Svelte/__snapshots__/ppsi.spec.cjs.snap create mode 100644 tests/TSDeclare/__snapshots__/ppsi.spec.cjs.snap create mode 100644 tests/Typescript/__snapshots__/ppsi.spec.cjs.snap create mode 100644 tests/Vue/__snapshots__/ppsi.spec.cjs.snap diff --git a/jest.config.js b/jest.config.js index 15af8821..a5465075 100644 --- a/jest.config.js +++ b/jest.config.js @@ -4,7 +4,7 @@ export default { displayName: 'test', setupFiles: ['/test-setup/run_spec.cjs'], snapshotSerializers: ['/test-setup/raw-serializer.cjs'], - testRegex: 'ppsi\\.spec\\.js$|__tests__/.*\\.ts$', + testRegex: 'ppsi\\.spec\\.cjs$|__tests__/.*\\.ts$', collectCoverage: ENABLE_COVERAGE, collectCoverageFrom: ['src/**/*.ts', '!/node_modules/'], preset: 'ts-jest', diff --git a/src/index.ts b/src/index.ts index fb30699d..562a5626 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,7 +7,7 @@ import { defaultPreprocessor } from './preprocessors/default-processor'; import { sveltePreprocessor } from './preprocessors/svelte-preprocessor'; import { vuePreprocessor } from './preprocessors/vue-preprocessor'; import type { Options } from 'prettier'; -import { createSvelteParsers } from './utils/create-svelte-parsers.cjs'; +import { createSvelteParsers } from './utils/create-svelte-parsers'; const svelteParsers = createSvelteParsers(); diff --git a/src/utils/create-svelte-parsers.cts b/src/utils/create-svelte-parsers.ts similarity index 100% rename from src/utils/create-svelte-parsers.cts rename to src/utils/create-svelte-parsers.ts diff --git a/test-setup/run_spec.cjs b/test-setup/run_spec.cjs index f9a3c191..682bb483 100644 --- a/test-setup/run_spec.cjs +++ b/test-setup/run_spec.cjs @@ -24,7 +24,7 @@ function run_spec(dirname, parsers, options) { extname(filename) !== '.snap' && fs.lstatSync(path).isFile() && filename[0] !== '.' && - filename !== 'ppsi.spec.js' + filename !== 'ppsi.spec.cjs' ) { const source = read(path).replace(/\r\n/g, '\n'); diff --git a/tests/Angular/__snapshots__/ppsi.spec.cjs.snap b/tests/Angular/__snapshots__/ppsi.spec.cjs.snap new file mode 100644 index 00000000..04a7a0ea --- /dev/null +++ b/tests/Angular/__snapshots__/ppsi.spec.cjs.snap @@ -0,0 +1,85 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`imports-with-decorators.js - typescript-verify: imports-with-decorators.js 1`] = ` +import { Body, Controller, HttpService, Logger, Post } from "@core/common"; +import { retry } from "@server/operators"; + +import { DesignTemplate, DesignTextElement } from "@server/design/interfaces"; + +import { RuntimeException } from "@server/core/errors/exceptions/runtime.exception"; +import { TemplateService } from "../service/template.service"; +import { UpdateTextDao } from "./update-text.dao"; +import { TextRender } from "@ui/design/render"; +import { CanvasKitService } from "../../../thrid-party/canvas-kit/canvas-kit.service"; +import { CanvasKit } from "@ui/canvaskit-wasm"; + +@Controller("/design/template") +export class TemplateController { + requestFile: (url) => Promise; + CanvasKit: CanvasKit; + + constructor(private templateService: TemplateService, private _httpService: HttpService, + private _canvaskitService: CanvasKitService) { + + + this.CanvasKit = this._canvaskitService.canvasKit; + this.requestFile = (url) => { + const req = this._httpService + .get(\`http:\${url}\`, { responseType: "arraybuffer" }) + .pipe(retry(3)) + .toPromise(); + return new Promise((resolve, reject) => { + req + .then((resp) => { + resolve(resp.data); + }) + .catch(reject); + }); + }; + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +import { Body, Controller, HttpService, Logger, Post } from "@core/common"; +import { retry } from "@server/operators"; + +import { DesignTemplate, DesignTextElement } from "@server/design/interfaces"; + +import { RuntimeException } from "@server/core/errors/exceptions/runtime.exception"; +import { TemplateService } from "../service/template.service"; +import { UpdateTextDao } from "./update-text.dao"; +import { TextRender } from "@ui/design/render"; +import { CanvasKitService } from "../../../thrid-party/canvas-kit/canvas-kit.service"; +import { CanvasKit } from "@ui/canvaskit-wasm"; + +@Controller("/design/template") +export class TemplateController { + requestFile: (url) => Promise; + CanvasKit: CanvasKit; + + constructor( + private templateService: TemplateService, + private _httpService: HttpService, + private _canvaskitService: CanvasKitService, + ) { + this.CanvasKit = this._canvaskitService.canvasKit; + this.requestFile = (url) => { + const req = + this._httpService.get < + ArrayBuffer > + (\`http:\${url}\`, { responseType: "arraybuffer" }) + .pipe(retry(3)) + .toPromise(); + return ( + new Promise() < + ArrayBuffer > + ((resolve, reject) => { + req.then((resp) => { + resolve(resp.data); + }).catch(reject); + }) + ); + }; + } +} + +`; diff --git a/tests/Babel/__snapshots__/ppsi.spec.cjs.snap b/tests/Babel/__snapshots__/ppsi.spec.cjs.snap new file mode 100644 index 00000000..58d674f7 --- /dev/null +++ b/tests/Babel/__snapshots__/ppsi.spec.cjs.snap @@ -0,0 +1,40 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`imports-with-comments.js - babel-verify: imports-with-comments.js 1`] = ` +// I am 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"; + +function add(a,b) { + return a + b; +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// I am 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"; + +function add(a, b) { + return a + b; +} + +`; diff --git a/tests/Flow/__snapshots__/ppsi.spec.cjs.snap b/tests/Flow/__snapshots__/ppsi.spec.cjs.snap new file mode 100644 index 00000000..65941674 --- /dev/null +++ b/tests/Flow/__snapshots__/ppsi.spec.cjs.snap @@ -0,0 +1,64 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`imports-with-comments.js - flow-verify: imports-with-comments.js 1`] = ` +/** + * @flow + */ + +// I am top level comment in this file. +import { type Something } from './__generated__/'; +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"; + +const handleChange = (value: ?string) => {} + +export type AliasFoo3 = { + givesANum(): number +}; +export function givesAFoo3Obj(): AliasFoo3 { + return { + givesANum(): number { return 42; } + }; +}; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/** + * @flow + */ + +// I am top level comment in this file. +import { type Something } from "./__generated__/"; +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"; + +const handleChange = (value: ?string) => {}; + +export type AliasFoo3 = { + givesANum(): number, +}; +export function givesAFoo3Obj(): AliasFoo3 { + return { + givesANum(): number { + return 42; + }, + }; +} + +`; diff --git a/tests/ImportPreventSortingSideEffects/__snapshots__/ppsi.spec.cjs.snap b/tests/ImportPreventSortingSideEffects/__snapshots__/ppsi.spec.cjs.snap new file mode 100644 index 00000000..1881878c --- /dev/null +++ b/tests/ImportPreventSortingSideEffects/__snapshots__/ppsi.spec.cjs.snap @@ -0,0 +1,95 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`imports-with-side-effect-imports.js - typescript-verify: imports-with-side-effect-imports.js 1`] = ` +// I am top level comment in this file. +import thirdParty0 from "third-party0"; +import something3 from "@core/something3"; +import thirdDisco0 from "third-disco0"; +import otherthing3 from "@core/otherthing3"; + +import "side-effect-z"; + +import anotherSameLevelRelativePath3 from "./anotherSameLevelRelativePath3"; +import something0 from "@core/something0"; +import thirdDisco1 from "third-disco1"; +import otherthing0 from "@core/otherthing0"; +import sameLevelRelativePath3 from "./sameLevelRelativePath3"; +import thirdParty1 from "third-party1"; +import oneLevelRelativePath1 from "../oneLevelRelativePath1"; +import anotherOneLevelRelativePath1 from "../anotherOneLevelRelativePath1"; + +import "side-effect-y3"; +import "side-effect-y1"; +import "side-effect-y2"; + +import oneLevelRelativePath2 from "../oneLevelRelativePath2"; +import anotherOneLevelRelativePath2 from "../anotherOneLevelRelativePath2"; +import something2 from "@core/something2"; +import thirdParty3 from "third-party3"; +import anotherSameLevelRelativePath1 from "./anotherSameLevelRelativePath1"; +import sameLevelRelativePath1 from "./sameLevelRelativePath1"; +import otherthing2 from "@core/otherthing2"; +import thirdDisco3 from "third-disco3"; + +import "side-effect-x"; +import anotherSameLevelRelativePath2 from "./anotherSameLevelRelativePath2"; +import sameLevelRelativePath2 from "./sameLevelRelativePath2"; +import something1 from "@core/something1"; +import oneLevelRelativePath3 from "../oneLevelRelativePath3"; +import anotherOneLevelRelativePath3 from "../anotherOneLevelRelativePath3"; +import otherthing1 from "@core/otherthing1"; +import thirdDisco2 from "third-disco2"; +import thirdParty2 from "third-party2"; + +import { Component } from "@angular/core"; + +function add(a,b) { + return a + b; +}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// I am top level comment in this file. +import thirdParty0 from "third-party0"; +import something3 from "@core/something3"; +import thirdDisco0 from "third-disco0"; +import otherthing3 from "@core/otherthing3"; + +import "side-effect-z"; + +import anotherSameLevelRelativePath3 from "./anotherSameLevelRelativePath3"; +import something0 from "@core/something0"; +import thirdDisco1 from "third-disco1"; +import otherthing0 from "@core/otherthing0"; +import sameLevelRelativePath3 from "./sameLevelRelativePath3"; +import thirdParty1 from "third-party1"; +import oneLevelRelativePath1 from "../oneLevelRelativePath1"; +import anotherOneLevelRelativePath1 from "../anotherOneLevelRelativePath1"; + +import "side-effect-y3"; +import "side-effect-y1"; +import "side-effect-y2"; + +import oneLevelRelativePath2 from "../oneLevelRelativePath2"; +import anotherOneLevelRelativePath2 from "../anotherOneLevelRelativePath2"; +import something2 from "@core/something2"; +import thirdParty3 from "third-party3"; +import anotherSameLevelRelativePath1 from "./anotherSameLevelRelativePath1"; +import sameLevelRelativePath1 from "./sameLevelRelativePath1"; +import otherthing2 from "@core/otherthing2"; +import thirdDisco3 from "third-disco3"; + +import "side-effect-x"; +import anotherSameLevelRelativePath2 from "./anotherSameLevelRelativePath2"; +import sameLevelRelativePath2 from "./sameLevelRelativePath2"; +import something1 from "@core/something1"; +import oneLevelRelativePath3 from "../oneLevelRelativePath3"; +import anotherOneLevelRelativePath3 from "../anotherOneLevelRelativePath3"; +import otherthing1 from "@core/otherthing1"; +import thirdDisco2 from "third-disco2"; +import thirdParty2 from "third-party2"; + +import { Component } from "@angular/core"; + +function add(a, b) { + return a + b; +} + +`; diff --git a/tests/ImportsNotSeparated/__snapshots__/ppsi.spec.cjs.snap b/tests/ImportsNotSeparated/__snapshots__/ppsi.spec.cjs.snap new file mode 100644 index 00000000..facfe9a2 --- /dev/null +++ b/tests/ImportsNotSeparated/__snapshots__/ppsi.spec.cjs.snap @@ -0,0 +1,407 @@ +// 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 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; +} + +`; + +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 "./commands"; +import React from "react"; +// 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 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; +} + +`; + +exports[`imports-with-directives.ts - typescript-verify: imports-with-directives.ts 1`] = ` +'use strict'; +'use client'; +import otherthing from "@core/otherthing"; +import abc from "@core/abc"; +// Comment +function add(a:number,b:number) { + return a + b; +} +function addStrict(a:number,b:number) { + 'use strict'; + return a + b; +} + +'preserve me'; + +const workletAdd = (a:number,b:number) => { + 'worklet'; + return a + b; +} + +(function() { + 'use strict'; + // some iffe example + return true; +})(); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +"use strict"; +"use client"; +import otherthing from "@core/otherthing"; +import abc from "@core/abc"; +// Comment +function add(a: number, b: number) { + return a + b; +} +function addStrict(a: number, b: number) { + "use strict"; + return a + b; +} + +("preserve me"); + +const workletAdd = (a: number, b: number) => { + "worklet"; + return a + b; +}; + +(function () { + "use strict"; + // some iffe example + return true; +})(); + +`; + +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 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 +} + +`; + +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 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; +} + +`; + +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 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"; + +`; + +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; +} + +`; diff --git a/tests/ImportsNotSeparatedRest/__snapshots__/ppsi.spec.cjs.snap b/tests/ImportsNotSeparatedRest/__snapshots__/ppsi.spec.cjs.snap new file mode 100644 index 00000000..c0cd32d5 --- /dev/null +++ b/tests/ImportsNotSeparatedRest/__snapshots__/ppsi.spec.cjs.snap @@ -0,0 +1,352 @@ +// 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 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; +} + +`; + +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 "./commands"; +import React from "react"; +// 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 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; +} + +`; + +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 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 +} + +`; + +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 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; +} + +`; + +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 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"; + +`; + +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; +} + +`; diff --git a/tests/ImportsSeparated/__snapshots__/ppsi.spec.cjs.snap b/tests/ImportsSeparated/__snapshots__/ppsi.spec.cjs.snap new file mode 100644 index 00000000..e63ea128 --- /dev/null +++ b/tests/ImportsSeparated/__snapshots__/ppsi.spec.cjs.snap @@ -0,0 +1,434 @@ +// 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 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; +} + +`; + +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[`import-with-type-imports-together.ts - typescript-verify: import-with-type-imports-together.ts 1`] = ` +import { foo } from "@server/foo" +import type { Quux } from "./quux" +import { Link } from "@ui/Link" +import type { Bar } from "@server/bar" +import type { LinkProps } from "@ui/Link/LinkProps" +import { baz } from "./baz" +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +import { foo } from "@server/foo"; +import type { Quux } from "./quux"; +import { Link } from "@ui/Link"; +import type { Bar } from "@server/bar"; +import type { LinkProps } from "@ui/Link/LinkProps"; +import { baz } from "./baz"; + +`; + +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 "./commands"; +import React from "react"; +// 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 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; +} + +`; + +exports[`imports-with-directives.ts - typescript-verify: imports-with-directives.ts 1`] = ` +'use strict'; +'use client'; + +// comment after directives +import otherthing from "@core/otherthing"; +import abc from "@core/abc"; + +// Comment + +function add(a:number,b:number) { + return a + b; +} + +function addStrict(a:number,b:number) { + 'use strict'; + return a + b; +} + +'preserve me'; + +const workletAdd = (a:number,b:number) => { + 'worklet'; + return a + b; +} + +(function() { + 'use strict'; + // some iffe example + return true; +})(); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +"use strict"; +"use client"; + +// comment after directives +import otherthing from "@core/otherthing"; +import abc from "@core/abc"; + +// Comment + +function add(a: number, b: number) { + return a + b; +} + +function addStrict(a: number, b: number) { + "use strict"; + return a + b; +} + +("preserve me"); + +const workletAdd = (a: number, b: number) => { + "worklet"; + return a + b; +}; + +(function () { + "use strict"; + // some iffe example + return true; +})(); + +`; + +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 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 +} + +`; + +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 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; +} + +`; + +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 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"; + +`; + +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; +} + +`; diff --git a/tests/ImportsSeparatedRest/__snapshots__/ppsi.spec.cjs.snap b/tests/ImportsSeparatedRest/__snapshots__/ppsi.spec.cjs.snap new file mode 100644 index 00000000..c0cd32d5 --- /dev/null +++ b/tests/ImportsSeparatedRest/__snapshots__/ppsi.spec.cjs.snap @@ -0,0 +1,352 @@ +// 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 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; +} + +`; + +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 "./commands"; +import React from "react"; +// 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 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; +} + +`; + +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 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 +} + +`; + +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 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; +} + +`; + +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 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"; + +`; + +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; +} + +`; diff --git a/tests/ImportsWithAttributesKeyword/__snapshots__/ppsi.spec.cjs.snap b/tests/ImportsWithAttributesKeyword/__snapshots__/ppsi.spec.cjs.snap new file mode 100644 index 00000000..c8e59097 --- /dev/null +++ b/tests/ImportsWithAttributesKeyword/__snapshots__/ppsi.spec.cjs.snap @@ -0,0 +1,36 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`imports-with-attributes-keyword.ts - typescript-verify: imports-with-attributes-keyword.ts 1`] = ` +// I am top level comment in this file. +import thirdParty0 from "third-party0"; +import something3 from "@core/something3"; +import thirdDisco0 from "third-disco0"; +import otherthing3 from "@core/otherthing3"; +import { a } from "b" with { type: "json" }; + +import anotherSameLevelRelativePath3 from "./anotherSameLevelRelativePath3"; +import something0 from "@core/something0"; + +import { b } from "r" with { type: "json" }; + + +function add(a,b) { + return a + b; +}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// I am top level comment in this file. +import thirdParty0 from "third-party0"; +import something3 from "@core/something3"; +import thirdDisco0 from "third-disco0"; +import otherthing3 from "@core/otherthing3"; +import { a } from "b" with { type: "json" }; + +import anotherSameLevelRelativePath3 from "./anotherSameLevelRelativePath3"; +import something0 from "@core/something0"; + +import { b } from "r" with { type: "json" }; + +function add(a, b) { + return a + b; +} + +`; diff --git a/tests/Svelte/__snapshots__/ppsi.spec.cjs.snap b/tests/Svelte/__snapshots__/ppsi.spec.cjs.snap new file mode 100644 index 00000000..e91ab346 --- /dev/null +++ b/tests/Svelte/__snapshots__/ppsi.spec.cjs.snap @@ -0,0 +1,545 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`module.svelte - svelte-verify: module.svelte 1`] = ` + + +
+
+ +
+ +
+ + +
+ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + +
+
+ +
+ +
+ + +
+ + + +`; + +exports[`questionale.svelte - svelte-verify: questionale.svelte 1`] = ` + + +
+
+ +
+ +
+ + +
+ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + +
+
+ +
+ +
+ + +
+ + + +`; + +exports[`simple.svelte - svelte-verify: simple.svelte 1`] = ` + + +
+
+ +
+ +
+ + +
+ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + +
+
+ +
+ +
+ + +
+ + + +`; + +exports[`ts.svelte - svelte-verify: ts.svelte 1`] = ` + + +
+
+ +
+ +
+ + +
+ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + +
+
+ +
+ +
+ + +
+ + + +`; diff --git a/tests/TSDeclare/__snapshots__/ppsi.spec.cjs.snap b/tests/TSDeclare/__snapshots__/ppsi.spec.cjs.snap new file mode 100644 index 00000000..6df2908a --- /dev/null +++ b/tests/TSDeclare/__snapshots__/ppsi.spec.cjs.snap @@ -0,0 +1,32 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`import-inside-ts-declare.ts - typescript-verify: import-inside-ts-declare.ts 1`] = ` +declare module '*.scss' { + const content: { [className: string]: string }; + export = content; +} + +declare const env: { + [key: string]: string; +}; + +declare module 'path-browserify' { + import * as path from 'path'; + export = path; +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +declare module "*.scss" { + const content: { [className: string]: string }; + export = content; +} + +declare const env: { + [key: string]: string; +}; + +declare module "path-browserify" { + import * as path from "path"; + export = path; +} + +`; diff --git a/tests/Typescript/__snapshots__/ppsi.spec.cjs.snap b/tests/Typescript/__snapshots__/ppsi.spec.cjs.snap new file mode 100644 index 00000000..009fa703 --- /dev/null +++ b/tests/Typescript/__snapshots__/ppsi.spec.cjs.snap @@ -0,0 +1,188 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`imports-with-comments.ts - typescript-verify: imports-with-comments.ts 1`] = ` +import z from 'z'; +import { isEmpty } from "lodash-es"; +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 { Component } from "@angular/core"; + +@Component({ + selector: "app-root", + templateUrl: "./app.component.html", + styleUrls: ["./app.component.css"] +}) +export class AppComponent extends BaseComponent { + title = "ng-prettier"; + + override get text(): string { + return isEmpty(this.title) ? "" : this.title; + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +import z from "z"; +import { isEmpty } from "lodash-es"; +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 { Component } from "@angular/core"; + +@Component({ + selector: "app-root", + templateUrl: "./app.component.html", + styleUrls: ["./app.component.css"], +}) +export class AppComponent extends BaseComponent { + title = "ng-prettier"; + + override get text(): string { + return isEmpty(this.title) ? "" : this.title; + } +} + +`; + +exports[`imports-with-satisfies.ts - typescript-verify: imports-with-satisfies.ts 1`] = ` +import z from 'z'; +import { isEmpty } from "lodash-es"; +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 { Component } from "@angular/core"; + +const somestring = "something" satisfies string + +const someobj = { hello : "world", world:"hello"} satisfies Record~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +import z from "z"; +import { isEmpty } from "lodash-es"; +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 { Component } from "@angular/core"; + +const somestring = "something" satisfies string; + +const someobj = { hello: "world", world: "hello" } satisfies Record< + string, + string +>; + +`; + +exports[`imports-with-unsorted-modules.ts - typescript-verify: imports-with-unsorted-modules.ts 1`] = ` +import z from 'z'; +import { isEmpty, concat, flatten } from "lodash-es"; +import threeLevelRelativePathA, { nonDefaultModuleC, nonDefaultModuleA, nonDefaultModuleB } from "../../../threeLevelRelativePathA"; +import * as allThreeLevelRelativePathBModules from "../../../threeLevelRelativePathB"; +import threeLevelRelativePathC, { + nonDefaultModuleC as nonConflictingModuleNameC, + nonDefaultModuleA as nonConflictingModuleNameA, + nonDefaultModuleB as nonConflictingModuleNameB, + nonDefaultModuleE, + nonDefaultModuleD +} from "../../../threeLevelRelativePathC"; +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 { Component } from "@angular/core"; + +@Component({ + selector: "app-root", + templateUrl: "./app.component.html", + styleUrls: ["./app.component.css"] +}) +export class AppComponent { + title = "ng-prettier"; + + get text(): string { + return isEmpty(this.title) ? "" : this.title; + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +import z from "z"; +import { isEmpty, concat, flatten } from "lodash-es"; +import threeLevelRelativePathA, { + nonDefaultModuleC, + nonDefaultModuleA, + nonDefaultModuleB, +} from "../../../threeLevelRelativePathA"; +import * as allThreeLevelRelativePathBModules from "../../../threeLevelRelativePathB"; +import threeLevelRelativePathC, { + nonDefaultModuleC as nonConflictingModuleNameC, + nonDefaultModuleA as nonConflictingModuleNameA, + nonDefaultModuleB as nonConflictingModuleNameB, + nonDefaultModuleE, + nonDefaultModuleD, +} from "../../../threeLevelRelativePathC"; +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 { Component } from "@angular/core"; + +@Component({ + selector: "app-root", + templateUrl: "./app.component.html", + styleUrls: ["./app.component.css"], +}) +export class AppComponent { + title = "ng-prettier"; + + get text(): string { + return isEmpty(this.title) ? "" : this.title; + } +} + +`; diff --git a/tests/Vue/__snapshots__/ppsi.spec.cjs.snap b/tests/Vue/__snapshots__/ppsi.spec.cjs.snap new file mode 100644 index 00000000..7c1e70bb --- /dev/null +++ b/tests/Vue/__snapshots__/ppsi.spec.cjs.snap @@ -0,0 +1,352 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`setup.vue - vue-verify: setup.vue 1`] = ` + + + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + + + +`; + +exports[`setupAndScript.vue - vue-verify: setupAndScript.vue 1`] = ` + + + + + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + + + + + +`; + +exports[`sfc.vue - vue-verify: sfc.vue 1`] = ` + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + +`; + +exports[`sfcNoScript.vue - vue-verify: sfcNoScript.vue 1`] = ` + + + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + + + +`; + +exports[`sfcWithSpecialReplacerGroups.vue - vue-verify: sfcWithSpecialReplacerGroups.vue 1`] = ` + + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + + +`; + +exports[`ts.vue - vue-verify: ts.vue 1`] = ` + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + +`; + +exports[`tsx.vue - vue-verify: tsx.vue 1`] = ` + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + +`; diff --git a/tsconfig.json b/tsconfig.json index 18184c4b..bbde89cd 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -60,5 +60,5 @@ "exclude": [ "node_modules" ], - "include": ["./src/**/*.ts", "src/utils/create-svelte-parsers.cts"] + "include": ["./src/**/*.ts", "src/utils/create-svelte-parsers.ts"] } From 34363f4bf2350ca7537878de06b10902b5bcac49 Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Wed, 2 Jul 2025 19:41:56 -0400 Subject: [PATCH 12/49] Correctly resolve plugin --- test-setup/run_spec.cjs | 3 +- .../Angular/__snapshots__/ppsi.spec.cjs.snap | 11 +- tests/Babel/__snapshots__/ppsi.spec.cjs.snap | 20 +-- tests/Flow/__snapshots__/ppsi.spec.cjs.snap | 21 +-- .../__snapshots__/ppsi.spec.cjs.snap | 45 +++--- .../__snapshots__/ppsi.spec.cjs.snap | 93 ++++++------ .../__snapshots__/ppsi.spec.cjs.snap | 91 ++++++------ .../__snapshots__/ppsi.spec.cjs.snap | 116 +++++++++------ .../__snapshots__/ppsi.spec.cjs.snap | 110 +++++++++------ .../__snapshots__/ppsi.spec.cjs.snap | 12 +- .../__snapshots__/ppsi.spec.cjs.snap | 69 +++++---- tests/Vue/__snapshots__/ppsi.spec.cjs.snap | 132 +++++++++++------- 12 files changed, 416 insertions(+), 307 deletions(-) diff --git a/test-setup/run_spec.cjs b/test-setup/run_spec.cjs index 682bb483..118d9943 100644 --- a/test-setup/run_spec.cjs +++ b/test-setup/run_spec.cjs @@ -3,11 +3,12 @@ const fs = require('fs'); const extname = require('path').extname; const prettier = require('prettier'); +const plugin = require('../src'); function run_spec(dirname, parsers, options) { options = Object.assign( { - plugins: ['./src'], + plugins: [plugin.default], tabWidth: 4, }, options, diff --git a/tests/Angular/__snapshots__/ppsi.spec.cjs.snap b/tests/Angular/__snapshots__/ppsi.spec.cjs.snap index 04a7a0ea..c9357cd7 100644 --- a/tests/Angular/__snapshots__/ppsi.spec.cjs.snap +++ b/tests/Angular/__snapshots__/ppsi.spec.cjs.snap @@ -40,16 +40,17 @@ export class TemplateController { } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ import { Body, Controller, HttpService, Logger, Post } from "@core/common"; -import { retry } from "@server/operators"; +import { RuntimeException } from "@server/core/errors/exceptions/runtime.exception"; import { DesignTemplate, DesignTextElement } from "@server/design/interfaces"; +import { retry } from "@server/operators"; -import { RuntimeException } from "@server/core/errors/exceptions/runtime.exception"; -import { TemplateService } from "../service/template.service"; -import { UpdateTextDao } from "./update-text.dao"; +import { CanvasKit } from "@ui/canvaskit-wasm"; import { TextRender } from "@ui/design/render"; + import { CanvasKitService } from "../../../thrid-party/canvas-kit/canvas-kit.service"; -import { CanvasKit } from "@ui/canvaskit-wasm"; +import { TemplateService } from "../service/template.service"; +import { UpdateTextDao } from "./update-text.dao"; @Controller("/design/template") export class TemplateController { diff --git a/tests/Babel/__snapshots__/ppsi.spec.cjs.snap b/tests/Babel/__snapshots__/ppsi.spec.cjs.snap index 58d674f7..84c62858 100644 --- a/tests/Babel/__snapshots__/ppsi.spec.cjs.snap +++ b/tests/Babel/__snapshots__/ppsi.spec.cjs.snap @@ -20,19 +20,23 @@ function add(a,b) { } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // I am 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 z from "z"; + import abc from "@core/abc"; -import twoLevelRelativePath from "../../twoLevelRelativePath"; -import component from "@ui/hello"; -import fourLevelRelativePath from "../../../../fourLevelRelativePath"; +import otherthing from "@core/otherthing"; + import something from "@server/something"; + +import component from "@ui/hello"; import xyz from "@ui/xyz"; +import fourLevelRelativePath from "../../../../fourLevelRelativePath"; +import threeLevelRelativePath from "../../../threeLevelRelativePath"; +import twoLevelRelativePath from "../../twoLevelRelativePath"; +import oneLevelRelativePath from "../oneLevelRelativePath"; +import sameLevelRelativePath from "./sameLevelRelativePath"; + function add(a, b) { return a + b; } diff --git a/tests/Flow/__snapshots__/ppsi.spec.cjs.snap b/tests/Flow/__snapshots__/ppsi.spec.cjs.snap index 65941674..0703b7dc 100644 --- a/tests/Flow/__snapshots__/ppsi.spec.cjs.snap +++ b/tests/Flow/__snapshots__/ppsi.spec.cjs.snap @@ -33,21 +33,24 @@ export function givesAFoo3Obj(): AliasFoo3 { /** * @flow */ - // I am top level comment in this file. -import { type Something } from "./__generated__/"; -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 otherthing from "@core/otherthing"; + import something from "@server/something"; + +import component from "@ui/hello"; import xyz from "@ui/xyz"; +import fourLevelRelativePath from "../../../../fourLevelRelativePath"; +import threeLevelRelativePath from "../../../threeLevelRelativePath"; +import twoLevelRelativePath from "../../twoLevelRelativePath"; +import oneLevelRelativePath from "../oneLevelRelativePath"; +import { type Something } from "./__generated__/"; +import sameLevelRelativePath from "./sameLevelRelativePath"; + const handleChange = (value: ?string) => {}; export type AliasFoo3 = { diff --git a/tests/ImportPreventSortingSideEffects/__snapshots__/ppsi.spec.cjs.snap b/tests/ImportPreventSortingSideEffects/__snapshots__/ppsi.spec.cjs.snap index 1881878c..fba106ea 100644 --- a/tests/ImportPreventSortingSideEffects/__snapshots__/ppsi.spec.cjs.snap +++ b/tests/ImportPreventSortingSideEffects/__snapshots__/ppsi.spec.cjs.snap @@ -47,46 +47,53 @@ function add(a,b) { return a + b; }~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // I am top level comment in this file. -import thirdParty0 from "third-party0"; -import something3 from "@core/something3"; import thirdDisco0 from "third-disco0"; +import thirdParty0 from "third-party0"; + import otherthing3 from "@core/otherthing3"; +import something3 from "@core/something3"; import "side-effect-z"; -import anotherSameLevelRelativePath3 from "./anotherSameLevelRelativePath3"; -import something0 from "@core/something0"; import thirdDisco1 from "third-disco1"; -import otherthing0 from "@core/otherthing0"; -import sameLevelRelativePath3 from "./sameLevelRelativePath3"; import thirdParty1 from "third-party1"; -import oneLevelRelativePath1 from "../oneLevelRelativePath1"; + +import otherthing0 from "@core/otherthing0"; +import something0 from "@core/something0"; + import anotherOneLevelRelativePath1 from "../anotherOneLevelRelativePath1"; +import oneLevelRelativePath1 from "../oneLevelRelativePath1"; +import anotherSameLevelRelativePath3 from "./anotherSameLevelRelativePath3"; +import sameLevelRelativePath3 from "./sameLevelRelativePath3"; import "side-effect-y3"; import "side-effect-y1"; import "side-effect-y2"; -import oneLevelRelativePath2 from "../oneLevelRelativePath2"; -import anotherOneLevelRelativePath2 from "../anotherOneLevelRelativePath2"; -import something2 from "@core/something2"; +import thirdDisco3 from "third-disco3"; import thirdParty3 from "third-party3"; + +import otherthing2 from "@core/otherthing2"; +import something2 from "@core/something2"; + +import anotherOneLevelRelativePath2 from "../anotherOneLevelRelativePath2"; +import oneLevelRelativePath2 from "../oneLevelRelativePath2"; import anotherSameLevelRelativePath1 from "./anotherSameLevelRelativePath1"; import sameLevelRelativePath1 from "./sameLevelRelativePath1"; -import otherthing2 from "@core/otherthing2"; -import thirdDisco3 from "third-disco3"; import "side-effect-x"; -import anotherSameLevelRelativePath2 from "./anotherSameLevelRelativePath2"; -import sameLevelRelativePath2 from "./sameLevelRelativePath2"; -import something1 from "@core/something1"; -import oneLevelRelativePath3 from "../oneLevelRelativePath3"; -import anotherOneLevelRelativePath3 from "../anotherOneLevelRelativePath3"; -import otherthing1 from "@core/otherthing1"; + +import { Component } from "@angular/core"; import thirdDisco2 from "third-disco2"; import thirdParty2 from "third-party2"; -import { Component } from "@angular/core"; +import otherthing1 from "@core/otherthing1"; +import something1 from "@core/something1"; + +import anotherOneLevelRelativePath3 from "../anotherOneLevelRelativePath3"; +import oneLevelRelativePath3 from "../oneLevelRelativePath3"; +import anotherSameLevelRelativePath2 from "./anotherSameLevelRelativePath2"; +import sameLevelRelativePath2 from "./sameLevelRelativePath2"; function add(a, b) { return a + b; diff --git a/tests/ImportsNotSeparated/__snapshots__/ppsi.spec.cjs.snap b/tests/ImportsNotSeparated/__snapshots__/ppsi.spec.cjs.snap index facfe9a2..79565021 100644 --- a/tests/ImportsNotSeparated/__snapshots__/ppsi.spec.cjs.snap +++ b/tests/ImportsNotSeparated/__snapshots__/ppsi.spec.cjs.snap @@ -22,22 +22,24 @@ function add(a:number,b:number) { return a + b; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -import threeLevelRelativePath from "../../../threeLevelRelativePath"; -import sameLevelRelativePath from "./sameLevelRelativePath"; -import thirdParty from "third-party"; -export { random } from "./random"; +import a from "a"; import c from "c"; -import oneLevelRelativePath from "../oneLevelRelativePath"; +import thirdParty from "third-party"; +import x from "x"; import otherthing from "@core/otherthing"; -import a from "a"; -import twoLevelRelativePath from "../../twoLevelRelativePath"; +import something from "@server/something"; import component from "@ui/hello"; +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", }; -import fourLevelRelativePath from "../../../../fourLevelRelativePath"; -import something from "@server/something"; -import x from "x"; function add(a: number, b: number) { return a + b; @@ -50,6 +52,7 @@ import React from 'react'; export const a = 1; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ import React from "react"; + export const a = 1; `; @@ -93,8 +96,9 @@ function add(a:number,b:number) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // 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"; +import "./commands"; + // Comment // Comment @@ -127,19 +131,19 @@ function add(a:number,b:number) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // 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 z from "z"; import abc from "@core/abc"; -import twoLevelRelativePath from "../../twoLevelRelativePath"; -import component from "@ui/hello"; -import fourLevelRelativePath from "../../../../fourLevelRelativePath"; +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 qwerty from "@server/qwerty"; +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; @@ -176,8 +180,10 @@ const workletAdd = (a:number,b:number) => { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "use strict"; "use client"; -import otherthing from "@core/otherthing"; + import abc from "@core/abc"; +import otherthing from "@core/otherthing"; + // Comment function add(a: number, b: number) { return a + b; @@ -239,31 +245,33 @@ function add(a:number,b:number) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //@ts-ignore // I am file top level comments -import threeLevelRelativePath from "../../../threeLevelRelativePath"; -// I am stick to sameLevelRelativePath -import sameLevelRelativePath from "./sameLevelRelativePath"; +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 otherthing from "@core/otherthing"; +import something from "@server/something"; +import component from "@ui/hello"; +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"; -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 @@ -289,14 +297,14 @@ function add(a:number,b:number) { } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #!/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 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 qwerty from "@server/qwerty"; +import fourLevelRelativePath from "../../../../fourLevelRelativePath"; +import twoLevelRelativePath from "../../twoLevelRelativePath"; function add(a: number, b: number) { return a + b; @@ -315,13 +323,13 @@ import fourLevelRelativePath from "../../../../fourLevelRelativePath"; import something from "@server/something"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // I am top level comment -import otherthing from "@core/otherthing"; import abc from "@core/abc"; -// I am comment -import twoLevelRelativePath from "../../twoLevelRelativePath"; +import otherthing from "@core/otherthing"; +import something from "@server/something"; import component from "@ui/hello"; import fourLevelRelativePath from "../../../../fourLevelRelativePath"; -import something from "@server/something"; +// I am comment +import twoLevelRelativePath from "../../twoLevelRelativePath"; `; @@ -370,7 +378,6 @@ import './commands'; // You can read more here: // https://on.cypress.io/configuration // *********************************************************** - // Import commands.js using ES2015 syntax: import "./commands"; diff --git a/tests/ImportsNotSeparatedRest/__snapshots__/ppsi.spec.cjs.snap b/tests/ImportsNotSeparatedRest/__snapshots__/ppsi.spec.cjs.snap index c0cd32d5..ecc8d513 100644 --- a/tests/ImportsNotSeparatedRest/__snapshots__/ppsi.spec.cjs.snap +++ b/tests/ImportsNotSeparatedRest/__snapshots__/ppsi.spec.cjs.snap @@ -22,22 +22,24 @@ function add(a:number,b:number) { return a + b; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -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 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 component from "@ui/hello"; +import oneLevelRelativePath from "../oneLevelRelativePath"; +import sameLevelRelativePath from "./sameLevelRelativePath"; + +export { random } from "./random"; + 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; @@ -50,6 +52,7 @@ import React from 'react'; export const a = 1; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ import React from "react"; + export const a = 1; `; @@ -93,8 +96,9 @@ function add(a:number,b:number) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // 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"; +import "./commands"; + // Comment // Comment @@ -127,19 +131,19 @@ function add(a:number,b:number) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // 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 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 qwerty from "@server/qwerty"; +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; @@ -184,31 +188,33 @@ function add(a:number,b:number) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //@ts-ignore // I am file top level comments -import threeLevelRelativePath from "../../../threeLevelRelativePath"; -// I am stick to sameLevelRelativePath -import sameLevelRelativePath from "./sameLevelRelativePath"; +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"; -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 @@ -234,14 +240,14 @@ function add(a:number,b:number) { } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #!/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 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 qwerty from "@server/qwerty"; +import fourLevelRelativePath from "../../../../fourLevelRelativePath"; +import twoLevelRelativePath from "../../twoLevelRelativePath"; function add(a: number, b: number) { return a + b; @@ -260,13 +266,13 @@ import fourLevelRelativePath from "../../../../fourLevelRelativePath"; import something from "@server/something"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // I am top level comment -import otherthing from "@core/otherthing"; import abc from "@core/abc"; -// I am comment -import twoLevelRelativePath from "../../twoLevelRelativePath"; +import otherthing from "@core/otherthing"; +import something from "@server/something"; import component from "@ui/hello"; import fourLevelRelativePath from "../../../../fourLevelRelativePath"; -import something from "@server/something"; +// I am comment +import twoLevelRelativePath from "../../twoLevelRelativePath"; `; @@ -315,7 +321,6 @@ import './commands'; // You can read more here: // https://on.cypress.io/configuration // *********************************************************** - // Import commands.js using ES2015 syntax: import "./commands"; diff --git a/tests/ImportsSeparated/__snapshots__/ppsi.spec.cjs.snap b/tests/ImportsSeparated/__snapshots__/ppsi.spec.cjs.snap index e63ea128..bb5d393f 100644 --- a/tests/ImportsSeparated/__snapshots__/ppsi.spec.cjs.snap +++ b/tests/ImportsSeparated/__snapshots__/ppsi.spec.cjs.snap @@ -22,22 +22,28 @@ function add(a:number,b:number) { return a + b; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -import threeLevelRelativePath from "../../../threeLevelRelativePath"; -import sameLevelRelativePath from "./sameLevelRelativePath"; -import thirdParty from "third-party"; -export { random } from "./random"; +import a from "a"; import c from "c"; -import oneLevelRelativePath from "../oneLevelRelativePath"; +import thirdParty from "third-party"; +import x from "x"; + import otherthing from "@core/otherthing"; -import a from "a"; -import twoLevelRelativePath from "../../twoLevelRelativePath"; + +import something from "@server/something"; + import component from "@ui/hello"; + +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", }; -import fourLevelRelativePath from "../../../../fourLevelRelativePath"; -import something from "@server/something"; -import x from "x"; function add(a: number, b: number) { return a + b; @@ -50,6 +56,7 @@ import React from 'react'; export const a = 1; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ import React from "react"; + export const a = 1; `; @@ -62,12 +69,14 @@ import type { Bar } from "@server/bar" import type { LinkProps } from "@ui/Link/LinkProps" import { baz } from "./baz" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +import type { Bar } from "@server/bar"; import { foo } from "@server/foo"; -import type { Quux } from "./quux"; + import { Link } from "@ui/Link"; -import type { Bar } from "@server/bar"; import type { LinkProps } from "@ui/Link/LinkProps"; + import { baz } from "./baz"; +import type { Quux } from "./quux"; `; @@ -110,8 +119,10 @@ function add(a:number,b:number) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // 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"; + +import "./commands"; + // Comment // Comment @@ -144,19 +155,23 @@ function add(a:number,b:number) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // 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 z from "z"; + import abc from "@core/abc"; -import twoLevelRelativePath from "../../twoLevelRelativePath"; -import component from "@ui/hello"; -import fourLevelRelativePath from "../../../../fourLevelRelativePath"; +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 qwerty from "@server/qwerty"; + +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; @@ -200,8 +215,8 @@ const workletAdd = (a:number,b:number) => { "use client"; // comment after directives -import otherthing from "@core/otherthing"; import abc from "@core/abc"; +import otherthing from "@core/otherthing"; // Comment @@ -266,31 +281,37 @@ function add(a:number,b:number) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //@ts-ignore // I am file top level comments -import threeLevelRelativePath from "../../../threeLevelRelativePath"; -// I am stick to sameLevelRelativePath -import sameLevelRelativePath from "./sameLevelRelativePath"; +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 otherthing from "@core/otherthing"; + +import something from "@server/something"; + +import component from "@ui/hello"; + +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"; -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 @@ -316,14 +337,17 @@ function add(a:number,b:number) { } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #!/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 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 qwerty from "@server/qwerty"; + +import fourLevelRelativePath from "../../../../fourLevelRelativePath"; +import twoLevelRelativePath from "../../twoLevelRelativePath"; function add(a: number, b: number) { return a + b; @@ -342,13 +366,16 @@ import fourLevelRelativePath from "../../../../fourLevelRelativePath"; import something from "@server/something"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // I am top level comment -import otherthing from "@core/otherthing"; import abc from "@core/abc"; -// I am comment -import twoLevelRelativePath from "../../twoLevelRelativePath"; +import otherthing from "@core/otherthing"; + +import something from "@server/something"; + import component from "@ui/hello"; + import fourLevelRelativePath from "../../../../fourLevelRelativePath"; -import something from "@server/something"; +// I am comment +import twoLevelRelativePath from "../../twoLevelRelativePath"; `; @@ -397,7 +424,6 @@ import './commands'; // You can read more here: // https://on.cypress.io/configuration // *********************************************************** - // Import commands.js using ES2015 syntax: import "./commands"; diff --git a/tests/ImportsSeparatedRest/__snapshots__/ppsi.spec.cjs.snap b/tests/ImportsSeparatedRest/__snapshots__/ppsi.spec.cjs.snap index c0cd32d5..b9a6b680 100644 --- a/tests/ImportsSeparatedRest/__snapshots__/ppsi.spec.cjs.snap +++ b/tests/ImportsSeparatedRest/__snapshots__/ppsi.spec.cjs.snap @@ -22,22 +22,28 @@ function add(a:number,b:number) { return a + b; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -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 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 component from "@ui/hello"; +import oneLevelRelativePath from "../oneLevelRelativePath"; +import sameLevelRelativePath from "./sameLevelRelativePath"; + +export { random } from "./random"; + 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; @@ -50,6 +56,7 @@ import React from 'react'; export const a = 1; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ import React from "react"; + export const a = 1; `; @@ -93,8 +100,10 @@ function add(a:number,b:number) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // 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"; + +import "./commands"; + // Comment // Comment @@ -127,19 +136,23 @@ function add(a:number,b:number) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // 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 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 qwerty from "@server/qwerty"; + +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; @@ -184,31 +197,37 @@ function add(a:number,b:number) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //@ts-ignore // I am file top level comments -import threeLevelRelativePath from "../../../threeLevelRelativePath"; -// I am stick to sameLevelRelativePath -import sameLevelRelativePath from "./sameLevelRelativePath"; +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"; -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 @@ -234,14 +253,17 @@ function add(a:number,b:number) { } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #!/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 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 qwerty from "@server/qwerty"; + +import fourLevelRelativePath from "../../../../fourLevelRelativePath"; +import twoLevelRelativePath from "../../twoLevelRelativePath"; function add(a: number, b: number) { return a + b; @@ -260,13 +282,16 @@ import fourLevelRelativePath from "../../../../fourLevelRelativePath"; import something from "@server/something"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // I am top level comment -import otherthing from "@core/otherthing"; import abc from "@core/abc"; -// I am comment -import twoLevelRelativePath from "../../twoLevelRelativePath"; +import otherthing from "@core/otherthing"; + +import something from "@server/something"; + import component from "@ui/hello"; + import fourLevelRelativePath from "../../../../fourLevelRelativePath"; -import something from "@server/something"; +// I am comment +import twoLevelRelativePath from "../../twoLevelRelativePath"; `; @@ -315,7 +340,6 @@ import './commands'; // You can read more here: // https://on.cypress.io/configuration // *********************************************************** - // Import commands.js using ES2015 syntax: import "./commands"; diff --git a/tests/ImportsWithAttributesKeyword/__snapshots__/ppsi.spec.cjs.snap b/tests/ImportsWithAttributesKeyword/__snapshots__/ppsi.spec.cjs.snap index c8e59097..7972df24 100644 --- a/tests/ImportsWithAttributesKeyword/__snapshots__/ppsi.spec.cjs.snap +++ b/tests/ImportsWithAttributesKeyword/__snapshots__/ppsi.spec.cjs.snap @@ -18,16 +18,14 @@ function add(a,b) { return a + b; }~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // I am top level comment in this file. -import thirdParty0 from "third-party0"; -import something3 from "@core/something3"; +import { a } from "b" with { type: "json" }; +import { b } from "r" with { type: "json" }; import thirdDisco0 from "third-disco0"; +import thirdParty0 from "third-party0"; import otherthing3 from "@core/otherthing3"; -import { a } from "b" with { type: "json" }; - -import anotherSameLevelRelativePath3 from "./anotherSameLevelRelativePath3"; import something0 from "@core/something0"; - -import { b } from "r" with { type: "json" }; +import something3 from "@core/something3"; +import anotherSameLevelRelativePath3 from "./anotherSameLevelRelativePath3"; function add(a, b) { return a + b; diff --git a/tests/Typescript/__snapshots__/ppsi.spec.cjs.snap b/tests/Typescript/__snapshots__/ppsi.spec.cjs.snap index 009fa703..4cbc0487 100644 --- a/tests/Typescript/__snapshots__/ppsi.spec.cjs.snap +++ b/tests/Typescript/__snapshots__/ppsi.spec.cjs.snap @@ -30,21 +30,24 @@ export class AppComponent extends BaseComponent { } } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -import z from "z"; +import { Component } from "@angular/core"; import { isEmpty } from "lodash-es"; -import threeLevelRelativePath from "../../../threeLevelRelativePath"; -import sameLevelRelativePath from "./sameLevelRelativePath"; import thirdParty from "third-party"; -import oneLevelRelativePath from "../oneLevelRelativePath"; -import otherthing from "@core/otherthing"; +import z from "z"; + import abc from "@core/abc"; -import twoLevelRelativePath from "../../twoLevelRelativePath"; -import component from "@ui/hello"; -import fourLevelRelativePath from "../../../../fourLevelRelativePath"; +import otherthing from "@core/otherthing"; + import something from "@server/something"; + +import component from "@ui/hello"; import xyz from "@ui/xyz"; -import { Component } from "@angular/core"; +import fourLevelRelativePath from "../../../../fourLevelRelativePath"; +import threeLevelRelativePath from "../../../threeLevelRelativePath"; +import twoLevelRelativePath from "../../twoLevelRelativePath"; +import oneLevelRelativePath from "../oneLevelRelativePath"; +import sameLevelRelativePath from "./sameLevelRelativePath"; @Component({ selector: "app-root", @@ -81,21 +84,24 @@ import { Component } from "@angular/core"; const somestring = "something" satisfies string const someobj = { hello : "world", world:"hello"} satisfies Record~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -import z from "z"; +import { Component } from "@angular/core"; import { isEmpty } from "lodash-es"; -import threeLevelRelativePath from "../../../threeLevelRelativePath"; -import sameLevelRelativePath from "./sameLevelRelativePath"; import thirdParty from "third-party"; -import oneLevelRelativePath from "../oneLevelRelativePath"; -import otherthing from "@core/otherthing"; +import z from "z"; + import abc from "@core/abc"; -import twoLevelRelativePath from "../../twoLevelRelativePath"; -import component from "@ui/hello"; -import fourLevelRelativePath from "../../../../fourLevelRelativePath"; +import otherthing from "@core/otherthing"; + import something from "@server/something"; + +import component from "@ui/hello"; import xyz from "@ui/xyz"; -import { Component } from "@angular/core"; +import fourLevelRelativePath from "../../../../fourLevelRelativePath"; +import threeLevelRelativePath from "../../../threeLevelRelativePath"; +import twoLevelRelativePath from "../../twoLevelRelativePath"; +import oneLevelRelativePath from "../oneLevelRelativePath"; +import sameLevelRelativePath from "./sameLevelRelativePath"; const somestring = "something" satisfies string; @@ -144,8 +150,20 @@ export class AppComponent { } } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -import z from "z"; +import { Component } from "@angular/core"; import { isEmpty, concat, flatten } from "lodash-es"; +import thirdParty from "third-party"; +import z from "z"; + +import abc from "@core/abc"; +import otherthing from "@core/otherthing"; + +import something from "@server/something"; + +import component from "@ui/hello"; +import xyz from "@ui/xyz"; + +import fourLevelRelativePath from "../../../../fourLevelRelativePath"; import threeLevelRelativePathA, { nonDefaultModuleC, nonDefaultModuleA, @@ -159,18 +177,9 @@ import threeLevelRelativePathC, { nonDefaultModuleE, nonDefaultModuleD, } from "../../../threeLevelRelativePathC"; -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 { Component } from "@angular/core"; +import oneLevelRelativePath from "../oneLevelRelativePath"; +import sameLevelRelativePath from "./sameLevelRelativePath"; @Component({ selector: "app-root", diff --git a/tests/Vue/__snapshots__/ppsi.spec.cjs.snap b/tests/Vue/__snapshots__/ppsi.spec.cjs.snap index 7c1e70bb..afad6e57 100644 --- a/tests/Vue/__snapshots__/ppsi.spec.cjs.snap +++ b/tests/Vue/__snapshots__/ppsi.spec.cjs.snap @@ -28,19 +28,23 @@ function add(a,b) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -205,30 +209,37 @@ exports[`questionale.svelte - svelte-verify: questionale.svelte 1`] = ` } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -346,20 +357,24 @@ exports[`simple.svelte - svelte-verify: simple.svelte 1`] = ` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -478,20 +493,24 @@ exports[`ts.svelte - svelte-verify: ts.svelte 1`] = ` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/tests/Svelte/ppsi.spec.cjs b/tests/Svelte/ppsi.spec.cjs index df8cae0d..d2b2d3f5 100644 --- a/tests/Svelte/ppsi.spec.cjs +++ b/tests/Svelte/ppsi.spec.cjs @@ -1,6 +1,8 @@ +const plugin = require('../../src'); + run_spec(__dirname, ["svelte"], { importOrder: ['^@core/(.*)$', '^@server/(.*)', '^@ui/(.*)$', '^[./]'], importOrderSeparation: true, - plugins: ['prettier-plugin-svelte', './src'], + plugins: ['prettier-plugin-svelte', plugin.default], overrides: [{ "files": "*.svelte", "options": { "parser": "svelte" } }] }); From 916f7e2c1219af9456f164418fdfa92ee723ff8a Mon Sep 17 00:00:00 2001 From: Robbie Wagner Date: Wed, 9 Jul 2025 07:52:52 -0400 Subject: [PATCH 15/49] Require node >= 20.x (#367) * Require node >= 20.x * Add checking 24.x --- .github/workflows/ci.yml | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7fcc87a6..2e8b31d4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,7 +5,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node: [18.x, 20.x, 22.x] + node: [20.x, 22.x, 24.x] steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 diff --git a/package.json b/package.json index ed819244..b16bb9d4 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "svelte": "4.x || 5.x" }, "engines": { - "node": ">18.12" + "node": ">= 20" }, "peerDependenciesMeta": { "@vue/compiler-sfc": { From 10414cff58b9317a852038ad27ef1989fecd458b Mon Sep 17 00:00:00 2001 From: "Nathan H. Leung" Date: Wed, 9 Jul 2025 05:00:03 -0700 Subject: [PATCH 16/49] docs: add pnpm install command to README (#361) --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d89f3130..141b210b 100644 --- a/README.md +++ b/README.md @@ -53,18 +53,24 @@ import { add, filter, repeat } from '../utils'; ### Install -npm +using npm ```shell script npm install --save-dev @trivago/prettier-plugin-sort-imports ``` -or, using yarn +using yarn ```shell script yarn add --dev @trivago/prettier-plugin-sort-imports ``` +using pnpm + +```shell script +pnpm add -D @trivago/prettier-plugin-sort-imports +``` + **Note: If you are migrating from v2.x.x to v3.x.x, [Please Read Migration Guidelines](./docs/MIGRATION.md)** **Note: If formatting `.vue` sfc files please install `@vue/compiler-sfc` if not in your dependency tree - this normally is within Vue projects.** From 7e7678567940a3498a52cf7a096fc71e49676180 Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Wed, 9 Jul 2025 10:43:28 -0400 Subject: [PATCH 17/49] Switch to vitest for better ESM support I was still hitting issues with jest and trying to get full ESM support, so I decided to switch to vitest. This seems to be working and snapshots are generated essentially the same. --- README.md | 4 +- docs/TROUBLESHOOTING.md | 2 +- examples/example.ts | 2 +- jest.config.js | 12 - package.json | 15 +- src/index.ts | 2 +- src/utils/adjust-comments-on-sorted-nodes.ts | 2 +- src/utils/create-svelte-parsers.ts | 9 +- src/utils/get-sorted-nodes-by-import-order.ts | 2 +- ...{raw-serializer.cjs => raw-serializer.mjs} | 2 +- test-setup/{run_spec.cjs => run_spec.mjs} | 16 +- .../Angular/__snapshots__/ppsi.spec.cjs.snap | 4 +- tests/Babel/__snapshots__/ppsi.spec.cjs.snap | 4 +- tests/Flow/__snapshots__/ppsi.spec.cjs.snap | 4 +- .../__snapshots__/ppsi.spec.cjs.snap | 4 +- .../__snapshots__/ppsi.spec.cjs.snap | 26 +- .../__snapshots__/ppsi.spec.cjs.snap | 24 +- .../__snapshots__/ppsi.spec.cjs.snap | 28 +- .../__snapshots__/ppsi.spec.js.snap | 49 +- .../__snapshots__/ppsi.spec.cjs.snap | 24 +- .../__snapshots__/ppsi.spec.cjs.snap | 4 +- tests/Svelte/__snapshots__/ppsi.spec.cjs.snap | 10 +- tests/Svelte/ppsi.spec.cjs | 4 +- .../__snapshots__/ppsi.spec.cjs.snap | 4 +- .../__snapshots__/ppsi.spec.cjs.snap | 8 +- tests/Vue/__snapshots__/ppsi.spec.cjs.snap | 16 +- tsconfig.json | 4 +- vitest.config.ts | 10 + yarn.lock | 2504 ++++------------- 29 files changed, 740 insertions(+), 2059 deletions(-) delete mode 100644 jest.config.js rename test-setup/{raw-serializer.cjs => raw-serializer.mjs} (93%) rename test-setup/{run_spec.cjs => run_spec.mjs} (90%) create mode 100644 vitest.config.ts diff --git a/README.md b/README.md index 141b210b..a06644c6 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ import React, { KeyboardEvent, } from 'react'; import { logger } from '@core/logger'; -import { reduce, debounce } from 'lodash'; +import { reduce, debounce } from 'lodash-es'; import { Message } from '../Message'; import { createServer } from '@server/node'; import { Alert } from '@ui/Alert'; @@ -29,7 +29,7 @@ import { createConnection } from '@server/database'; ### Output ```javascript -import { debounce, reduce } from 'lodash'; +import { debounce, reduce } from 'lodash-es'; import React, { ChangeEvent, FC, diff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.md index 3aadcd8a..9b9b3ffa 100644 --- a/docs/TROUBLESHOOTING.md +++ b/docs/TROUBLESHOOTING.md @@ -87,7 +87,7 @@ Due to the package handling of the pnpm, sometimes, the plugin is not automatica via prettier config. ```js module.exports = { - plugins: [require('@trivago/prettier-plugin-sort-imports')], + plugins: ['@trivago/prettier-plugin-sort-imports'], } ``` diff --git a/examples/example.ts b/examples/example.ts index f9a69c4c..9bcb69c4 100644 --- a/examples/example.ts +++ b/examples/example.ts @@ -6,7 +6,7 @@ import React, { KeyboardEvent, } from 'react'; import { logger } from '@core/logger'; -import { reduce, debounce } from 'lodash'; +import { reduce, debounce } from 'lodash-es'; import { Message } from '../Message'; import { createServer } from '@server/node'; import { Alert } from '@ui/Alert'; diff --git a/jest.config.js b/jest.config.js deleted file mode 100644 index a5465075..00000000 --- a/jest.config.js +++ /dev/null @@ -1,12 +0,0 @@ -const ENABLE_COVERAGE = false; // !!process.env.CI; - -export default { - displayName: 'test', - setupFiles: ['/test-setup/run_spec.cjs'], - snapshotSerializers: ['/test-setup/raw-serializer.cjs'], - testRegex: 'ppsi\\.spec\\.cjs$|__tests__/.*\\.ts$', - collectCoverage: ENABLE_COVERAGE, - collectCoverageFrom: ['src/**/*.ts', '!/node_modules/'], - preset: 'ts-jest', - testEnvironment: 'node', -}; \ No newline at end of file diff --git a/package.json b/package.json index b16bb9d4..4c633ff2 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "compile": "tsc", "preexample": "yarn run compile", "example": "prettier --config ./examples/.prettierrc --plugin lib/src/index.js", - "test": "yarn node --experimental-vm-modules $(yarn bin jest)", + "test": "vitest run", "type-check": "tsc --noEmit", "prepublishOnly": "npm run compile && npm run test" }, @@ -39,21 +39,22 @@ "@babel/traverse": "^7.26.7", "@babel/types": "^7.26.7", "javascript-natural-sort": "^0.7.1", - "lodash": "^4.17.21" + "lodash-es": "^4.17.21" }, "devDependencies": { "@babel/core": "^7.26.7", + "@types/babel__core": "^7.20.5", + "@types/babel__generator": "^7.27.0", + "@types/babel__traverse": "^7.20.7", "@types/chai": "^5.0.1", - "@types/jest": "^29.5.14", - "@types/lodash": "^4.17.14", + "@types/lodash-es": "^4.17.12", "@types/node": "^22.10.10", "@vue/compiler-sfc": "^3.5.13", - "jest": "^29.7.0", "prettier": "^3.4.2", "prettier-plugin-svelte": "^3.3.3", "svelte": "^4.2.19", - "ts-jest": "^29.2.5", - "typescript": "^5.7.3" + "typescript": "^5.7.3", + "vitest": "^3.2.4" }, "peerDependencies": { "@vue/compiler-sfc": "3.x", diff --git a/src/index.ts b/src/index.ts index 562a5626..f4fa1467 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,7 +9,7 @@ import { vuePreprocessor } from './preprocessors/vue-preprocessor'; import type { Options } from 'prettier'; import { createSvelteParsers } from './utils/create-svelte-parsers'; -const svelteParsers = createSvelteParsers(); +const svelteParsers = await createSvelteParsers(); const options: Options = { importOrder: { diff --git a/src/utils/adjust-comments-on-sorted-nodes.ts b/src/utils/adjust-comments-on-sorted-nodes.ts index 91396e9e..e4e13a67 100644 --- a/src/utils/adjust-comments-on-sorted-nodes.ts +++ b/src/utils/adjust-comments-on-sorted-nodes.ts @@ -1,5 +1,5 @@ import { ImportDeclaration, addComments, removeComments } from '@babel/types'; -import { clone, isEqual } from 'lodash'; +import { clone, isEqual } from 'lodash-es'; import { ImportOrLine } from '../types'; diff --git a/src/utils/create-svelte-parsers.ts b/src/utils/create-svelte-parsers.ts index 1c72863d..25086ecc 100644 --- a/src/utils/create-svelte-parsers.ts +++ b/src/utils/create-svelte-parsers.ts @@ -1,8 +1,9 @@ -export function createSvelteParsers() { +export async function createSvelteParsers() { try { - var { parsers } = require('prettier-plugin-svelte'); + const sveltePlugin = await import('prettier-plugin-svelte'); + const { parsers } = (sveltePlugin.default || sveltePlugin) as any; + return { parsers }; } catch { return {}; } - return { parsers }; -} \ No newline at end of file +} diff --git a/src/utils/get-sorted-nodes-by-import-order.ts b/src/utils/get-sorted-nodes-by-import-order.ts index 5450df7e..7aa0e9ea 100644 --- a/src/utils/get-sorted-nodes-by-import-order.ts +++ b/src/utils/get-sorted-nodes-by-import-order.ts @@ -1,4 +1,4 @@ -import { clone } from 'lodash'; +import { clone } from 'lodash-es'; import { THIRD_PARTY_MODULES_SPECIAL_WORD, newLineNode, SEPARATOR_SPECIAL_WORD } from '../constants'; import { naturalSort } from '../natural-sort'; diff --git a/test-setup/raw-serializer.cjs b/test-setup/raw-serializer.mjs similarity index 93% rename from test-setup/raw-serializer.cjs rename to test-setup/raw-serializer.mjs index 20c66071..2e6fdefc 100644 --- a/test-setup/raw-serializer.cjs +++ b/test-setup/raw-serializer.mjs @@ -2,7 +2,7 @@ const RAW = Symbol.for('raw'); -module.exports = { +export default { print(val) { return val[RAW]; }, diff --git a/test-setup/run_spec.cjs b/test-setup/run_spec.mjs similarity index 90% rename from test-setup/run_spec.cjs rename to test-setup/run_spec.mjs index 118d9943..3f2bec19 100644 --- a/test-setup/run_spec.cjs +++ b/test-setup/run_spec.mjs @@ -1,14 +1,14 @@ 'use strict'; -const fs = require('fs'); -const extname = require('path').extname; -const prettier = require('prettier'); -const plugin = require('../src'); +import fs from 'fs'; +import { extname } from 'path'; +import prettier from 'prettier'; +import plugin from '../src/'; function run_spec(dirname, parsers, options) { options = Object.assign( { - plugins: [plugin.default], + plugins: [plugin], tabWidth: 4, }, options, @@ -59,6 +59,12 @@ function run_spec(dirname, parsers, options) { } }); } +import { expect } from 'vitest'; +import rawSerializer from './raw-serializer.mjs'; + +// Add custom snapshot serializer for Vitest +expect.addSnapshotSerializer(rawSerializer); + global.run_spec = run_spec; function stripLocation(ast) { diff --git a/tests/Angular/__snapshots__/ppsi.spec.cjs.snap b/tests/Angular/__snapshots__/ppsi.spec.cjs.snap index c9357cd7..6c1b0ed3 100644 --- a/tests/Angular/__snapshots__/ppsi.spec.cjs.snap +++ b/tests/Angular/__snapshots__/ppsi.spec.cjs.snap @@ -1,6 +1,6 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`imports-with-decorators.js - typescript-verify: imports-with-decorators.js 1`] = ` +exports[`imports-with-decorators.js - typescript-verify > imports-with-decorators.js 1`] = ` import { Body, Controller, HttpService, Logger, Post } from "@core/common"; import { retry } from "@server/operators"; diff --git a/tests/Babel/__snapshots__/ppsi.spec.cjs.snap b/tests/Babel/__snapshots__/ppsi.spec.cjs.snap index 84c62858..b3c3cafe 100644 --- a/tests/Babel/__snapshots__/ppsi.spec.cjs.snap +++ b/tests/Babel/__snapshots__/ppsi.spec.cjs.snap @@ -1,6 +1,6 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`imports-with-comments.js - babel-verify: imports-with-comments.js 1`] = ` +exports[`imports-with-comments.js - babel-verify > imports-with-comments.js 1`] = ` // I am top level comment in this file. import z from 'z'; import threeLevelRelativePath from "../../../threeLevelRelativePath"; diff --git a/tests/Flow/__snapshots__/ppsi.spec.cjs.snap b/tests/Flow/__snapshots__/ppsi.spec.cjs.snap index 0703b7dc..2ed522c6 100644 --- a/tests/Flow/__snapshots__/ppsi.spec.cjs.snap +++ b/tests/Flow/__snapshots__/ppsi.spec.cjs.snap @@ -1,6 +1,6 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`imports-with-comments.js - flow-verify: imports-with-comments.js 1`] = ` +exports[`imports-with-comments.js - flow-verify > imports-with-comments.js 1`] = ` /** * @flow */ diff --git a/tests/ImportPreventSortingSideEffects/__snapshots__/ppsi.spec.cjs.snap b/tests/ImportPreventSortingSideEffects/__snapshots__/ppsi.spec.cjs.snap index fba106ea..fe63d9de 100644 --- a/tests/ImportPreventSortingSideEffects/__snapshots__/ppsi.spec.cjs.snap +++ b/tests/ImportPreventSortingSideEffects/__snapshots__/ppsi.spec.cjs.snap @@ -1,6 +1,6 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`imports-with-side-effect-imports.js - typescript-verify: imports-with-side-effect-imports.js 1`] = ` +exports[`imports-with-side-effect-imports.js - typescript-verify > imports-with-side-effect-imports.js 1`] = ` // I am top level comment in this file. import thirdParty0 from "third-party0"; import something3 from "@core/something3"; diff --git a/tests/ImportsNotSeparated/__snapshots__/ppsi.spec.cjs.snap b/tests/ImportsNotSeparated/__snapshots__/ppsi.spec.cjs.snap index 79565021..8b905158 100644 --- a/tests/ImportsNotSeparated/__snapshots__/ppsi.spec.cjs.snap +++ b/tests/ImportsNotSeparated/__snapshots__/ppsi.spec.cjs.snap @@ -1,6 +1,6 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`import-export-in-between.ts - typescript-verify: import-export-in-between.ts 1`] = ` +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"; @@ -47,7 +47,7 @@ function add(a: number, b: number) { `; -exports[`import-export-only.ts - typescript-verify: import-export-only.ts 1`] = ` +exports[`import-export-only.ts - typescript-verify > import-export-only.ts 1`] = ` import React from 'react'; export const a = 1; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -57,7 +57,7 @@ export const a = 1; `; -exports[`imports-with-comments.ts - typescript-verify: imports-with-comments.ts 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'; @@ -82,7 +82,7 @@ function add(a: number, b: number) { `; -exports[`imports-with-comments-and-third-party.ts - typescript-verify: imports-with-comments-and-third-party.ts 1`] = ` +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'; @@ -108,7 +108,7 @@ function add(a: number, b: number) { `; -exports[`imports-with-comments-on-top.ts - typescript-verify: imports-with-comments-on-top.ts 1`] = ` +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'; @@ -151,7 +151,7 @@ function add(a: number, b: number) { `; -exports[`imports-with-directives.ts - typescript-verify: imports-with-directives.ts 1`] = ` +exports[`imports-with-directives.ts - typescript-verify > imports-with-directives.ts 1`] = ` 'use strict'; 'use client'; import otherthing from "@core/otherthing"; @@ -208,7 +208,7 @@ const workletAdd = (a: number, b: number) => { `; -exports[`imports-with-file-level-comments.ts - typescript-verify: imports-with-file-level-comments.ts 1`] = ` +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"; @@ -281,7 +281,7 @@ function add(a: number, b: number) { `; -exports[`imports-with-interpreter-directive.ts - typescript-verify: imports-with-interpreter-directive.ts 1`] = ` +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"; @@ -312,7 +312,7 @@ function add(a: number, b: number) { `; -exports[`imports-without-third-party.ts - typescript-verify: imports-without-third-party.ts 1`] = ` +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"; @@ -333,7 +333,7 @@ import twoLevelRelativePath from "../../twoLevelRelativePath"; `; -exports[`no-import-export.ts - typescript-verify: no-import-export.ts 1`] = ` +exports[`no-import-export.ts - typescript-verify > no-import-export.ts 1`] = ` function add(a:number,b:number) { return a + b; } @@ -344,7 +344,7 @@ function add(a: number, b: number) { `; -exports[`one-import.ts - typescript-verify: one-import.ts 1`] = ` +exports[`one-import.ts - typescript-verify > one-import.ts 1`] = ` // This example support/index.js is processed and // loaded automatically before your test files. // @@ -386,7 +386,7 @@ import "./commands"; `; -exports[`sort-imports-ignored.ts - typescript-verify: sort-imports-ignored.ts 1`] = ` +exports[`sort-imports-ignored.ts - typescript-verify > sort-imports-ignored.ts 1`] = ` // sort-imports-ignore import './commands'; diff --git a/tests/ImportsNotSeparatedRest/__snapshots__/ppsi.spec.cjs.snap b/tests/ImportsNotSeparatedRest/__snapshots__/ppsi.spec.cjs.snap index ecc8d513..5e70bc36 100644 --- a/tests/ImportsNotSeparatedRest/__snapshots__/ppsi.spec.cjs.snap +++ b/tests/ImportsNotSeparatedRest/__snapshots__/ppsi.spec.cjs.snap @@ -1,6 +1,6 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`import-export-in-between.ts - typescript-verify: import-export-in-between.ts 1`] = ` +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"; @@ -47,7 +47,7 @@ function add(a: number, b: number) { `; -exports[`import-export-only.ts - typescript-verify: import-export-only.ts 1`] = ` +exports[`import-export-only.ts - typescript-verify > import-export-only.ts 1`] = ` import React from 'react'; export const a = 1; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -57,7 +57,7 @@ export const a = 1; `; -exports[`imports-with-comments.ts - typescript-verify: imports-with-comments.ts 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'; @@ -82,7 +82,7 @@ function add(a: number, b: number) { `; -exports[`imports-with-comments-and-third-party.ts - typescript-verify: imports-with-comments-and-third-party.ts 1`] = ` +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'; @@ -108,7 +108,7 @@ function add(a: number, b: number) { `; -exports[`imports-with-comments-on-top.ts - typescript-verify: imports-with-comments-on-top.ts 1`] = ` +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'; @@ -151,7 +151,7 @@ function add(a: number, b: number) { `; -exports[`imports-with-file-level-comments.ts - typescript-verify: imports-with-file-level-comments.ts 1`] = ` +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"; @@ -224,7 +224,7 @@ function add(a: number, b: number) { `; -exports[`imports-with-interpreter-directive.ts - typescript-verify: imports-with-interpreter-directive.ts 1`] = ` +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"; @@ -255,7 +255,7 @@ function add(a: number, b: number) { `; -exports[`imports-without-third-party.ts - typescript-verify: imports-without-third-party.ts 1`] = ` +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"; @@ -276,7 +276,7 @@ import twoLevelRelativePath from "../../twoLevelRelativePath"; `; -exports[`no-import-export.ts - typescript-verify: no-import-export.ts 1`] = ` +exports[`no-import-export.ts - typescript-verify > no-import-export.ts 1`] = ` function add(a:number,b:number) { return a + b; } @@ -287,7 +287,7 @@ function add(a: number, b: number) { `; -exports[`one-import.ts - typescript-verify: one-import.ts 1`] = ` +exports[`one-import.ts - typescript-verify > one-import.ts 1`] = ` // This example support/index.js is processed and // loaded automatically before your test files. // @@ -329,7 +329,7 @@ import "./commands"; `; -exports[`sort-imports-ignored.ts - typescript-verify: sort-imports-ignored.ts 1`] = ` +exports[`sort-imports-ignored.ts - typescript-verify > sort-imports-ignored.ts 1`] = ` // sort-imports-ignore import './commands'; diff --git a/tests/ImportsSeparated/__snapshots__/ppsi.spec.cjs.snap b/tests/ImportsSeparated/__snapshots__/ppsi.spec.cjs.snap index bb5d393f..aa22efad 100644 --- a/tests/ImportsSeparated/__snapshots__/ppsi.spec.cjs.snap +++ b/tests/ImportsSeparated/__snapshots__/ppsi.spec.cjs.snap @@ -1,6 +1,6 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`import-export-in-between.ts - typescript-verify: import-export-in-between.ts 1`] = ` +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"; @@ -51,7 +51,7 @@ function add(a: number, b: number) { `; -exports[`import-export-only.ts - typescript-verify: import-export-only.ts 1`] = ` +exports[`import-export-only.ts - typescript-verify > import-export-only.ts 1`] = ` import React from 'react'; export const a = 1; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -61,7 +61,7 @@ export const a = 1; `; -exports[`import-with-type-imports-together.ts - typescript-verify: import-with-type-imports-together.ts 1`] = ` +exports[`import-with-type-imports-together.ts - typescript-verify > import-with-type-imports-together.ts 1`] = ` import { foo } from "@server/foo" import type { Quux } from "./quux" import { Link } from "@ui/Link" @@ -80,7 +80,7 @@ import type { Quux } from "./quux"; `; -exports[`imports-with-comments.ts - typescript-verify: imports-with-comments.ts 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'; @@ -105,7 +105,7 @@ function add(a: number, b: number) { `; -exports[`imports-with-comments-and-third-party.ts - typescript-verify: imports-with-comments-and-third-party.ts 1`] = ` +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'; @@ -132,7 +132,7 @@ function add(a: number, b: number) { `; -exports[`imports-with-comments-on-top.ts - typescript-verify: imports-with-comments-on-top.ts 1`] = ` +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'; @@ -179,7 +179,7 @@ function add(a: number, b: number) { `; -exports[`imports-with-directives.ts - typescript-verify: imports-with-directives.ts 1`] = ` +exports[`imports-with-directives.ts - typescript-verify > imports-with-directives.ts 1`] = ` 'use strict'; 'use client'; @@ -244,7 +244,7 @@ const workletAdd = (a: number, b: number) => { `; -exports[`imports-with-file-level-comments.ts - typescript-verify: imports-with-file-level-comments.ts 1`] = ` +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"; @@ -321,7 +321,7 @@ function add(a: number, b: number) { `; -exports[`imports-with-interpreter-directive.ts - typescript-verify: imports-with-interpreter-directive.ts 1`] = ` +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"; @@ -355,7 +355,7 @@ function add(a: number, b: number) { `; -exports[`imports-without-third-party.ts - typescript-verify: imports-without-third-party.ts 1`] = ` +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"; @@ -379,7 +379,7 @@ import twoLevelRelativePath from "../../twoLevelRelativePath"; `; -exports[`no-import-export.ts - typescript-verify: no-import-export.ts 1`] = ` +exports[`no-import-export.ts - typescript-verify > no-import-export.ts 1`] = ` function add(a:number,b:number) { return a + b; } @@ -390,7 +390,7 @@ function add(a: number, b: number) { `; -exports[`one-import.ts - typescript-verify: one-import.ts 1`] = ` +exports[`one-import.ts - typescript-verify > one-import.ts 1`] = ` // This example support/index.js is processed and // loaded automatically before your test files. // @@ -432,7 +432,7 @@ import "./commands"; `; -exports[`sort-imports-ignored.ts - typescript-verify: sort-imports-ignored.ts 1`] = ` +exports[`sort-imports-ignored.ts - typescript-verify > sort-imports-ignored.ts 1`] = ` // sort-imports-ignore import './commands'; diff --git a/tests/ImportsSeparatedByUser/__snapshots__/ppsi.spec.js.snap b/tests/ImportsSeparatedByUser/__snapshots__/ppsi.spec.js.snap index b83765d9..de2d5a44 100644 --- a/tests/ImportsSeparatedByUser/__snapshots__/ppsi.spec.js.snap +++ b/tests/ImportsSeparatedByUser/__snapshots__/ppsi.spec.js.snap @@ -1,6 +1,6 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`import-export-in-between.ts - typescript-verify: import-export-in-between.ts 1`] = ` +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"; @@ -48,7 +48,7 @@ function add(a: number, b: number) { `; -exports[`import-export-only.ts - typescript-verify: import-export-only.ts 1`] = ` +exports[`import-export-only.ts - typescript-verify > import-export-only.ts 1`] = ` import React from 'react'; export const a = 1; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -58,7 +58,7 @@ export const a = 1; `; -exports[`import-with-type-imports-together.ts - typescript-verify: import-with-type-imports-together.ts 1`] = ` +exports[`import-with-type-imports-together.ts - typescript-verify > import-with-type-imports-together.ts 1`] = ` import { foo } from "@server/foo" import type { Quux } from "./quux" import { Link } from "@ui/Link" @@ -76,7 +76,7 @@ import type { Quux } from "./quux"; `; -exports[`imports-with-comments.ts - typescript-verify: imports-with-comments.ts 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'; @@ -101,7 +101,7 @@ function add(a: number, b: number) { `; -exports[`imports-with-comments-and-third-party.ts - typescript-verify: imports-with-comments-and-third-party.ts 1`] = ` +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'; @@ -128,7 +128,7 @@ function add(a: number, b: number) { `; -exports[`imports-with-comments-on-top.ts - typescript-verify: imports-with-comments-on-top.ts 1`] = ` +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'; @@ -172,7 +172,7 @@ function add(a: number, b: number) { `; -exports[`imports-with-directives.ts - typescript-verify: imports-with-directives.ts 1`] = ` +exports[`imports-with-directives.ts - typescript-verify > imports-with-directives.ts 1`] = ` 'use strict'; 'use client'; @@ -237,7 +237,7 @@ const workletAdd = (a: number, b: number) => { `; -exports[`imports-with-file-level-comments.ts - typescript-verify: imports-with-file-level-comments.ts 1`] = ` +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"; @@ -311,7 +311,7 @@ function add(a: number, b: number) { `; -exports[`imports-with-interpreter-directive.ts - typescript-verify: imports-with-interpreter-directive.ts 1`] = ` +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"; @@ -343,7 +343,7 @@ function add(a: number, b: number) { `; -exports[`imports-without-third-party.ts - typescript-verify: imports-without-third-party.ts 1`] = ` +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"; @@ -365,7 +365,7 @@ import twoLevelRelativePath from "../../twoLevelRelativePath"; `; -exports[`no-import-export.ts - typescript-verify: no-import-export.ts 1`] = ` +exports[`no-import-export.ts - typescript-verify > no-import-export.ts 1`] = ` function add(a:number,b:number) { return a + b; } @@ -376,7 +376,7 @@ function add(a: number, b: number) { `; -exports[`one-import.ts - typescript-verify: one-import.ts 1`] = ` +exports[`one-import.ts - typescript-verify > one-import.ts 1`] = ` // This example support/index.js is processed and // loaded automatically before your test files. // @@ -418,7 +418,28 @@ import "./commands"; `; -exports[`sort-imports-ignored.ts - typescript-verify: sort-imports-ignored.ts 1`] = ` +exports[`ppsi.spec.js - typescript-verify > ppsi.spec.js 1`] = ` +run_spec(__dirname, ["typescript"], { + importOrder: ['^@core/(.*)$', '^@server/(.*)', '', '^@ui/(.*)$', '^[./]'], + importOrderSeparation: true, + importOrderParserPlugins: ['typescript'] +}); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +run_spec(__dirname, ["typescript"], { + importOrder: [ + "^@core/(.*)$", + "^@server/(.*)", + "", + "^@ui/(.*)$", + "^[./]", + ], + importOrderSeparation: true, + importOrderParserPlugins: ["typescript"], +}); + +`; + +exports[`sort-imports-ignored.ts - typescript-verify > sort-imports-ignored.ts 1`] = ` // sort-imports-ignore import './commands'; diff --git a/tests/ImportsSeparatedRest/__snapshots__/ppsi.spec.cjs.snap b/tests/ImportsSeparatedRest/__snapshots__/ppsi.spec.cjs.snap index b9a6b680..b9842cbf 100644 --- a/tests/ImportsSeparatedRest/__snapshots__/ppsi.spec.cjs.snap +++ b/tests/ImportsSeparatedRest/__snapshots__/ppsi.spec.cjs.snap @@ -1,6 +1,6 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`import-export-in-between.ts - typescript-verify: import-export-in-between.ts 1`] = ` +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"; @@ -51,7 +51,7 @@ function add(a: number, b: number) { `; -exports[`import-export-only.ts - typescript-verify: import-export-only.ts 1`] = ` +exports[`import-export-only.ts - typescript-verify > import-export-only.ts 1`] = ` import React from 'react'; export const a = 1; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -61,7 +61,7 @@ export const a = 1; `; -exports[`imports-with-comments.ts - typescript-verify: imports-with-comments.ts 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'; @@ -86,7 +86,7 @@ function add(a: number, b: number) { `; -exports[`imports-with-comments-and-third-party.ts - typescript-verify: imports-with-comments-and-third-party.ts 1`] = ` +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'; @@ -113,7 +113,7 @@ function add(a: number, b: number) { `; -exports[`imports-with-comments-on-top.ts - typescript-verify: imports-with-comments-on-top.ts 1`] = ` +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'; @@ -160,7 +160,7 @@ function add(a: number, b: number) { `; -exports[`imports-with-file-level-comments.ts - typescript-verify: imports-with-file-level-comments.ts 1`] = ` +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"; @@ -237,7 +237,7 @@ function add(a: number, b: number) { `; -exports[`imports-with-interpreter-directive.ts - typescript-verify: imports-with-interpreter-directive.ts 1`] = ` +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"; @@ -271,7 +271,7 @@ function add(a: number, b: number) { `; -exports[`imports-without-third-party.ts - typescript-verify: imports-without-third-party.ts 1`] = ` +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"; @@ -295,7 +295,7 @@ import twoLevelRelativePath from "../../twoLevelRelativePath"; `; -exports[`no-import-export.ts - typescript-verify: no-import-export.ts 1`] = ` +exports[`no-import-export.ts - typescript-verify > no-import-export.ts 1`] = ` function add(a:number,b:number) { return a + b; } @@ -306,7 +306,7 @@ function add(a: number, b: number) { `; -exports[`one-import.ts - typescript-verify: one-import.ts 1`] = ` +exports[`one-import.ts - typescript-verify > one-import.ts 1`] = ` // This example support/index.js is processed and // loaded automatically before your test files. // @@ -348,7 +348,7 @@ import "./commands"; `; -exports[`sort-imports-ignored.ts - typescript-verify: sort-imports-ignored.ts 1`] = ` +exports[`sort-imports-ignored.ts - typescript-verify > sort-imports-ignored.ts 1`] = ` // sort-imports-ignore import './commands'; diff --git a/tests/ImportsWithAttributesKeyword/__snapshots__/ppsi.spec.cjs.snap b/tests/ImportsWithAttributesKeyword/__snapshots__/ppsi.spec.cjs.snap index 7972df24..bb99c506 100644 --- a/tests/ImportsWithAttributesKeyword/__snapshots__/ppsi.spec.cjs.snap +++ b/tests/ImportsWithAttributesKeyword/__snapshots__/ppsi.spec.cjs.snap @@ -1,6 +1,6 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`imports-with-attributes-keyword.ts - typescript-verify: imports-with-attributes-keyword.ts 1`] = ` +exports[`imports-with-attributes-keyword.ts - typescript-verify > imports-with-attributes-keyword.ts 1`] = ` // I am top level comment in this file. import thirdParty0 from "third-party0"; import something3 from "@core/something3"; diff --git a/tests/Svelte/__snapshots__/ppsi.spec.cjs.snap b/tests/Svelte/__snapshots__/ppsi.spec.cjs.snap index 382c31fe..1010ebba 100644 --- a/tests/Svelte/__snapshots__/ppsi.spec.cjs.snap +++ b/tests/Svelte/__snapshots__/ppsi.spec.cjs.snap @@ -1,6 +1,6 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`module.svelte - svelte-verify: module.svelte 1`] = ` +exports[`module.svelte - svelte-verify > module.svelte 1`] = `