Rules: Add the 'commas' rule

This commit is contained in:
Adrien Vergé
2016-01-13 17:56:07 +01:00
parent cfea0661ed
commit a5b384ab21
4 changed files with 197 additions and 3 deletions

View File

@@ -6,9 +6,9 @@ rules:
colons:
max-spaces-before: 0
max-spaces-after: 1
#comma:
# max-spaces-before: 0
# max-spaces-after: 1
commas:
max-spaces-before: 0
max-spaces-after: 1
#comment:
# min-spaces-after: 1
# min-spaces-before: 2

View File

@@ -16,6 +16,7 @@
from yamllint.rules import (
colons,
commas,
document_end,
document_start,
empty_lines,
@@ -29,6 +30,7 @@ from yamllint.rules import (
_RULES = {
colons.ID: colons,
commas.ID: commas,
document_end.ID: document_end,
document_start.ID: document_start,
empty_lines.ID: empty_lines,

38
yamllint/rules/commas.py Normal file
View File

@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2016 Adrien Vergé
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import yaml
from yamllint.rules.common import max_spaces_after, max_spaces_before
ID = 'commas'
TYPE = 'token'
CONF = {'max-spaces-before': int,
'max-spaces-after': int}
def check(conf, token, prev, next):
if isinstance(token, yaml.FlowEntryToken):
problem = max_spaces_before(conf['max-spaces-before'], token, prev,
next, 'too many spaces before comma')
if problem is not None:
yield problem
problem = max_spaces_after(conf['max-spaces-after'], token, prev, next,
'too many spaces after comma')
if problem is not None:
yield problem