Eslint-plugin-react: No errors shown when having undefined components

Created on 1 Jul 2016  路  4Comments  路  Source: yannickcr/eslint-plugin-react

eslintbug

An error should be shown that Text is undefined.

To reproduce:

import React from 'react'

import { View } from 'react-native'

export default class Root extends React.Component {
  render() {
    return (
      <View>
        <Text>Hello!</Text>
      </View>
    )
  }
}

Rules:

{
  "extends": "plugin:react/recommended",
  "env": {
    "es6": true,
    "browser": true,
    "node": true
  },
  "plugins": [
    "react",
    "babel"
  ],
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    },
    "sourceType": "module"
  }
}

Most helpful comment

This is happening because Text is a global in the browser environment.

Here's the data that ESLint uses to set up the globals for the environments: https://developer.mozilla.org/en-US/docs/Web/API/Text

And here's more information on the Text API: https://developer.mozilla.org/en-US/docs/Web/API/Text

All 4 comments

Actually I've encountered more strange behaviour, unless I'm missing something:
eslintbug2

I believe lowercased components are just treated as HTML element tag strings - ie, no error is expected there.

This is happening because Text is a global in the browser environment.

Here's the data that ESLint uses to set up the globals for the environments: https://developer.mozilla.org/en-US/docs/Web/API/Text

And here's more information on the Text API: https://developer.mozilla.org/en-US/docs/Web/API/Text

Yep, It's an edge case an there is nothing we can do to fix this.

Was this page helpful?
0 / 5 - 0 ratings