digitalbazaar / eslint-config-digitalbazaar

BSD 3-Clause "New" or "Revised" License
2 stars 1 forks source link

Use eslint plugin import #62

Closed aljones15 closed 1 year ago

aljones15 commented 2 years ago

These are the gains from using this plugin:

  rules: {
    // if the file path for an import can't be resolved locally error
    // FIXME: use of webpack aliases might cause issues with this
    'import/no-unresolved': 'error',
    // Verifies that all named imports are part of the set of named
    // exports in the imported module.
    'import/named': 'error',
    // If a default import is requested, this rule will report if
    // there is no default export in the imported module.
    'import/default': 'error',
    // throws if a namespace like `import * as all` is used and
    // `all.foo` is not exported
    'import/namespace': 'error',
    // throws if a module imports itself
    'import/no-self-import': 'error',
    // Reports funny business with exports, like repeated exports
    // of names or defaults.
    'import/export': 'error',
    // warns if an imported member if marked @deprecated
    'import/no-deprecated': 'error',
    // warns if a dep is not in the package.json
    'import/no-extraneous-dependencies': 'error',
    // disallows exporting members with let & var
    // FIXME: there could be edge cases where we do
    // need mutable exports
    'import/no-mutable-exports': 'error',
    // throw if you import something more than once in a file/module
    'import/no-duplicates': 'error'
  }

Notes:

  1. I have observed this rule working not as intended: import/no-extraneous-dependencies (it seems to be a bit flaky)
  2. We might want to move the sort-order to the modules rules
  3. We might want to move these rules to the modules rules & update the README.

Note: this plugin speeds up refactoring to use es6 import/export statements. It primarily does this, but telling you when you refactor a require to an import if the members you're importing are still there or if there is a default export etc.

aljones15 commented 1 year ago

Closing this PR as it easier and cleaner to just open another one based off of main here: https://github.com/digitalbazaar/eslint-config-digitalbazaar/pull/66