Skip to content

Illegal whitespace not found by no-raw-text #203

@draperunner

Description

@draperunner

We just encountered a problem which we hoped no-raw-text would find, but it does not. The problematic case is when extra whitespace is padded around the curly brackets when referencing from JSX from a variable like so:

render() {
  const someComponent = <View />
  return (<View>   { someComponent }   </View> )

I am not sure what the proper logic would be, because not all whitespace is illegal (newlines, etc.) You can add the following tests to tests/lib/rules/no-raw-text.js to handle this case:

const tests = {
  valid: [
    {
      code: `
        export default class MyComponent extends Component {
          render() {
            return (
              <View>
                <View />
              </View>
            );
          }
        }
      `,
    },
  ],
  invalid: [
    {
      code: `
        export default class MyComponent extends Component {
          render() {
            const someJsx = <View />
            return <View> {someJsx}</View>;
          }
        }
      `,
      errors: [{
        message: 'Raw whitespace cannot be used outside of a <Text> tag',
      }],
    },
  ],
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions