Search code examples
eslinttypescript-eslint

ESLint disable default export


So far I've been unable to figure out a ready to use solution for throwing an error if something does a default export.

We internally have the standard to only do named exports, but I'd like the linter to ensure it doesn't happen.

Is there a way to accomplish this short of writing a custom rule?

EDIT: I'm assuming, but could very easily be wrong, that I could use the no-restricted-syntax rule like I was pointed to here. I just didn't want to reach for that if there was a better solution.


Solution

  • It would be best to use eslint-plugin-import to enforce import and export rules. It has a lovely rule to prevent default exports import/no-default-export.

    npm install --save-dev eslint-plugin-import
    

    .eslintrc

    {
      "plugins": [
        "import"
      ],
      "rules": {
        "import/no-default-export": "error"
      }
    }