ArnaudBarre / eslint-plugin-react-refresh

Validate that your components can safely be updated with Fast Refresh
MIT License
206 stars 13 forks source link

Consider all-uppercase exports as components #11

Closed silverwind closed 1 year ago

silverwind commented 1 year ago

Why not consider uppercase exports as components? I for example have one like this:

export function SVG() {
  return <svg/>;
}

It's mostly stylistic, but a Svg looks suboptimal to me.

Another idea may be that such a component could just be automatically detected as one because it returns JSX content, e.g. don't purely rely on export name, but actually analyze the return value of the function.

ArnaudBarre commented 1 year ago

Yeah when I wrote it the first time I knew this could be improve by looking at what is the value type. I though I would need type info from eslint-typescript but actually I think allowing any function and disabling the rest should be ok. I will change this :)

silverwind commented 1 year ago

Return value analyzation would be awesome, yes.

silverwind commented 1 year ago

The rule is still giving me trouble when the component is wrapped:

These work:

export function SVG() {
  return <svg/>;
}
export const SVG = () => {
  return <svg/>;
};

These all fail:

export const SVG = forwardRef(() => {
  return <svg/>;
});
export const SVG = memo(forwardRef(() => {
  return <svg/>;
}));
export const SVG = memo(forwardRef(function SVG() {
  return <svg/>;
}));
ArnaudBarre commented 1 year ago

Added in 0.4.1

(I've decided to not use type analysis because this could block a lot of people (not the default with TS-ESLint), so I need to add cases one by one)