Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add external modules setting (pick by package name) #1524

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,24 @@ Contribution of more such shared configs for other platforms are welcome!

An array of folders. Resolved modules only from those folders will be considered as "external". By default - `["node_modules"]`. Makes sense if you have configured your path or webpack to handle your internal paths differently and want to considered modules from some folders, for example `bower_components` or `jspm_modules`, as "external".

#### `import/external-modules`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


An array of modules. Imports from those modules will be considered as "external".
For example with

```yaml
# .eslintrc.yml
settings:
import/external-modules: [ my-module ]
```

these imports will be considered as "external".

```js
import myModule from 'my-module'
import mySubModule from 'my-module/submodule'
```

#### `import/parsers`

A map from parsers to file extension arrays. If a file extension is matched, the
Expand Down
5 changes: 4 additions & 1 deletion src/core/importType.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ export function isBuiltIn(name, settings, path) {
}

function isExternalPath(path, name, settings) {
const modules = (settings && settings['import/external-modules']) || []
const folders = (settings && settings['import/external-module-folders']) || ['node_modules']

// extract the part before the first / (redux-saga/effects => redux-saga)
const packageName = name.match(/([^/]+)/)[0]

return !path || folders.some(folder => -1 < path.indexOf(join(folder, packageName)))
return !path
|| folders.some(folder => -1 < path.indexOf(join(folder, packageName)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for a yoda condition, and "includes" exists:

Suggested change
|| folders.some(folder => -1 < path.indexOf(join(folder, packageName)))
|| folders.some(folder => path.includes(join(folder, packageName)))

|| modules.includes(packageName)
}

const externalModuleRegExp = /^\w/
Expand Down
10 changes: 10 additions & 0 deletions tests/src/core/importType.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,14 @@ describe('importType(name)', function () {
const foldersContext = testContext({ 'import/external-module-folders': ['node_modules'] })
expect(importType('resolve', foldersContext)).to.equal('external')
})

it("should return 'internal' for 'core/importType' if 'core' missed in 'external-modules'", function() {
const foldersContext = testContext({ 'import/external-modules': [] })
expect(importType('core/importType', foldersContext)).to.equal('external')
})

it("should return 'external' for 'core/importType' if 'core' contained in 'external-modules'", function() {
const foldersContext = testContext({ 'import/external-modules': ['core'] })
expect(importType('core/importType', foldersContext)).to.equal('external')
})
})