-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds skipAnalysisNotInRules option (#979)
## Description - adds a `skipAnalysisNotInRules` option that, when switched to `true` skips all analyses not necessary for checking the current rule set. - Defaults the option to `false` for backwards compatibility of both cli and api. - Add this option with the value `true` to the --init template that scaffolds initial .dependency-cruiser.js configurations - Takes the new option into account in the cache-dirty check - Adds a paragraph in the options reference TODO: - [x] implement for cycle analysis - [x] implement for dependents analysis - [x] implement for orphan check For the _focus_, _metrics_ and _reachables_ analyses this was already in place by default ## Motivation and Context Addresses #978 ## How Has This Been Tested? - [x] green ci - [x] additional and updated automated non-regression tests ## Types of changes - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] Documentation only change - [ ] Refactor (non-breaking change which fixes an issue without changing functionality) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change)
- Loading branch information
Showing
60 changed files
with
639 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,41 @@ | ||
import getDependents from "./get-dependents.mjs"; | ||
|
||
export default function addDependents(pModules) { | ||
return pModules.map((pModule) => ({ | ||
...pModule, | ||
dependents: getDependents(pModule, pModules), | ||
})); | ||
/** @import { IFlattenedRuleSet } from "../../../../types/rule-set.mjs" */ | ||
|
||
function isDependentsRule(pRule) { | ||
// used in folder rules and when moreUnstable is in the 'to' => governed by | ||
// the 'metrics' flag in options, sot not going to repeat that here | ||
|
||
// dependents are used in the orphans analsys. hHwever, there is a fall back | ||
// where it does its own analysis, so not going to repeat that check here. | ||
return ( | ||
/* c8 ignore start */ | ||
Object.hasOwn(pRule?.module ?? {}, "numberOfDependentsLessThan") || | ||
Object.hasOwn(pRule?.module ?? {}, "numberOfDependentsMoreThan") | ||
/* c8 ignore stop */ | ||
); | ||
} | ||
|
||
/** | ||
* @param {IFlattenedRuleSet} pRuleSet | ||
* @returns {boolean} | ||
*/ | ||
export function hasDependentsRule(pRuleSet) { | ||
return ( | ||
(pRuleSet?.forbidden ?? []).some(isDependentsRule) || | ||
(pRuleSet?.allowed ?? []).some(isDependentsRule) | ||
); | ||
} | ||
|
||
export default function addDependents( | ||
pModules, | ||
{ skipAnalysisNotInRules, metrics, ruleSet }, | ||
) { | ||
if (!skipAnalysisNotInRules || metrics || hasDependentsRule(ruleSet)) { | ||
return pModules.map((pModule) => ({ | ||
...pModule, | ||
dependents: getDependents(pModule, pModules), | ||
})); | ||
} | ||
return pModules; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,34 @@ | ||
import isOrphan from "./is-orphan.mjs"; | ||
|
||
export default function deriveOrphans(pModules) { | ||
return pModules.map((pModule) => ({ | ||
...pModule, | ||
orphan: isOrphan(pModule, pModules), | ||
})); | ||
/** @import { IFlattenedRuleSet } from "../../../../types/rule-set.mjs" */ | ||
|
||
function isOrphanRule(pRule) { | ||
return ( | ||
/* c8 ignore start */ | ||
Object.hasOwn(pRule?.from ?? {}, "orphan") | ||
/* c8 ignore stop */ | ||
); | ||
} | ||
/** | ||
* @param {IFlattenedRuleSet} pRuleSet | ||
* @returns {boolean} | ||
*/ | ||
export function hasOrphanRule(pRuleSet) { | ||
return ( | ||
(pRuleSet?.forbidden ?? []).some(isOrphanRule) || | ||
(pRuleSet?.allowed ?? []).some(isOrphanRule) | ||
); | ||
} | ||
|
||
export default function deriveOrphans( | ||
pModules, | ||
{ skipAnalysisNotInRules, ruleSet }, | ||
) { | ||
if (!skipAnalysisNotInRules || hasOrphanRule(ruleSet)) { | ||
return pModules.map((pModule) => ({ | ||
...pModule, | ||
orphan: isOrphan(pModule, pModules), | ||
})); | ||
} | ||
return pModules; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.