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

Add context.isFile for rules #12133

Closed
sindresorhus opened this issue Aug 20, 2019 · 12 comments
Closed

Add context.isFile for rules #12133

sindresorhus opened this issue Aug 20, 2019 · 12 comments
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion auto closed The bot closed this issue core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion needs design Important details about this change need to be discussed

Comments

@sindresorhus
Copy link
Contributor

The version of ESLint you are using.

6.2.1

The problem you want to solve.

I have some ESLint rules that needs to know whether the linted code is a string or an actual file. Currently, I use context.getFilename() === '<input>' || context.getFilename() === '<text>' (see sindresorhus/eslint-plugin-unicorn#346).

Your take on the correct solution to problem.

Add a context.isFile property, so I don't have to check multiple internal filename placeholders.

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

No

@sindresorhus sindresorhus added core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint triage An ESLint team member will look at this issue soon labels Aug 20, 2019
@kaicataldo
Copy link
Member

This seems like a reasonable request to me. It would be nice to abstract those internal input placeholders away from rule authors.

@kaicataldo kaicataldo 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 Aug 20, 2019
@ilyavolodin
Copy link
Member

I would be fine with adding a utility like that. But out of curiosity, could you provide an example of a rule that needs to know if it's linting a file or a string?

@sindresorhus
Copy link
Contributor Author

This filename-case rule lints the filename of JS files, and this prevent-abbreviations rule prevents use of abbreviations in variables, properties, but also filenames.

@mysticatea
Copy link
Member

  • This is a core feature, so we need an RFC: https://github.com/eslint/rfcs#eslint-rfcs
  • I'm wondering if isFile() is a good name because I'm not sure how it works if it's a valid filename but doesn't exist. For example, engine.executeOnText(code, "a-dummy-filename.js"). It's not a file but is a valid filename. For another example, engine.executeOnText(code, "/path/to/a/directory/").

@mysticatea mysticatea added the needs design Important details about this change need to be discussed label Aug 23, 2019
@sindresorhus
Copy link
Contributor Author

I'm wondering if isFile() is a good name because I'm not sure how it works if it's a valid filename but doesn't exist.

Good point. I don't think it should be concerned with whether it's a valid filename or existing file. It should only indicate that the filename option / --stdin-filename was used. How about .hasFilename?

@eslint-deprecated eslint-deprecated bot added the auto closed The bot closed this issue label Sep 23, 2019
@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.

@sindresorhus
Copy link
Contributor Author

@mysticatea I can do a RFC, but it would be good to get some of the open questions here resolved first.

@kaicataldo kaicataldo reopened this Sep 23, 2019
@kaicataldo
Copy link
Member

@mysticatea does the comment above address your concern?

@kaicataldo kaicataldo removed the auto closed The bot closed this issue label Sep 23, 2019
@mysticatea
Copy link
Member

I'm sorry that I have lost track on this issue.

hasFilename sounds better, but I still have a concern technically.

I guess that the Linter class does make the value of hasFilename from whether filename option was given or not. But in fact, CLIEngine#executeOnText() method gives <text> as filename to Linter instance if users didn't give filename option to the CLIEngine instance.

And if we consider eslint/rfcs#35 (it returns undefined if cwd was not given) and #11989 (it has been requested to return the actual filename), I think that it's the best if we add the API that retrieves the actual filename and it returns undefined when the actual filename was not given.

@eslint-deprecated eslint-deprecated bot added the auto closed The bot closed this issue label Oct 25, 2019
@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.

@g-plane g-plane reopened this Oct 25, 2019
@g-plane g-plane removed the auto closed The bot closed this issue label Oct 25, 2019
@kaicataldo
Copy link
Member

@sindresorhus Does @mysticatea's response clarify things? Want to make sure this doesn't get auto closed again :)

@eslint-deprecated eslint-deprecated bot added the auto closed The bot closed this issue label Dec 2, 2019
@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.

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Jun 1, 2020
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Jun 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion auto closed The bot closed this issue core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion needs design Important details about this change need to be discussed
Projects
None yet
Development

No branches or pull requests

5 participants