|
1 | 1 | import 'dart:convert';
|
2 | 2 | import 'dart:io' as io;
|
3 | 3 |
|
| 4 | +import 'package:analyzer/error/error.dart'; |
4 | 5 | import 'package:analyzer/file_system/file_system.dart';
|
5 | 6 | import 'package:analyzer/file_system/physical_file_system.dart';
|
6 | 7 | import 'package:custom_lint_core/custom_lint_core.dart';
|
@@ -115,6 +116,7 @@ custom_lint:
|
115 | 116 | test('Empty config', () {
|
116 | 117 | expect(CustomLintConfigs.empty.enableAllLintRules, null);
|
117 | 118 | expect(CustomLintConfigs.empty.rules, isEmpty);
|
| 119 | + expect(CustomLintConfigs.empty.errors, isEmpty); |
118 | 120 | });
|
119 | 121 |
|
120 | 122 | group('parse', () {
|
@@ -188,6 +190,25 @@ custom_lint:
|
188 | 190 | );
|
189 | 191 | });
|
190 | 192 |
|
| 193 | + test('has an immutable map of errors', () { |
| 194 | + final analysisOptions = createAnalysisOptions(''' |
| 195 | +custom_lint: |
| 196 | + errors: |
| 197 | + a: error |
| 198 | +'''); |
| 199 | + final configs = CustomLintConfigs.parse(analysisOptions, packageConfig); |
| 200 | + |
| 201 | + expect( |
| 202 | + configs.errors, |
| 203 | + {'a': ErrorSeverity.ERROR}, |
| 204 | + ); |
| 205 | + |
| 206 | + expect( |
| 207 | + () => configs.errors['a'] = ErrorSeverity.INFO, |
| 208 | + throwsUnsupportedError, |
| 209 | + ); |
| 210 | + }); |
| 211 | + |
191 | 212 | test(
|
192 | 213 | 'if custom_lint is present and defines some properties, merges with "include"',
|
193 | 214 | () {
|
@@ -338,6 +359,68 @@ foo:
|
338 | 359 | });
|
339 | 360 | });
|
340 | 361 |
|
| 362 | + test('Parses error severities from configs', () { |
| 363 | + final analysisOptions = createAnalysisOptions(''' |
| 364 | +custom_lint: |
| 365 | + errors: |
| 366 | + rule_name_1: error |
| 367 | + rule_name_2: warning |
| 368 | + rule_name_3: info |
| 369 | + rule_name_4: none |
| 370 | +'''); |
| 371 | + final configs = CustomLintConfigs.parse(analysisOptions, packageConfig); |
| 372 | + |
| 373 | + expect(configs.errors, { |
| 374 | + 'rule_name_1': ErrorSeverity.ERROR, |
| 375 | + 'rule_name_2': ErrorSeverity.WARNING, |
| 376 | + 'rule_name_3': ErrorSeverity.INFO, |
| 377 | + 'rule_name_4': ErrorSeverity.NONE, |
| 378 | + }); |
| 379 | + }); |
| 380 | + |
| 381 | + test('Handles unknown error severity values', () { |
| 382 | + final analysisOptions = createAnalysisOptions(''' |
| 383 | +custom_lint: |
| 384 | + errors: |
| 385 | + rule_name_1: invalid_severity |
| 386 | +'''); |
| 387 | + expect( |
| 388 | + () => CustomLintConfigs.parse(analysisOptions, packageConfig), |
| 389 | + throwsA( |
| 390 | + isArgumentError.having( |
| 391 | + (e) => e.message, |
| 392 | + 'message', |
| 393 | + 'Provided error severity: invalid_severity specified for key: rule_name_1 is not valid. ' |
| 394 | + 'Valid error severities are: none, info, warning, error', |
| 395 | + ), |
| 396 | + ), |
| 397 | + ); |
| 398 | + }); |
| 399 | + |
| 400 | + test('Merges error severities from included config file', () { |
| 401 | + final includedFile = createAnalysisOptions(''' |
| 402 | +custom_lint: |
| 403 | + errors: |
| 404 | + rule_name_1: error |
| 405 | + rule_name_2: warning |
| 406 | +'''); |
| 407 | + |
| 408 | + final analysisOptions = createAnalysisOptions(''' |
| 409 | +include: ${includedFile.path} |
| 410 | +custom_lint: |
| 411 | + errors: |
| 412 | + rule_name_2: info |
| 413 | + rule_name_3: error |
| 414 | +'''); |
| 415 | + final configs = CustomLintConfigs.parse(analysisOptions, packageConfig); |
| 416 | + |
| 417 | + expect(configs.errors, { |
| 418 | + 'rule_name_1': ErrorSeverity.ERROR, |
| 419 | + 'rule_name_2': ErrorSeverity.INFO, |
| 420 | + 'rule_name_3': ErrorSeverity.ERROR, |
| 421 | + }); |
| 422 | + }); |
| 423 | + |
341 | 424 | group('package config', () {
|
342 | 425 | test('single package', () async {
|
343 | 426 | final dir = createDir();
|
|
353 | 436 |
|
354 | 437 | test('workspace', () async {
|
355 | 438 | final dir = createDir();
|
356 |
| - print(dir); |
357 | 439 | final projectPath = await createTempProject(
|
358 | 440 | tempDirPath: dir.path,
|
359 | 441 | projectName: testPackageName,
|
|
0 commit comments