A-Shleifman / eslint-plugin-export-scope

Disallows importing scoped exports outside their scope
https://www.npmjs.com/package/eslint-plugin-export-scope
110 stars 0 forks source link

Using ImportNamespaceSpecifier circumvents this rule #4

Closed smartinio closed 6 months ago

smartinio commented 7 months ago

Hi, thanks for this plugin. Not sure if it's intended but this does not error:

import * as hax from 'some-scoped-module'

While this does:

import { myPrivateThing } from 'some-scoped-module'
A-Shleifman commented 7 months ago

Thanks for bringing this up. It's not intentional but I'm not sure what's the best way to handle it yet. Similar to dynamic imports, the * as hax import statement doesn't give any info about which exports you're planning to access. Maybe the plugin should analyze the rest of the code checking each instance of hax.{importName} and displaying the error there.

smartinio commented 7 months ago

Yeah that could be a good solution

A-Shleifman commented 7 months ago

I'm short on time now. I'll try to find some time for this in 3 weeks.

smartinio commented 7 months ago

An alternative would be to treat import * as hax from 'bar' the same as import 'bar' or import hax from 'bar' since it's effectively importing everything.

My guess is that would also only need something like this to work?

ImportNamespaceSpecifier: (node) => validateNode(node)
A-Shleifman commented 7 months ago

import hax from 'bar' only depends on the default export import 'bar' runs the whole script, so it should depend on file/folder scope. import * as hax from 'bar' can only display an error if there are no importable exports at all. Otherwise, this syntax is valid, so validation should happen later in the code.

checkIsImportable function would need to be updated to create a map of all exports/scopes whenever star syntax is used and to check all hax.{importName} calls.

A-Shleifman commented 6 months ago

@smartinio, try v2.1.0! Please let me know if there are still any issues.