import-js / import-js/eslint-plugin-import

Help/Suggestion: No Export in a Shebang file

Open
#2,465 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
JavaScript
Stars
5.9k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

I feel like this rule would help a lot of new node users that love making CLI & bin application with it (like me😊).

I found out that exporting a function from a file that has a shebang declaration the top of it (like #! /usr/bin/env node) gives a lot of trouble in execution.

The rule to catch export statement would probably look like that:

create(context) {
      if (context.parserOptions.sourceType !== 'module') { // ignore non-modules
         return {};
      }
      return {
         ExportDefaultDeclaration(node) {
            context.report({
               node,
               message:
                  'Export declaration is not allowed in a shebang file. Try exporting from another file and then import it here.'
            })
         },
      }
   }

But how can I add a condition to test if a shebang line is present in the file?

Thanks

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the proposed create(context) entry point and ExportDefaultDeclaration visitor, then inspect existing rule and test conventions in the repository. Verify how a shebang is represented and how the visitor can distinguish module files; done means the rule reports the proposed export case only for shebang files and has coverage for it.

Written by the indexing model from the issue text.

Assessment

Tech stack
eslint, javascript
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.