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

Feature request: Add option to filter out modules that do or do not pass rules #344

Open
forivall opened this issue Aug 5, 2020 · 2 comments
Labels
enhancement this will make dependency-cruiser sweeter

Comments

@forivall
Copy link
Contributor

forivall commented Aug 5, 2020

Context

I want to show only tsx files that actually require react in my dependency graph visualization.

see #343 for more context

For the given rule

/** @type {import('dependency-cruiser').IRuleSetType} */
module.exports = {
  required: [
    {
      name: 'tsx-must-require-react',
      comment: 'tsx modules must require react, otherwise, they should be .ts',
      severity: 'info',
      module: {
        path: '\\.[tj]sx$',
      },
      to: {
        path: 'node_modules/react/'
      }
    }
  ],

i'd like to only show modules that pass this rule

Expected Behavior

these non-react modules are hidden in the dependency graph

Current Behavior

the modules are shown in the dependency graph

Possible Solution

Update IReporterFiltersType

export interface IReporterFiltersType {
  exclude: IExcludeType;
  includeOnly: IIncludeOnlyFilterType;
  focus: IFocusType;
  pass: string | string[];
  /** this would include only those modules that fail rules */
  fail: string | string[];
}

where, in my example, i would use

  reporterOptions: { 
    dot: {
      filters: {
        pass: 'tsx-must-require-react'
      }
    }
  }

Considered alternatives

Current workaround is to run depcruise --config .dependency-cruiser.js src|grep tsx-must-require-react | cut -d: -f2
and paste that into reporterOptions.dot.filters.exclude. not the worst.

@sverweij
Copy link
Owner

Hi @forivall thanks for this suggestion (and the research), sorry for the slow reaction - I needed some time to reflect on this and see the general applicability and usability - and now see 'show me a graph focussing on all modules (& dependencies) that fail (/ pass) rule x' could be useful especially if the repo is larger.

@stale stale bot added the stale label Aug 22, 2020
@sverweij sverweij removed the stale label Aug 22, 2020
Repository owner deleted a comment from stale bot Aug 22, 2020
@stale
Copy link

stale bot commented Aug 29, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the stale label Aug 29, 2020
@sverweij sverweij added enhancement this will make dependency-cruiser sweeter and removed stale labels Aug 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement this will make dependency-cruiser sweeter
Projects
None yet
Development

No branches or pull requests

2 participants