Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no raw text rule fail #266

Closed
tomdyqin opened this issue Aug 21, 2020 · 3 comments · Fixed by #268
Closed

no raw text rule fail #266

tomdyqin opened this issue Aug 21, 2020 · 3 comments · Fixed by #268

Comments

@tomdyqin
Copy link

{
  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

@Intellicode
Copy link
Owner

Did this happen after the latest release?

@alexisbronchart
Copy link

Did this happen after the latest release?

Same issue here. Indeed after upgrading to 3.9.0

@adrianocola
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants