सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।
Import Sorter एक डेवलपर टूल है जो आपके कोड में डार्ट आयात कथनों को स्वचालित रूप से व्यवस्थित करता है। यह आयात को सुसंगत ढंग से व्यवस्थित करने की गारंटी देता है, जिससे पठनीयता और रखरखाव में सुधार होता है। पैकेज विकास कार्यप्रणालियों में बिना किसी अड़चन के एकीकृत होता है, जो सभी प्रमुख प्लेटफॉर्मों को समर्थन देता है, जिसमें एंड्रॉइड, आईओएस, मैकओएस, विंडोज और लिनक्स शामिल हैं। एक सरल कमांड चलाकर डेवलपर्स अपने आयात सूचियों को पूर्वनिर्धारित नियमों के अनुसार फॉर्मेट कर सकते हैं, जिससे हाथ से काम कम होता है और मर्ज कॉन्फ्लिक्ट कम होते हैं। प्रोजेक्ट में एक समान कोड शैली को बनाए रखने के लिए आदर्श।
उपयोग
आवत संगठन को स्वचालित करना
समान कोड शैली का प्रभावी रूप से अनुपालन
मर्ज संघर्षों को कम करना
कोड पढ़ने में आसानी बढ़ाना
टीम के कार्य प्रवाह को सुगम बनाना
मुख्य विशेषताएँ
स्वचालित आयात क्रम
कमांड-लाइन एंटीग्रेशन
कई प्लेटफॉर्म का समर्थन करता है
हस्तचालित आयात त्रुटियों से बचाएं
Flutter वर्कफ़्लो के साथ एकीकृत करें
इनके लिए उपयुक्त
Flutter टीमें
कोड गुणवत्ता प्रवर्तक
बड़े प्रोजेक्ट
CI/CD पाइपलाइन्स
विकासक लगातारता को प्राथमिकता देते हैं
विचार योग्य बातें
प्रोजेक्ट में सेटअप की आवश्यकता है
अन्य फॉर्मेटर्स के साथ टकराव हो सकता है
नियमित अपडेट की आवश्यकता है
सही कॉन्फ़िगरेशन पर निर्भर करता है
एक बार के स्क्रिप्ट के लिए उपयुक्त नहीं
मूल README
संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।
🎯 Dart package to automatically organize your dart imports. Any dart project supported! Will sorts imports alphabetically and then group them in the following order:
Simply add import_sorter: ^4.6.0 to your pubspec.yaml's dev_dependencies.
🏃♂️ Running
Once you've installed it simply run flutter pub run import_sorter (pub run import_sorter if normal dart application) to format every file dart file in your lib, bin, test, and tests folder! Don't worry if these folders don't exist.
💻 Command Line
Add the -e flag to the run command and have emojis added to your imports 😄.
If you're using a config in the pubspec.yaml you can have the program ignore it by adding --ignore-config.
Want to make sure your files are sorted? Add --exit-if-changed to make sure the files are sorted. Good for things like CI.
Have no comments before your imports by adding the --no-comments flag.
Add the -h flag if you need any help from the command line!
You can only run import_sorter on certain files by passing in a regular expression(s) that will only sort certain files. Below are two examples:
pub run import_sorter bin/main.dart lib/args.dart (only sorts bin/main.dart and lib/args.dart)
pub run import_sorter lib\/* test\/* (only sorts files in the lib and test folders)
🏗️ Config
If you use import_sorter a lot or need to ignore certain files you should look at using the config you put in your pubspec.yaml. Ignored files are in the format of regex. This regex is then applied to the project root path (the one outputted to the terminal). Below is an example config setting emojis to true and ignoring all files in the lib folder:
import_sorter:emojis:true# Optional, defaults to falsecomments:false# Optional, defaults to trueignored_files:# Optional, defaults to []-\/lib\/*
There are two pre-commit hooks available: dart-import-sorter and flutter-import-sorter. They use pub run and flutter pub run respectively. Use the former for a generic Dart project and the latter for a Flutter project.
Using pre-commit hooks in your project:
Install and configure pre-commit.
Install and configure import_sorter using instructions above.
Add the following to the repos section of your .pre-commit-config.yaml:
-repo:https://github.com/fluttercommunity/import_sorterrev:'master'hooks:-id:dart-import-sorter# use `flutter-import-sorter` for a Flutter project
Run initial sort:
pre-commit run --all-files
🙋♀️🙋♂️ Contributing
All contributions are welcome! Just make sure that it's not an already existing issue or pull request.