| OLD | NEW |
| 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 /** | 5 /** |
| 6 * Logic to validate that developers are correctly using Polymer constructs. | 6 * Logic to validate that developers are correctly using Polymer constructs. |
| 7 * This is mainly used to produce warnings for feedback in the editor. | 7 * This is mainly used to produce warnings for feedback in the editor. |
| 8 */ | 8 */ |
| 9 library polymer.src.build.linter; | 9 library polymer.src.build.linter; |
| 10 | 10 |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 break; | 247 break; |
| 248 } | 248 } |
| 249 } | 249 } |
| 250 | 250 |
| 251 void run(Document doc) { | 251 void run(Document doc) { |
| 252 visit(doc); | 252 visit(doc); |
| 253 | 253 |
| 254 if (_isEntrypoint && !_dartTagSeen) { | 254 if (_isEntrypoint && !_dartTagSeen) { |
| 255 _logger.error(USE_INIT_DART, span: doc.body.sourceSpan); | 255 _logger.error(USE_INIT_DART, span: doc.body.sourceSpan); |
| 256 } | 256 } |
| 257 |
| 258 if (_isEntrypoint && !_dartJSSeen) { |
| 259 // TODO(sigmund): remove this when webkitStartDart is gone. |
| 260 _logger.error(USE_DART_JS, span: doc.body.sourceSpan); |
| 261 } |
| 257 } | 262 } |
| 258 | 263 |
| 259 /** Produce warnings for invalid link-rel tags. */ | 264 /** Produce warnings for invalid link-rel tags. */ |
| 260 void _validateLinkElement(Element node) { | 265 void _validateLinkElement(Element node) { |
| 261 var rel = node.attributes['rel']; | 266 var rel = node.attributes['rel']; |
| 262 if (rel != 'import' && rel != 'stylesheet') return; | 267 if (rel != 'import' && rel != 'stylesheet') return; |
| 263 | 268 |
| 264 if (rel == 'import' && _dartTagSeen) { | 269 if (rel == 'import' && _dartTagSeen) { |
| 265 _logger.warning( | 270 _logger.warning( |
| 266 "Move HTML imports above your Dart script tag.", | 271 "Move HTML imports above your Dart script tag.", |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 span: node.attributeSpans[name]); | 489 span: node.attributeSpans[name]); |
| 485 return; | 490 return; |
| 486 } | 491 } |
| 487 | 492 |
| 488 if (!_inPolymerElement) { | 493 if (!_inPolymerElement) { |
| 489 _logger.warning('Inline event handlers are only supported inside ' | 494 _logger.warning('Inline event handlers are only supported inside ' |
| 490 'declarations of <polymer-element>.', | 495 'declarations of <polymer-element>.', |
| 491 span: node.attributeSpans[name]); | 496 span: node.attributeSpans[name]); |
| 492 } | 497 } |
| 493 | 498 |
| 499 var eventName = name.substring('on-'.length); |
| 500 if (eventName.contains('-')) { |
| 501 var newEvent = toCamelCase(eventName); |
| 502 _logger.warning('Invalid event name "$name". After the "on-" the event ' |
| 503 'name should not use dashes. For example use "on-$newEvent" or ' |
| 504 '"on-${newEvent.toLowerCase()}" (both forms are equivalent in HTML).', |
| 505 span: node.attributeSpans[name]); |
| 506 } |
| 507 |
| 494 if (value.contains('.') || value.contains('(')) { | 508 if (value.contains('.') || value.contains('(')) { |
| 495 _logger.warning('Invalid event handler body "$value". Declare a method ' | 509 _logger.warning('Invalid event handler body "$value". Declare a method ' |
| 496 'in your custom element "void handlerName(event, detail, target)" ' | 510 'in your custom element "void handlerName(event, detail, target)" ' |
| 497 'and use the form $name="handlerName".', | 511 'and use the form $name="handlerName".', |
| 498 span: node.attributeSpans[name]); | 512 span: node.attributeSpans[name]); |
| 499 } | 513 } |
| 500 } | 514 } |
| 501 } | 515 } |
| 502 | 516 |
| 503 | 517 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 521 bool _isCustomTag(String name) { | 535 bool _isCustomTag(String name) { |
| 522 if (name == null || !name.contains('-')) return false; | 536 if (name == null || !name.contains('-')) return false; |
| 523 return !_invalidTagNames.containsKey(name); | 537 return !_invalidTagNames.containsKey(name); |
| 524 } | 538 } |
| 525 | 539 |
| 526 const String _RED_COLOR = '\u001b[31m'; | 540 const String _RED_COLOR = '\u001b[31m'; |
| 527 const String _MAGENTA_COLOR = '\u001b[35m'; | 541 const String _MAGENTA_COLOR = '\u001b[35m'; |
| 528 const String _NO_COLOR = '\u001b[0m'; | 542 const String _NO_COLOR = '\u001b[0m'; |
| 529 | 543 |
| 530 const String USE_INIT_DART = | 544 const String USE_INIT_DART = |
| 531 'To run a polymer application, you need to call "initPolymer". You can ' | 545 'To run a polymer applications, you need to call "initPolymer". You can ' |
| 532 'either include a generic script tag that does this for you:' | 546 'either include a generic script tag that does this for you:' |
| 533 '\'<script type="application/dart">export "package:polymer/init.dart";' | 547 '\'<script type="application/dart">export "package:polymer/init.dart";' |
| 534 '</script>\' or add your own script tag and call that function. ' | 548 '</script>\' or add your own script tag and call that function. ' |
| 535 'Make sure the script tag is placed after all HTML imports.'; | 549 'Make sure the script tag is placed after all HTML imports.'; |
| 536 | 550 |
| 551 const String USE_DART_JS = |
| 552 'To run a polymer applications in Dartium, make sure to include' |
| 553 '\'<script src="packages/browser/dart.js"></script>\' in your page'; |
| 554 |
| 537 const String BOOT_JS_DEPRECATED = | 555 const String BOOT_JS_DEPRECATED = |
| 538 '"boot.js" is now deprecated. Instead, you can initialize your polymer ' | 556 '"boot.js" is now deprecated. Instead, you can initialize your polymer ' |
| 539 'application by calling "initPolymer()" in your main. If you don\'t have a ' | 557 'application by calling "initPolymer()" in your main. If you don\'t have a ' |
| 540 'main, then you can include our generic main by adding the following ' | 558 'main, then you can include our generic main by adding the following ' |
| 541 'script tag to your page: \'<script type="application/dart">export ' | 559 'script tag to your page: \'<script type="application/dart">export ' |
| 542 '"package:polymer/init.dart";</script>\'. Additionally you need to ' | 560 '"package:polymer/init.dart";</script>\'. Additionally you need to ' |
| 543 'include: \'<script src="packages/browser/dart.js"></script>\' in the page ' | 561 'include: \'<script src="packages/browser/dart.js"></script>\' in the page ' |
| 544 'too. Make sure these script tags come after all HTML imports.'; | 562 'too. Make sure these script tags come after all HTML imports.'; |
| OLD | NEW |