Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Is it possible to sort imports based on variable names within group? #1577

Open
techsin opened this issue Dec 19, 2019 · 4 comments
Open

Is it possible to sort imports based on variable names within group? #1577

techsin opened this issue Dec 19, 2019 · 4 comments

Comments

@techsin
Copy link

techsin commented Dec 19, 2019

"Sort the order within each group in alphabetical manner based on import path"

That's the current way... what If I wanted something like this..


import React from 'react';
import CompA from './zecomp.js
import CompB from './abigcomp.com

but sorting based on path gives me


import React from 'react';
import CompB from './abigcomp.com
import CompA from './zecomp.js

@ljharb
Copy link
Member

ljharb commented Dec 20, 2019

It seems doable to allow a config option alphebeticalBy that defaults to "specifier" but can be set to "binding".

However, this only really makes sense with a default import, or a namespace import - what about import { z, a } from 'path'?

@techsin
Copy link
Author

techsin commented Dec 20, 2019

sort to {a, z} then use first word, a?

@ljharb
Copy link
Member

ljharb commented Dec 20, 2019

Would the rule sort the named imports, as well? That almost feels like a bit of an overreach of this rule.

@techsin
Copy link
Author

techsin commented Dec 20, 2019

yes, but if i had a rule expecting it to autofix (sort) my import based on var names, i'd want it to take the liberty of making opinionated choices as long as it doesn't modify function of my code.

how many imports are there?

const a = require(..)
import * from '...';
import abc from 'abc';
import * as abc from 'abc';
import {props} from 'abc';

  • could be at the most top.
    if there is as then that name
    if {..} then first prop name, after sorting...

very opinionated for sure. But complexity is inherent.

# for free to join this conversation on GitHub. Already have an account? # to comment
Development

No branches or pull requests

2 participants