Created
April 17, 2018 05:48
-
-
Save svnlto/e653406c939a5aa3c167d8bcbf975536 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const checkCategoryMapping = require('./check_category_mapping'); | |
const categories = (checkName) => [checkCategoryMapping[checkName] || 'Style']; | |
// Here Be Dragons: this function extracts the relevant value that triggered the issue for | |
// checks in the Complexity category. Unfortunately, these values are not available in a | |
// structured way, so we extract them from strings. That means that any check categorized | |
// as Complexity MUST have a rule here to extract value. | |
// | |
// If a matching string segment cannot be found, `null` will be returned. | |
var messageMetricValue = function(message) { | |
var match = null; | |
switch (message.ruleId) { | |
case 'complexity': | |
match = message.message.match(/complexity of (\d+)/); | |
break; | |
case 'max-statements': | |
match = message.message.match(/too many statements \((\d+)\)/); | |
break; | |
} | |
if (null !== match) { | |
return parseInt(match[1], 10); | |
} | |
return null; | |
}; | |
const metricThreshold = (ruleId, eslintConfig) => { | |
return eslintConfig.rules[ruleId][1]; | |
}; | |
var remediationPoints = function(checkName, message, eslintConfig) { | |
if (categories(checkName)[0] === 'Complexity') { | |
// (@base_cost + (overage * @cost_per))*1_000_000 | |
// cost_per: 0.1, base: 1 | |
var costPer = 70000, | |
points = 1000000, | |
threshold = metricThreshold(message.ruleId, eslintConfig), | |
overage, | |
metricValue; | |
metricValue = messageMetricValue(message); | |
if (null !== metricValue) { | |
overage = metricValue - threshold; | |
if (overage > 0) { | |
points += costPer * overage; | |
} | |
} | |
return points; | |
} else { | |
return 50000; | |
} | |
}; | |
module.exports = { | |
categories: categories, | |
remediationPoints: remediationPoints | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment