{"size": 4731, "ext": "js", "max_stars_repo_path": "lib/rules/__tests__/string-is-marked-for-translation.test.js", "max_stars_repo_name": "elastic/eslint-plugin-react-intl", "max_stars_repo_stars_event_min_datetime": "2020-01-02T08:50:23.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-02T08:50:23.000Z", "max_issues_repo_path": "lib/rules/__tests__/string-is-marked-for-translation.test.js", "max_issues_repo_name": "elastic/eslint-plugin-react-intl", "max_issues_repo_issues_event_min_datetime": "2020-03-31T14:07:24.000Z", "max_issues_repo_issues_event_max_datetime": "2020-03-31T14:07:24.000Z", "max_forks_repo_path": "lib/rules/__tests__/string-is-marked-for-translation.test.js", "max_forks_repo_name": "elastic/eslint-plugin-react-intl", "max_forks_repo_forks_event_min_datetime": "2020-11-19T18:22:17.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-19T18:22:17.000Z"}
{"max_stars_count": 1, "max_issues_count": 1, "max_forks_count": 1, "avg_line_length": 28.5, "max_line_length": 107, "alphanum_fraction": 0.4104840414}
/**
 * @fileoverview Catch strings that aren't marked for translation
 * @author Rami Valta
 */

// ------------------------------------------------------------------------------
// Requirements
// ------------------------------------------------------------------------------

const rule = require(`../string-is-marked-for-translation`)
const RuleTester = require(`eslint`).RuleTester

// ------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------

const ruleTester = new RuleTester()
ruleTester.run(`string-is-marked-for-translation`, rule, {
  valid: [
    {
      code: [
        `class Comp1 extends Component {`,
        `  render() {`,
        `    return (`,
        `      <div>`,
        `        <FormattedMessage id='asdjl'`,
        `            description='asdjfl'`,
        `            defaultMessage='asdasdasd'`,
        `        />`,
        `      </div>`,
        `    );`,
        `  }`,
        `}`
      ].join(`\n`),
      parser: `babel-eslint`
    },
    {
      code: [
        `class Comp1 extends Component {`,
        `  render() {`,
        `    return (<div>+()</div>);`, // Non-letter characters should be allowed
        `  }`,
        `}`
      ].join(`\n`),
      parser: `babel-eslint`
    }
  ],

  invalid: [
    {
      code: [
        `class Comp1 extends Component {`,
        `  render() {`,
        `    return (<div>test</div>);`,
        `  }`,
        `}`
      ].join(`\n`),
      parser: `babel-eslint`,
      errors: [{ message: `Found string literal inside JSX, should be inside a <Formatted* /> component` }]
    },
    {
      code: [
        `class Comp1 extends Component {`,
        `  render() {`,
        `    return (<div>æøå</div>);`,
        `  }`,
        `}`
      ].join(`\n`),
      parser: `babel-eslint`,
      errors: [{ message: `Found string literal inside JSX, should be inside a <Formatted* /> component` }]
    },
    {
      code: [
        `class Comp1 extends Component {`,
        `  render() {`,
        `    return (<div>{'test'}</div>);`,
        `  }`,
        `}`
      ].join(`\n`),
      parser: `babel-eslint`,
      errors: [{ message: `Found string literal inside JSX, should be inside a <Formatted* /> component` }]
    },

    {
      code: [
        `class Comp1 extends Component {`,
        `  render() {`,
        `    const foo = (<div>test</div>);`,
        `    return foo;`,
        `  }`,
        `}`
      ].join(`\n`),
      parser: `babel-eslint`,
      errors: [{ message: `Found string literal inside JSX, should be inside a <Formatted* /> component` }]
    }, {
      code: [
        `class Comp1 extends Component {`,
        `  render() {`,
        `    const varObjectTest = { testKey : (<div>test</div>) };`,
        `    return varObjectTest.testKey;`,
        `  }`,
        `}`
      ].join(`\n`),
      parser: `babel-eslint`,
      errors: [{ message: `Found string literal inside JSX, should be inside a <Formatted* /> component` }]
    }, {
      code: [
        `var Hello = React.createClass({`,
        `  foo: (<div>hello</div>),`,
        `  render() {`,
        `    return this.foo;`,
        `  },`,
        `});`
      ].join(`\n`),
      parser: `babel-eslint`,
      errors: [{ message: `Found string literal inside JSX, should be inside a <Formatted* /> component` }]
    }, {
      code: [
        `class Comp1 extends Component {`,
        `  render() {`,
        `    return (`,
        `      <div>`,
        `        asdjfl`,
        `      </div>`,
        `    );`,
        `  }`,
        `}`
      ].join(`\n`),
      parser: `babel-eslint`,
      errors: [{ message: `Found string literal inside JSX, should be inside a <Formatted* /> component` }]
    }, {
      code: [
        `class Comp1 extends Component {`,
        `  render() {`,
        `    return (`,
        `      <div>`,
        `        asdjfl`,
        `        test`,
        `        foo`,
        `      </div>`,
        `    );`,
        `  }`,
        `}`
      ].join(`\n`),
      parser: `babel-eslint`,
      errors: [{ message: `Found string literal inside JSX, should be inside a <Formatted* /> component` }]
    },
    {
      code: [
        `class Comp1 extends Component {`,
        `  render() {`,
        `    return (`,
        `      <div>`,
        `        <FormattedMessage id="erodfasf" defaultMessage="houheirh"/>`,
        `        <h4>FALSELS</h4>`,
        `      </div>`,
        `    );`,
        `  }`,
        `}`
      ].join(`\n`),
      parser: `babel-eslint`,
      errors: [{ message: `Found string literal inside JSX, should be inside a <Formatted* /> component` }]
    }
  ]
})
