Skip to content

常见问题

提交代码时候,校验速度慢

提交代码的时候会对代码进行 fix 和 lint 操作,是根据文件数量来决定时间快慢。一般一次提交的文件不是很多,只在以一次接入的时候会比较慢,且开发之中 git commit 频率其实不会太高,所以整体相比一觉校验时间会慢点。

为什么我们需要将 prettier 与 ESLint 一起使用?

答案很简单: prettier 格式的代码要好得多

它从头开始删除所有格式并以一致的样式重新打印代码。这允许开发人员忘记格式化代码,而不是浪费时间在代码审查中讨论代码风格。

例如,我们有这么长的代码字符串

js
// prettier-ignore
const example = ['1', 'long string', 'another string', '0123456789', '1', 'long string', 'another string'];

如果我们尝试用 ESLint 格式化这个字符串,它只会在控制台中抛出一个错误:

bash

eslint example.ts --fix

output:
error    This line has a length of 105. Maximum allowed is 80

这个例子表明,linter 并不总是有助于代码格式化。因此,开发人员可以根据个人考虑以不同的方式自行格式化代码。

如果我们使用 Prettier 保存并格式化文件,该字符串将被重新打印为:

js
const example = [
  '1',
  'long string',
  'another string',
  '0123456789',
  '1',
  'long string',
  'another string',
];

git 修改文件名后大小写问题

git 会忽略文件名大小写修改,需要使用 git mv 来进行修改

为什么不建议全局安装 lint 工具

pospal-lint 强依赖 stylelint, eslint 等工具。而对于 eslint,其文档中写到:

Any plugins or shareable configs that you use must also be installed globally to work with a globally-installed ESLint.

全局安装 lint 工具和所有的 plugin,项目数量较多时容易引起混乱,且可能对 ci、部署等带来麻烦。

Last updated: