Skip to content

Relax rule: JSX: Consider the global scope when checking for defined Components (react/jsx-no-undef) #1115

Closed
@DimiTech

Description

Hi, I'm using standard with react-native and babel-plugin-jsx-control-statements.

Standard version: v11.0.1

Problem

standard shows errors for babel-plugin-jsx-control-statements globals such as If, Choose etc. even though they're declared in package.json standard.globals and the babel-plugin-jsx-control-statements is specified in .babelrc (as seen below)

file: package.json
...
  "standard": {
    "parser": "babel-eslint",
    "globals": [
      "describe",
      "test",
      "it",
      "jest",
      "beforeAll",
      "beforeEach",
      "afterAll",
      "afterEach",
      "expect",
      "fetch",
      "navigator",
      "__DEV__",
      "XMLHttpRequest",
      "FormData",
      "React$Element",
      "If",
      "Choose",
      "When",
      "Otherwise",
      "For",
      "With"
    ]
  }
...
file: .babelrc
...
  "plugins": [
    "jsx-control-statements"
  ],
...

Example output

$ standard --verbose | snazzy
...
  36:14  error  'Choose' is not defined     react/jsx-no-undef
  37:16  error  'When' is not defined       react/jsx-no-undef
  40:16  error  'Otherwise' is not defined  react/jsx-no-undef
  45:12  error  'Choose' is not defined     react/jsx-no-undef
  46:14  error  'When' is not defined       react/jsx-no-undef
  49:14  error  'Otherwise' is not defined  react/jsx-no-undef
  53:12  error  'Choose' is not defined     react/jsx-no-undef
  54:14  error  'When' is not defined       react/jsx-no-undef
  57:14  error  'Otherwise' is not defined  react/jsx-no-undef
...

Expected behavior

standard should not throw react/jsx-no-undef errors for variables declared in package.json > standard.globals:

      "If",
      "Choose",
      "When",
      "Otherwise",
      "For",
      "With"

I've seen this line in the CHANGELOG.md:

Fix jsx-no-undef will not check the global scope by default.

But I guess it doesn't relate to this case.

Let me know if I can provide any more details.
Thanks a lot,
D.D.

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions