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

func-style "expression" conflicts with ESM named exports #12829

Closed
ljharb opened this issue Jan 25, 2020 · 25 comments · Fixed by #18444
Closed

func-style "expression" conflicts with ESM named exports #12829

ljharb opened this issue Jan 25, 2020 · 25 comments · Fixed by #18444
Assignees
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules

Comments

@ljharb
Copy link
Sponsor Contributor

ljharb commented Jan 25, 2020

What rule do you want to change?
func-style

Does this change cause the rule to produce more or fewer warnings?
Fewer or more, depending on how the option is configured.

How will the change be implemented? (New option, new default behavior, etc.)?
A new namedExports option, which can be set to "expression" or "declaration" or "ignore".

Please provide some example code that this change will affect:

/* eslint func-style: [2, "expression"] */
export function foo() {}

What does the rule currently do for this code?
warns

What will the rule do after it's changed?
/* eslint func-style: [2, "expression", { "namedExports": "declaration"] */ will cause no warning to be issued.

Are you willing to submit a pull request to implement this change?
Yes.

@ljharb ljharb added enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules triage An ESLint team member will look at this issue soon labels Jan 25, 2020
@mdjermanovic
Copy link
Member

Just to clarify the issue, I believe this configuration expects something like:

/* eslint func-style: [2, "expression"] */
export const foo = function () {};

What conflict does this cause? Asking because "conflict" is mentioned in the title.

@mdjermanovic mdjermanovic added evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels Jan 25, 2020
@ljharb
Copy link
Sponsor Contributor Author

ljharb commented Jan 26, 2020

I suppose it isn’t a conflict; it’s just that i don’t see these as the same as function declarations since they’re under a tdz, and so altho i never want declarations, i do want the export function form.

@mdjermanovic
Copy link
Member

So, the motivation is to allow hoisting only for exported functions because good practice is to define all exports at the end?

foo(); // this wouldn't be possible here with export const foo = function () {};

export function foo() {};

@ljharb
Copy link
Sponsor Contributor Author

ljharb commented Jan 26, 2020

Unfortunately that does result in hoisting, but in this case I don't care about it, because i don't want to create an extra variable in my named exports.

@mdjermanovic
Copy link
Member

Unfortunately that does result in hoisting, but in this case I don't care about it, because i don't want to create an extra variable in my named exports.

I'm not sure that I understand the part about an extra variable, an example of code you'd like to avoid with this option would be helpful!

@ljharb
Copy link
Sponsor Contributor Author

ljharb commented Jan 26, 2020

i want to avoid export const = - i don’t want equals signs in my export statements, but i do want to prohibit declarations everywhere else.

@mdjermanovic
Copy link
Member

Makes sense to me 👍

@eslint-deprecated eslint-deprecated bot added the auto closed The bot closed this issue label Feb 26, 2020
@eslint-deprecated
Copy link

Unfortunately, it looks like there wasn't enough interest from the team
or community to implement this change. While we wish we'd be able to
accommodate everyone's requests, we do need to prioritize. We've found
that issues failing to reach accepted status after 21 days tend to
never be accepted, and as such, we close those issues.
This doesn't mean the idea isn't interesting or useful, just that it's
not something the team can commit to.

Thanks for contributing to ESLint and we appreciate your understanding.

@ljharb
Copy link
Sponsor Contributor Author

ljharb commented Feb 26, 2020

It'd be great if this could be reopened.

@mdjermanovic
Copy link
Member

I'll champion this.

@mdjermanovic mdjermanovic reopened this Feb 26, 2020
@mdjermanovic mdjermanovic removed the auto closed The bot closed this issue label Feb 26, 2020
@mdjermanovic mdjermanovic self-assigned this Feb 26, 2020
@krainboltgreene
Copy link

How can I help with this?

@mdjermanovic
Copy link
Member

@krainboltgreene this enhancement doesn't have consensus from the team yet.

If and when this issue gets accepted, a PR will be welcome :)

@krainboltgreene
Copy link

Ahhh, that makes sense thanks!

@ljharb
Copy link
Sponsor Contributor Author

ljharb commented Jan 24, 2021

@mdjermanovic any update on consensus from the team? this is still an issue for all the packages I'm writing ESM wrappers for.

@nzakas
Copy link
Member

nzakas commented Aug 14, 2023

@mdjermanovic you championed this initially, do you want to move forward? If so, can you explain the exact change?

@Tanujkanti4441
Copy link
Contributor

@mdjermanovic a friendly ping, waiting for your suggestion to move this issue forward, Thanks.

@nzakas
Copy link
Member

nzakas commented Mar 5, 2024

@mdjermanovic still looking for your input here

@ljharb
Copy link
Sponsor Contributor Author

ljharb commented Mar 5, 2024

I'd still like it to move forward, as the OP :-p the exact change would be one of:

  • func-style just ignores inline exported functions
  • func-style gets a new option, that when enabled, ignores inline exported functions

@mdjermanovic
Copy link
Member

I don't think this rule should ignore named exports by default.

We could add a boolean option to ignore named exports:

"func-style": [2, "expression", { "ignoreNamedExports": true }] // `false` by default

or an option to override base settings for named exports or ignore them:

"func-style": [2, "expression", {
    "overrides": { 
        "namedExports": "declaration" // allowed values are: "expression", "declaration`, "ignore"
    }
}]

The latter is similar to the original proposal, I only added "overrides" because options that override base settings for certain cases are typically under "overrides" in core rules.

Thoughts?

@ljharb
Copy link
Sponsor Contributor Author

ljharb commented Apr 4, 2024

An option sounds perfectly fine, thanks.

@nzakas
Copy link
Member

nzakas commented Apr 16, 2024

@ljharb is that in favor of a boolean option or the overrides option?

@ljharb
Copy link
Sponsor Contributor Author

ljharb commented Apr 17, 2024

Either is fine.

@nzakas
Copy link
Member

nzakas commented Apr 29, 2024

@mdjermanovic I think either solution is fine as well, do you have a preference?

@mdjermanovic
Copy link
Member

I'd prefer overrides:

"func-style": [2, "expression", {
    "overrides": { 
        "namedExports": "declaration" // allowed values are: "expression", "declaration`, "ignore"
    }
}]

Marked as accepted, PR is welcome.

@mdjermanovic mdjermanovic added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels May 7, 2024
@ljharb
Copy link
Sponsor Contributor Author

ljharb commented May 14, 2024

i see #18444 was filed; i was planning to file one this week since i was traveling last week, but i'm happy @kecrily beat me to it :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules
Projects
Status: Complete
Development

Successfully merging a pull request may close this issue.

5 participants