Rules: document-start: Allow directives

pull/4/head
Adrien Vergé 9 years ago
parent 851b9ac42c
commit 5cc900f2a8

@ -85,6 +85,20 @@ class DocumentStartTestCase(RuleTestCase):
'third: document\n', conf, problem=(4, 1)) 'third: document\n', conf, problem=(4, 1))
def test_directives(self): def test_directives(self):
# TODO conf = 'document-start: {present: yes}'
# %YAML 1.2 self.check('%YAML 1.2\n'
pass '---\n'
'doc: ument\n'
'...\n', conf)
self.check('%YAML 1.2\n'
'%TAG ! tag:clarkevans.com,2002:\n'
'---\n'
'doc: ument\n'
'...\n', conf)
self.check('---\n'
'doc: 1\n'
'...\n'
'%YAML 1.2\n'
'---\n'
'doc: 2\n'
'...\n', conf)

@ -29,3 +29,9 @@ class YamlLintTestCase(RuleTestCase):
'this is an error: [\n' 'this is an error: [\n'
'\n' '\n'
'...\n', None, problem=(6, 1)) '...\n', None, problem=(6, 1))
def test_directives(self):
self.check('%YAML 1.2\n'
'%TAG ! tag:clarkevans.com,2002:\n'
'doc: ument\n'
'...\n', None, problem=(3, 1))

@ -24,15 +24,14 @@ TYPE = 'token'
CONF = {'present': bool} CONF = {'present': bool}
# TODO: Don't fail if document contains directives such as
# %YAML 1.2
def check(conf, token, prev, next): def check(conf, token, prev, next):
if conf['present']: if conf['present']:
if ((isinstance(prev, yaml.StreamStartToken) or if (isinstance(prev, (yaml.StreamStartToken,
isinstance(prev, yaml.DocumentEndToken)) and yaml.DocumentEndToken,
not (isinstance(token, yaml.DocumentStartToken) or yaml.DirectiveToken)) and
isinstance(token, yaml.StreamEndToken))): not isinstance(token, (yaml.DocumentStartToken,
yaml.DirectiveToken,
yaml.StreamEndToken))):
yield LintProblem(token.start_mark.line + 1, 1, yield LintProblem(token.start_mark.line + 1, 1,
'missing document start "---"') 'missing document start "---"')

Loading…
Cancel
Save