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

Propose a new rule. Combine imports and exports from the same file #33

Open
fshabanov opened this issue Feb 29, 2024 · 1 comment
Open

Comments

@fshabanov
Copy link
Contributor

fshabanov commented Feb 29, 2024

Problem

JS allows to have multiple imports/exports from the same source within one file. This can reduce readability of code and create some confusion when trying to understand the code.
Example:

import { type UserDto } from "shared";
import { type UserCreateRequestDto } from "shared";
import { type UserCreateResponseDto } from "shared";

Or the same with exports:

export { type UserDto } from "shared";
export { type UserCreateRequestDto } from "shared";
export { type UserCreateResponseDto } from "shared";

Proposal

I propose to add a rule, where combining those imports/exports is mandatory. I believe in one file we should only have one import/export from a particular source file. This will make it easier to understand and see the imports and exports in a file.

import {
  type UserDto,
  type UserCreateRequestDto,
  type UserCreateResponseDto
} from "shared";

And for exports:

export {
  type UserDto,
  type UserCreateRequestDto,
  type UserCreateResponseDto
} from "shared";
@what1s1ove
Copy link
Collaborator

Hey @fshabanov!

Thanks for your activity!

I'm not sure if this should be part of the quality criteria since it can easily be dealt with using this ESLint rule – https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-duulates.md

I agree that the code is easy to read when all the imports are grouped, but the quality criteria is about more than just readability. It's also about potential bugs that could break the code.

But I'm open to new things, just like your suggestion. Let's see, maybe someone will support this proposal too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants