A Prettier plugin for formatting imports in Astro files
Installations
npm install prettier-plugin-astro-organize-imports
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
20.18.0
NPM Version
10.8.2
Score
75.3
Supply Chain
97.2
Quality
82.4
Maintenance
100
Vulnerability
98.6
License
Releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (89.85%)
JavaScript (10.15%)
Developer
Download Statistics
Total Downloads
67,061
Last Day
158
Last Week
1,458
Last Month
7,051
Last Year
60,529
GitHub Statistics
40 Stars
320 Commits
2 Forks
1 Watching
4 Branches
2 Contributors
Package Meta Information
Latest Version
0.4.11
Package Id
prettier-plugin-astro-organize-imports@0.4.11
Unpacked Size
3.34 MB
Size
0.96 MB
File Count
4
NPM Version
10.8.2
Node Version
20.18.0
Publised On
04 Nov 2024
Total Downloads
Cumulative downloads
Total Downloads
67,061
Last day
-35%
158
Compared to previous day
Last week
-18.6%
1,458
Compared to previous week
Last month
21.8%
7,051
Compared to previous month
Last year
826.7%
60,529
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
2
Peer Dependencies
3
Prettier Plugin: Organize Imports for Astro
A plugin that makes Prettier organize your imports (i. e. sorts, combines and removes unused ones) in Astro files using the organizeImports
feature of the TypeScript language service API.
Installation
1npm install -D prettier prettier-plugin-astro-organize-imports
Recommended configuration
1// .prettierrc 2{ 3 "plugins": ["prettier-plugin-astro-organize-imports"], 4 "overrides": [ 5 { 6 "files": "*.astro", 7 "options": { 8 "parser": "astro" 9 } 10 } 11 ] 12}
Usage
After following the steps in the 'Installation' section, the plugin will function when you run the Prettier formatting command.
Files containing the substring // organize-imports-ignore
or // tslint:disable:ordered-imports
will be skipped and won't be processed by this plugin.
The plugin provides an option named astroOrganizeImportsMode
that lets you choose the mode of formatting. The available options are:
All
: This is the default option. It removes unused imports, coalesces imports from the same module, and sorts imports.SortAndCombine
: This option coalesces imports from the same module and sorts imports.RemoveUnused
: This option removes the unused imports.
You can specify the mode in your Prettier configuration file as follows:
1// .prettierrc 2{ 3 // .. 4 "astroOrganizeImportsMode": "All" // or "SortAndCombine" or "RemoveUnused" 5}
Remember to replace "All" with "SortAndCombine" or "RemoveUnused" depending on your preferences.
Compatibility with other Prettier plugins
This plugin uses Prettier APIs that can only be used by one plugin at a time, making it incompatible with other Prettier plugins implemented the same way. To solve this we've added explicit per-plugin workarounds that enable compatibility with the following Prettier plugins:
prettier-plugin-astro
prettier-plugin-tailwindcss
One limitation with this approach is that prettier-plugin-astro-organize-imports
must be loaded last. You can do this by listing each of your Prettier plugins in the plugins
array:
1// .prettierrc 2{ 3 // .. 4 "plugins": [ 5 "prettier-plugin-astro", 6 "prettier-plugin-tailwindcss", 7 "prettier-plugin-astro-organize-imports" // MUST come last 8 ], 9 "overrides": [ 10 { 11 "files": "*.astro", 12 "options": { 13 "parser": "astro" 14 } 15 } 16 ] 17}
Related Prettier plugins
This plugin is heavily inspired by following plugins:
And, for implementation reference, the following plugins:
No vulnerabilities found.
No security vulnerabilities found.