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

Proposal: context.version #9317

Closed
wants to merge 1 commit into from
Closed

Proposal: context.version #9317

wants to merge 1 commit into from

Conversation

mysticatea
Copy link
Member

What is the purpose of this pull request? (put an "X" next to item)

[X] Add something to the core

I request to add version to the rule context.

exports.create = (context) => {
    console.log(context.version) // → 4.7.0
    return {}
}

The context.version is useful in many cases. Below cases are examples, though this is too late.

Check the behavior of directive comments

Since 4.7.0, eslint-enable's behavior was changed a bit (#9216 (comment)).
eslint-plugin-eslint-comments plugin want to follow the change. It wants to detect the actual behavior on the ESLint which is running, but cannot know without the context.version.

Check the behavior of auto-fixing.

Since 4.1.0, fix functions which are passed to context.report can return an iterable object (includes an array) (#8101).
I want to use it and to avoid critical error on <4.1.0, but rules cannot know whether the fix functions can return an iterable object or not without the context.version.

Check the behavior of the location of problems.

Since 3.1.0, loc properties which are passed to context.report can be {start: object, end: object} to express the range of the problem (#6640).
I had wanted to use it and to avoid critical error on <3.1.0, but rules could not know whether the context.report accepts the range or not without context.version.

What changes did you make? (Give an overview)

This PR adds the version property into rule contexts.

Is there anything you'd like reviewers to focus on?

Direction.

@mysticatea mysticatea added 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 labels Sep 16, 2017
@mention-bot
Copy link

@mysticatea, thanks for your PR! By analyzing the history of the files in this pull request, we identified @not-an-aardvark, @nzakas and @gyandeeps to be potential reviewers.

@eslintbot
Copy link

LGTM

@eslint eslint deleted a comment from eslintbot Sep 19, 2017
@ilyavolodin
Copy link
Member

On one hand, this is a small enhancement that I have no issue with adding, on the other, I really don't think it's a good idea for rules to know anything about the core, since that could lead to unpredictable behavior based on the version of ESLint you have installed. To me, a better solution is to mark a given version of ESLint as required in a plugin, and drop support for older version.

@not-an-aardvark
Copy link
Member

We should probably create an issue for this since it's a core change (see here)

@mysticatea
Copy link
Member Author

Closing since I don't have enough time.

@mysticatea mysticatea closed this Oct 27, 2017
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Apr 26, 2018
@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 Apr 26, 2018
@mysticatea mysticatea deleted the context-version branch June 1, 2018 04:46
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 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants