From 50ab9cfc55fbbe4d9661da4056a0ad232295033d Mon Sep 17 00:00:00 2001 From: smhxx Date: Sat, 14 Oct 2017 04:29:48 -0500 Subject: [PATCH] Detect and run tslint for TypeScript projects --- build-package.ps1 | 53 +++++++++++++++++++++++++++++++++++++++++++++-- build-package.sh | 30 +++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 2 deletions(-) diff --git a/build-package.ps1 b/build-package.ps1 index 67f26e0..39f7006 100644 --- a/build-package.ps1 +++ b/build-package.ps1 @@ -135,7 +135,9 @@ function RunLinters() { $lintwitheslint = HasLinter -LinterName "eslint" $standardpath = "$script:PACKAGE_FOLDER\node_modules\.bin\standard.cmd" $lintwithstandard = HasLinter -LinterName "standard" - if (($libpathexists -or $srcpathexists) -and ($lintwithcoffeelint -or $lintwitheslint -or $lintwithstandard)) { + $tslintpath = "$script:PACKAGE_FOLDER\node_modules\.bin\tslint.cmd" + $lintwithtslint = HasLinter -LinterName "tslint" + if (($libpathexists -or $srcpathexists) -and ($lintwithcoffeelint -or $lintwitheslint -or $lintwithstandard -or $lintwithtslint)) { Write-Host "Linting package..." } @@ -160,6 +162,23 @@ function RunLinters() { ExitWithCode -exitcode $LASTEXITCODE } } + + if ($lintwithtslint) { + if (Test-Path tsconfig.json) { + Write-Host "Found tsconfig.json in project root directory, enabling type checking..." + & "$tslintpath" --project tsconfig.json --type-check + } + elseif (Test-Path lib\tsconfig.json) { + Write-Host "Found tsconfig.json in lib directory, enabling type checking..." + & "$tslintpath" --project lib\tsconfig.json --type-check + } else { + Write-Host "No tsconfig.json found for lib directory, disabling type checking..." + & "$tslintpath" lib + } + if ($LASTEXITCODE -ne 0) { + ExitWithCode -exitcode $LASTEXITCODE + } + } } if ($srcpathexists) { @@ -183,9 +202,26 @@ function RunLinters() { ExitWithCode -exitcode $LASTEXITCODE } } + + if ($lintwithtslint) { + if (Test-Path tsconfig.json) { + Write-Host "Found tsconfig.json in project root directory, enabling type checking..." + & "$tslintpath" --project tsconfig.json --type-check + } + elseif (Test-Path lib\tsconfig.json) { + Write-Host "Found tsconfig.json in src directory, enabling type checking..." + & "$tslintpath" --project src\tsconfig.json --type-check + } else { + Write-Host "No tsconfig.json found for src directory, disabling type checking..." + & "$tslintpath" src + } + if ($LASTEXITCODE -ne 0) { + ExitWithCode -exitcode $LASTEXITCODE + } + } } - if ($specpathexists -and ($lintwithcoffeelint -or $lintwitheslint -or $lintwithstandard)) { + if ($specpathexists -and ($lintwithcoffeelint -or $lintwitheslint -or $lintwithstandard -or $lintwithtslint)) { Write-Host "Linting package specs..." if ($lintwithcoffeelint) { & "$coffeelintpath" spec @@ -207,6 +243,19 @@ function RunLinters() { ExitWithCode -exitcode $LASTEXITCODE } } + + if ($lintwithtslint) { + if (Test-Path spec\tsconfig.json) { + Write-Host "Found tsconfig.json in spec directory, enabling type checking..." + & "$tslintpath" --project spec\tsconfig.json --type-check + } else { + Write-Host "No tsconfig.json found for spec directory, disabling type checking..." + & "$tslintpath" spec + } + if ($LASTEXITCODE -ne 0) { + ExitWithCode -exitcode $LASTEXITCODE + } + } } } diff --git a/build-package.sh b/build-package.sh index 91ba99a..974edae 100755 --- a/build-package.sh +++ b/build-package.sh @@ -178,6 +178,36 @@ if has_linter "standard"; then fi fi +if has_linter "tslint"; then + if [ -e ./tsconfig.json ]; then + echo "Linting package using tslint..." + echo "Found tsconfig.json in project root directory, enabling type checking..." + ./node_modules/bin/tslint --project tsconfig.json --type-check + rc=$?; if [ $rc -ne 0 ]; then exit $rc; fi + elif [ -d ./lib ]; then + echo "Linting package using tslint..." + if [ -e ./lib/tsconfig.json ]; then + echo "Found tsconfig.json in lib directory, enabling type checking..." + ./node_modules/.bin/tslint --project lib/tsconfig.json --type-check + else + echo "No tsconfig.json found for lib directory, disabling type checking..." + ./node_modules/.bin/tslint lib + fi + rc=$?; if [ $rc -ne 0 ]; then exit $rc; fi + fi + if [ -d ./spec ]; then + echo "Linting package specs using tslint..." + if [ -e ./spec/tsconfig.json ]; then + echo "Found tsconfig.json in spec directory, enabling type checking..." + ./node_modules/.bin/tslint --project spec/tsconfig.json --type-check + else + echo "No tsconfig.json found in spec directory, disabling type checking..." + ./node_modules/.bin/tslint spec + fi + rc=$?; if [ $rc -ne 0 ]; then exit $rc; fi + fi +fi + if [ -d ./spec ]; then echo "Running specs..." "${ATOM_SCRIPT_PATH}" --test spec