0

I would like to make sure that JavaScript files (with js extension) in VS Code contain valid JavaScript syntax only.

Is it possible to disallow JSX syntax for .js files in VS Code?

Ideally of course I would like to still allow the JSX syntax for .jsx files.

5
  • What specifically do you mean by "disallow"? Are you talking about not showing syntax highlighting, which is maybe something you'd configure in the IDE, or actually having warnings/errors, which seems more like a responsibility of your linting or build process? Commented Jul 18, 2018 at 9:47
  • JSX syntax typically found in a render function should produce an error since it is not valid JavaScript. Commented Jul 18, 2018 at 9:51
  • An error from... what? Are you using linting, is that configured correctly? Does your build step reject it? You haven't really clarified what role you want VSCode to play. Commented Jul 18, 2018 at 9:54
  • JSX syntax should be underlined in red like any invalid JavaScript code. I do not have a problem, I just want to be alerted in the editor when a JavaScript file contains invalid JavaScript syntax. Commented Jul 18, 2018 at 9:58
  • @jonrsharpe to be clear I am not talking about execution time, only about hints in the editor. If the system is properly configured for JSX it should execute. But unless I explicitly allow it in a project I would like VS Code to alert me that JSX syntax is not valid JavaScript (in a .js file). Commented Jul 18, 2018 at 10:07

1 Answer 1

1

You can use the react/jsx-filename-extension rule of eslint-plugin-react.

By default it only allows JSX inside *.jsx files so you will have an error/warning (depending on how you configure it) when it detects JSX in a file where it shouldn't be.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.