| 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 } | |
| 262 } | 257 } |
| 263 | 258 |
| 264 /** Produce warnings for invalid link-rel tags. */ | 259 /** Produce warnings for invalid link-rel tags. */ |
| 265 void _validateLinkElement(Element node) { | 260 void _validateLinkElement(Element node) { |
| 266 var rel = node.attributes['rel']; | 261 var rel = node.attributes['rel']; |
| 267 if (rel != 'import' && rel != 'stylesheet') return; | 262 if (rel != 'import' && rel != 'stylesheet') return; |
| 268 | 263 |
| 269 if (rel == 'import' && _dartTagSeen) { | 264 if (rel == 'import' && _dartTagSeen) { |
| 270 _logger.warning( | 265 _logger.warning( |
| 271 "Move HTML imports above your Dart script tag.", | 266 "Move HTML imports above your Dart script tag.", |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 span: node.attributeSpans[name]); | 484 span: node.attributeSpans[name]); |
| 490 return; | 485 return; |
| 491 } | 486 } |
| 492 | 487 |
| 493 if (!_inPolymerElement) { | 488 if (!_inPolymerElement) { |
| 494 _logger.warning('Inline event handlers are only supported inside ' | 489 _logger.warning('Inline event handlers are only supported inside ' |
| 495 'declarations of <polymer-element>.', | 490 'declarations of <polymer-element>.', |
| 496 span: node.attributeSpans[name]); | 491 span: node.attributeSpans[name]); |
| 497 } | 492 } |
| 498 | 493 |
| 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 | |
| 508 if (value.contains('.') || value.contains('(')) { | 494 if (value.contains('.') || value.contains('(')) { |
| 509 _logger.warning('Invalid event handler body "$value". Declare a method ' | 495 _logger.warning('Invalid event handler body "$value". Declare a method ' |
| 510 'in your custom element "void handlerName(event, detail, target)" ' | 496 'in your custom element "void handlerName(event, detail, target)" ' |
| 511 'and use the form $name="handlerName".', | 497 'and use the form $name="handlerName".', |
| 512 span: node.attributeSpans[name]); | 498 span: node.attributeSpans[name]); |
| 513 } | 499 } |
| 514 } | 500 } |
| 515 } | 501 } |
| 516 | 502 |
| 517 | 503 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 535 bool _isCustomTag(String name) { | 521 bool _isCustomTag(String name) { |
| 536 if (name == null || !name.contains('-')) return false; | 522 if (name == null || !name.contains('-')) return false; |
| 537 return !_invalidTagNames.containsKey(name); | 523 return !_invalidTagNames.containsKey(name); |
| 538 } | 524 } |
| 539 | 525 |
| 540 const String _RED_COLOR = '\u001b[31m'; | 526 const String _RED_COLOR = '\u001b[31m'; |
| 541 const String _MAGENTA_COLOR = '\u001b[35m'; | 527 const String _MAGENTA_COLOR = '\u001b[35m'; |
| 542 const String _NO_COLOR = '\u001b[0m'; | 528 const String _NO_COLOR = '\u001b[0m'; |
| 543 | 529 |
| 544 const String USE_INIT_DART = | 530 const String USE_INIT_DART = |
| 545 'To run a polymer applications, you need to call "initPolymer". You can ' | 531 'To run a polymer application, you need to call "initPolymer". You can ' |
| 546 'either include a generic script tag that does this for you:' | 532 'either include a generic script tag that does this for you:' |
| 547 '\'<script type="application/dart">export "package:polymer/init.dart";' | 533 '\'<script type="application/dart">export "package:polymer/init.dart";' |
| 548 '</script>\' or add your own script tag and call that function. ' | 534 '</script>\' or add your own script tag and call that function. ' |
| 549 'Make sure the script tag is placed after all HTML imports.'; | 535 'Make sure the script tag is placed after all HTML imports.'; |
| 550 | 536 |
| 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 | |
| 555 const String BOOT_JS_DEPRECATED = | 537 const String BOOT_JS_DEPRECATED = |
| 556 '"boot.js" is now deprecated. Instead, you can initialize your polymer ' | 538 '"boot.js" is now deprecated. Instead, you can initialize your polymer ' |
| 557 'application by calling "initPolymer()" in your main. If you don\'t have a ' | 539 'application by calling "initPolymer()" in your main. If you don\'t have a ' |
| 558 'main, then you can include our generic main by adding the following ' | 540 'main, then you can include our generic main by adding the following ' |
| 559 'script tag to your page: \'<script type="application/dart">export ' | 541 'script tag to your page: \'<script type="application/dart">export ' |
| 560 '"package:polymer/init.dart";</script>\'. Additionally you need to ' | 542 '"package:polymer/init.dart";</script>\'. Additionally you need to ' |
| 561 'include: \'<script src="packages/browser/dart.js"></script>\' in the page ' | 543 'include: \'<script src="packages/browser/dart.js"></script>\' in the page ' |
| 562 'too. Make sure these script tags come after all HTML imports.'; | 544 'too. Make sure these script tags come after all HTML imports.'; |
| OLD | NEW |