daidodo / format-imports

JavaScript and TypeScript Import/Export Sorter
MIT License
45 stars 2 forks source link

How to sort the import statement which not contains import name #8

Closed tjx666 closed 3 years ago

tjx666 commented 3 years ago

For Example, I want the import './SaveNFTModal.less'; to be last line.

My configuration:

{
  // Wiki: https://github.com/daidodo/format-imports/wiki/Grouping-Rules
  "tsImportSorter.configuration.groupRules": [
    ["^[@]", {}],
    ["^api", "^components", "^features", "^style", "^util"],
    "^[.]"
  ],
  "tsImportSorter.configuration.wrappingStyle": {
    // Max binding names per line before wrapping for imports. 0 for no limit.
    "maxBindingNamesPerLine": 0,
    // Max default and binding names per line before wrapping for imports. 0 for no limit.
    "maxDefaultAndBindingNamesPerLine": 0,
    // Max binding names per line before wrapping for exports. 0 for no limit.
    "maxExportNamesPerLine": 0,
    // Max names on wrapped lines. 0 for no limit.
    "maxNamesPerWrappedLine": 0,
    // Whether to ignore trailing comments when counting line length.
    "ignoreComments": false
  },

  "tsImportSorter.configuration.sortRules": {
    // Sorting rule for import paths. Valid values are 'none' or an array.
    "paths": ["_", "aA"],

    // Sorting rule for imported/exported names. Valid values are 'none' or an array.
    "names": ["_", "aA"]
  }
}

image

tjx666 commented 3 years ago

@daidodo

daidodo commented 3 years ago

Hi @tjx666, thanks for the feedback!

The imports are classified as script and named imports: Types of Imports And they are dealt with differently: flags Example: How to customise script imports

In your case, probably you want another line in your config:

"tsImportSorter.configuration.groupRules": [
    ["^[@]", {}],
    ["^api", "^components", "^features", "^style", "^util"],
    "^[.]",
    {"flags": "script", "regex": "[.]less$"}   // Move *.less imports to the end
  ],

Please tell me if you have further questions!

tjx666 commented 3 years ago

Thanks for so awesome project!