eslint / typescript-eslint-parser

An ESLint custom parser which leverages TypeScript ESTree to allow for ESLint to lint TypeScript source code.
Other
915 stars 92 forks source link

parserOptions.ecmaFeatures.jsx option not passed to estree #594

Closed bradzacher closed 5 years ago

bradzacher commented 5 years ago

What version of TypeScript are you using? 3.1.1

What version of typescript-eslint-parser are you using? 21.0.2

What code were you trying to parse?

const RuleTester = require("eslint").RuleTester;

const ruleTester = new RuleTester({
    parserOptions: {
        ecmaVersion: 6,
        sourceType: "module",
        ecmaFeatures: {
            jsx: true,
        },
    },
    parser: "typescript-eslint-parser",
});

ruleTester.run("no-unused-vars", rule, {
    valid: [
        `
const Foo = function () {}
function render() {
    return (<Foo />);
}
        `,
    ],
    invalid: [],
})

What did you expect to happen? The code should parse successfully, so I can test the rule.

What happened? Parsing error: \'>\' expected.

see astexplorer repl Note the parser has the jsx option set to true

bradzacher commented 5 years ago

Looking at the parser code, it just passes the raw parserOptions object into typescript-estree, however typescript-estree has its jsx option on the root options object, not on ecmaFeatures.

Workaround is to set jsx: true on the base parserOptions object:

 const ruleTester = new RuleTester({
     parserOptions: {
         ecmaVersion: 6,
         sourceType: "module",
-        ecmaFeatures: {
-            jsx: true,
-        },
+        jsx: true,
     },
     parser: "typescript-eslint-parser",
});
JamesHenry commented 5 years ago

This issue has been migrated to the new project here: typescript-eslint/typescript-eslint#24

Thanks!