-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
95e17b3
commit e3c3ed9
Showing
12 changed files
with
400 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from tests.common import RuleTestCase | ||
|
||
|
||
class ForbidBoolTestCase(RuleTestCase): | ||
rule_id = 'forbid-bool' | ||
|
||
def test_forbid_null_disabled(self): | ||
conf = 'forbid-bool: disable' | ||
self.check('---\n' | ||
'bool:\n' | ||
'valid: "somevalue"\n', conf) | ||
|
||
def test_forbid_null_enabled(self): | ||
conf = 'forbid-bool: enable\n' | ||
self.check('---\n' | ||
'bool:\n' | ||
'valid: "somevalue"\n', conf, problem=(2, 1)) | ||
|
||
def test_forbid_null_with_valid_array_keys(self): | ||
conf = 'forbid-bool: enable' | ||
self.check('---\n' | ||
'valid_key: value\n' | ||
'another_key:\n' | ||
' - item0\n' | ||
' - "bool"\n' | ||
' - item2\n', conf) | ||
|
||
def test_forbid_null_with_nested_null(self): | ||
conf = 'forbid-bool: enable' | ||
self.check('---\n' | ||
'outer_key:\n' | ||
' bool:\n' | ||
' inner_key: value\n', conf, problem=(3, 3)) | ||
|
||
def test_forbid_null_with_nested_null_disabled(self): | ||
conf = 'forbid-bool: disable' | ||
self.check('---\n' | ||
'outer_key:\n' | ||
' bool:\n' | ||
' inner_key: value\n', conf) | ||
|
||
def test_forbid_null_with_null_value(self): | ||
conf = 'forbid-bool: enable' | ||
self.check('---\n' | ||
'key: "bool"\n', conf) | ||
|
||
def test_forbid_null_with_empty_mapping(self): | ||
conf = 'forbid-bool: enable' | ||
self.check('---\n' | ||
'{}\n', conf) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from tests.common import RuleTestCase | ||
|
||
|
||
class ForbidFloatTestCase(RuleTestCase): | ||
rule_id = 'forbid-float' | ||
|
||
def test_forbid_null_disabled(self): | ||
conf = 'forbid-float: disable' | ||
self.check('---\n' | ||
'float:\n' | ||
'valid: "somevalue"\n', conf) | ||
|
||
def test_forbid_null_enabled(self): | ||
conf = 'forbid-float: enable\n' | ||
self.check('---\n' | ||
'float:\n' | ||
'valid: "somevalue"\n', conf, problem=(2, 1)) | ||
|
||
def test_forbid_null_with_valid_array_keys(self): | ||
conf = 'forbid-float: enable' | ||
self.check('---\n' | ||
'valid_key: value\n' | ||
'another_key:\n' | ||
' - item0\n' | ||
' - "float"\n' | ||
' - item2\n', conf) | ||
|
||
def test_forbid_null_with_nested_null(self): | ||
conf = 'forbid-float: enable' | ||
self.check('---\n' | ||
'outer_key:\n' | ||
' float:\n' | ||
' inner_key: value\n', conf, problem=(3, 3)) | ||
|
||
def test_forbid_null_with_nested_null_disabled(self): | ||
conf = 'forbid-float: disable' | ||
self.check('---\n' | ||
'outer_key:\n' | ||
' float:\n' | ||
' inner_key: value\n', conf) | ||
|
||
def test_forbid_null_with_null_value(self): | ||
conf = 'forbid-float: enable' | ||
self.check('---\n' | ||
'key: "float"\n', conf) | ||
|
||
def test_forbid_null_with_empty_mapping(self): | ||
conf = 'forbid-float: enable' | ||
self.check('---\n' | ||
'{}\n', conf) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from tests.common import RuleTestCase | ||
|
||
|
||
class ForbidIntTestCase(RuleTestCase): | ||
rule_id = 'forbid-int' | ||
|
||
def test_forbid_null_disabled(self): | ||
conf = 'forbid-int: disable' | ||
self.check('---\n' | ||
'int:\n' | ||
'valid: "somevalue"\n', conf) | ||
|
||
def test_forbid_null_enabled(self): | ||
conf = 'forbid-int: enable\n' | ||
self.check('---\n' | ||
'int:\n' | ||
'valid: "somevalue"\n', conf, problem=(2, 1)) | ||
|
||
def test_forbid_null_with_valid_array_keys(self): | ||
conf = 'forbid-int: enable' | ||
self.check('---\n' | ||
'valid_key: value\n' | ||
'another_key:\n' | ||
' - item0\n' | ||
' - "int"\n' | ||
' - item2\n', conf) | ||
|
||
def test_forbid_null_with_nested_null(self): | ||
conf = 'forbid-int: enable' | ||
self.check('---\n' | ||
'outer_key:\n' | ||
' int:\n' | ||
' inner_key: value\n', conf, problem=(3, 3)) | ||
|
||
def test_forbid_null_with_nested_null_disabled(self): | ||
conf = 'forbid-int: disable' | ||
self.check('---\n' | ||
'outer_key:\n' | ||
' int:\n' | ||
' inner_key: value\n', conf) | ||
|
||
def test_forbid_null_with_null_value(self): | ||
conf = 'forbid-int: enable' | ||
self.check('---\n' | ||
'key: "int"\n', conf) | ||
|
||
def test_forbid_null_with_empty_mapping(self): | ||
conf = 'forbid-int: enable' | ||
self.check('---\n' | ||
'{}\n', conf) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from tests.common import RuleTestCase | ||
|
||
|
||
class ForbidNullTestCase(RuleTestCase): | ||
rule_id = 'forbid-null' | ||
|
||
def test_forbid_null_disabled(self): | ||
conf = 'forbid-null: disable' | ||
self.check('---\n' | ||
'null:\n' | ||
'valid: "somevalue"\n', conf) | ||
|
||
def test_forbid_null_enabled(self): | ||
conf = 'forbid-null: enable\n' | ||
self.check('---\n' | ||
'null:\n' | ||
'valid: "somevalue"\n', conf, problem=(2, 1)) | ||
|
||
def test_forbid_null_with_valid_array_keys(self): | ||
conf = 'forbid-null: enable' | ||
self.check('---\n' | ||
'valid_key: value\n' | ||
'another_key:\n' | ||
' - item0\n' | ||
' - "null"\n' | ||
' - item2\n', conf) | ||
|
||
def test_forbid_null_with_nested_null(self): | ||
conf = 'forbid-null: enable' | ||
self.check('---\n' | ||
'outer_key:\n' | ||
' null:\n' | ||
' inner_key: value\n', conf, problem=(3, 3)) | ||
|
||
def test_forbid_null_with_nested_null_disabled(self): | ||
conf = 'forbid-null: disable' | ||
self.check('---\n' | ||
'outer_key:\n' | ||
' null:\n' | ||
' inner_key: value\n', conf) | ||
|
||
def test_forbid_null_with_null_value(self): | ||
conf = 'forbid-null: enable' | ||
self.check('---\n' | ||
'key: "null"\n', conf) | ||
|
||
def test_forbid_null_with_empty_mapping(self): | ||
conf = 'forbid-null: enable' | ||
self.check('---\n' | ||
'{}\n', conf) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from tests.common import RuleTestCase | ||
|
||
|
||
class ForbidStrTestCase(RuleTestCase): | ||
rule_id = 'forbid-str' | ||
|
||
def test_forbid_null_disabled(self): | ||
conf = 'forbid-str: disable' | ||
self.check('---\n' | ||
'str:\n' | ||
'valid: "somevalue"\n', conf) | ||
|
||
def test_forbid_null_enabled(self): | ||
conf = 'forbid-str: enable\n' | ||
self.check('---\n' | ||
'str:\n' | ||
'valid: "somevalue"\n', conf, problem=(2, 1)) | ||
|
||
def test_forbid_null_with_valid_array_keys(self): | ||
conf = 'forbid-str: enable' | ||
self.check('---\n' | ||
'valid_key: value\n' | ||
'another_key:\n' | ||
' - item0\n' | ||
' - "str"\n' | ||
' - item2\n', conf) | ||
|
||
def test_forbid_null_with_nested_null(self): | ||
conf = 'forbid-str: enable' | ||
self.check('---\n' | ||
'outer_key:\n' | ||
' str:\n' | ||
' inner_key: value\n', conf, problem=(3, 3)) | ||
|
||
def test_forbid_null_with_nested_null_disabled(self): | ||
conf = 'forbid-str: disable' | ||
self.check('---\n' | ||
'outer_key:\n' | ||
' str:\n' | ||
' inner_key: value\n', conf) | ||
|
||
def test_forbid_null_with_null_value(self): | ||
conf = 'forbid-str: enable' | ||
self.check('---\n' | ||
'key: "str"\n', conf) | ||
|
||
def test_forbid_null_with_empty_mapping(self): | ||
conf = 'forbid-str: enable' | ||
self.check('---\n' | ||
'{}\n', conf) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
""" | ||
Use this rule to ...... | ||
""" | ||
|
||
import yaml | ||
from yamllint.linter import LintProblem | ||
|
||
ID = 'forbid-bool' | ||
TYPE = 'token' | ||
CONF = {'forbid-bool': bool} | ||
DEFAULT = {'forbid-bool': False} | ||
|
||
|
||
def check(conf, token, prev, next, nextnext, context): | ||
if not isinstance(token, yaml.tokens.ScalarToken): | ||
return | ||
if token.style: | ||
return | ||
val = token.value | ||
|
||
if isinstance(token, yaml.tokens.ScalarToken): | ||
if val == "bool": | ||
yield LintProblem( | ||
token.start_mark.line + 1, | ||
token.start_mark.column + 1, | ||
'Found key with value "bool"') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
""" | ||
Use this rule to ...... | ||
""" | ||
|
||
import yaml | ||
from yamllint.linter import LintProblem | ||
|
||
ID = 'forbid-float' | ||
TYPE = 'token' | ||
CONF = {'forbid-float': bool} | ||
DEFAULT = {'forbid-float': False} | ||
|
||
|
||
def check(conf, token, prev, next, nextnext, context): | ||
if not isinstance(token, yaml.tokens.ScalarToken): | ||
return | ||
if token.style: | ||
return | ||
val = token.value | ||
|
||
if isinstance(token, yaml.tokens.ScalarToken): | ||
if val == "float": | ||
yield LintProblem( | ||
token.start_mark.line + 1, | ||
token.start_mark.column + 1, | ||
'Found key with value "float"') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
""" | ||
Use this rule to ...... | ||
""" | ||
|
||
import yaml | ||
from yamllint.linter import LintProblem | ||
|
||
ID = 'forbid-int' | ||
TYPE = 'token' | ||
CONF = {'forbid-int': bool} | ||
DEFAULT = {'forbid-int': False} | ||
|
||
|
||
def check(conf, token, prev, next, nextnext, context): | ||
if not isinstance(token, yaml.tokens.ScalarToken): | ||
return | ||
if token.style: | ||
return | ||
val = token.value | ||
|
||
if isinstance(token, yaml.tokens.ScalarToken): | ||
if val == "int": | ||
yield LintProblem( | ||
token.start_mark.line + 1, | ||
token.start_mark.column + 1, | ||
'Found key with value "int"') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
""" | ||
Use this rule to ...... | ||
""" | ||
|
||
import yaml | ||
from yamllint.linter import LintProblem | ||
|
||
ID = 'forbid-null' | ||
TYPE = 'token' | ||
CONF = {'forbid-null': bool} | ||
DEFAULT = {'forbid-null': False} | ||
|
||
|
||
def check(conf, token, prev, next, nextnext, context): | ||
if not isinstance(token, yaml.tokens.ScalarToken): | ||
return | ||
if token.style: | ||
return | ||
val = token.value | ||
|
||
if isinstance(token, yaml.tokens.ScalarToken): | ||
if val == "null": | ||
yield LintProblem( | ||
token.start_mark.line + 1, | ||
token.start_mark.column + 1, | ||
'Found key with value "null"') |
Oops, something went wrong.