| 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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 var src = node.attributes['src']; | 280 var src = node.attributes['src']; |
| 281 | 281 |
| 282 if (isDart) { | 282 if (isDart) { |
| 283 if (_dartTagSeen) _logger.warning(ONLY_ONE_TAG, span: node.sourceSpan); | 283 if (_dartTagSeen) _logger.warning(ONLY_ONE_TAG, span: node.sourceSpan); |
| 284 if (_isEntrypoint && _polymerExperimentalHtmlSeen) { | 284 if (_isEntrypoint && _polymerExperimentalHtmlSeen) { |
| 285 _logger.warning(NO_DART_SCRIPT_AND_EXPERIMENTAL, span: node.sourceSpan); | 285 _logger.warning(NO_DART_SCRIPT_AND_EXPERIMENTAL, span: node.sourceSpan); |
| 286 } | 286 } |
| 287 _dartTagSeen = true; | 287 _dartTagSeen = true; |
| 288 } | 288 } |
| 289 | 289 |
| 290 if (src == null) return; | 290 var isEmpty = node.innerHtml.trim() == ''; |
| 291 |
| 292 if (src == null) { |
| 293 if (isDart && isEmpty) { |
| 294 _logger.warning('script tag seems empty.', span: node.sourceSpan); |
| 295 } |
| 296 return; |
| 297 } |
| 291 | 298 |
| 292 if (src.endsWith('.dart') && !isDart) { | 299 if (src.endsWith('.dart') && !isDart) { |
| 293 _logger.warning('Wrong script type, expected type="application/dart".', | 300 _logger.warning('Wrong script type, expected type="application/dart".', |
| 294 span: node.sourceSpan); | 301 span: node.sourceSpan); |
| 295 return; | 302 return; |
| 296 } | 303 } |
| 297 | 304 |
| 298 if (!src.endsWith('.dart') && isDart) { | 305 if (!src.endsWith('.dart') && isDart) { |
| 299 _logger.warning('"application/dart" scripts should use the .dart file ' | 306 _logger.warning('"application/dart" scripts should use the .dart file ' |
| 300 'extension.', span: node.sourceSpan); | 307 'extension.', span: node.sourceSpan); |
| 301 return; | 308 return; |
| 302 } | 309 } |
| 303 | 310 |
| 304 if (node.innerHtml.trim() != '') { | 311 if (!isEmpty) { |
| 305 _logger.warning('script tag has "src" attribute and also has script ' | 312 _logger.warning('script tag has "src" attribute and also has script ' |
| 306 'text.', span: node.sourceSpan); | 313 'text.', span: node.sourceSpan); |
| 307 } | 314 } |
| 308 } | 315 } |
| 309 | 316 |
| 310 /// Produces warnings for misuses of on-foo event handlers, and for instanting | 317 /// Produces warnings for misuses of on-foo event handlers, and for instanting |
| 311 /// custom tags incorrectly. | 318 /// custom tags incorrectly. |
| 312 void _validateNormalElement(Element node) { | 319 void _validateNormalElement(Element node) { |
| 313 // Event handlers only allowed inside polymer-elements | 320 // Event handlers only allowed inside polymer-elements |
| 314 node.attributes.forEach((name, value) { | 321 node.attributes.forEach((name, value) { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 const String USE_INIT_DART = | 444 const String USE_INIT_DART = |
| 438 'To run a polymer application, you need to call "initPolymer". You can ' | 445 'To run a polymer application, you need to call "initPolymer". You can ' |
| 439 'either include a generic script tag that does this for you:' | 446 'either include a generic script tag that does this for you:' |
| 440 '\'<script type="application/dart">export "package:polymer/init.dart";' | 447 '\'<script type="application/dart">export "package:polymer/init.dart";' |
| 441 '</script>\' or add your own script tag and call that function. ' | 448 '</script>\' or add your own script tag and call that function. ' |
| 442 'Make sure the script tag is placed after all HTML imports.'; | 449 'Make sure the script tag is placed after all HTML imports.'; |
| 443 | 450 |
| 444 const String NO_DART_SCRIPT_AND_EXPERIMENTAL = | 451 const String NO_DART_SCRIPT_AND_EXPERIMENTAL = |
| 445 'The experimental bootstrap feature doesn\'t support script tags on ' | 452 'The experimental bootstrap feature doesn\'t support script tags on ' |
| 446 'the main document (for now).'; | 453 'the main document (for now).'; |
| OLD | NEW |