Skip to content

Latest commit

 

History

History
40 lines (32 loc) · 1.16 KB

File metadata and controls

40 lines (32 loc) · 1.16 KB

Consistently order import statements (import-sorting/order)

🔧 This rule is automatically fixable by the --fix CLI option.

The grouping order is as follows:

  1. Unassigned imports (only grouped, existing order is preserved)
  2. Node/Bun standard modules (protocol is ignored when sorting)
  3. Framework modules (see below)
  4. External modules
  5. Internal modules (see below)
  6. Explicitly local modules (paths starting with a dot segment)
  7. Style imports

Settings

The framework and internal groups can be configured by passing a RegEx string to the different plugin setting. This allows the rule itself to be implemented by a shared config, while individual projects can determine what constitutes an “internal” module.

For example:

export default [
	{
		settings: {
			// Group official React packages together.
			'import-sorting/framework-patterns': /^react(\/|-dom|-router|$)/.source,
			// Group aliased imports together.
			'import-sorting/internal-patterns': /^~/.source,
		},
		rules: {
			'import-sorting/order': 'error',
		},
	},
]