Created
February 3, 2018 06:02
-
-
Save dicko2/f41f3a4c7bf8787510f68a97d2b2f2ab to your computer and use it in GitHub Desktop.
Importing TypeScript tslint Rules into Sonarqube
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
$YourRepoRoot ="C:\DATA\Repos" # replace with your repoistory root on you computer | |
$targetPath ="$YourRepoRoot\tslint-react\src\rules" | |
$hardcodedRuleLink="https://github.com/palantir/tslint-react/blob/master/README.md" | |
$StartMetaBlock = "metadata: Lint.IRuleMetadata" | |
$MetaDatQuoteTypes ='"'; | |
function ExtractMetaDataBlock() | |
{ | |
Param( | |
[string]$block | |
) | |
$start = $block.IndexOf($StartMetaBlock) | |
if($start -eq -1) | |
{ | |
return; | |
} | |
$blockResult1 = $block.SubString($start, $block.Length-$start) | |
$end = $blockResult1.IndexOf("commonWeaknessEnumeration") | |
if($end -eq -1) | |
{ | |
$end = $blockResult1.IndexOf("}") | |
} | |
$blockResult2=$blockResult1.Substring(0,$end) | |
$bracketStart = $blockResult2.IndexOf("{") | |
$blockResult3 = $blockResult2.Substring($bracketStart+1,$blockResult2.Length-$bracketStart-1) | |
return $blockResult3 | |
} | |
function GetDataObjectFromBlock | |
{ | |
Param( | |
[string]$BlockText | |
) | |
$rule = New-Object System.Object | |
foreach( $line in $BlockText.Split(",")) | |
{ | |
if($line.Contains(":")) | |
{ | |
$Key = $line.Split(":")[0].Trim() | |
$Value = $line.Split(":")[1].Trim().Trim($MetaDatQuoteTypes) | |
if ($Key.Contains("/*")) | |
{ | |
return; | |
} | |
# Write-Host "Key $key Value $Value" | |
$rule | Add-Member -type NoteProperty -name $Key -Value $Value | |
} | |
} | |
return $rule | |
} | |
$ListOfRules = New-Object System.Collections.ArrayList | |
$files = Get-ChildItem $targetPath -File -Filter "*Rule.ts" | |
foreach ( $file in $files ) | |
{ | |
$file.FullName | |
$fileData = [System.IO.File]::ReadAllLines($file.FullName) | |
$rawData = ExtractMetaDataBlock -block $fileData | |
$Rule = GetDataObjectFromBlock -BlockText $rawData | |
$i =$ListOfRules.Add($Rule) | |
} | |
foreach ($newRule in $ListOfRules) | |
{ | |
$ruleName = $newRule.ruleName | |
$hardcodedLink ="Please see the readme and search for $ruleName on $hardcodedRuleLink" | |
Write-Host "$($newRule.ruleName)=true | |
$($newRule.ruleName).name=$($newRule.description) | |
$($newRule.ruleName).severity=$newSeverity | |
$($newRule.ruleName).description=$($newRule.description) $hardcodedLink | |
$($newRule.ruleName).debtFunc=LINEAR_OFFSET | |
$($newRule.ruleName).debtScalar=15min | |
$($newRule.ruleName).debtOffset=1h | |
$($newRule.ruleName).debtType=USABILITY_EASE_OF_USE | |
" | |
} |
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
$YourRepoRoot ="C:\DATA\Repos\" # replace with your repoistory root on you computer | |
$targetPath ="$YourRepoRoot\tslint-consistent-codestyle\docs" | |
$hardcodedRuleLink="https://github.com/ajafff/tslint-consistent-codestyle/blob/master/docs/naming-convention.md " | |
$files = Get-ChildItem $targetPath -File | |
foreach ( $file in $files ) | |
{ | |
$ruleName = $file.Name.Replace(".md","") | |
$ruleHumanName = $ruleName.Replace("-", " ") | |
Write-Host "$ruleName=true | |
$ruleName.name=$ruleHumanName | |
$ruleName.severity=$newSeverity | |
$ruleName.description= See this link for details https://github.com/ajafff/tslint-consistent-codestyle/blob/master/docs/naming-convention.md | |
$ruleName.debtFunc=LINEAR_OFFSET | |
$ruleName.debtScalar=15min | |
$ruleName.debtOffset=1h | |
$ruleName.debtType=USABILITY_EASE_OF_USE | |
" | |
} |
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
$YourRepoRoot ="C:\DATA\Repos" # replace with your repoistory root on you computer | |
$targetPath ="$YourRepoRoot\tslint-eslint-rules\src\docs\rules" | |
$hardcodedRuleLink="https://github.com/palantir/tslint-react/blob/master/README.md" | |
$files = Get-ChildItem $targetPath -File | |
function ExtractMetaDataBlock() | |
{ | |
Param( | |
[string]$block | |
) | |
$start = $block.IndexOf("##") | |
$blockResult1 = $block.SubString($start+3, $block.Length-$start-3) | |
$end = $blockResult1.IndexOf(" ") | |
$blockResult2=$block.Substring($start+3,$end) | |
return $blockResult2 | |
} | |
foreach ( $file in $files ) | |
{ | |
$raw = [System.IO.File]::ReadAllLines($file.FullName); | |
$ruleName = ExtractMetaDataBlock -block $raw | |
$FileName=$file.Name | |
$ruleHumanName = $ruleName.Replace("-", " ") | |
Write-Host "$ruleName=true | |
$ruleName.name=$ruleHumanName | |
$ruleName.severity=$newSeverity | |
$ruleName.description= See this link for details https://github.com/buzinas/tslint-eslint-rules/blob/master/src/docs/rules/$FileName | |
$ruleName.debtFunc=LINEAR_OFFSET | |
$ruleName.debtScalar=15min | |
$ruleName.debtOffset=1h | |
$ruleName.debtType=USABILITY_EASE_OF_USE | |
" | |
} |
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
$YourRepoRoot ="C:\DATA\Repos\" # replace with your repoistory root on you computer | |
$targetPath ="$YourRepoRoot\tslint-microsoft-contrib\src" | |
function ExtractMetaDataBlock() | |
{ | |
Param( | |
[string]$block | |
) | |
$start = $block.IndexOf("metadata: ExtendedMetadata") | |
$blockResult1 = $block.SubString($start, $block.Length-$start) | |
$end = $blockResult1.IndexOf("commonWeaknessEnumeration") | |
if($end -eq -1) | |
{ | |
$end = $blockResult1.IndexOf("}") | |
} | |
$blockResult2=$blockResult1.Substring(0,$end) | |
$bracketStart = $blockResult2.IndexOf("{") | |
$blockResult3 = $blockResult2.Substring($bracketStart+1,$blockResult2.Length-$bracketStart-1) | |
return $blockResult3 | |
} | |
function GetDataObjectFromBlock | |
{ | |
Param( | |
[string]$BlockText | |
) | |
$rule = New-Object System.Object | |
foreach( $line in $BlockText.Split(",")) | |
{ | |
if($line.Contains(":")) | |
{ | |
$Key = $line.Split(":")[0].Trim() | |
$Value = $line.Split(":")[1].Trim().Trim("'") | |
if ($Key.Contains("/*")) | |
{ | |
return; | |
} | |
# Write-Host "Key $key Value $Value" | |
$rule | Add-Member -type NoteProperty -name $Key -Value $Value | |
} | |
} | |
return $rule | |
} | |
$ListOfRules = New-Object System.Collections.ArrayList | |
$files = Get-ChildItem $targetPath -File -Filter "*Rule.ts" | |
foreach ( $file in $files ) | |
{ | |
$fileData = [System.IO.File]::ReadAllLines($file.FullName) | |
$rawData = ExtractMetaDataBlock -block $fileData | |
$Rule = GetDataObjectFromBlock -BlockText $rawData | |
$i =$ListOfRules.Add($Rule) | |
} | |
foreach ($newRule in $ListOfRules) | |
{ | |
$ruleName = $newRule.ruleName | |
$hardcodedLink ="please see the readme and search for $ruleName on https://github.com/Microsoft/tslint-microsoft-contrib/blob/master/README.md" | |
#debtType | |
$newRuleGroup = switch($newRule.group) | |
{ | |
"Correctness" {"ARCHITECTURE_CHANGEABILITY"} | |
"Clarity" {"READABILITY"} | |
"Whitespace" {"USABILITY_COMPLIANCE"} | |
"Security" {"SECURITY_COMPLIANCE"} | |
"Deprecated" {"COMPILER_RELATED_PORTABILITY"} | |
"Accessibility" {"USABILITY_ACCESSIBILITY"} | |
} | |
$newSeverity = switch($newRule.severity) | |
{ | |
"Low" {"MINOR"} | |
"Moderate" {"MAJOR"} | |
"Important" {"CRITICAL"} | |
"Critical" {"BLOCKER"} | |
} | |
Write-Host "$($newRule.ruleName)=true | |
$($newRule.ruleName).name=$($newRule.description) | |
$($newRule.ruleName).severity=$newSeverity | |
$($newRule.ruleName).description=$($newRule.ruleName) $hardcodedLink | |
$($newRule.ruleName).debtFunc=LINEAR_OFFSET | |
$($newRule.ruleName).debtScalar=15min | |
$($newRule.ruleName).debtOffset=1h | |
$($newRule.ruleName).debtType=$newRuleGroup | |
" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment