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.

Exceptions when traversing using sibling, adjacent and nth-child selectors and non-standard AST nodes

See original GitHub issue

Tell us about your environment

  • ESLint Version: v7.7.0
  • Node Version: v12.14.1
  • npm Version: v6.13.4

What parser (default, @babel/eslint-parser, @typescript-eslint/parser, etc.) are you using?

@typescript-eslint/parser

Please show your full configuration:

Configuration
module.exports = {
  "parser": "@typescript-eslint/parser",
  "plugins": [ "eslint-plugin-test" ],
  "rules": { "test/test": "error" }
};

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

eslint-plugin-test source:

exports.rules = {
    test: {
        create(context) {
            return {
                "Program ~ *": node => {
                    context.report({
                        message: "test",
                        node
                    })

                    // this code doesn't get a chance to get called :(
                }
            }
        }
    }
}

lint file source:

const foo: string = "bar"
eslint ./test.ts

What actually happened? Please include the actual, raw output from ESLint.

Oops! Something went wrong! :(

ESLint: 7.7.0

TypeError: Cannot read property 'length' of undefined
Occurred while linting /home/samual/test/index.ts:1
    at u (/home/samual/test/node_modules/esquery/dist/esquery.min.js:1:31904)
    at Function.l [as matches] (/home/samual/test/node_modules/esquery/dist/esquery.min.js:1:30807)
    at NodeEventGenerator.applySelector (/home/samual/test/node_modules/eslint/lib/linter/node-event-generator.js:253:21)
    at NodeEventGenerator.applySelectors (/home/samual/test/node_modules/eslint/lib/linter/node-event-generator.js:281:22)
    at NodeEventGenerator.enterNode (/home/samual/test/node_modules/eslint/lib/linter/node-event-generator.js:297:14)
    at CodePathAnalyzer.enterNode (/home/samual/test/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:673:23)
    at /home/samual/test/node_modules/eslint/lib/linter/linter.js:949:32
    at Array.forEach (<anonymous>)
    at runRules (/home/samual/test/node_modules/eslint/lib/linter/linter.js:944:15)
    at Linter._verifyWithoutProcessors (/home/samual/test/node_modules/eslint/lib/linter/linter.js:1170:31)

Context

Original issue: https://github.com/typescript-eslint/typescript-eslint/issues/2439

Investigation so far:

Our parser (@typescript-eslint/parser) returns an extended list of visitor-keys (as specified by the ESLint docs) right here

However esquery uses its own (hard coded) visitor keys for 3 selectors:

So I think that this is this something we’ll have to PR into the underlying esquery library?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
brettz9commented, Feb 5, 2021

esquery has just published a new release with the support for custom visitor keys, so I think this should no longer be blocking.

1reaction
mdjermanoviccommented, Aug 31, 2020

I think we should treat this as a bug, since our selectors documentation lists those selectors, so it’s reasonable to expect that they can work with custom parsers.

Also, they’ll crash even with the default parser on any JSX code, as in this demo.

It’s true that this needs to be supported in esquery first, so we could pass visitors keys.

Relevant PR: https://github.com/estools/esquery/pull/112

An alternative is to remove those selectors from the documentation. If this doesn’t get fixed, it seems best not to use them at all.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adjacent sibling combinator - CSS: Cascading Style Sheets
The adjacent sibling combinator (+) separates two selectors and matches the second element only if it immediately follows the first element, ...
Read more >
Selectors - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
HTML and CSS Flashcards | Chegg.com
Study HTML and CSS flashcards. Create flashcards for FREE and quiz yourself with an interactive flipper.
Read more >
Test by Test Test - Issuu
Given a jQuery object that represents a set of DOM elements, the .parent() method allows us to search through the parents of these...
Read more >
CsQuery - Select & Go.
CsQuery is a complete CSS selector engine, HTML parser, and jQuery port for C# ... element) methods you're familiar with to traverse and...
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