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

Side by Side Diff: pkg/polymer/lib/src/build/linter.dart

Issue 334003003: Reduce warnings in polymer: (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « pkg/polymer/lib/src/build/common.dart ('k') | pkg/polymer/pubspec.yaml » ('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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 /// Logic to validate that developers are correctly using Polymer constructs. 5 /// Logic to validate that developers are correctly using Polymer constructs.
6 /// This is mainly used to produce warnings for feedback in the editor. 6 /// This is mainly used to produce warnings for feedback in the editor.
7 library polymer.src.build.linter; 7 library polymer.src.build.linter;
8 8
9 import 'dart:async'; 9 import 'dart:async';
10 10
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 } 64 }
65 return _addElements(document, transform.logger, elements); 65 return _addElements(document, transform.logger, elements);
66 }) 66 })
67 .then((_) => elements); 67 .then((_) => elements);
68 } 68 }
69 69
70 Future _readAndCollectElements(AssetId id, Transform transform, 70 Future _readAndCollectElements(AssetId id, Transform transform,
71 Set<AssetId> seen, Map<String, _ElementSummary> elements) { 71 Set<AssetId> seen, Map<String, _ElementSummary> elements) {
72 if (id == null || seen.contains(id)) return new Future.value(null); 72 if (id == null || seen.contains(id)) return new Future.value(null);
73 seen.add(id); 73 seen.add(id);
74 return readAsHtml(id, transform).then( 74 return readAsHtml(id, transform, showWarnings: false).then(
75 (doc) => _collectElements(doc, id, transform, seen, elements)); 75 (doc) => _collectElements(doc, id, transform, seen, elements));
76 } 76 }
77 77
78 Future<List<AssetId>> _getImportedIds( 78 Future<List<AssetId>> _getImportedIds(
79 Document document, AssetId sourceId, Transform transform) { 79 Document document, AssetId sourceId, Transform transform) {
80 var importIds = []; 80 var importIds = [];
81 var logger = transform.logger; 81 var logger = transform.logger;
82 for (var tag in document.querySelectorAll('link')) { 82 for (var tag in document.querySelectorAll('link')) {
83 if (tag.attributes['rel'] != 'import') continue; 83 if (tag.attributes['rel'] != 'import') continue;
84 var href = tag.attributes['href']; 84 var href = tag.attributes['href'];
85 var span = tag.sourceSpan; 85 var span = tag.sourceSpan;
86 var id = uriToAssetId(sourceId, href, logger, span); 86 var id = uriToAssetId(sourceId, href, logger, span);
87 if (id == null) continue; 87 if (id == null) continue;
88 importIds.add(assetExists(id, transform).then((exists) { 88 importIds.add(assetExists(id, transform).then((exists) {
89 if (exists) return id; 89 if (exists) return id;
90 if (sourceId == transform.primaryInput.id) { 90 if (sourceId == transform.primaryInput.id) {
91 logger.error('couldn\'t find imported asset "${id.path}" in package ' 91 logger.warning('couldn\'t find imported asset "${id.path}" in package'
Siggi Cherem (dart-lang) 2014/06/14 02:24:57 no reason to make this an error (errors make the b
92 '"${id.package}".', span: span); 92 ' "${id.package}".', span: span);
93 } 93 }
94 })); 94 }));
95 } 95 }
96 return Future.wait(importIds); 96 return Future.wait(importIds);
97 } 97 }
98 98
99 void _addElements(Document document, TransformLogger logger, 99 void _addElements(Document document, TransformLogger logger,
100 Map<String, _ElementSummary> elements) { 100 Map<String, _ElementSummary> elements) {
101 for (var tag in document.querySelectorAll('polymer-element')) { 101 for (var tag in document.querySelectorAll('polymer-element')) {
102 var name = tag.attributes['name']; 102 var name = tag.attributes['name'];
(...skipping 25 matching lines...) Expand all
128 /// Note: these are only created for polymer-element, because pure custom 128 /// Note: these are only created for polymer-element, because pure custom
129 /// elements don't have a declarative form. 129 /// elements don't have a declarative form.
130 class _ElementSummary { 130 class _ElementSummary {
131 final String tagName; 131 final String tagName;
132 final String extendsTag; 132 final String extendsTag;
133 final Span span; 133 final Span span;
134 134
135 _ElementSummary extendsType; 135 _ElementSummary extendsType;
136 bool hasConflict = false; 136 bool hasConflict = false;
137 137
138 String get baseExtendsTag => extendsType == null 138 String get baseExtendsTag {
139 ? extendsTag : extendsType.baseExtendsTag; 139 if (extendsType != null) return extendsType.baseExtendsTag;
140 if (extendsTag != null && !extendsTag.contains('-')) return extendsTag;
Siggi Cherem (dart-lang) 2014/06/14 02:24:57 this compensates for allowing the warning above
141 return null;
142 }
140 143
141 _ElementSummary(this.tagName, this.extendsTag, this.span); 144 _ElementSummary(this.tagName, this.extendsTag, this.span);
142 145
143 String toString() => "($tagName <: $extendsTag)"; 146 String toString() => "($tagName <: $extendsTag)";
144 } 147 }
145 148
146 class _LinterVisitor extends TreeVisitor { 149 class _LinterVisitor extends TreeVisitor {
147 TransformLogger _logger; 150 TransformLogger _logger;
148 AssetId _sourceId; 151 AssetId _sourceId;
149 bool _inPolymerElement = false; 152 bool _inPolymerElement = false;
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 _logger.warning('PolymerElement no longer recognizes attribute names with ' 378 _logger.warning('PolymerElement no longer recognizes attribute names with '
376 'dashes such as "$name". Use "$newName" or "${newName.toLowerCase()}" ' 379 'dashes such as "$name". Use "$newName" or "${newName.toLowerCase()}" '
377 'instead (both forms are equivalent in HTML).', span: span); 380 'instead (both forms are equivalent in HTML).', span: span);
378 return false; 381 return false;
379 } 382 }
380 return true; 383 return true;
381 } 384 }
382 385
383 /// Validate event handlers are used correctly. 386 /// Validate event handlers are used correctly.
384 void _validateEventHandler(Element node, String name, String value) { 387 void _validateEventHandler(Element node, String name, String value) {
385 if (!name.startsWith('on-')) { 388 if (!name.startsWith('on-')) return;
386 // TODO(sigmund): technically these are valid attribtues in HTML, so we
387 // might want to remove this warning, or only produce it if the value
388 // looks like a binding.
389 _logger.warning('Event handler "$name" will be interpreted as an inline'
390 ' JavaScript event handler. Use the form '
391 'on-event-name="{{handlerName}}" if you want a Dart handler '
392 'that will automatically update the UI based on model changes.',
393 span: node.attributeSpans[name]);
394 return;
395 }
396 389
397 if (!_inPolymerElement) { 390 if (!_inPolymerElement) {
398 _logger.warning('Inline event handlers are only supported inside ' 391 _logger.warning('Inline event handlers are only supported inside '
399 'declarations of <polymer-element>.', 392 'declarations of <polymer-element>.',
400 span: node.attributeSpans[name]); 393 span: node.attributeSpans[name]);
401 return; 394 return;
402 } 395 }
403 396
404 397
405 // Valid bindings have {{ }}, don't look like method calls foo(bar), and are 398 // Valid bindings have {{ }}, don't look like method calls foo(bar), and are
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 const String USE_INIT_DART = 437 const String USE_INIT_DART =
445 'To run a polymer application, you need to call "initPolymer". You can ' 438 'To run a polymer application, you need to call "initPolymer". You can '
446 'either include a generic script tag that does this for you:' 439 'either include a generic script tag that does this for you:'
447 '\'<script type="application/dart">export "package:polymer/init.dart";' 440 '\'<script type="application/dart">export "package:polymer/init.dart";'
448 '</script>\' or add your own script tag and call that function. ' 441 '</script>\' or add your own script tag and call that function. '
449 'Make sure the script tag is placed after all HTML imports.'; 442 'Make sure the script tag is placed after all HTML imports.';
450 443
451 const String NO_DART_SCRIPT_AND_EXPERIMENTAL = 444 const String NO_DART_SCRIPT_AND_EXPERIMENTAL =
452 'The experimental bootstrap feature doesn\'t support script tags on ' 445 'The experimental bootstrap feature doesn\'t support script tags on '
453 'the main document (for now).'; 446 'the main document (for now).';
OLDNEW
« no previous file with comments | « pkg/polymer/lib/src/build/common.dart ('k') | pkg/polymer/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698