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 /// 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 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 'dashes such as "$name". Use "$newName" or "${newName.toLowerCase()}"
' | 360 'dashes such as "$name". Use "$newName" or "${newName.toLowerCase()}"
' |
361 'instead (both forms are equivalent in HTML).', span: span); | 361 'instead (both forms are equivalent in HTML).', span: span); |
362 return false; | 362 return false; |
363 } | 363 } |
364 return true; | 364 return true; |
365 } | 365 } |
366 | 366 |
367 /// Validate event handlers are used correctly. | 367 /// Validate event handlers are used correctly. |
368 void _validateEventHandler(Element node, String name, String value) { | 368 void _validateEventHandler(Element node, String name, String value) { |
369 if (!name.startsWith('on-')) { | 369 if (!name.startsWith('on-')) { |
| 370 // TODO(sigmund): technically these are valid attribtues in HTML, so we |
| 371 // might want to remove this warning, or only produce it if the value |
| 372 // looks like a binding. |
370 _logger.warning('Event handler "$name" will be interpreted as an inline' | 373 _logger.warning('Event handler "$name" will be interpreted as an inline' |
371 ' JavaScript event handler. Use the form ' | 374 ' JavaScript event handler. Use the form ' |
372 'on-event-name="handlerName" if you want a Dart handler ' | 375 'on-event-name="{{handlerName}}" if you want a Dart handler ' |
373 'that will automatically update the UI based on model changes.', | 376 'that will automatically update the UI based on model changes.', |
374 span: node.attributeSpans[name]); | 377 span: node.attributeSpans[name]); |
375 return; | 378 return; |
376 } | 379 } |
377 | 380 |
378 if (!_inPolymerElement) { | 381 if (!_inPolymerElement) { |
379 _logger.warning('Inline event handlers are only supported inside ' | 382 _logger.warning('Inline event handlers are only supported inside ' |
380 'declarations of <polymer-element>.', | 383 'declarations of <polymer-element>.', |
381 span: node.attributeSpans[name]); | 384 span: node.attributeSpans[name]); |
| 385 return; |
382 } | 386 } |
383 | 387 |
384 if (value.contains('(')) { | 388 |
| 389 // Valid bindings have {{ }}, don't look like method calls foo(bar), and are |
| 390 // non empty. |
| 391 if (!value.startsWith("{{") || !value.endsWith("}}") || value.contains('(') |
| 392 || value.substring(2, value.length - 2).trim() == '') { |
385 _logger.warning('Invalid event handler body "$value". Declare a method ' | 393 _logger.warning('Invalid event handler body "$value". Declare a method ' |
386 'in your custom element "void handlerName(event, detail, target)" ' | 394 'in your custom element "void handlerName(event, detail, target)" ' |
387 'and use the form $name="handlerName".', | 395 'and use the form $name="{{handlerName}}".', |
388 span: node.attributeSpans[name]); | 396 span: node.attributeSpans[name]); |
389 } | 397 } |
390 } | 398 } |
391 } | 399 } |
392 | 400 |
393 const String ONLY_ONE_TAG = | 401 const String ONLY_ONE_TAG = |
394 'Only one "application/dart" script tag per document is allowed.'; | 402 'Only one "application/dart" script tag per document is allowed.'; |
395 | 403 |
396 const String USE_POLYMER_HTML = | 404 const String USE_POLYMER_HTML = |
397 'Besides the initPolymer invocation, to run a polymer application you need ' | 405 'Besides the initPolymer invocation, to run a polymer application you need ' |
398 'to include the following HTML import: ' | 406 'to include the following HTML import: ' |
399 '<link rel="import" href="packages/polymer/polymer.html">. This will ' | 407 '<link rel="import" href="packages/polymer/polymer.html">. This will ' |
400 'include the common polymer logic needed to boostrap your application.'; | 408 'include the common polymer logic needed to boostrap your application.'; |
401 | 409 |
402 const String USE_INIT_DART = | 410 const String USE_INIT_DART = |
403 'To run a polymer application, you need to call "initPolymer". You can ' | 411 'To run a polymer application, you need to call "initPolymer". You can ' |
404 'either include a generic script tag that does this for you:' | 412 'either include a generic script tag that does this for you:' |
405 '\'<script type="application/dart">export "package:polymer/init.dart";' | 413 '\'<script type="application/dart">export "package:polymer/init.dart";' |
406 '</script>\' or add your own script tag and call that function. ' | 414 '</script>\' or add your own script tag and call that function. ' |
407 'Make sure the script tag is placed after all HTML imports.'; | 415 'Make sure the script tag is placed after all HTML imports.'; |
408 | 416 |
409 const String NO_DART_SCRIPT_AND_EXPERIMENTAL = | 417 const String NO_DART_SCRIPT_AND_EXPERIMENTAL = |
410 'The experimental bootstrap feature doesn\'t support script tags on ' | 418 'The experimental bootstrap feature doesn\'t support script tags on ' |
411 'the main document (for now).'; | 419 'the main document (for now).'; |
OLD | NEW |