Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(341)

Side by Side Diff: pkg/analyzer/lib/src/task/options.dart

Issue 2144383002: fix #26782, add no-implicit-casts, no-implicit-dynamic options (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: merged Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pkg/analyzer_cli/lib/src/driver.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.src.task.options; 5 library analyzer.src.task.options;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/analyzer.dart'; 9 import 'package:analyzer/analyzer.dart';
10 import 'package:analyzer/plugin/options.dart'; 10 import 'package:analyzer/plugin/options.dart';
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 static const String enableStrictCallChecks = 'enableStrictCallChecks'; 48 static const String enableStrictCallChecks = 'enableStrictCallChecks';
49 static const String enableSuperMixins = 'enableSuperMixins'; 49 static const String enableSuperMixins = 'enableSuperMixins';
50 static const String enableTrailingCommas = 'enableTrailingCommas'; 50 static const String enableTrailingCommas = 'enableTrailingCommas';
51 51
52 static const String errors = 'errors'; 52 static const String errors = 'errors';
53 static const String exclude = 'exclude'; 53 static const String exclude = 'exclude';
54 static const String language = 'language'; 54 static const String language = 'language';
55 static const String plugins = 'plugins'; 55 static const String plugins = 'plugins';
56 static const String strong_mode = 'strong-mode'; 56 static const String strong_mode = 'strong-mode';
57 57
58 // Strong mode options, see AnalysisOptionsImpl for documentation.
59 static const String implicitCasts = 'implicit-casts';
60 static const String implicitDynamic = 'implicit-dynamic';
61
58 /// Ways to say `ignore`. 62 /// Ways to say `ignore`.
59 static const List<String> ignoreSynonyms = const ['ignore', 'false']; 63 static const List<String> ignoreSynonyms = const ['ignore', 'false'];
60 64
61 /// Valid error `severity`s. 65 /// Valid error `severity`s.
62 static final List<String> severities = 66 static final List<String> severities =
63 new List.unmodifiable(severityMap.keys); 67 new List.unmodifiable(severityMap.keys);
64 68
65 /// Ways to say `include`. 69 /// Ways to say `include`.
66 static const List<String> includeSynonyms = const ['include', 'true']; 70 static const List<String> includeSynonyms = const ['include', 'true'];
67 71
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 */ 425 */
422 void applyToAnalysisOptions( 426 void applyToAnalysisOptions(
423 AnalysisOptionsImpl options, Map<String, Object> optionMap) { 427 AnalysisOptionsImpl options, Map<String, Object> optionMap) {
424 if (optionMap == null) { 428 if (optionMap == null) {
425 return; 429 return;
426 } 430 }
427 var analyzer = optionMap[AnalyzerOptions.analyzer]; 431 var analyzer = optionMap[AnalyzerOptions.analyzer];
428 if (analyzer is Map) { 432 if (analyzer is Map) {
429 // Process strong mode option. 433 // Process strong mode option.
430 var strongMode = analyzer[AnalyzerOptions.strong_mode]; 434 var strongMode = analyzer[AnalyzerOptions.strong_mode];
431 if (strongMode is bool) { 435 _applyStrongOptions(options, strongMode);
432 options.strongMode = strongMode; 436
433 }
434 // Process language options. 437 // Process language options.
435 var language = analyzer[AnalyzerOptions.language]; 438 var language = analyzer[AnalyzerOptions.language];
436 _applyLanguageOptions(options, language); 439 _applyLanguageOptions(options, language);
437 } 440 }
438 } 441 }
439 442
440 /// Configure [context] based on the given [options] (which can be `null` 443 /// Configure [context] based on the given [options] (which can be `null`
441 /// to restore [defaults]). 444 /// to restore [defaults]).
442 void configure(AnalysisContext context, Map<String, Object> options) { 445 void configure(AnalysisContext context, Map<String, Object> options) {
443 if (options == null) { 446 if (options == null) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 } 520 }
518 } 521 }
519 522
520 void setProcessors(AnalysisContext context, Object codes) { 523 void setProcessors(AnalysisContext context, Object codes) {
521 ErrorConfig config = new ErrorConfig(codes); 524 ErrorConfig config = new ErrorConfig(codes);
522 context.setConfigurationData( 525 context.setConfigurationData(
523 CONFIGURED_ERROR_PROCESSORS, config.processors); 526 CONFIGURED_ERROR_PROCESSORS, config.processors);
524 } 527 }
525 528
526 void setStrongMode(AnalysisContext context, Object strongMode) { 529 void setStrongMode(AnalysisContext context, Object strongMode) {
527 bool strong = strongMode is bool ? strongMode : false; 530 if (strongMode is Map) {
528 if (context.analysisOptions.strongMode != strong) {
529 AnalysisOptionsImpl options = 531 AnalysisOptionsImpl options =
530 new AnalysisOptionsImpl.from(context.analysisOptions); 532 new AnalysisOptionsImpl.from(context.analysisOptions);
531 options.strongMode = strong; 533 _applyStrongOptions(options, strongMode);
532 context.analysisOptions = options; 534 context.analysisOptions = options;
535 } else {
536 strongMode = strongMode is bool ? strongMode : false;
537 if (context.analysisOptions.strongMode != strongMode) {
538 AnalysisOptionsImpl options =
539 new AnalysisOptionsImpl.from(context.analysisOptions);
540 options.strongMode = strongMode;
541 context.analysisOptions = options;
542 }
533 } 543 }
534 } 544 }
535 545
536 void _applyLanguageOption( 546 void _applyLanguageOption(
537 AnalysisOptionsImpl options, Object feature, Object value) { 547 AnalysisOptionsImpl options, Object feature, Object value) {
538 bool boolValue = toBool(value); 548 bool boolValue = toBool(value);
539 if (boolValue != null) { 549 if (boolValue != null) {
540 if (feature == AnalyzerOptions.enableAsync) { 550 if (feature == AnalyzerOptions.enableAsync) {
541 options.enableAsync = boolValue; 551 options.enableAsync = boolValue;
542 } 552 }
(...skipping 12 matching lines...) Expand all
555 if (key is YamlScalar && value is YamlScalar) { 565 if (key is YamlScalar && value is YamlScalar) {
556 String feature = key.value?.toString(); 566 String feature = key.value?.toString();
557 _applyLanguageOption(options, feature, value.value); 567 _applyLanguageOption(options, feature, value.value);
558 } 568 }
559 }); 569 });
560 } else if (configs is Map) { 570 } else if (configs is Map) {
561 configs 571 configs
562 .forEach((key, value) => _applyLanguageOption(options, key, value)); 572 .forEach((key, value) => _applyLanguageOption(options, key, value));
563 } 573 }
564 } 574 }
575
576 void _applyStrongOptions(AnalysisOptionsImpl options, Object config) {
577 if (config is YamlMap) {
578 options.strongMode = true;
579 config.nodes.forEach((k, v) {
580 if (k is YamlScalar && v is YamlScalar) {
581 _applyStrongModeOption(options, k.value?.toString(), v.value);
582 }
583 });
584 } else if (config is Map) {
585 options.strongMode = true;
586 config.forEach((k, v) => _applyStrongModeOption(options, k, v));
587 } else {
588 options.strongMode = config is bool ? config : false;
589 }
590 }
591
592 void _applyStrongModeOption(
593 AnalysisOptionsImpl options, Object feature, Object value) {
594 bool boolValue = toBool(value);
595 if (boolValue != null) {
596 if (feature == AnalyzerOptions.implicitCasts) {
597 options.implicitCasts = boolValue;
598 }
599 if (feature == AnalyzerOptions.implicitDynamic) {
600 options.implicitDynamic = boolValue;
601 }
602 }
603 }
565 } 604 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer_cli/lib/src/driver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698