thepassle / eslint-plugin-barrel-files

MIT License
118 stars 10 forks source link

Potential false positive when exporting default function #5

Closed rowellx68 closed 7 months ago

rowellx68 commented 7 months ago

Plugin version: 1.0.3 System: macOS


Setting the barrel-files/avoid-barrel-files rule with the following options seems to be treating files with default exported functions as barrel files. We've got a workaround without disabling the rule for the file or increasing the amountOfExportsToConsiderModuleAsBarrel.

Config:

'barrel-files/avoid-barrel-files': [
  'error',
  { amountOfExportsToConsiderModuleAsBarrel: 0 }
],

Examples:

// LazyLoadThisPage.tsx
export default function LazyLoadThisPage() {
  return (
    <></>
  );
}
// add.ts
export default function add(a: number, b: number): number {
  return a + b;
}
// some-config.ts
export default defineConfig({});

Workaround:

// LazyLoadThisPage.tsx
function LazyLoadThisPage() {
  return (
    <></>
  );
}

export default LazyLoadThisPage;
// add.ts
function add(a: number, b: number): number {
  return a + b;
}

export default add;
// some-config.ts
const config = defineConfig({});

export default config;
thepassle commented 7 months ago

Not sure I understand, if you set amountOfExportsToConsiderModuleAsBarrel to 0, that means it'll pretty much consider everything to be a barrel file, because youve set the barrier to 0. Is there a reason you're setting it to 0?

rowellx68 commented 7 months ago

Our intention is to completely get rid of/lint for barrel files so we set amountOfExportsToConsiderModuleAsBarrel to 0. If we were to set it to 1 we would still be able to create them like so:

// LazyLoadThisPage/index.ts
export { LazyLoadThisPage } from './LazyLoadThisPage';

More than happy to do the changes and PR if you think this is a valid use case.

thepassle commented 7 months ago

sure, happy to take a PR