|
19 | 19 | ordering is case-sensitive and not accent-friendly (see examples below).
|
20 | 20 | This can be changed by setting the global ``locale`` option. This allows one
|
21 | 21 | to sort case and accents properly.
|
22 |
| -It also allows one to ignore certain keys by setting the ``ignored`` option. |
| 22 | +It also allows one to ignore certain keys by setting the ``ignored-keys`` |
| 23 | +(PCRE regexes list) option. |
23 | 24 |
|
24 | 25 | .. rubric:: Examples
|
25 | 26 |
|
|
80 | 81 | hais: true
|
81 | 82 | haïssable: true
|
82 | 83 |
|
83 |
| -#. With rule ``key-ordering: {ignored: ["name"]}`` |
| 84 | +#. With rule ``key-ordering: {ignored-keys: ["name"]}`` |
84 | 85 |
|
85 | 86 | the following code snippet would **PASS**:
|
86 | 87 | ::
|
|
89 | 90 | age: 30
|
90 | 91 | city: New York
|
91 | 92 | """
|
92 |
| - |
| 93 | +import re |
93 | 94 | from locale import strcoll
|
94 | 95 |
|
95 | 96 | import yaml
|
|
98 | 99 |
|
99 | 100 | ID = 'key-ordering'
|
100 | 101 | TYPE = 'token'
|
101 |
| -CONF = {'ignored': [str]} |
102 |
| -DEFAULT = {'ignored': []} |
| 102 | + |
| 103 | +CONF = {'ignored-keys': [str]} |
| 104 | +DEFAULT = {'ignored-keys': []} |
103 | 105 | MAP, SEQ = range(2)
|
104 | 106 |
|
105 | 107 |
|
@@ -128,9 +130,11 @@ def check(conf, token, prev, next, nextnext, context):
|
128 | 130 | # This check is done because KeyTokens can be found inside flow
|
129 | 131 | # sequences... strange, but allowed.
|
130 | 132 | if len(context['stack']) > 0 and context['stack'][-1].type == MAP:
|
131 |
| - if any(strcoll(next.value, key) < 0 |
132 |
| - for key in context['stack'][-1].keys |
133 |
| - if key not in conf['ignored']): |
| 133 | + if any( |
| 134 | + strcoll(next.value, key) < 0 |
| 135 | + for key in context['stack'][-1].keys |
| 136 | + if not any(re.search(r, key) for r in conf['ignored-keys']) |
| 137 | + ): |
134 | 138 | yield LintProblem(
|
135 | 139 | next.start_mark.line + 1, next.start_mark.column + 1,
|
136 | 140 | f'wrong ordering of key "{next.value}" in mapping')
|
|
0 commit comments