mirror of
https://github.com/adrienverge/yamllint.git
synced 2025-02-25 18:55:20 -06:00
WIP - test by Adrien
This commit is contained in:
0
tests/plugins/yamllint_plugin_example/README.rst
Normal file
0
tests/plugins/yamllint_plugin_example/README.rst
Normal file
11
tests/plugins/yamllint_plugin_example/setup.cfg
Normal file
11
tests/plugins/yamllint_plugin_example/setup.cfg
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
[metadata]
|
||||||
|
name = yamllint_plugin_example
|
||||||
|
version = 1.0.0
|
||||||
|
|
||||||
|
[options]
|
||||||
|
packages = find:
|
||||||
|
install_requires = yamllint
|
||||||
|
|
||||||
|
[options.entry_points]
|
||||||
|
yamllint.plugins.rules =
|
||||||
|
example = yamllint_plugin_example
|
||||||
2
tests/plugins/yamllint_plugin_example/setup.py
Normal file
2
tests/plugins/yamllint_plugin_example/setup.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
import setuptools
|
||||||
|
setuptools.setup()
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (C) 2020 Satoru SATOH
|
||||||
|
#
|
||||||
|
# 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/>.
|
||||||
|
|
||||||
|
"""yamllint plugin entry point
|
||||||
|
"""
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
from . import override_comments, random_failure
|
||||||
|
|
||||||
|
|
||||||
|
RULES_MAP = {
|
||||||
|
override_comments.ID: override_comments,
|
||||||
|
random_failure.ID: random_failure,
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
#
|
||||||
|
# Copyright (C) 2020 Satoru SATOH
|
||||||
|
#
|
||||||
|
# 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/>.
|
||||||
|
#
|
||||||
|
"""
|
||||||
|
Use this rule to override some comments' rules.
|
||||||
|
|
||||||
|
.. rubric:: Options
|
||||||
|
|
||||||
|
* Use ``forbid`` to control comments. Set to ``true`` to forbid comments
|
||||||
|
completely.
|
||||||
|
|
||||||
|
.. rubric:: Examples
|
||||||
|
|
||||||
|
#. With ``override-comments: {forbid: true}``
|
||||||
|
|
||||||
|
the following code snippet would **PASS**:
|
||||||
|
::
|
||||||
|
|
||||||
|
foo: 1
|
||||||
|
|
||||||
|
the following code snippet would **FAIL**:
|
||||||
|
::
|
||||||
|
|
||||||
|
# baz
|
||||||
|
foo: 1
|
||||||
|
|
||||||
|
.. rubric:: Default values (when enabled)
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
rules:
|
||||||
|
override-comments:
|
||||||
|
forbid: False
|
||||||
|
|
||||||
|
"""
|
||||||
|
from yamllint.linter import LintProblem
|
||||||
|
|
||||||
|
|
||||||
|
ID = 'override-comments'
|
||||||
|
TYPE = 'comment'
|
||||||
|
CONF = {'forbid': bool}
|
||||||
|
DEFAULT = {'forbid': False}
|
||||||
|
|
||||||
|
|
||||||
|
def check(conf, comment):
|
||||||
|
"""Check if comments are found.
|
||||||
|
"""
|
||||||
|
if conf['forbid']:
|
||||||
|
yield LintProblem(comment.line_no, comment.column_no,
|
||||||
|
'forbidden comment')
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (C) 2020 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 random
|
||||||
|
|
||||||
|
from yamllint.linter import LintProblem
|
||||||
|
|
||||||
|
|
||||||
|
ID = 'random-failure'
|
||||||
|
TYPE = 'token'
|
||||||
|
|
||||||
|
|
||||||
|
def check(conf, token, prev, next, nextnext, context):
|
||||||
|
if random.random() > 0.9:
|
||||||
|
yield LintProblem(token.start_mark.line + 1,
|
||||||
|
token.start_mark.column + 1,
|
||||||
|
'random failure')
|
||||||
@@ -29,5 +29,7 @@ rules:
|
|||||||
octal-values: disable
|
octal-values: disable
|
||||||
quoted-strings: disable
|
quoted-strings: disable
|
||||||
trailing-spaces: enable
|
trailing-spaces: enable
|
||||||
|
random-failure: enable
|
||||||
|
override-comments: {forbid: true}
|
||||||
truthy:
|
truthy:
|
||||||
level: warning
|
level: warning
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ def load_plugin_rules_itr(entry_points=None, group=PACKAGE_GROUP):
|
|||||||
if rule_id in rule_ids or not validate_rule_module(rule_mod):
|
if rule_id in rule_ids or not validate_rule_module(rule_mod):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
print(rule_id, rule_mod)###
|
||||||
yield (rule_id, rule_mod)
|
yield (rule_id, rule_mod)
|
||||||
rule_ids.add(rule_id)
|
rule_ids.add(rule_id)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user