Import Sorter is a powerful Visual Studio Code extension that automatically organizes and sorts your import statements in TypeScript and JavaScript files. Keep your code clean and consistent with minimal effort!
Ctrl+P
(or Cmd+P
on macOS) to open the Quick Open dialogext install eternal.ts-js-import-sorter
to find the extensionCtrl+Shift+P
or Cmd+Shift+P
on macOS)Enable the sortOnSave
option in your settings to automatically sort imports whenever you save a file.
You can customize the behavior of Import Sorter through VS Code settings. Here are some available options:
importSorter.sortOnSave
: Enable/disable automatic sorting on save (default: false
)importSorter.method
: Choose the sorting method (options: "length"
, "alphabetical"
, "alphabetical-specifier"
, default: "length"
)importSorter.order
: Set the sorting order (options: "ascending"
, "descending"
, default: "descending"
)importSorter.newLineCount
: Set the number of newlines at the end of all imports (default: 2
)importSorter.categorizeSideEffectImports
: Enable categorization for side-effect imports (default: true
)importSorter.categorizeRelativeImports
: Enable categorization for relative imports (default: true
)importSorter.categoryNewLineCount
: Set the number of newlines between categories (default: 1
)importSorter.importCategoryOrder
: Set the order of import categories (default: ["sideEffect", "other", "relative"]
)You can configure the order of import categories using the importSorter.importCategoryOrder
setting. The default order is:
"importSorter.importCategoryOrder": ["sideEffect", "other", "relative"]
You can rearrange these categories to suit your preferences. For example, to place relative imports first:
"importSorter.importCategoryOrder": ["relative", "other", "sideEffect"]
[!NOTE] For a full list of configuration options, check the extension settings in VS Code.
Before sorting (Length):
import { useState } from 'react';
import './styles.css';
import axios from 'axios';
import { API_URL } from '../constants';
import React from 'react';
After sorting (Length):
import { API_URL } from '../constants';
import { useState } from 'react';
import React from 'react';
import axios from 'axios';
import './styles.css';
Before sorting (Length, Categorized):
import { useState } from 'react';
import './styles.css';
import axios from 'axios';
import { API_URL } from '../constants';
import React from 'react';
After sorting (Length, Categorized):
import './styles.css';
import { useState } from 'react';
import React from 'react';
import axios from 'axios';
import { API_URL } from '../constants';
Contributions are welcome! Please feel free to submit a Pull Request.
If you encounter any problems or have feature requests, please file an issue on the GitHub repository.
This project is licensed under the GPLv3 License - see the LICENSE file for details.
Enjoy sorting your imports with ease! 🚀