|
17 | 17 | r"(?:\n|^)diff --git a\/.* b\/.*(?:\n|$)")
|
18 | 18 |
|
19 | 19 |
|
| 20 | +class RelintError(Exception): |
| 21 | + pass |
| 22 | + |
| 23 | + |
| 24 | +class ConfigError(ValueError, RelintError): |
| 25 | + pass |
| 26 | + |
| 27 | + |
20 | 28 | Test = namedtuple(
|
21 | 29 | 'Test', (
|
22 | 30 | 'name',
|
@@ -63,27 +71,36 @@ def parse_args(args):
|
63 | 71 |
|
64 | 72 | def load_config(path, fail_warnings):
|
65 | 73 | with open(path) as fs:
|
66 |
| - for test in yaml.safe_load(fs): |
67 |
| - filename = test.get('filename') |
68 |
| - if filename: |
69 |
| - warnings.warn( |
70 |
| - "The glob style 'filename' configuration attribute has been" |
71 |
| - " deprecated in favor of a new RegEx based 'filePattern' attribute." |
72 |
| - " 'filename' support will be removed in relint version 2.0.", |
73 |
| - DeprecationWarning |
| 74 | + try: |
| 75 | + for test in yaml.safe_load(fs): |
| 76 | + filename = test.get('filename') |
| 77 | + if filename: |
| 78 | + warnings.warn( |
| 79 | + "The glob style 'filename' configuration attribute has been" |
| 80 | + " deprecated in favor of a new RegEx based 'filePattern' attribute." |
| 81 | + " 'filename' support will be removed in relint version 2.0.", |
| 82 | + DeprecationWarning |
| 83 | + ) |
| 84 | + if not isinstance(filename, list): |
| 85 | + filename = list(filename) |
| 86 | + file_pattern = test.get('filePattern', '.*') |
| 87 | + file_pattern = re.compile(file_pattern) |
| 88 | + yield Test( |
| 89 | + name=test['name'], |
| 90 | + pattern=re.compile(test['pattern'], re.MULTILINE), |
| 91 | + hint=test.get('hint'), |
| 92 | + file_pattern=file_pattern, |
| 93 | + filename=filename, |
| 94 | + error=test.get('error', True) or fail_warnings |
74 | 95 | )
|
75 |
| - if not isinstance(filename, list): |
76 |
| - filename = list(filename) |
77 |
| - file_pattern = test.get('filePattern', '.*') |
78 |
| - file_pattern = re.compile(file_pattern) |
79 |
| - yield Test( |
80 |
| - name=test['name'], |
81 |
| - pattern=re.compile(test['pattern'], re.MULTILINE), |
82 |
| - hint=test.get('hint'), |
83 |
| - file_pattern=file_pattern, |
84 |
| - filename=filename, |
85 |
| - error=test.get('error', True) or fail_warnings |
86 |
| - ) |
| 96 | + except yaml.YAMLError as e: |
| 97 | + raise ConfigError("Error parsing your relint config file.") from e |
| 98 | + except TypeError: |
| 99 | + warnings.warn("Your relint config is empty, no tests were executed.", UserWarning) |
| 100 | + except (AttributeError, ValueError) as e: |
| 101 | + raise ConfigError( |
| 102 | + "Your relint config is not a valid YAML list of relint tests." |
| 103 | + ) from e |
87 | 104 |
|
88 | 105 |
|
89 | 106 | def lint_file(filename, tests):
|
|
0 commit comments