Intellicode / eslint-plugin-react-native

React Native plugin for ESLint

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

no raw text rule fail

tomdyqin opened this issue · comments

{
  code: `
    export default class MyComponent extends Component {
      render() {
        const styles = StyleSheet.create({})
        return (<View>
          <Text>text1</Text>
          <Text style={styles.a}>text2</Text>
        </View>);
      }
    }
  `,
},

this is my test code, line text1 is ok, but text2 use style props is fail
1

Did this happen after the latest release?

Did this happen after the latest release?

Same issue here. Indeed after upgrading to 3.9.0

This seems to be related with #247 .

This PR was created to allow components that use dot notation to work (ie: Animated.Text). This rule works by checking if the component name is in a list of allowed components that can contain text. But the function used to get the component name now is also appending the prop names to the component name.

This happens in this function:

const elementName = (node, scope) => {
const identifiers = [];
traverse(node, {
JSXOpeningElement({ node: element }) {
traverse(element, {
JSXIdentifier({ node: identifier }) {
identifiers.push(identifier.name);
},
}, scope);
},
}, scope);
return identifiers.join('.');
};

Changing this section fixes the problem:

      traverse(element, {
        JSXIdentifier({ node: identifier }) {
          if (identifier.parent.type === 'JSXOpeningElement' || identifier.parent.type === 'JSXMemberExpression') {
            identifiers.push(identifier.name);
          }
        },
      }, scope);

I'll make some more tests and send a new PR to fix this issue.