Skip to content

Commit

Permalink
fix(eslint-plugin): [no-use-before-define] false positive with jsx pr…
Browse files Browse the repository at this point in the history
…agma reference

Fixes #2502
  • Loading branch information
bradzacher committed Sep 6, 2020
1 parent 3b0e58f commit 00450e9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/no-use-before-define.ts
Expand Up @@ -258,7 +258,7 @@ export default util.createRule<Options, MessageIds>({
reference.init ||
!variable ||
variable.identifiers.length === 0 ||
(variable.identifiers[0].range[1] < reference.identifier.range[1] &&
(variable.identifiers[0].range[1] <= reference.identifier.range[1] &&
!isInInitializer(variable, reference)) ||
!isForbidden(variable, reference)
) {
Expand Down
53 changes: 53 additions & 0 deletions packages/eslint-plugin/tests/rules/no-use-before-define.test.ts
Expand Up @@ -290,6 +290,59 @@ enum Foo {
`,
options: [{ enums: false }],
},
// https://github.com/typescript-eslint/typescript-eslint/issues/2502
{
code: `
import * as React from 'react';
<div />;
`,
parserOptions: {
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
},
},
{
code: `
import React from 'react';
<div />;
`,
parserOptions: {
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
},
},
{
code: `
import { h } from 'preact';
<div />;
`,
parserOptions: {
sourceType: 'module',
jsxPragma: 'h',
ecmaFeatures: {
jsx: true,
},
},
},
{
code: `
const React = require('react');
<div />;
`,
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},
],
invalid: [
{
Expand Down

0 comments on commit 00450e9

Please sign in to comment.