Support ignoring shebangs

Some usages of YAML (like Ansible) supports running the file as a script.

Support (by default) an ignore-shebangs setting for the comments module.

Fixes #116 - comments rule with require-starting-space: true should special case shebang
This commit is contained in:
Mattias Bengtsson
2018-12-06 13:50:24 +01:00
committed by Adrien Vergé
parent 0f073f7a09
commit b77f78f677
2 changed files with 42 additions and 5 deletions

View File

@@ -80,6 +80,33 @@ class CommentsTestCase(RuleTestCase):
problem3=(9, 2), problem4=(10, 4),
problem5=(15, 3))
def test_shebang(self):
conf = ('comments:\n'
' require-starting-space: true\n'
' ignore-shebangs: false\n'
'comments-indentation: disable\n')
self.check('#!/bin/env my-interpreter\n',
conf, problem1=(1, 2))
self.check('#!/bin/env my-interpreter\n'
'---\n'
'#comment\n'
'#!/bin/env my-interpreter\n'
'', conf,
problem1=(1, 2), problem2=(3, 2), problem3=(4, 2))
def test_ignore_shebang(self):
conf = ('comments:\n'
' require-starting-space: true\n'
' ignore-shebangs: true\n'
'comments-indentation: disable\n')
self.check('#!/bin/env my-interpreter\n', conf)
self.check('#!/bin/env my-interpreter\n'
'---\n'
'#comment\n'
'#!/bin/env my-interpreter\n'
'', conf,
problem2=(3, 2), problem3=(4, 2))
def test_spaces_from_content(self):
conf = ('comments:\n'
' require-starting-space: false\n'