Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule proposal: no-export-named-after-filename #1478

Open
edbrannin opened this issue Sep 17, 2019 · 4 comments
Open

Rule proposal: no-export-named-after-filename #1478

edbrannin opened this issue Sep 17, 2019 · 4 comments

Comments

@edbrannin
Copy link

Similar ideas have been floated in #1041 and #325, but this is a bit different:

If you have a Default export, don't also have a Named export that's named the same as the file.

This is to flag a possible root cause of import/no-named-as-default.

Bad:

// Foo.jsx
import React from 'react'
import myHOC from './my-hoc'

const Foo = () => <p>Foo</p>

export default myHOC(Foo)
export { Foo } // For testing

Good:

// Foo.jsx
import React from 'react'
import myHOC from './my-hoc'

const FooComponent = () => <p>Foo</p>

export default myHOC(Foo)
export { FooComponent } // For testing

Also good:

// FooComponent.jsx
import React from 'react'

const FooComponent = () => <p>Foo</p>

export default FooComponent // OR export { FooComponent }
// Foo.jsx
import React from 'react'
import FooComponent from './FooComponent'
import myHOC from './my-hoc'

export default myHOC(Foo)

Thoughts?

@ljharb
Copy link
Member

ljharb commented Sep 17, 2019

Perhaps #1476 should also include an option that controls checking imports, exports, or both, and this issue’s suggestion could be the “exports” part? cc @golopot

@golopot
Copy link
Contributor

golopot commented Sep 17, 2019

Another similar rule proposal is export-default-match-filename, mentioned here,
which reports cases like:

// foo.js
export default function bar() {}
//                      ~~~  should match filename "foo.js"

I am not sure whether they should be separate rules, or all rolled into one.

@ljharb
Copy link
Member

ljharb commented Sep 17, 2019

Having it rolled into one means the matching logic can be more centralized, both conceptually and technically.

@golopot
Copy link
Contributor

golopot commented Oct 1, 2019

I find it hard to name rule name and options when these are rolled into one. An attempt:

{
  "default-name-match-filename": [2, {
    importDefaultName: true | {ignorePaths: string[]},
    exportDefaultName: true,
    noExportNameAfterFilename: true,
  }]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants