New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于 excludeFiles 的问题 #34

Open
wi1dcard opened this Issue Jan 25, 2019 · 6 comments

Comments

Projects
None yet
2 participants
@wi1dcard
Copy link

wi1dcard commented Jan 25, 2019

目录结构如下,典型 Hexo 目录:

source
├── _posts
│   ├── ...... more files
│   ├── jootu-copywriting-style-guide.md
│   └── ...... more files

我需要忽略 jootu-copywriting-style-guide.md 文件,于是配置 lint-md.json

{
  "excludeFiles": ["jootu-copywriting-style-guide.md"],
  // ...
}

执行命令:

lint-md source/_posts/* --config lint-md.json

但并没有忽略该文件,同时,我也尝试了以下的配置:

{
  "excludeFiles": ["**/jootu-copywriting-style-guide.md"],
  // ...
}

请问正确的使用方法是?谢谢!

@ZiQiangWang

This comment has been minimized.

Copy link
Collaborator

ZiQiangWang commented Jan 26, 2019

执行命令可以直接后面跟着目录就行了

lint-md source/_posts --config lint-md.json

忽略文件的逻辑,是使用glob的ignore来实现。下面的方式应该是生效的

{
  "excludeFiles": ["**/jootu-copywriting-style-guide.md"],
  // ...
}
@wi1dcard

This comment has been minimized.

Copy link
Author

wi1dcard commented Jan 26, 2019

@ZiQiangWang 感谢回复,我误以为使用 * 让 Shell 替换通配符 —— 而非传递目录作为参数,也会进行规则匹配、忽略。

个人见解,无论是传多个文件作为参数,还是传单个目录作为参数,在最终进行 Lint 时,都应该进行 glob 匹配,若符合规则则应当忽略该文件。

不知这样做是否更合适?

@ZiQiangWang

This comment has been minimized.

Copy link
Collaborator

ZiQiangWang commented Jan 26, 2019

@wi1dcard 传递目录和*只是写法不同,不会有影响。下面的语法没有生效吗?我在本地尝试了下,是可以的

{
  "excludeFiles": ["**/jootu-copywriting-style-guide.md"],
  // ...
}
@wi1dcard

This comment has been minimized.

Copy link
Author

wi1dcard commented Jan 27, 2019

@ZiQiangWang 在 Shell 中,传递 * 时,Shell 会解析该通配符并替换为文件名列表,也就是说,在 lint-md 内是拿不到该通配符的,lint-md 「看到」的只有 a.md b.md c.md ...,这意味着相当于指定多个文件作为参数。

例如您可以在 Shell 中复现:

~ cd /
➜  / ls
Applications              cores                     opt
Library                   data                      private
Network                   dev                       sbin
System                    etc                       tmp
Users                     home                      usr
Volumes                   installer.failurerequests var
bin                       net
➜  / echo *
Applications Library Network System Users Volumes bin cores data dev etc home installer.failurerequests net opt private sbin tmp usr var
➜  / echo "*"
*
➜  /

您说的传目录路径作为参数,不带通配符,是正常的。但您可以尝试指定多个文件,使用 excludeFiles 忽略某个文件,应该是无效的。

@ZiQiangWang

This comment has been minimized.

Copy link
Collaborator

ZiQiangWang commented Jan 27, 2019

很奇怪,我自己尝试了下,使用通配符也是可以的,我在mac上运行的。
能不能麻烦提供你的环境和具体可复现的步骤

@wi1dcard

This comment has been minimized.

Copy link
Author

wi1dcard commented Jan 27, 2019

@ZiQiangWang 感谢您的积极回复,我尝试最简单的复现方法,发现不是由于通配符引起的,十分抱歉。复现流程基本如下:

bash-3.2$ mkdir test-with-wildcard
bash-3.2$ cd test-with-wildcard/
bash-3.2$ echo "## title-trailing-a-comma," > test.md
bash-3.2$ echo '{"excludeFiles":["test.md"]}' > config.json
# -----
bash-3.2$ lint-md . --config config.json
/Users/jootu/test-with-wildcard/test.md
   1:4-1:27          no-trailing-punctuation   Header content can not end with symbol. 'title-trailing-a-comma,'

Lint total 1 files, 0 warnings 1 errors

bash-3.2$ lint-md *.md --config config.json
/Users/jootu/test-with-wildcard/test.md
   1:4-1:27          no-trailing-punctuation   Header content can not end with symbol. 'title-trailing-a-comma,'

Lint total 1 files, 0 warnings 1 errors
# ------
bash-3.2$ echo '{"excludeFiles":["**/test.md"]}' > config.json
bash-3.2$ lint-md . --config config.json
Lint total 0 files, 0 warnings 0 errors

bash-3.2$ lint-md *.md --config config.json
Lint total 0 files, 0 warnings 0 errors

* 被 Shell 替换为了相对路径的文件名,在以上例子里就直接是文件名了。但实际 glob 匹配的不是传参的文件路径,而似乎是绝对路径。

也就是说:

bash-3.2$ echo '{"excludeFiles":["test.md"]}' > config.json
bash-3.2$ lint-md test.md --config config.json
/Users/jootu/test-with-wildcard/test.md
   1:4-1:27          no-trailing-punctuation   Header content can not end with symbol. 'title-trailing-a-comma,'

Lint total 1 files, 0 warnings 1 errors

再次抱歉,不好意思前面说的问题原因有误,是我误解了。

另外,假设当前目录有 2 个文件。我发现使用 lint-md .,若 glob 匹配后忽略了 1 个文件,那么最终的提示信息为 Lint total 1 files,也就是总文件 - 忽略的文件。但 lint-md a.md b.md c.md,那么即便 glob 忽略了其中某个文件,最终提示仍然为 Lint total 3 files。似乎这种处理不太得当?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment