问题标签 [lint-staged]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
3252 浏览

node.js - Husky 给出错误 SyntaxError:在严格模式下使用 const

我正在使用带有Lint-stagedStylelint的Husky

操作系统 - 最新的 OSX

节点 -6.10.0

新PM -3.10.00

我收到此错误git commit

0 投票
0 回答
773 浏览

typescript - lint-staged 和 tslint “警告”严重性

在我的项目中,我使用tslintwith"defaultSeverity": "warning"选项。有没有办法配置lint-staged来捕获警告并在它们发生时中止提交?我的lint-staged配置:

0 投票
1 回答
3264 浏览

javascript - 如何使用 lint-staged 和 jest --collectCoverageFrom

我正在使用lint-stagedJest测试框架来仅测试上次提交中更改的文件,如本博客所述。

我的配置如下:

我还想只为更改的文件生成覆盖率报告。为此,我必须将已更改文件的列表放在多个位置。

jest --bail --findRelatedTests <spaceSeparatedListOfSourceFiles> --collectCoverageFrom=<glob>

使用lint-staged,我怎样才能限制测试和覆盖报告只针对更改的文件?

0 投票
23 回答
95728 浏览

javascript - lint-staged 未在预提交时运行

precommit 上没有运行 prettier。这在其他项目中使用相同的配置,所以我很困惑为什么这次它不起作用。

这是我的 package.json 文件的相关部分:

编辑。以下是相关的 devDependencies:

0 投票
2 回答
12269 浏览

typescript - How to lint for Typescript compilation issues?

Take the following Typescript arrow function:

When Typescript is configured in tsconfig.json as such:

This correctly results in a compilation error:

[ts] Parameter 'baseName' implicitly has an 'any' type.

Visual Studio Code is also smart enough to inform you about this issue during development.

My goal is to create a precommit git hook that prevents such errors from ending up in version control. I tried to do this with tslint, husky and lint-staged using this npm script:

However, this does not result in the compilation error showing up by tslint. It is silently ignored.

I then tried to add a rule in tslint.json:

While this did make tslint complain, it also started to complain in anonymous arrow functions where the tsc compiler does not complain. In these arrow functions it should not be necessary to add types because the types were already set previously in the parent scope (they are inferred).

So basically, I would like for tslint to behave the same as tsc in this case. Anytime there is an error that would cause compilation to fail (such as the above arrow function), I would like to prevent the commit, but without actually compiling to Javascript. Is this possible?

0 投票
5 回答
31768 浏览

husky - 这是使用 husky + lint-staged 的​​正确方法吗?

我发现许多博客(包括 lint-staged doc)介绍了一种使用 husky+ lint-staged 的​​方法,如下在 package.json 中定义的代码:

由于存在“prettier”和“eslint --fix”都无法修复的错误,我们如何防止这种用法导致错误提交?

0 投票
0 回答
1305 浏览

javascript - lint-staged 没有阶段文件匹配

使用 create-react-app 模板。视窗,开放服务器。

包.json

.lintstagedrc

结果:截图

为什么“没有暂存文件匹配 *.js”?

0 投票
1 回答
1925 浏览

git - 参数列表太长 - lint-staged -> tslint

在我们的项目中,我们在将 lint-staged 与 prettier 和 tslint 集成后遇到了一个奇怪的问题。这个想法是使用pre-commit git hook应用prettier然后应用tslint到提交中的所有文件。husky

为了使整个项目符合 描述的新代码样式prettier,我们决定首先运行prettier整个项目,然后使用上述 git 钩子提交所有这些文件。

运行后,prettier我们最终提交了 400 多个文件。因此,在运行时将git commit lint-staged所有这 400 多个文件作为参数传递给脚本。prettiertslint

最初我们有tslint一个脚本package.json,如下所示:

"lint": "tslint -c tslint.json --project src/tsconfig.json"

配置lint-staged如下所示:

当我们运行git commitnpm 时,在 linting 阶段出现错误。输出中没有给出错误描述。然后我们尝试将 lint-staged 提供给我们的所有文件路径复制到终端并npm run lint手动运行所有这些文件路径。

我们所说的错误Argument list too long

通过进一步的试验,我们发现在没有任何错误的情况下可以接受的最大文件路径数是 357。因此,当我们运行 linting 脚本时,npm run lint我们最多只能传递 357 个文件路径作为参数。

然而,有趣的是,如果我们将lint staged脚本更改为立即使用tslint(不带npm run lint):

这个错误Argument list too long消失了,linting 开始工作而没有错误 - 无论有多少文件作为参数传递。

这样,问题本身就解决了。但问题仍然存在——这种行为的原因是什么?基本上,当使用我们运行脚本时,npm run我们可以传递有限数量的参数,否则 - 无论有多少参数都不会出现问题。

0 投票
2 回答
7481 浏览

git - lint-staged:“git add”命令的目的是什么

最近我开始引入lint-staged我的前端构建工具链。当我检查有关它的文档时,我总是发现它的工作原理如下:

您可以在链接中找到更多类似的用法:https ://github.com/okonet/lint-staged

我的困惑点是最后一个命令git add,它的目的是什么?

我的理解是lint-staged只验证暂存区 after git add和 before中的代码git commit。所以无法理解为什么我们需要再添加一个git add

0 投票
2 回答
1275 浏览

git - 有没有办法只在新文件上运行 lint-staged (之前 git 未跟踪的文件)

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