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

Add lint rule against unnamed default exports #8924

Closed
gaearon opened this issue Apr 28, 2020 · 5 comments · Fixed by #8926
Closed

Add lint rule against unnamed default exports #8924

gaearon opened this issue Apr 28, 2020 · 5 comments · Fixed by #8926

Comments

@gaearon
Copy link
Contributor

gaearon commented Apr 28, 2020

We should add https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-anonymous-default-export.md to our rule set. Warning level.

@shakib609
Copy link
Contributor

shakib609 commented Apr 28, 2020

I would like to work on this issue.
Can I be assigned to this if it's is up for grabs?

@gaearon
Copy link
Contributor Author

gaearon commented Apr 28, 2020

Sure.

@overfuse
Copy link

Would it show warnings for default exports with HOC like React.memo(Foo) as well?

@shakib609
Copy link
Contributor

Would it show warnings for default exports with HOC like React.memo(Foo) as well?

No, it's disabled by default.
These are the default settings

{
  "allowArray": false,
  "allowArrowFunction": false,
  "allowAnonymousClass": false,
  "allowAnonymousFunction": false,
  "allowCallExpression": true, // The true value here is for backward compatibility
  "allowLiteral": false,
  "allowObject": false
}

The allowCallExpression is the case you're referring to.

@millermedeiros
Copy link

millermedeiros commented Apr 30, 2020

FYI, I created a jscodeshift codemod script to add names to unnamed default exports: https://astexplorer.net/#/gist/28db7eb6dccb39dd388c030ca75b5de8 — it uses the file name and/or folder name as the function/variable name, and avoids name conflicts... — I used it today to process a few thousand JS files and it worked really well, YMMV tho...

# convert all the files inside the "src" folder
jscodeshift -t ~/Desktop/named-exports-codemod.js src

# open all the files that had name conflicts inside vim
git diff --name-only | xargs grep -l 'FIXME: identifier' | xargs -o vim

# run prettier on all the edited files
git diff --name-only | xargs prettier --write

@lock lock bot locked and limited conversation to collaborators May 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants