Skip to content

Commit

Permalink
feature: added custom glob groups
Browse files Browse the repository at this point in the history
  • Loading branch information
ykanavalik committed Jun 3, 2020
1 parent 03e4ed4 commit d85e5de
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
19 changes: 17 additions & 2 deletions src/core/importType.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import minimatch from 'minimatch'

import coreModules from 'resolve/lib/core'

import resolve from 'eslint-module-utils/resolve'
Expand Down Expand Up @@ -80,7 +82,18 @@ function isRelativeToSibling(name) {
return /^\.[\\/]/.test(name)
}

function typeTest(name, settings, path) {
function findMatchGlobGroup(name, groups) {
for (let globPatter of groups) {
if (minimatch(name, globPatter)) {
return globPatter
}
}
}

function typeTest(name, settings, groups, path) {
const matchedGlob = findMatchGlobGroup(name, groups)

if (matchedGlob) { return matchedGlob }
if (isAbsolute(name, settings, path)) { return 'absolute' }
if (isBuiltIn(name, settings, path)) { return 'builtin' }
if (isInternalModule(name, settings, path)) { return 'internal' }
Expand All @@ -97,5 +110,7 @@ export function isScopedModule(name) {
}

export default function resolveImportType(name, context) {
return typeTest(name, context.settings, resolve(name, context))
const groups = (context.options[0] || {}).groups

return typeTest(name, context.settings, groups, resolve(name, context))
}
4 changes: 0 additions & 4 deletions src/rules/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,6 @@ function convertGroupsToRanks(groups) {
group = [group]
}
group.forEach(function(groupItem) {
if (types.indexOf(groupItem) === -1) {
throw new Error('Incorrect configuration of the rule: Unknown type `' +
JSON.stringify(groupItem) + '`')
}
if (res[groupItem] !== undefined) {
throw new Error('Incorrect configuration of the rule: `' + groupItem + '` is duplicated')
}
Expand Down

0 comments on commit d85e5de

Please sign in to comment.