question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Infer the endLocation of a problem from the reported node

See original GitHub issue

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 https://github.com/eslint/eslint/issues/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"
}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
not-an-aardvarkcommented, Mar 12, 2017

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?

0reactions
not-an-aardvarkcommented, Mar 16, 2017

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Migrating to v4.0.0 - ESLint - Pluggable JavaScript Linter
Starting in 4.0, if a node is reported rather than a location, the end location of the range will automatically be inferred from...
Read more >
Using natural travel paths to infer and compare primate ...
Here, we propose a third, complementary approach: inferring and comparing cognitive abilities through observational field records of natural ...
Read more >
Efficient Data Inference and Compression over RFID Streams
Abstract—Despite its promise, RFID technology presents nu- merous challenges, including incomplete data, lack of location.
Read more >
Learning and Inferring Transportation Routines
Abstract. This paper introduces a hierarchical Markov model that can learn and infer a user's daily movements through the commu-.
Read more >
SNAF: Observation filtering and location inference for event ...
By aggregating the observation reports with location information, ... The other challenge is to provide the missing location information.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found