Intellicode / eslint-plugin-react-native

React Native plugin for ESLint
MIT License
720 stars 130 forks source link

[react-native/no-raw-tex] crash when have a template literals string #330

Open yepMad opened 1 year ago

yepMad commented 1 year ago

Code:

<View>
  <Text>{`Text text text text`}</Text>
</View>

Error:


Rule: "react-native/no-raw-text"
    at report (C:\Users\eudes\Documents\Git\lumine\node_modules\eslint-plugin-react-native\lib\rules\no-raw-text.js:34:49)
    at TemplateLiteral (C:\Users\eudes\Documents\Git\lumine\node_modules\eslint-plugin-react-native\lib\rules\no-raw-text.js:85:9)
    at ruleErrorHandler (C:\Users\eudes\Documents\Git\lumine\node_modules\eslint\lib\linter\linter.js:1118:28)
    at C:\Users\eudes\Documents\Git\lumine\node_modules\eslint\lib\linter\safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (C:\Users\eudes\Documents\Git\lumine\node_modules\eslint\lib\linter\safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (C:\Users\eudes\Documents\Git\lumine\node_modules\eslint\lib\linter\node-event-generator.js:297:26)
    at NodeEventGenerator.applySelectors (C:\Users\eudes\Documents\Git\lumine\node_modules\eslint\lib\linter\node-event-generator.js:326:22)
    at NodeEventGenerator.enterNode (C:\Users\eudes\Documents\Git\lumine\node_modules\eslint\lib\linter\node-event-generator.js:340:14)
    at CodePathAnalyzer.enterNode (C:\Users\eudes\Documents\Git\lumine\node_modules\eslint\lib\linter\code-path-analysis\code-path-analyzer.js:795:23)```
ejfrancis commented 1 year ago

I see the same error

TypeError: Cannot read properties of undefined (reading 'name')

The error is on this line because node.expressions is an empty array []

 const report = (node) => {
    const errorValue = node.type === 'TemplateLiteral'
      ? `TemplateLiteral: ${node.expressions[0].name}`
      : node.value.trim();