Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
IanVS committed Mar 15, 2024
1 parent 9a1cfe4 commit 8fd1444
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/utils/__tests__/get-all-comments-from-nodes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ import type {
} from '@babel/types';
import { expect, test } from 'vitest';

import { DEFAULT_IMPORT_ORDER } from '../../constants';
import { getAllCommentsFromNodes } from '../get-all-comments-from-nodes';
import { getImportNodes } from '../get-import-nodes';
import { getSortedNodes } from '../get-sorted-nodes';
import { testingOnly } from '../normalize-plugin-options';
import { DEFAULT_IMPORT_ORDER } from '../../constants';

const getSortedImportNodes = (code: string, options?: ParserOptions) => {
const importNodes: ImportDeclaration[] = getImportNodes(code, options);

return getSortedNodes(importNodes, {
importOrder: testingOnly.normalizeImportOrderOption(DEFAULT_IMPORT_ORDER),
importOrder:
testingOnly.normalizeImportOrderOption(DEFAULT_IMPORT_ORDER),
importOrderCombineTypeAndValueImports: true,
});
};
Expand Down
5 changes: 3 additions & 2 deletions src/utils/__tests__/get-code-from-ast.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { format } from 'prettier';
import { expect, test } from 'vitest';

import { DEFAULT_IMPORT_ORDER } from '../../constants';
import { getCodeFromAst } from '../get-code-from-ast';
import { getImportNodes } from '../get-import-nodes';
import { getSortedNodes } from '../get-sorted-nodes';
import { testingOnly } from '../normalize-plugin-options';
import { DEFAULT_IMPORT_ORDER } from '../../constants';

const defaultImportOrder = testingOnly.normalizeImportOrderOption(DEFAULT_IMPORT_ORDER);
const defaultImportOrder =
testingOnly.normalizeImportOrderOption(DEFAULT_IMPORT_ORDER);

test('sorts imports correctly', async () => {
const code = `import z from 'z';
Expand Down
5 changes: 3 additions & 2 deletions src/utils/__tests__/get-sorted-nodes.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { ImportDeclaration } from '@babel/types';
import { expect, test } from 'vitest';

import { DEFAULT_IMPORT_ORDER } from '../../constants';
import { getImportNodes } from '../get-import-nodes';
import { getSortedNodes } from '../get-sorted-nodes';
import { getSortedNodesModulesNames } from '../get-sorted-nodes-modules-names';
import { getSortedNodesNamesAndNewlines } from '../get-sorted-nodes-names-and-newlines';
import { testingOnly } from '../normalize-plugin-options';
import { DEFAULT_IMPORT_ORDER } from '../../constants';

const code = `
import "se3";
Expand All @@ -30,7 +30,8 @@ import "se2";
test('it returns all sorted nodes, preserving the order side effect nodes', () => {
const result = getImportNodes(code);
const sorted = getSortedNodes(result, {
importOrder: testingOnly.normalizeImportOrderOption(DEFAULT_IMPORT_ORDER),
importOrder:
testingOnly.normalizeImportOrderOption(DEFAULT_IMPORT_ORDER),
importOrderCombineTypeAndValueImports: true,
}) as ImportDeclaration[];
expect(getSortedNodesNamesAndNewlines(sorted)).toEqual([
Expand Down
5 changes: 3 additions & 2 deletions src/utils/__tests__/remove-nodes-from-original-code.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { parse as babelParser } from '@babel/parser';
import { format } from 'prettier';
import { expect, test } from 'vitest';

import { DEFAULT_IMPORT_ORDER } from '../../constants';
import { getAllCommentsFromNodes } from '../get-all-comments-from-nodes';
import { getImportNodes } from '../get-import-nodes';
import { getSortedNodes } from '../get-sorted-nodes';
import { testingOnly } from '../normalize-plugin-options';
import { removeNodesFromOriginalCode } from '../remove-nodes-from-original-code';
import { DEFAULT_IMPORT_ORDER } from '../../constants';

const code = `"some directive";// first comment
// second comment
Expand All @@ -25,7 +25,8 @@ test('it should remove nodes from the original code', async () => {
const ast = babelParser(code, { sourceType: 'module' });
const importNodes = getImportNodes(code);
const sortedNodes = getSortedNodes(importNodes, {
importOrder: testingOnly.normalizeImportOrderOption(DEFAULT_IMPORT_ORDER),
importOrder:
testingOnly.normalizeImportOrderOption(DEFAULT_IMPORT_ORDER),
importOrderCombineTypeAndValueImports: true,
});
const allCommentsFromImports = getAllCommentsFromNodes(sortedNodes);
Expand Down

0 comments on commit 8fd1444

Please sign in to comment.