mdx-js / eslint-mdx

ESLint Parser/Plugin for MDX
https://npmjs.org/eslint-plugin-mdx
MIT License
264 stars 30 forks source link

`no-unused-expressions` reported on `{' '}` #548

Open karlhorky opened 1 month ago

karlhorky commented 1 month ago

Initial checklist

Affected packages and versions

eslint-plugin-mdx@3.1.5

Link to runnable example

No response

Steps to reproduce

  1. Set up eslint-plugin-mdx@3.1.5 using the recommended config
  2. Lint the following file

index.mdx

Before{' '}after

Observe that a problem is reported on the {' '}:

Screenshot 2024-08-07 at 18 28 31

Expected an assignment or function call and instead saw an expression. eslint no-unused-expressions

Possibly related

Expected behavior

No problem is reported

I'm assuming this should be accepted syntax because the MDX Playground shows that the {' '} will result in a space:

Screenshot 2024-08-07 at 18 28 47

Actual behavior

Problem is reported, as above

Runtime

No response

Package manager

No response

OS

macOS

Build and bundle tools

No response

ChristianMurphy commented 1 month ago

@karlhorky the expression does indeed look like it isn't needed, it could be a space. Is you concern with the word "unused"? Do you see this more as being a different rule, like "no-useless-expression"?

karlhorky commented 1 month ago

My thought here is that this isn't actually invalid syntax - it's a valid style in case a user would want to use it (eg. for our projects, we would like to use a space in JSX expression interpolation to avoid formatting problems with Prettier, rather than taking the route of disabling Prettier)

Stylistically, I can see how this is arguably an interesting rule for some users, but I would suggest that it doesn't absolutely need to be default