字体检查样式
Typescript- checkstyle 是报告的工具 typescript compiler 输出于 checkstyle 格式。 创建它是为了改进有编译器错误的拉动请求装饰.
先决条件
项目要求:
- 节点 10
- 无
安装
所有离相被公布为npm. 要使用最新版本,可以使用:
npm i --save-dev @bartekbp/typescript-checkstyle
使用量
从命令行和javascript中可以使用打字检查样式.
命令行
图书馆读取 tsc 从标准输入输出。 你也许想一起跑 以下命令类型检查您的工程并显示编译错误 checkstyle 格式 :
> npx tsc --noEmit | npx @bartekbp/typescript-checkstyle
如果你已经有 npm scripts 配置并想要使用其中之一的输出来打字检查样式, 您需要引用 npm 与 安静 以压制 npm 预告 :
> npm --silent run lint:tsc | npx @bartekbp/typescript-checkstyle
拖动有打字错误的请求装饰
如果您想要根据压缩输出将注释自动添加到拉动请求中,则打字检查样式将帮助您实现. 要配置它,我会用 jenkins,但该解决方案也适用于其他连续集成系统.
詹金斯平线
你需要设置一个 jenkins pipeline 将随 bitbucket 分支源插件 或者说 github 分支源插件在管道中,您需要运行打印检查样式 tsc 并重定向输出到文件 :
stage('tsc') {
steps {
sh 'npx tsc --noEmit | npx @bartekbp/typescript-checkstyle > tsc-checkstyle.xml'
}
}
根据你的代码审查系统, 假发 为拉动请求装饰创建了不同的插件. 你可以在底部找到完整的名单 违反- lib readme我将专注于配置 bitbucket cloud。 。 。 .
您需要更新管道, 并添加一个 pr 装饰 :
stage('Decorate pr') {
steps {
withCredentials([usernamePassword(credentialsId: 'jenkins-pr-writes', passwordVariable: 'JENKINS_VIOLATION_PASSWORD', usernameVariable: 'JENKINS_VIOLATION_USER')]) {
sh 'npx violation-comments-to-bitbucket-cloud-command-line -u "$JENKINS_VIOLATION_USER" -p "$JENKINS_VIOLATION_PASSWORD" -ws workspace -rs repoName -prid "$CHANGE_ID" -v "CHECKSTYLE" "." ".*tsc-checkstyle.xml$" "tsc" || true'
}
}
}
舞台上的粗体部分需要更新以反映您的项目:
- jenkins 复写 带有证书到比特巴克特用户
- 工作空间 带有 bitbucket 工作空间
- 重播Name 拥有已打开的拉动请求的仓库
Javascript
Typescript- checkstyle 显示一个函数 format数字 :
/**
* Converts tsc errors to checkstyle format
*
* @param {string} input - errors from tsc
* @return {string} errors in checkstyle format
function format(input) {}
*/
其使用方式如下:
import format from '@bartekbp/typescript-checkstyle';
const input = `src/test.component.ts(3, 12): error TS2564: Property 'name' has no initializer`;
const errorsInCheckstyleFormat = format(input);
console.log(errorsInCheckstyleFormat);
此代码打印出错误 input 以检查样式格式.
许可证
根据麻省理工学院的许可证分发。 更多信息见LICENSE.
鸣谢
非常感谢: