Skip to content

Commit 9dc506b

Browse files
committed
Require pathspec ≥ 1.0.0 and follow Git's gitignore implementation
To follow Git's implementation, use `GitIgnoreSpec.from_lines(…)`. The change for using this is Git allows including files from excluded directories which directly contradicts the gitignore docs. Thanks to Wong Hoi Sing Edison for the initial proposal. Fixes #800.
1 parent 73b9c0b commit 9dc506b

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ classifiers = [
1717
"Topic :: Software Development :: Testing",
1818
]
1919
dependencies = [
20-
"pathspec >= 0.5.3",
20+
"pathspec >= 1.0.0",
2121
"pyyaml",
2222
]
2323
dynamic = ["version"]

yamllint/config.py

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import os.path
1717

18-
import pathspec
18+
from pathspec import GitIgnoreSpec
1919
import yaml
2020

2121
from yamllint import decoder
@@ -32,8 +32,8 @@ def __init__(self, content=None, file=None):
3232

3333
self.ignore = None
3434

35-
self.yaml_files = pathspec.PathSpec.from_lines(
36-
'gitwildmatch', ['*.yaml', '*.yml', '.yamllint'])
35+
self.yaml_files = GitIgnoreSpec.from_lines(
36+
['*.yaml', '*.yml', '.yamllint'])
3737

3838
self.locale = None
3939

@@ -112,18 +112,16 @@ def parse(self, raw_content):
112112
raise YamlLintConfigError(
113113
'invalid config: ignore-from-file should contain '
114114
'filename(s), either as a list or string')
115-
self.ignore = pathspec.PathSpec.from_lines(
116-
'gitwildmatch',
115+
self.ignore = GitIgnoreSpec.from_lines(
117116
decoder.lines_in_files(conf['ignore-from-file'])
118117
)
119118
elif 'ignore' in conf:
120119
if isinstance(conf['ignore'], str):
121-
self.ignore = pathspec.PathSpec.from_lines(
122-
'gitwildmatch', conf['ignore'].splitlines())
120+
self.ignore = GitIgnoreSpec.from_lines(
121+
conf['ignore'].splitlines())
123122
elif (isinstance(conf['ignore'], list) and
124123
all(isinstance(line, str) for line in conf['ignore'])):
125-
self.ignore = pathspec.PathSpec.from_lines(
126-
'gitwildmatch', conf['ignore'])
124+
self.ignore = GitIgnoreSpec.from_lines(conf['ignore'])
127125
else:
128126
raise YamlLintConfigError(
129127
'invalid config: ignore should contain file patterns')
@@ -134,8 +132,7 @@ def parse(self, raw_content):
134132
raise YamlLintConfigError(
135133
'invalid config: yaml-files '
136134
'should be a list of file patterns')
137-
self.yaml_files = pathspec.PathSpec.from_lines('gitwildmatch',
138-
conf['yaml-files'])
135+
self.yaml_files = GitIgnoreSpec.from_lines(conf['yaml-files'])
139136

140137
if 'locale' in conf:
141138
if not isinstance(conf['locale'], str):
@@ -158,8 +155,8 @@ def validate_rule_conf(rule, conf):
158155
return False
159156

160157
if isinstance(conf, dict):
161-
if ('ignore-from-file' in conf and not isinstance(
162-
conf['ignore-from-file'], pathspec.pathspec.PathSpec)):
158+
if ('ignore-from-file' in conf and
159+
not isinstance(conf['ignore-from-file'], GitIgnoreSpec)):
163160
if isinstance(conf['ignore-from-file'], str):
164161
conf['ignore-from-file'] = [conf['ignore-from-file']]
165162
if not (isinstance(conf['ignore-from-file'], list)
@@ -168,19 +165,17 @@ def validate_rule_conf(rule, conf):
168165
raise YamlLintConfigError(
169166
'invalid config: ignore-from-file should contain '
170167
'valid filename(s), either as a list or string')
171-
conf['ignore'] = pathspec.PathSpec.from_lines(
172-
'gitwildmatch',
168+
conf['ignore'] = GitIgnoreSpec.from_lines(
173169
decoder.lines_in_files(conf['ignore-from-file'])
174170
)
175-
elif ('ignore' in conf and not isinstance(
176-
conf['ignore'], pathspec.pathspec.PathSpec)):
171+
elif ('ignore' in conf and
172+
not isinstance(conf['ignore'], GitIgnoreSpec)):
177173
if isinstance(conf['ignore'], str):
178-
conf['ignore'] = pathspec.PathSpec.from_lines(
179-
'gitwildmatch', conf['ignore'].splitlines())
174+
conf['ignore'] = GitIgnoreSpec.from_lines(
175+
conf['ignore'].splitlines())
180176
elif (isinstance(conf['ignore'], list) and
181177
all(isinstance(line, str) for line in conf['ignore'])):
182-
conf['ignore'] = pathspec.PathSpec.from_lines(
183-
'gitwildmatch', conf['ignore'])
178+
conf['ignore'] = GitIgnoreSpec.from_lines(conf['ignore'])
184179
else:
185180
raise YamlLintConfigError(
186181
'invalid config: ignore should contain file patterns')

0 commit comments

Comments
 (0)