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/make severity for allowed rules configurable #39

Merged

Conversation

sverweij
Copy link
Owner

@sverweij sverweij commented Feb 25, 2018

Description

Adds an allowedSeverity attribute to the rule set format to so you can set the severity of the allowed rule (which was hitherto fixed to "warn")

Example dependency-cruiser.json (adapted from fimbullinter/wotan/.dependency-cruiser.json):

{
  "allowedSeverity": "error",
  "allowed": [
    {
      "from": {
        "path": "^packages/[^/]+/(src/|bin/|index.[jt]s$)"
      },
      "to": {
        "dependencyTypes": ["local", "npm", "npm-optional", "npm-peer", "core"]
      }
    },
    {
      "from": {
        "path": "^(packages/[^/]+/test|scripts)/"
      },
      "to": {
        "dependencyTypes": ["local", "npm", "npm-optional", "npm-dev", "core"]
      }
    },
    {
      "from": {
        "path": "^packages/[^/]+/test/"
      },
      "to": {
        "path": "^(node_modules/(typescript|ava|tslint)|packages)/"
      }
    }
  ],
  "options": {
    "doNotFollow": "(^|/)node_modules/",
    "moduleSystems": ["cjs", "es6"]
  }
}

Motivation and Context

fixes #34

There's a few options configuring the severity of 'allowed' rules could've gone:

  • in the options section
    Not the best one; it's actually a property of a rule (/ group of rules) and not a general rule.
  • in the allowed section
    Semantically correct and I'm still tempted to do this, but it's backward incompatible - every ruleset with an allowed section should be transformed from this
"allowed": [
    {"from": {"path": "something"}, "to": {"path": "somethingElse"}},
    {"from": {"path": "somethingElse},"to": {"dependencyTypes": ["local", "npm", "core"]}}
]

to this:

"allowed": {
    "severity": "error",
    "rules": [
        {"from": {"path": "something"}, "to": {"path": "somethingElse"}},
        {"from": {"path": "somethingElse}, "to": {"dependencyTypes": ["local", "npm", "core"]}}
    ]
}

(which could be (semi) automated with a utility b.t.w.)

  • in the rules part add a allowedSeverity attribute
    Not as clean, but less of a pain to migrate to.

How Has This Been Tested?

Types of changes

  • New feature (non-breaking change which adds functionality)
  • 
    

Checklist:

  • The code I add will be subject to The MIT license, and I'm OK with that.
  • The code I've added is my own original work.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Copy link
Contributor

@ajafff ajafff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tried it and it works as expected.

satisfy at least one of them.
will emit a 'not-in-allowed' message for each dependency that does not
satisfy at least one of them. The severity of the message is _warning_ by
default, but you can override it with `
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something is missing at the end of this line

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch!

@sverweij sverweij merged commit 5b0ff20 into develop Feb 26, 2018
@sverweij sverweij deleted the feature/make-severity-for-allowed-rules-configurable branch February 26, 2018 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Option to treat warnings as errors
2 participants