有没有一种方法可以仅在新文件(之前由git取消跟踪的文件)上运行lint-stage [英] Is there a way to run lint-staged only on new files (the ones that were untracked by git before)

查看:244
本文介绍了有没有一种方法可以仅在新文件(之前由git取消跟踪的文件)上运行lint-stage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在用Typescript编写的项目中,我想开始对所有函数的返回类型和参数类型强制执行类型注释.为此,我创建了一个单独的tslint配置,该配置扩展了我的主配置并在此基础上添加了此规则.我正在通过husky和lint-staged使用此扩展配置运行tslint,以在提交更改之前检查所有已暂存的文件.问题是:如果我对其中一个旧文件(其中一些文件很大)进行了更改,则lint stage也会检查该文件,除非我在所有文件中键入所有功能的注释,否则我不会提交.但这是很多工作,我只想在新文件上执行此操作.有没有一种方法可以将暂存文件筛选为仅包含此提交中添加的文件?

On my project written in Typescript I want to start enforcing type annotations for returned types and parameter types of all functions. For that I created a separate tslint config that extends my main config and adds this rule on top of that. I'm running tslint via husky and lint-staged with this extended config to check all staged files before committing changes. The problem is: if I do a change in one of the old files (some of them are pretty big) lint staged will check this file too and won't let me to commit unless I type-annotate all the functions in all files. But it's a lot of work and I want to enforce this only on new files. Is there a way to filter staged files to only ones that are added in this commit?

推荐答案

分阶段整理的使用了另一个名为

lint-staged makes use of another library named staged-git-files(sgf) for retrieving the list of files staged before a git commit.

以下是sgf使用的一些状态代码.

Here are some status codes which sgf uses.

  • 添加了(A)
  • 已复制(C)
  • 已删除(D)
  • 已修改(M)
  • 重命名(R)

lint-staged 将状态代码 ACM 传递给了sgf程序包.

lint-staged passed the status code ACM to sgf package.

 sgf.cwd = gitDir
  *return pify(sgf)('ACM').then(files => {*
    /* files is an Object{ filename: String, status: String } */
    const filenames = files.map(file => file.filename)

如果您只想lint-staged仅检索添加的文件,则可以分叉存储库并将 AC 传递给sgf.如果我们有一种配置方法,那将是理想的.我在回购协议中提出了问题.希望他们能解决

If you want lint-staged to retrieve added files only, then you can fork the repo and pass AC instead to sgf. It would be ideal if we have a way of configuring this. I raised an issue in the repo. I hope they address it

这篇关于有没有一种方法可以仅在新文件(之前由git取消跟踪的文件)上运行lint-stage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆