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

eslint does not work with .jsx #443

Closed
1 of 2 tasks
dcangulo opened this issue Aug 18, 2023 · 0 comments · Fixed by #452
Closed
1 of 2 tasks

eslint does not work with .jsx #443

dcangulo opened this issue Aug 18, 2023 · 0 comments · Fixed by #452
Assignees
Labels
bug Something isn't working

Comments

@dcangulo
Copy link
Contributor

Description

Steps to reproduce:

  1. npx create-react-native-library@latest awesome-library
  2. cd awesome-library
  3. Rename example/src/App.tsx to example/src/App.jsx
  4. Modify example/src/App.jsx.
- const [result, setResult] = React.useState<number | undefined>();
+ const [result, setResult] = React.useState();
  1. Modify package.json
- "lint": "eslint \"**/*.{js,ts,tsx}\"",
+ "lint": "eslint \"**/*.{js,jsx,ts,tsx}\"",
  1. Run yarn lint
MacBook-Pro:awesome-library davidangulo$ yarn lint
yarn run v1.22.19
$ eslint "**/*.{js,jsx,ts,tsx}"

/Users/davidangulo/Desktop/apps/awesome-library/example/src/App.jsx
  14:5  error  Parsing error: Unexpected token <

Expectations:

Should not throw an error.

Why this happens?

As mentioned in #432, this uses an old eslint config which does not have jsx defined so you have to manually add it.
https://github.com/facebook/react-native/blob/v0.71.12/packages/eslint-config-react-native-community/index.js#L37-L68

Where in the latest version jsx is defined.
https://github.com/facebook/react-native/blob/v0.72.0/packages/eslint-config-react-native-community/index.js#L52-L55

Temporary fix:

Add to eslintConfig

"overrides": [
  {
    "files": [
      "*.jsx"
    ],
   "parser": "@babel/eslint-parser"
  }
]

Permanent fix:

Migrate @react-native-community/eslint-config to @react-native/eslint-config.

Packages

  • create-react-native-library
  • react-native-builder-bob

Selected options

--

Link to repro

No response

Environment

--

@dcangulo dcangulo added the bug Something isn't working label Aug 18, 2023
@atlj atlj self-assigned this Aug 25, 2023
satya164 pushed a commit that referenced this issue Sep 1, 2023
### Summary

Fixes #443 
Replaced `@react-native-community/eslint-config` with
`@react-native/eslint-config`. Please see the PR that changes the name
on the React Native repository
[here](facebook/react-native#34581)

### Test plan

1. Create a new React Native library
2. cd into the library you have created.
3. run `yarn lint`
4. Make sure linting works properly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants