Skip to content

[Question][RSPEC-2208] Is Wildcard imports should not be used in js supposed to be marked as 'critical'? #16

Description

@wootra

this issue is about this rule page: https://rules.sonarsource.com/javascript/RSPEC-2208/
image

while I agree that this should not be used for everytime, I still think this is not a critical but up to developer's decision.

for example, if I have 2 files which hold a lot of same functions, and I have to import them at the same time, using wildcard is pretty clear to differentiate those functions instead of importing them with bunch of aliases.

// mobile.js
export const clickButton(){...}
export const selectTab(){...}
export const getImageList(){...}
// desktop.js
export const clickButton(){...}
export const selectTab(){...}
export const getImageList(){...}

// app.js
import * as mobile from './mobile'
import * as desktop from './desktop'
const clickButton(){
  if(screen === 'mobile') mobile.clickButton();
  else if(screen === 'desktop') desktop.clickButton();
}
...

but If we don't use wildcard, we might need to do something like this:

import {
  clickButton as mobileClickButton,
  selectTab as mobileSelectTab,
  getImageList as mobileGetImageList
}
...

I don't think above code is cleaner than the first code.
In my opinion, this should be marked a minor rather than critical or should be removed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions