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

Infer the endLocation of a problem from the reported node #8004

Closed
not-an-aardvark opened this issue Feb 1, 2017 · 11 comments
Closed

Infer the endLocation of a problem from the reported node #8004

not-an-aardvark opened this issue Feb 1, 2017 · 11 comments
Assignees
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion breaking This change is backwards-incompatible core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint

Comments

@not-an-aardvark
Copy link
Member

not-an-aardvark commented Feb 1, 2017

Problem

Currently, the context.report API allows rules to specify a start and end location for problems:

context.report({
  loc: {
    start: {
      line: 1,
      column: 3
    },
    end: {
      line: 1,
      column: 5
    }
  },
  message: 'Detected a problem.'
});

This was added to address #3307, and it's very useful because it allows editor integrations to highlight an entire range.

However, as currently implemented this API is tedious to use, because it only works if a report includes aloc key. As a result, most rules don't use this API, because they report a node instead of an explicit location. (When a node is reported, only the start location of the node appears in the resulting message -- the end location does not appear.)

Proposal

When a node is reported without a location, the end location of the node should be used as the end location of the report. (The start location of the node is already used for the start location of the report.)

For example, given the following node:

{
  "type": "Identifier",
  "start": 0,
  "end": 3,
  "name": "foo"
}

Suppose a rule uses

context.report({ node, message: 'report message' });

The resulting problem message currently looks like this:

{
  "ruleId": "some-rule",
  "severity": 2,
  "message": "report message",
  "line": 1,
  "column": 1,
  "nodeType": "Identifier",
  "source": "foo"
}

With this change, the resulting problem message would look like this:

{
  "ruleId": "some-rule",
  "severity": 2,
  "message": "report message",
  "line": 1,
  "column": 1,
+ "endLine": 1,
+ "endColumn": 4,
  "nodeType": "Identifier",
  "source": "foo"
}
@not-an-aardvark not-an-aardvark 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 Feb 1, 2017
@not-an-aardvark not-an-aardvark self-assigned this Feb 1, 2017
@ilyavolodin
Copy link
Member

I was under impression that we are already doing this. But if we are not, then I definitely support this.

@mysticatea mysticatea added the breaking This change is backwards-incompatible label Feb 1, 2017
@mysticatea
Copy link
Member

I avoided it: #6640

Because some rules in core and plugin ecosystem have sometimes used big node (Program, FunctionDeclaration, Property, .*Statement, ...). I'm afraid that it fills editors with red.

@platinumazure
Copy link
Member

Maybe we could implement it and then try to fix rules using large nodes as reports come in?

@not-an-aardvark
Copy link
Member Author

Personally I think the issue with filling a screen is an editor integration problem, not an ESLint problem. I'm fine with waiting until a major release, but if we do that then we might also want to give some warning so that editors can display the best possible UI.

@mysticatea
Copy link
Member

For example:

return {
    Program(node) {
        context.report({ node, message: 'report message' });
    }
}

In this case, currently the report is at the head of the source code, but the report spans whole the source code after this change. It's a breaking change that plugin owners need to modify their plugins.

@mysticatea
Copy link
Member

I don't oppose this if it happens on the next major release.

@not-an-aardvark not-an-aardvark 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 Feb 23, 2017
@not-an-aardvark
Copy link
Member Author

not-an-aardvark commented Feb 24, 2017

Since it looks like we're probably going ahead with this change, we should probably notify editor integrations about this in case they want to change their behavior ahead of time. I pulled the list from the integrations page:

I haven't used most of these integrations, so I'm not sure how many of them are maintained. Also, there are probably some of integrations that wouldn't be affected by this change anyway.

@mysticatea
Copy link
Member

At least, vscode-eslint and atom-linter are using endLine and endColumn to show reports.

I think the announcement is needed for plugin's authors rather than editor integrations because this is a breaking change of RuleContext API and the form of reports are not changed. This change does not affect to editors, but affects to plugins.

@kaicataldo
Copy link
Member

To add to the list of Vim editor integrations, neomake is also quite popular alongside Syntastic.

@not-an-aardvark
Copy link
Member Author

I'll add this to the TSC agenda since it's a change to core that could break things.

TSC Summary: As currently implemented, the endLine and endColumn report API is tedious to use, because it only works if a report includes a loc key. As a result, most rules don't use this API, because they report a node instead of an explicit location. We could update core to infer the endLine and endColumn of a reported node, but this would be a breaking change because it could cause a poor user experience in some existing editor integrations (e.g. if hundreds of lines are highlighted because a large node is reported).

TSC Question: Should we make this change?

@not-an-aardvark not-an-aardvark added evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion tsc agenda This issue will be discussed by ESLint's TSC at the next meeting and removed accepted There is consensus among the team that this change meets the criteria for inclusion labels Mar 12, 2017
not-an-aardvark added a commit that referenced this issue Mar 12, 2017
Previously, rules could specify an endLine and endColumn in a report. However, when a rule reported a node without explicitly giving a location, only the start location of the node was included in the final report object. This commit updates the report-handling logic to ensure that the end location of the node is also included.

This is considered a potentially-breaking change because if a rule specifies a very large node to report, the report range will be very large, which could cause a poor user experience in editor integrations (e.g. if hundreds of lines are highlighted).
@not-an-aardvark not-an-aardvark 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 tsc agenda This issue will be discussed by ESLint's TSC at the next meeting labels Mar 16, 2017
@not-an-aardvark
Copy link
Member Author

In today's TSC meeting, the TSC accepted this issue.

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 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 Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion breaking This change is backwards-incompatible core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint
Projects
None yet
Development

No branches or pull requests

5 participants