diff --git a/lib/rules/no-restricted-imports.js b/lib/rules/no-restricted-imports.js index 2a142d61aff1..f4f3d219a1b0 100644 --- a/lib/rules/no-restricted-imports.js +++ b/lib/rules/no-restricted-imports.js @@ -8,7 +8,7 @@ // Rule Definition //------------------------------------------------------------------------------ -const ignore = require("../shared/ignore"); +const ignore = require("ignore"); const arrayOfStringsOrObjects = { type: "array", @@ -145,12 +145,18 @@ module.exports = { }, {}); // Handle patterns too, either as strings or groups - const restrictedPatterns = (isPathAndPatternsObject ? options[0].patterns : []) || []; - const restrictedPatternGroups = restrictedPatterns.length > 0 && typeof restrictedPatterns[0] === "string" - ? [{ matcher: ignore().add(restrictedPatterns) }] - : restrictedPatterns.map(({ group, message, caseSensitive }) => ({ - matcher: ignore({ ignorecase: !caseSensitive }).add(group), customMessage: message - })); + let restrictedPatterns = (isPathAndPatternsObject ? options[0].patterns : []) || []; + + // standardize to array of objects if we have an array of strings + if (restrictedPatterns.length > 0 && typeof restrictedPatterns[0] === "string") { + restrictedPatterns = [{ group: restrictedPatterns }]; + } + + // relative paths are supported for this rule + const restrictedPatternGroups = restrictedPatterns.map(({ group, message, caseSensitive }) => ({ + matcher: ignore({ allowRelativePaths: true, ignorecase: !caseSensitive }).add(group), + customMessage: message + })); // if no imports are restricted we don't need to check if (Object.keys(restrictedPaths).length === 0 && restrictedPatternGroups.length === 0) { diff --git a/lib/rules/no-restricted-modules.js b/lib/rules/no-restricted-modules.js index 3cc192cc3161..d92aa7a86bcf 100644 --- a/lib/rules/no-restricted-modules.js +++ b/lib/rules/no-restricted-modules.js @@ -9,7 +9,7 @@ // Rule Definition //------------------------------------------------------------------------------ -const ignore = require("../shared/ignore"); +const ignore = require("ignore"); const arrayOfStrings = { type: "array", @@ -103,7 +103,8 @@ module.exports = { return {}; } - const ig = ignore().add(restrictedPatterns); + // relative paths are supported for this rule + const ig = ignore({ allowRelativePaths: true }).add(restrictedPatterns); /** diff --git a/lib/shared/ignore.js b/lib/shared/ignore.js deleted file mode 100644 index ae446fb53cb6..000000000000 --- a/lib/shared/ignore.js +++ /dev/null @@ -1,24 +0,0 @@ -/** - * @fileoverview Create instance of Ignore validator. - * @author gfyoung - */ -"use strict"; - -//------------------------------------------------------------------------------ -// Requirements -//------------------------------------------------------------------------------ - -const ignoreFactory = require("ignore"); - -//------------------------------------------------------------------------------ -// Public Interface -//------------------------------------------------------------------------------ - -module.exports = (additionalOptions = {}) => { - const ignore = ignoreFactory({ - allowRelativePaths: true, - ...additionalOptions - }); - - return ignore; -};