forked from sverweij/dependency-cruiser
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds the rule violated to the output object (/ json)
- v11.6.0
- v11.5.0
- v11.4.1
- v11.4.0
- v11.3.1
- v11.3.0
- v11.2.1
- v11.2.0
- v11.1.0
- v11.0.0
- v10.9.0
- v10.8.0
- v10.8.0-beta-3
- v10.8.0-beta-2
- v10.8.0-beta-1
- v10.7.0
- v10.6.0
- v10.5.0
- v10.4.0
- v10.4.0-beta-4
- v10.4.0-beta-3
- v10.4.0-beta-2
- v10.4.0-beta-1
- v10.3.1
- v10.3.1-beta-3
- v10.3.1-beta-2
- v10.3.1-beta-1
- v10.3.0
- v10.3.0-beta-8
- v10.3.0-beta-7
- v10.3.0-beta-6
- v10.3.0-beta-5
- v10.3.0-beta-4
- v10.3.0-beta-3
- v10.3.0-beta-2
- v10.3.0-beta-1
- v10.2.0
- v10.1.1
- v10.1.0
- v10.1.0-beta-2
- v10.1.0-beta-1
- v10.0.8-beta-1
- v10.0.7
- v10.0.6
- v10.0.5
- v10.0.4
- v10.0.3
- v10.0.2
- v10.0.1
- v10.0.0
- v9.26.2-beta-1
- v9.26.1
- v9.26.0
- v9.25.1
- v9.25.0
- v9.24.0
- v9.24.0-beta-2
- v9.24.0-beta-1
- v9.23.3
- v9.23.2
- v9.23.1
- v9.23.1-beta-1
- v9.23.0
- v9.22.1
- v9.22.0
- v9.21.8-beta-1
- v9.21.7
- v9.21.7-beta-1
- v9.21.6
- v9.21.5
- v9.21.4
- v9.21.3
- v9.21.2
- v9.21.2-beta-1
- v9.21.1
- v9.21.1-beta-1
- v9.21.0
- v9.19.1
- v9.19.0
- v9.18.0
- v9.17.1
- v9.17.0
- v9.17.0-beta-1
- v9.16.0
- v9.15.1
- v9.15.0
- v9.14.1
- v9.14.0
- v9.13.2-beta-1
- v9.13.1
- v9.13.0
- v9.13.0-beta-1
- v9.12.0
- v9.12.0-beta-1
- v9.11.1
- v9.11.0
- v9.11.0-beta-2
- v9.11.0-beta-1
- v9.10.1
- v9.10.0
- v9.9.5
- v9.9.4
- v9.9.3
- v9.9.3-beta-3
- v9.9.3-beta-2
- v9.9.3-beta-1
- v9.9.2
- v9.9.1
- v9.9.0
- v9.9.0-beta-4
- v9.9.0-beta-3
- v9.9.0-beta-2
- v9.9.0-beta-1
- v9.8.1
- v9.8.0
- v9.7.0
- v9.6.0
- v9.5.0
- v9.4.0
- v9.4.0-beta-2
- v9.4.0-beta-1
- v9.3.0
- v9.3.0-beta-1
- v9.2.0
- v9.2.0-beta-1-focus
- v9.1.0
- v9.1.0-beta-3
- v9.1.0-beta-2
- v9.1.0-beta-1
- v9.0.1-beta-1
- v9.0.0
- v8.3.0-beta-5
- v8.3.0-beta-4
- v8.3.0-beta-3
- v8.3.0-beta-2
- v8.3.0-beta-1
- v8.2.0
- v8.1.1
- v8.1.0
- v8.1.0-beta-1
- v8.0.2
- v8.0.1
- v8.0.0
- v7.3.0-beta-5
- v7.3.0-beta-4
- v7.3.0-beta-3
- v7.3.0-beta-2
- v7.3.0-beta-1
- v7.2.0
- v7.2.0-beta-1
- v7.1.0
- v7.0.0
- v7.0.0-beta-2
- v7.0.0-beta-1
- v6.3.0
- v6.2.0
- v6.1.0
- v6.1.0-beta-2
- v6.1.0-beta-1
- v6.0.1-beta-1
- v6.0.0
- v5.6.0-beta-0
- v5.5.0
- v5.5.0-beta-3
- v5.5.0-beta-2
- v5.5.0-beta-1
- v5.4.0
- v5.4.0-beta-0
- v5.3.2
- v5.3.1
- v5.3.0
- v5.2.3
- v5.2.2
- v5.2.1
- v5.2.1-beta-1
- v5.2.0
- v5.2.0-beta-1
- v5.2.0-beta-0
- v5.1.3
- v5.1.2
- v5.1.2-beta-1
- v5.1.1
- v5.1.0
- v5.0.1
- v5.0.0
- v5.0.0-beta-2
- v5.0.0-beta-1
- v5.0.0-beta-0
- v4.32.0-beta-1
- v4.27.3
- v4.27.2
- v4.27.2-beta-3
- v4.27.2-beta-2
- v4.27.2-beta-1
- v4.27.1
- v4.27.0
- v4.26.0
- v4.25.0
- v4.24.0
- v4.23.0
- v4.23.0-beta-2
- v4.23.0-beta-1
- v4.22.0
- v4.22.0-beta-4
- v4.22.0-beta-3
- v4.22.0-beta-2
- v4.22.0-beta-1
- v4.21.0
- v4.21.0-beta-3
- v4.21.0-beta-2
- v4.21.0-beta-1
- v4.20.0
- v4.19.1
- v4.19.0
- v4.18.0
- v4.18.0-beta-3
- v4.18.0-beta-2
- v4.18.0-beta-1
- v4.17.0
- v4.17.0-beta-1
- v4.16.1
- v4.16.1-beta-1
- v4.16.0
- v4.16.0-beta-0
- v4.15.4
- v4.15.3
- v4.15.2
- v4.15.1
- v4.15.1-beta-0
- v4.15.0
- v4.15.0-beta-2
- v4.15.0-beta-1
- v4.14.0
- v4.14.0-beta-7
- v4.14.0-beta-6
- v4.14.0-beta-5
- v4.14.0-beta-4
- v4.14.0-beta-3
- v4.14.0-beta-2
- v4.14.0-beta-1
- v4.13.3
- v4.13.3-beta-3
- v4.13.3-beta-2
- v4.13.3-beta-1
- v4.13.2
- v4.13.2-beta-1
- v4.13.1
- v4.13.1-beta-1
- v4.13.1-beta-0
- v4.13.0
- v4.13.0-beta-5
- v4.13.0-beta-4
- v4.13.0-beta-3
- v4.13.0-beta-2
- v4.13.0-beta-1
- v4.12.1
- v4.12.1-beta-0
- v4.12.0
- v4.12.0-beta-3
- v4.12.0-beta-2
- v4.12.0-beta-1
- v4.12.0-beta-0
- v4.11.0
- v4.11.0-beta-2
- v4.11.0-beta-1
- v4.11.0-beta-0
- v4.10.0
- v4.10.0-beta-3
- v4.10.0-beta-2
- v4.10.0-beta-1
- v4.10.0-beta-0
- v4.9.0
- v4.9.0-beta-4
- v4.9.0-beta-3
- v4.9.0-beta-2
- v4.9.0-beta-1
- v4.9.0-beta-0
- v4.8.0
- v4.8.0-beta-4
- v4.8.0-beta-3
- v4.8.0-beta-2
- v4.8.0-beta-1
- v4.8.0-beta-0
- v4.7.1
- v4.7.1-beta-1
- v4.7.1-beta-0
- v4.7.0
- v4.7.0-beta-1
- v4.7.0-beta-0
- v4.6.3
- v4.6.3-beta-2
- v4.6.3-beta-1
- v4.6.2
- v4.6.2-beta-1
- v4.6.1
- v4.6.1-beta-3
- v4.6.1-beta-1
- v4.6.0
- v4.5.2-beta-4
- v4.5.2-beta-3
- v4.5.2-beta-2
- v4.5.2-beta-1
- v4.5.2-beta-0
- v4.5.1
- v4.5.0
- v4.5.0-beta-2
- v4.4.0
- v4.4.0-beta-1
- v4.4.0-beta-0
- v4.3.2
- v4.3.1
- v4.3.1-beta-0
- v4.3.0
- v4.2.0-beta-2
- v4.2.0-beta-1
- v4.2.0-beta-0
- v4.1.1
- v4.1.0
- v4.1.0-beta-5
- v4.1.0-beta-4
- v4.1.0-beta-3
- v4.1.0-beta-2
- v4.1.0-beta-1
- v4.1.0-beta-0
- v4.0.1
- v4.0.0
- v4.0.0-beta-2
- v4.0.0-beta-1
- v4.0.0-beta-0
- v3.1.1
- v3.1.0
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- v3.0.0-beta-6
- v3.0.0-beta-5
- v3.0.0-beta-4
- v3.0.0-beta-3
- v3.0.0-beta-0
- v2.14.0
- v2.14.0-beta-1
- v2.14.0-beta-0
- v2.13.1
- v2.13.0
- v2.13.0-beta-1
- v2.12.1
- v2.12.0
- v2.12.0-beta-2
- v2.12.0-beta-1
- v2.11.1
- v2.11.0
- v2.11.0-beta-1
- v2.10.1
- v2.10.0
- v2.9.0
- v2.8.0
- v2.7.2
- v2.7.1
- v2.7.0
- v2.6.0
- v2.5.0
- v2.4.2
- v2.4.1
- v2.4.0
- v2.3.2
- v2.3.1
- v2.3.0
- v2.2.3
- v2.2.2
- v2.2.1
- v2.2.0
- v2.1.1
- v2.1.0
- v2.0.2
- v2.0.1
- v2.0.0
- v1.15.7
- v1.15.5
- v1.15.4
- v1.15.3
- v1.15.2
- v1.15.1
- v1.15.0
- v1.14.1
- v1.14.0
- v1.13.0
- v1.12.0
- v1.11.0
- v1.10.1
- v1.10.0
- v1.9.3
- v1.9.2
- v1.9.1
- v1.9.0
- v1.8.0
- v1.7.3
- v1.7.2
- v1.7.1
- v1.7.0
- v1.6.3
- v1.6.2
- v1.6.1
- v1.6.0
- v1.5.4
- v1.5.3
- v1.5.2
- v1.5.1
- v1.5.0
- v1.4.0
- v1.3.0
- v1.2.3
- v1.2.2
- v1.2.1
Showing
10 changed files
with
252 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"use strict"; | ||
|
||
const VALID_LEVELS = /^(error|warning|information)$/; | ||
const DEFAULT_LEVEL = 'warning'; | ||
const DEFAULT_RULE = 'unnamed'; | ||
|
||
function normalizeLevel (pLevel){ | ||
let lLevel = pLevel ? pLevel : DEFAULT_LEVEL; | ||
|
||
return Boolean(lLevel.match(VALID_LEVELS)) ? lLevel : DEFAULT_LEVEL; | ||
} | ||
|
||
function normalizeName(pRule) { | ||
return pRule ? pRule : DEFAULT_RULE; | ||
} | ||
|
||
function normalizeRule(pRule) { | ||
return Object.assign( | ||
pRule, | ||
{ | ||
level : normalizeLevel(pRule.level), | ||
name : normalizeName(pRule.name) | ||
} | ||
); | ||
} | ||
|
||
function normalize(pRuleSet) { | ||
if (pRuleSet.hasOwnProperty("allowed")){ | ||
pRuleSet.allowed = pRuleSet.allowed.map(normalizeRule); | ||
} | ||
|
||
if (pRuleSet.hasOwnProperty("forbidden")){ | ||
pRuleSet.forbidden = pRuleSet.forbidden.map(normalizeRule); | ||
} | ||
|
||
return pRuleSet; | ||
} | ||
|
||
exports.normalize = normalize; |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"use strict"; | ||
|
||
const safeRegex = require('safe-regex'); | ||
|
||
function checkRuleSafety(pRule) { | ||
if ( | ||
!( | ||
safeRegex(pRule.from) && | ||
safeRegex(pRule.to) | ||
) | ||
){ | ||
throw new Error( | ||
`rule ${JSON.stringify(pRule, null, "")} has an unsafe regular expression. Bailing out.\n` | ||
); | ||
} | ||
} | ||
|
||
function validate(pRuleSet) { | ||
if (pRuleSet.hasOwnProperty("allowed")){ | ||
pRuleSet.allowed.forEach(checkRuleSafety); | ||
} | ||
if (pRuleSet.hasOwnProperty("forbidden")){ | ||
pRuleSet.forbidden.forEach(checkRuleSafety); | ||
} | ||
} | ||
|
||
exports.validate = validate; |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"allowed":[{ | ||
"from": "only-this-one", | ||
"to": "only-that-one" | ||
}] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
"use strict"; | ||
const expect = require('chai').expect; | ||
const normalizer = require('../src/validate/ruleSetNormalizer'); | ||
|
||
describe("validator", () => { | ||
it("leaves the empty ruleset alone", () => { | ||
expect(normalizer.normalize({})).to.deep.equal({}); | ||
}); | ||
|
||
it("adds defaults for level and warning when they're not filled", () => { | ||
expect(normalizer.normalize({ | ||
"allowed": [{ | ||
"from": ".+", | ||
"to": ".+" | ||
}] | ||
})).to.deep.equal({ | ||
"allowed": [{ | ||
"from": ".+", | ||
"to": ".+", | ||
"level": "warning", | ||
"name": "unnamed" | ||
}] | ||
}); | ||
}); | ||
|
||
it("corrects the level to a default when it's not a recognized one", () => { | ||
expect(normalizer.normalize({ | ||
"allowed": [{ | ||
"from": ".+", | ||
"to": ".+", | ||
"level": "unrecognized", | ||
"name": "all-ok" | ||
}] | ||
})).to.deep.equal({ | ||
"allowed": [{ | ||
"from": ".+", | ||
"to": ".+", | ||
"level": "warning", | ||
"name": "all-ok" | ||
}] | ||
}); | ||
}); | ||
|
||
it("keeps the level if it's a recognized one", () => { | ||
expect(normalizer.normalize({ | ||
"allowed": [{ | ||
"from": ".+", | ||
"to": ".+", | ||
"level": "error", | ||
"name": "all-ok" | ||
}] | ||
})).to.deep.equal({ | ||
"allowed": [{ | ||
"from": ".+", | ||
"to": ".+", | ||
"level": "error", | ||
"name": "all-ok" | ||
}] | ||
}); | ||
}); | ||
|
||
it("also works for 'forbidden' rules", () => { | ||
expect(normalizer.normalize({ | ||
"forbidden": [{ | ||
"from": ".+", | ||
"to": ".+", | ||
"level": "error", | ||
"name": "all-ok", | ||
"comment": "this comment is kept" | ||
}] | ||
})).to.deep.equal({ | ||
"forbidden": [{ | ||
"from": ".+", | ||
"to": ".+", | ||
"level": "error", | ||
"name": "all-ok", | ||
"comment": "this comment is kept" | ||
}] | ||
}); | ||
}); | ||
}); |
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