Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Rule proposal: sort export #659

Open
gajus opened this issue Nov 9, 2016 · 5 comments
Open

Rule proposal: sort export #659

gajus opened this issue Nov 9, 2016 · 5 comments

Comments

@gajus
Copy link
Contributor

gajus commented Nov 9, 2016

I'd like to be able to sort exports in a file when file only contains exports, e.g.

// @flow

export type ScraperSourceType = {
  country: string,
  nid: string,
  name: string,
  url: string
};

export type ScraperFeaturesType = {
  hasTimeAttributes: Array<Object>,
  hasTimeUrls: boolean
};

export type ScraperType = {
  source: ScraperSourceType,
  features: ScraperFeaturesType,
  scrapeVenues: Function,
  scrapeMovies: Function,
  scrapeShowtimes: Function
};

This file only contains exports. I'd like the latter to become into:

// @flow

export type ScraperFeaturesType = {
  hasTimeAttributes: Array<Object>,
  hasTimeUrls: boolean
};

export type ScraperSourceType = {
  country: string,
  nid: string,
  name: string,
  url: string
};

export type ScraperType = {
  source: ScraperSourceType,
  features: ScraperFeaturesType,
  scrapeVenues: Function,
  scrapeMovies: Function,
  scrapeShowtimes: Function
};
@gajus
Copy link
Contributor Author

gajus commented Nov 9, 2016

To make this fixable, I can see how this causes a number of complications, e.g. what to do with potential commits surrounding an export statement.

However, reporting alone would be nice.

@carlost
Copy link

carlost commented May 25, 2018

piling onto this ... it would be useful for me if we could force the default export to follow any named exports. currently we have be manually enforce that convention ... which means it isn't followed very well.

@saltman424
Copy link

saltman424 commented Feb 4, 2020

Agreed.

In our case, we want to do this particularly for alphabetizing exports in index files, which for us often look like this:

export * from './file1'
export * from './file2'
export * from './file3'
export * from './file4'

@saltman424
Copy link

For those with the same use case as me, I found this: https://www.npmjs.com/package/eslint-plugin-sort-exports

@nirtamir2
Copy link

Agreed.

In our case, we want to do this particularly for alphabetizing exports in index files, which for us often look like this:

export * from './file1'
export * from './file2'
export * from './file3'
export * from './file4'

@saltman424 I created an ESLint plugin especially for that.
It targets export * cases and also auto-fix them.
See https://github.com/nirtamir2/eslint-plugin-sort-export-all
We can merge it to be part of the eslint-plugin-import if it's acceptable by this repository maintainers.

@tfoxy tfoxy mentioned this issue Sep 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

5 participants