Skip to content

Commit

Permalink
Set allowRelativePaths directly in files
Browse files Browse the repository at this point in the history
Per member feedback, the allowing of relative paths
was not entirely intentional for rules using the
`ignore` library. This commit also reverts the
utility for creating `ignore` instances.
  • Loading branch information
gfyoung committed Dec 28, 2021
1 parent 4e57bc9 commit 734538c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 33 deletions.
20 changes: 13 additions & 7 deletions lib/rules/no-restricted-imports.js
Expand Up @@ -8,7 +8,7 @@
// Rule Definition
//------------------------------------------------------------------------------

const ignore = require("../shared/ignore");
const ignore = require("ignore");

const arrayOfStringsOrObjects = {
type: "array",
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions lib/rules/no-restricted-modules.js
Expand Up @@ -9,7 +9,7 @@
// Rule Definition
//------------------------------------------------------------------------------

const ignore = require("../shared/ignore");
const ignore = require("ignore");

const arrayOfStrings = {
type: "array",
Expand Down Expand Up @@ -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);


/**
Expand Down
24 changes: 0 additions & 24 deletions lib/shared/ignore.js

This file was deleted.

0 comments on commit 734538c

Please sign in to comment.