gtap-dev / javascript

JavaScript Style Guide
MIT License
0 stars 0 forks source link

Inverted 10.6 (prefer-default-export -> no-default-export) #5

Closed mjomble closed 2 months ago

mihkeleidast commented 3 years ago

An issue here is our usage of Fractal in our React projects, where Fractal's React adapter looks for a default export in a component template file in order to know what to render. Not sure if there are better solutions than just overriding this rule for React, but maybe you have some ideas?

mjomble commented 3 years ago

Maybe something like this:

export const Button = ...

// For Fractal
export default Button

Although the rule mainly talks about exports, the benefit of consistency mostly comes out in the import code blocks.

mihkeleidast commented 3 years ago

Yup, totally agree. Additionally, exporting everything as named makes it easier to re-export things in an index file (when building a library) - you can do export * from './my/module'; instead of having to re-export the default export separately.

The issue is that if we want to enforce this with an ESLint rule, we need to either disable it for React projects or disable it line-by-line where necessary, neither of which is too nice.

mjomble commented 3 years ago

Maybe for React projects we could disable the rule only in src/patterns, but still use it in src/app and elsewhere.