| 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 library polymer.test.linter_test; | 5 library polymer.test.linter_test; |
| 6 | 6 |
| 7 import 'dart:convert'; | 7 import 'dart:convert'; |
| 8 | 8 |
| 9 import 'package:polymer/src/build/common.dart'; | 9 import 'package:polymer/src/build/common.dart'; |
| 10 import 'package:polymer/src/build/linter.dart'; | 10 import 'package:polymer/src/build/linter.dart'; |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 group('single script tag per document', () { | 157 group('single script tag per document', () { |
| 158 _testLinter('two top-level tags', { | 158 _testLinter('two top-level tags', { |
| 159 'a|web/test.html': '<!DOCTYPE html><html>' | 159 'a|web/test.html': '<!DOCTYPE html><html>' |
| 160 '<link rel="import" href="packages/polymer/polymer.html">' | 160 '<link rel="import" href="packages/polymer/polymer.html">' |
| 161 '<script type="application/dart" src="a.dart">' | 161 '<script type="application/dart" src="a.dart">' |
| 162 '</script>\n' | 162 '</script>\n' |
| 163 '<script type="application/dart" src="b.dart">' | 163 '<script type="application/dart" src="b.dart">' |
| 164 '</script>' | 164 '</script>' |
| 165 '<script src="packages/browser/dart.js"></script>', | 165 '<script src="packages/browser/dart.js"></script>', |
| 166 }, [ | 166 }, [ |
| 167 'warning: Only one "application/dart" script tag per document is' | 167 'warning: ${ONLY_ONE_TAG.snippet} (web/test.html 1 0)', |
| 168 ' allowed. (web/test.html 1 0)', | |
| 169 ]); | 168 ]); |
| 170 | 169 |
| 171 _testLinter('two top-level tags, non entrypoint', { | 170 _testLinter('two top-level tags, non entrypoint', { |
| 172 'a|lib/test.html': '<!DOCTYPE html><html>' | 171 'a|lib/test.html': '<!DOCTYPE html><html>' |
| 173 '<script type="application/dart" src="a.dart">' | 172 '<script type="application/dart" src="a.dart">' |
| 174 '</script>\n' | 173 '</script>\n' |
| 175 '<script type="application/dart" src="b.dart">' | 174 '<script type="application/dart" src="b.dart">' |
| 176 '</script>' | 175 '</script>' |
| 177 '<script src="packages/browser/dart.js"></script>' | 176 '<script src="packages/browser/dart.js"></script>' |
| 178 }, [ | 177 }, [ |
| 179 'warning: Only one "application/dart" script tag per document is' | 178 'warning: ${ONLY_ONE_TAG.snippet} (lib/test.html 1 0)', |
| 180 ' allowed. (lib/test.html 1 0)', | |
| 181 ]); | 179 ]); |
| 182 | 180 |
| 183 _testLinter('tags inside elements', { | 181 _testLinter('tags inside elements', { |
| 184 'a|web/test.html': '<!DOCTYPE html><html>' | 182 'a|web/test.html': '<!DOCTYPE html><html>' |
| 185 '<link rel="import" href="packages/polymer/polymer.html">' | 183 '<link rel="import" href="packages/polymer/polymer.html">' |
| 186 '<polymer-element name="x-a">' | 184 '<polymer-element name="x-a">' |
| 187 '<script type="application/dart" src="a.dart">' | 185 '<script type="application/dart" src="a.dart">' |
| 188 '</script>' | 186 '</script>' |
| 189 '</polymer-element>\n' | 187 '</polymer-element>\n' |
| 190 '<script type="application/dart" src="b.dart">' | 188 '<script type="application/dart" src="b.dart">' |
| 191 '</script>' | 189 '</script>' |
| 192 '<script src="packages/browser/dart.js"></script>', | 190 '<script src="packages/browser/dart.js"></script>', |
| 193 }, [ | 191 }, [ |
| 194 'warning: Only one "application/dart" script tag per document is' | 192 'warning: ${ONLY_ONE_TAG.snippet} (web/test.html 1 0)', |
| 195 ' allowed. (web/test.html 1 0)', | |
| 196 ]); | 193 ]); |
| 197 }); | 194 }); |
| 198 | 195 |
| 199 group('doctype warning', () { | 196 group('doctype warning', () { |
| 200 _testLinter('in web', { | 197 _testLinter('in web', { |
| 201 'a|web/test.html': '<html></html>', | 198 'a|web/test.html': '<html></html>', |
| 202 }, [ | 199 }, [ |
| 203 'warning: (from html5lib) Unexpected start tag (html). ' | 200 'warning: (from html5lib) Unexpected start tag (html). ' |
| 204 'Expected DOCTYPE. (web/test.html 0 0)', | 201 'Expected DOCTYPE. (web/test.html 0 0)', |
| 205 'warning: ${MISSING_INIT_POLYMER.snippet}', | 202 'warning: ${MISSING_INIT_POLYMER.snippet}', |
| 206 ]); | 203 ]); |
| 207 | 204 |
| 208 _testLinter('in lib', { | 205 _testLinter('in lib', { |
| 209 'a|lib/test.html': '<html></html>', | 206 'a|lib/test.html': '<html></html>', |
| 210 }, []); | 207 }, []); |
| 211 }); | 208 }); |
| 212 | 209 |
| 213 group('duplicate polymer-elements,', () { | 210 group('duplicate polymer-elements,', () { |
| 214 _testLinter('same file', { | 211 _testLinter('same file', { |
| 215 'a|lib/test.html': '''<html> | 212 'a|lib/test.html': '''<html> |
| 216 <link rel="import" href="../../packages/polymer/polymer.html"> | 213 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 217 <polymer-element name="x-a"></polymer-element> | 214 <polymer-element name="x-a"></polymer-element> |
| 218 <polymer-element name="x-a"></polymer-element> | 215 <polymer-element name="x-a"></polymer-element> |
| 219 </html>'''.replaceAll(' ', ''), | 216 </html>'''.replaceAll(' ', ''), |
| 220 }, [ | 217 }, [ |
| 221 'warning: duplicate definition for custom tag "x-a". ' | 218 'warning: ${DUPLICATE_DEFINITION.create( |
| 222 '(lib/test.html 2 0)', | 219 {'name': 'x-a', 'second': ''}).snippet} (lib/test.html 2 0)', |
| 223 'warning: duplicate definition for custom tag "x-a". ' | 220 'warning: ${DUPLICATE_DEFINITION.create( |
| 224 '(second definition). (lib/test.html 3 0)' | 221 {'name': 'x-a', 'second': ' (second definition).'}).snippet} ' |
| 222 '(lib/test.html 3 0)', |
| 225 ]); | 223 ]); |
| 226 | 224 |
| 227 _testLinter('other file', { | 225 _testLinter('other file', { |
| 228 'a|lib/b.html': '''<html> | 226 'a|lib/b.html': '''<html> |
| 229 <link rel="import" href="../../packages/polymer/polymer.html"> | 227 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 230 <polymer-element name="x-a"></polymer-element> | 228 <polymer-element name="x-a"></polymer-element> |
| 231 </html>'''.replaceAll(' ', ''), | 229 </html>'''.replaceAll(' ', ''), |
| 232 'a|lib/test.html': '''<html> | 230 'a|lib/test.html': '''<html> |
| 233 <link rel="import" href="b.html"> | 231 <link rel="import" href="b.html"> |
| 234 <polymer-element name="x-a"></polymer-element> | 232 <polymer-element name="x-a"></polymer-element> |
| 235 </html>'''.replaceAll(' ', ''), | 233 </html>'''.replaceAll(' ', ''), |
| 236 }, [ | 234 }, [ |
| 237 'warning: duplicate definition for custom tag "x-a". ' | 235 'warning: ${DUPLICATE_DEFINITION.create( |
| 238 '(lib/b.html 2 0)', | 236 {'name': 'x-a', 'second': ''}).snippet} (lib/b.html 2 0)', |
| 239 'warning: duplicate definition for custom tag "x-a". ' | 237 'warning: ${DUPLICATE_DEFINITION.create( |
| 240 '(second definition). (lib/test.html 2 0)' | 238 {'name': 'x-a', 'second': ' (second definition).'}).snippet} ' |
| 239 '(lib/test.html 2 0)', |
| 241 ]); | 240 ]); |
| 242 | 241 |
| 243 _testLinter('non existing file', { | 242 _testLinter('non existing file', { |
| 244 'a|lib/test.html': '''<html> | 243 'a|lib/test.html': '''<html> |
| 245 <link rel="import" href="../../packages/polymer/polymer.html"> | 244 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 246 <link rel="import" href="b.html"> | 245 <link rel="import" href="b.html"> |
| 247 <polymer-element name="x-a"></polymer-element> | 246 <polymer-element name="x-a"></polymer-element> |
| 248 </html>'''.replaceAll(' ', ''), | 247 </html>'''.replaceAll(' ', ''), |
| 249 }, [ | 248 }, [ |
| 250 'warning: couldn\'t find imported asset "lib/b.html" in package ' | 249 'warning: ${IMPORT_NOT_FOUND.create( |
| 251 '"a". (lib/test.html 2 0)' | 250 {'path': 'lib/b.html', 'package': 'a'}).snippet} ' |
| 251 '(lib/test.html 2 0)' |
| 252 ]); | 252 ]); |
| 253 | 253 |
| 254 _testLinter('other package', { | 254 _testLinter('other package', { |
| 255 'b|lib/b.html': '''<html> | 255 'b|lib/b.html': '''<html> |
| 256 <link rel="import" href="../../packages/polymer/polymer.html"> | 256 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 257 <polymer-element name="x-a"></polymer-element> | 257 <polymer-element name="x-a"></polymer-element> |
| 258 </html>'''.replaceAll(' ', ''), | 258 </html>'''.replaceAll(' ', ''), |
| 259 'a|lib/test.html': '''<html> | 259 'a|lib/test.html': '''<html> |
| 260 <link rel="import" href="../../packages/b/b.html"> | 260 <link rel="import" href="../../packages/b/b.html"> |
| 261 <polymer-element name="x-a"></polymer-element> | 261 <polymer-element name="x-a"></polymer-element> |
| 262 </html>'''.replaceAll(' ', ''), | 262 </html>'''.replaceAll(' ', ''), |
| 263 }, [ | 263 }, [ |
| 264 'warning: duplicate definition for custom tag "x-a". ' | 264 'warning: ${DUPLICATE_DEFINITION.create( |
| 265 '(package:b/b.html 2 0)', | 265 {'name': 'x-a', 'second': ''}).snippet} (package:b/b.html 2 0)', |
| 266 'warning: duplicate definition for custom tag "x-a". ' | 266 'warning: ${DUPLICATE_DEFINITION.create( |
| 267 '(second definition). (lib/test.html 2 0)' | 267 {'name': 'x-a', 'second': ' (second definition).'}).snippet} ' |
| 268 '(lib/test.html 2 0)', |
| 268 ]); | 269 ]); |
| 269 }); | 270 }); |
| 270 | 271 |
| 271 _testLinter('bad link-rel tag (href missing)', { | 272 _testLinter('bad link-rel tag (href missing)', { |
| 272 'a|lib/test.html': '''<html> | 273 'a|lib/test.html': '''<html> |
| 273 <link rel="import"> | 274 <link rel="import"> |
| 274 <link rel="stylesheet"> | 275 <link rel="stylesheet"> |
| 275 <link rel="foo"> | 276 <link rel="foo"> |
| 276 <link rel="import" href=""> | 277 <link rel="import" href=""> |
| 277 </html>'''.replaceAll(' ', ''), | 278 </html>'''.replaceAll(' ', ''), |
| 278 }, [ | 279 }, [ |
| 279 'warning: link rel="import" missing href. (lib/test.html 1 0)', | 280 'warning: ${MISSING_HREF.create({'rel': 'import'}).snippet} ' |
| 280 'warning: link rel="stylesheet" missing href. (lib/test.html 2 0)', | 281 '(lib/test.html 1 0)', |
| 281 'warning: link rel="import" missing href. (lib/test.html 4 0)' | 282 'warning: ${MISSING_HREF.create({'rel': 'stylesheet'}).snippet} ' |
| 283 '(lib/test.html 2 0)', |
| 284 'warning: ${MISSING_HREF.create({'rel': 'import'}).snippet} ' |
| 285 '(lib/test.html 4 0)', |
| 282 ]); | 286 ]); |
| 283 | 287 |
| 284 _testLinter('<element> is not supported', { | 288 _testLinter('<element> is not supported', { |
| 285 'a|lib/test.html': '''<html> | 289 'a|lib/test.html': '''<html> |
| 286 <element name="x-a"></element> | 290 <element name="x-a"></element> |
| 287 </html>'''.replaceAll(' ', ''), | 291 </html>'''.replaceAll(' ', ''), |
| 288 }, [ | 292 }, [ |
| 289 'warning: <element> elements are not supported, use <polymer-element>' | 293 'warning: ${ELEMENT_DEPRECATED_EONS_AGO.snippet} (lib/test.html 1 0)' |
| 290 ' instead. (lib/test.html 1 0)' | |
| 291 ]); | 294 ]); |
| 292 | 295 |
| 293 _testLinter('do not nest <polymer-element>', { | 296 _testLinter('do not nest <polymer-element>', { |
| 294 'a|lib/test.html': '''<html> | 297 'a|lib/test.html': '''<html> |
| 295 <link rel="import" href="../../packages/polymer/polymer.html"> | 298 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 296 <polymer-element name="x-a"> | 299 <polymer-element name="x-a"> |
| 297 <template><div> | 300 <template><div> |
| 298 <polymer-element name="b"></polymer-element> | 301 <polymer-element name="b"></polymer-element> |
| 299 </div></template> | 302 </div></template> |
| 300 </polymer-element> | 303 </polymer-element> |
| 301 </html>'''.replaceAll(' ', ''), | 304 </html>'''.replaceAll(' ', ''), |
| 302 }, [ | 305 }, [ |
| 303 'error: Nested polymer element definitions are not allowed.' | 306 'error: ${NESTED_POLYMER_ELEMENT.snippet} (lib/test.html 4 4)' |
| 304 ' (lib/test.html 4 4)' | |
| 305 ]); | 307 ]); |
| 306 | 308 |
| 307 _testLinter('do put import inside <polymer-element>', { | 309 _testLinter('do put import inside <polymer-element>', { |
| 308 'a|lib/b.html': '<html></html>', | 310 'a|lib/b.html': '<html></html>', |
| 309 'a|lib/test.html': '''<html> | 311 'a|lib/test.html': '''<html> |
| 310 <link rel="import" href="../../packages/polymer/polymer.html"> | 312 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 311 <polymer-element name="x-a"> | 313 <polymer-element name="x-a"> |
| 312 <link rel="import" href="b.html"> | 314 <link rel="import" href="b.html"> |
| 313 <template><div> | 315 <template><div> |
| 314 </div></template> | 316 </div></template> |
| 315 </polymer-element> | 317 </polymer-element> |
| 316 </html>'''.replaceAll(' ', ''), | 318 </html>'''.replaceAll(' ', ''), |
| 317 }, [ | 319 }, [ |
| 318 'error: ${NO_IMPORT_WITHIN_ELEMENT.snippet} (lib/test.html 3 2)' | 320 'error: ${NO_IMPORT_WITHIN_ELEMENT.snippet} (lib/test.html 3 2)' |
| 319 ]); | 321 ]); |
| 320 | 322 |
| 321 _testLinter('need a name for <polymer-element>', { | 323 _testLinter('need a name for <polymer-element>', { |
| 322 'a|lib/test.html': '''<html> | 324 'a|lib/test.html': '''<html> |
| 323 <link rel="import" href="../../packages/polymer/polymer.html"> | 325 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 324 <polymer-element></polymer-element> | 326 <polymer-element></polymer-element> |
| 325 </html>'''.replaceAll(' ', ''), | 327 </html>'''.replaceAll(' ', ''), |
| 326 }, [ | 328 }, [ |
| 327 'error: Missing tag name of the custom element. Please include an ' | 329 'error: ${MISSING_TAG_NAME.snippet} (lib/test.html 2 0)' |
| 328 'attribute like \'name="your-tag-name"\'. (lib/test.html 2 0)' | |
| 329 ]); | 330 ]); |
| 330 | 331 |
| 331 _testLinter('name for <polymer-element> should have dashes', { | 332 _testLinter('name for <polymer-element> should have dashes', { |
| 332 'a|lib/test.html': '''<html> | 333 'a|lib/test.html': '''<html> |
| 333 <link rel="import" href="../../packages/polymer/polymer.html"> | 334 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 334 <polymer-element name="a"></polymer-element> | 335 <polymer-element name="a"></polymer-element> |
| 335 </html>'''.replaceAll(' ', ''), | 336 </html>'''.replaceAll(' ', ''), |
| 336 }, [ | 337 }, [ |
| 337 'error: Invalid name "a". Custom element names must have at least one' | 338 'error: ${INVALID_TAG_NAME.create({'name': 'a'}).snippet} ' |
| 338 ' dash (-) and can\'t be any of the following names: annotation-xml, ' | 339 '(lib/test.html 2 0)' |
| 339 'color-profile, font-face, font-face-src, font-face-uri, ' | |
| 340 'font-face-format, font-face-name, missing-glyph. (lib/test.html 2 0)' | |
| 341 ]); | 340 ]); |
| 342 | 341 |
| 343 _testLinter('extend is a valid element or existing tag', { | 342 _testLinter('extend is a valid element or existing tag', { |
| 344 'a|lib/test.html': '''<html> | 343 'a|lib/test.html': '''<html> |
| 345 <link rel="import" href="../../packages/polymer/polymer.html"> | 344 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 346 <polymer-element name="x-a" extends="li"></polymer-element> | 345 <polymer-element name="x-a" extends="li"></polymer-element> |
| 347 </html>'''.replaceAll(' ', ''), | 346 </html>'''.replaceAll(' ', ''), |
| 348 }, []); | 347 }, []); |
| 349 | 348 |
| 350 _testLinter('extend is a valid element or existing tag', { | 349 _testLinter('extend is a valid element or existing tag', { |
| 351 'a|lib/test.html': '''<html> | 350 'a|lib/test.html': '''<html> |
| 352 <link rel="import" href="../../packages/polymer/polymer.html"> | 351 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 353 <polymer-element name="x-a" extends="x-b"></polymer-element> | 352 <polymer-element name="x-a" extends="x-b"></polymer-element> |
| 354 </html>'''.replaceAll(' ', ''), | 353 </html>'''.replaceAll(' ', ''), |
| 355 }, [ | 354 }, [ |
| 356 'warning: custom element with name "x-b" not found. (lib/test.html 2 0)' | 355 'warning: ${CUSTOM_ELEMENT_NOT_FOUND.create({'tag': 'x-b'}).snippet} ' |
| 356 '(lib/test.html 2 0)' |
| 357 ]); | 357 ]); |
| 358 | 358 |
| 359 | 359 |
| 360 group('script type matches code', () { | 360 group('script type matches code', () { |
| 361 _testLinter('top-level, .dart url', { | 361 _testLinter('top-level, .dart url', { |
| 362 'a|lib/test.html': '''<html> | 362 'a|lib/test.html': '''<html> |
| 363 <script src="foo.dart"></script> | 363 <script src="foo.dart"></script> |
| 364 </html>'''.replaceAll(' ', ''), | 364 </html>'''.replaceAll(' ', ''), |
| 365 }, [ | 365 }, [ |
| 366 'warning: Wrong script type, expected type="application/dart".' | 366 'warning: Wrong script type, expected type="application/dart".' |
| 367 ' (lib/test.html 1 0)' | 367 ' (lib/test.html 1 0)' |
| 368 ]); | 368 ]); |
| 369 | 369 |
| 370 _testLinter('in polymer-element, .dart url', { | 370 _testLinter('in polymer-element, .dart url', { |
| 371 'a|lib/test.html': '''<html> | 371 'a|lib/test.html': '''<html> |
| 372 <link rel="import" href="../../packages/polymer/polymer.html"> | 372 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 373 <polymer-element name="x-a"> | 373 <polymer-element name="x-a"> |
| 374 <script src="foo.dart"></script> | 374 <script src="foo.dart"></script> |
| 375 </polymer-element> | 375 </polymer-element> |
| 376 </html>'''.replaceAll(' ', ''), | 376 </html>'''.replaceAll(' ', ''), |
| 377 }, [ | 377 }, [ |
| 378 'warning: Wrong script type, expected type="application/dart".' | 378 'warning: ${EXPECTED_DART_MIME_TYPE.snippet} (lib/test.html 3 0)' |
| 379 ' (lib/test.html 3 0)' | |
| 380 ]); | 379 ]); |
| 381 | 380 |
| 382 _testLinter('in polymer-element, .js url', { | 381 _testLinter('in polymer-element, .js url', { |
| 383 'a|lib/test.html': '''<html> | 382 'a|lib/test.html': '''<html> |
| 384 <link rel="import" href="../../packages/polymer/polymer.html"> | 383 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 385 <polymer-element name="x-a"> | 384 <polymer-element name="x-a"> |
| 386 <script src="foo.js"></script> | 385 <script src="foo.js"></script> |
| 387 </polymer-element> | 386 </polymer-element> |
| 388 </html>'''.replaceAll(' ', ''), | 387 </html>'''.replaceAll(' ', ''), |
| 389 }, []); | 388 }, []); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 401 'a|lib/test.html': '''<html> | 400 'a|lib/test.html': '''<html> |
| 402 <script type="application/dart" src="foo.dart"></script> | 401 <script type="application/dart" src="foo.dart"></script> |
| 403 </html>'''.replaceAll(' ', ''), | 402 </html>'''.replaceAll(' ', ''), |
| 404 }, []); | 403 }, []); |
| 405 | 404 |
| 406 _testLinter('top-level, dart type & .js url', { | 405 _testLinter('top-level, dart type & .js url', { |
| 407 'a|lib/test.html': '''<html> | 406 'a|lib/test.html': '''<html> |
| 408 <script type="application/dart" src="foo.js"></script> | 407 <script type="application/dart" src="foo.js"></script> |
| 409 </html>'''.replaceAll(' ', ''), | 408 </html>'''.replaceAll(' ', ''), |
| 410 }, [ | 409 }, [ |
| 411 'warning: "application/dart" scripts should use the .dart file ' | 410 'warning: ${EXPECTED_DART_EXTENSION.snippet} (lib/test.html 1 0)' |
| 412 'extension. (lib/test.html 1 0)' | |
| 413 ]); | 411 ]); |
| 414 }); | 412 }); |
| 415 | 413 |
| 416 _testLinter('script tags should have at least src url or inline code', { | 414 _testLinter('script tags should have at least src url or inline code', { |
| 417 'a|lib/test.html': '''<html> | 415 'a|lib/test.html': '''<html> |
| 418 <script type="application/dart"></script> | 416 <script type="application/dart"></script> |
| 419 </html>'''.replaceAll(' ', ''), | 417 </html>'''.replaceAll(' ', ''), |
| 420 }, [ | 418 }, [ |
| 421 'warning: script tag seems empty. ' | 419 'warning: ${SCRIPT_TAG_SEEMS_EMPTY.snippet} (lib/test.html 1 0)' |
| 422 '(lib/test.html 1 0)' | |
| 423 ]); | 420 ]); |
| 424 | 421 |
| 425 _testLinter('script tags should have only src url or inline code', { | 422 _testLinter('script tags should have only src url or inline code', { |
| 426 'a|lib/test.html': '''<html> | 423 'a|lib/test.html': '''<html> |
| 427 <script type="application/dart" src="foo.dart">more</script> | 424 <script type="application/dart" src="foo.dart">more</script> |
| 428 </html>'''.replaceAll(' ', ''), | 425 </html>'''.replaceAll(' ', ''), |
| 429 }, [ | 426 }, [ |
| 430 'warning: script tag has "src" attribute and also has script text. ' | 427 'warning: ${FOUND_BOTH_SCRIPT_SRC_AND_TEXT.snippet} (lib/test.html 1 0)' |
| 431 '(lib/test.html 1 0)' | |
| 432 ]); | 428 ]); |
| 433 | 429 |
| 434 group('event handlers', () { | 430 group('event handlers', () { |
| 435 _testLinter('no longer warn about inline onfoo (Javascript)', { | 431 _testLinter('no longer warn about inline onfoo (Javascript)', { |
| 436 'a|lib/test.html': '''<html><body> | 432 'a|lib/test.html': '''<html><body> |
| 437 <div onfoo="something"></div> | 433 <div onfoo="something"></div> |
| 438 '''.replaceAll(' ', ''), | 434 '''.replaceAll(' ', ''), |
| 439 }, []); | 435 }, []); |
| 440 | 436 |
| 441 _testLinter('no longer warn about on-foo for auto-binding templates', { | 437 _testLinter('no longer warn about on-foo for auto-binding templates', { |
| 442 'a|lib/test.html': '''<html><body> | 438 'a|lib/test.html': '''<html><body> |
| 443 <template is="auto-binding-dart"> | 439 <template is="auto-binding-dart"> |
| 444 <div on-foo="{{something}}"></div> | 440 <div on-foo="{{something}}"></div> |
| 445 </template> | 441 </template> |
| 446 '''.replaceAll(' ', ''), | 442 '''.replaceAll(' ', ''), |
| 447 }, []); | 443 }, []); |
| 448 | 444 |
| 449 _testLinter('on-foo is only supported in polymer elements', { | 445 _testLinter('on-foo is only supported in polymer elements', { |
| 450 'a|lib/test.html': '''<html><body> | 446 'a|lib/test.html': '''<html><body> |
| 451 <div on-foo="something"></div> | 447 <div on-foo="something"></div> |
| 452 '''.replaceAll(' ', ''), | 448 '''.replaceAll(' ', ''), |
| 453 }, [ | 449 }, [ |
| 454 'warning: Inline event handlers are only supported inside ' | 450 'warning: ${EVENT_HANDLERS_ONLY_WITHIN_POLYMER.snippet} ' |
| 455 'declarations of <polymer-element>. ' | 451 '(lib/test.html 1 5)' |
| 456 '(lib/test.html 1 5)' | |
| 457 ]); | 452 ]); |
| 458 | 453 |
| 459 _testLinter('on-foo uses the {{ binding }} syntax', { | 454 _testLinter('on-foo uses the {{ binding }} syntax', { |
| 460 'a|lib/test.html': '''<html><body> | 455 'a|lib/test.html': '''<html><body> |
| 461 <link rel="import" href="../../packages/polymer/polymer.html"> | 456 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 462 <polymer-element name="x-a"><div on-foo="bar"></div> | 457 <polymer-element name="x-a"><div on-foo="bar"></div> |
| 463 </polymer-element> | 458 </polymer-element> |
| 464 '''.replaceAll(' ', ''), | 459 '''.replaceAll(' ', ''), |
| 465 }, [ | 460 }, [ |
| 466 'warning: Invalid event handler body "bar". Declare a method ' | 461 'warning: ${INVALID_EVENT_HANDLER_BODY.create( |
| 467 'in your custom element "void handlerName(event, detail, target)" ' | 462 {'value': 'bar', 'name': 'on-foo'}).snippet} (lib/test.html 2 33)' |
| 468 'and use the form on-foo="{{handlerName}}". ' | |
| 469 '(lib/test.html 2 33)' | |
| 470 ]); | 463 ]); |
| 471 | 464 |
| 472 _testLinter('on-foo is not an expression', { | 465 _testLinter('on-foo is not an expression', { |
| 473 'a|lib/test.html': '''<html><body> | 466 'a|lib/test.html': '''<html><body> |
| 474 <link rel="import" href="../../packages/polymer/polymer.html"> | 467 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 475 <polymer-element name="x-a"><div on-foo="{{bar()}}"></div> | 468 <polymer-element name="x-a"><div on-foo="{{bar()}}"></div> |
| 476 </polymer-element> | 469 </polymer-element> |
| 477 '''.replaceAll(' ', ''), | 470 '''.replaceAll(' ', ''), |
| 478 }, [ | 471 }, [ |
| 479 'warning: Invalid event handler body "{{bar()}}". Declare a method ' | 472 'warning: ${INVALID_EVENT_HANDLER_BODY.create( |
| 480 'in your custom element "void handlerName(event, detail, target)" ' | 473 {'value': '{{bar()}}', 'name': 'on-foo'}).snippet} ' |
| 481 'and use the form on-foo="{{handlerName}}". ' | 474 '(lib/test.html 2 33)' |
| 482 '(lib/test.html 2 33)' | |
| 483 ]); | 475 ]); |
| 484 | 476 |
| 485 _testLinter('on-foo can\'t be empty', { | 477 _testLinter('on-foo can\'t be empty', { |
| 486 'a|lib/test.html': '''<html><body> | 478 'a|lib/test.html': '''<html><body> |
| 487 <link rel="import" href="../../packages/polymer/polymer.html"> | 479 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 488 <polymer-element name="x-a"><div on-foo="{{}}"></div> | 480 <polymer-element name="x-a"><div on-foo="{{}}"></div> |
| 489 </polymer-element> | 481 </polymer-element> |
| 490 '''.replaceAll(' ', ''), | 482 '''.replaceAll(' ', ''), |
| 491 }, [ | 483 }, [ |
| 492 'warning: Invalid event handler body "{{}}". Declare a method ' | 484 'warning: ${INVALID_EVENT_HANDLER_BODY.create( |
| 493 'in your custom element "void handlerName(event, detail, target)" ' | 485 {'value': '{{}}', 'name': 'on-foo'}).snippet} (lib/test.html 2 33)' |
| 494 'and use the form on-foo="{{handlerName}}". ' | |
| 495 '(lib/test.html 2 33)' | |
| 496 ]); | 486 ]); |
| 497 | 487 |
| 498 _testLinter('on-foo can\'t be just space', { | 488 _testLinter('on-foo can\'t be just space', { |
| 499 'a|lib/test.html': '''<html><body> | 489 'a|lib/test.html': '''<html><body> |
| 500 <link rel="import" href="../../packages/polymer/polymer.html"> | 490 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 501 <polymer-element name="x-a"><div on-foo="{{ }}"></div> | 491 <polymer-element name="x-a"><div on-foo="{{ }}"></div> |
| 502 </polymer-element> | 492 </polymer-element> |
| 503 '''.replaceAll(' ', ''), | 493 '''.replaceAll(' ', ''), |
| 504 }, [ | 494 }, [ |
| 505 'warning: Invalid event handler body "{{ }}". Declare a method ' | 495 'warning: ${INVALID_EVENT_HANDLER_BODY.create( |
| 506 'in your custom element "void handlerName(event, detail, target)" ' | 496 {'value': '{{ }}', 'name': 'on-foo'}).snippet} (lib/test.html 2 33)' |
| 507 'and use the form on-foo="{{handlerName}}". ' | |
| 508 '(lib/test.html 2 33)' | |
| 509 ]); | 497 ]); |
| 510 | 498 |
| 511 _testLinter('on-foo-bar is supported as a custom event name', { | 499 _testLinter('on-foo-bar is supported as a custom event name', { |
| 512 'a|lib/test.html': '''<html><body> | 500 'a|lib/test.html': '''<html><body> |
| 513 <link rel="import" href="../../packages/polymer/polymer.html"> | 501 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 514 <polymer-element name="x-a"><div on-foo-bar="{{quux}}"></div> | 502 <polymer-element name="x-a"><div on-foo-bar="{{quux}}"></div> |
| 515 </polymer-element> | 503 </polymer-element> |
| 516 '''.replaceAll(' ', ''), | 504 '''.replaceAll(' ', ''), |
| 517 }, []); | 505 }, []); |
| 518 }); | 506 }); |
| 519 | 507 |
| 520 group('using custom tags', () { | 508 group('using custom tags', () { |
| 521 _testLinter('tag exists (x-tag)', { | 509 _testLinter('tag exists (x-tag)', { |
| 522 'a|lib/test.html': '<x-foo></x-foo>', | 510 'a|lib/test.html': '<x-foo></x-foo>', |
| 523 }, [ | 511 }, [ |
| 524 'warning: custom element with name "x-foo" not found. ' | 512 'warning: ${CUSTOM_ELEMENT_NOT_FOUND.create({'tag': 'x-foo'}).snippet} ' |
| 525 '(lib/test.html 0 0)' | 513 '(lib/test.html 0 0)' |
| 526 ]); | 514 ]); |
| 527 | 515 |
| 528 _testLinter('tag exists (type extension)', { | 516 _testLinter('tag exists (type extension)', { |
| 529 'a|lib/test.html': '<div is="x-foo"></div>', | 517 'a|lib/test.html': '<div is="x-foo"></div>', |
| 530 }, [ | 518 }, [ |
| 531 'warning: custom element with name "x-foo" not found. ' | 519 'warning: ${CUSTOM_ELEMENT_NOT_FOUND.create({'tag': 'x-foo'}).snippet} ' |
| 532 '(lib/test.html 0 0)' | 520 '(lib/test.html 0 0)' |
| 533 ]); | 521 ]); |
| 534 | 522 |
| 535 _testLinter('tag exists (internally defined in code)', { | 523 _testLinter('tag exists (internally defined in code)', { |
| 536 'a|lib/test.html': '<div is="auto-binding-dart"></div>', | 524 'a|lib/test.html': '<div is="auto-binding-dart"></div>', |
| 537 }, []); | 525 }, []); |
| 538 | 526 |
| 539 _testLinter('used correctly (no base tag)', { | 527 _testLinter('used correctly (no base tag)', { |
| 540 'a|lib/test.html': ''' | 528 'a|lib/test.html': ''' |
| 541 <link rel="import" href="../../packages/polymer/polymer.html"> | 529 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 542 <polymer-element name="x-a"></polymer-element> | 530 <polymer-element name="x-a"></polymer-element> |
| 543 <x-a></x-a> | 531 <x-a></x-a> |
| 544 '''.replaceAll(' ', ''), | 532 '''.replaceAll(' ', ''), |
| 545 }, []); | 533 }, []); |
| 546 | 534 |
| 547 _testLinter('used incorrectly (no base tag)', { | 535 _testLinter('used incorrectly (no base tag)', { |
| 548 'a|lib/test.html': ''' | 536 'a|lib/test.html': ''' |
| 549 <link rel="import" href="../../packages/polymer/polymer.html"> | 537 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 550 <polymer-element name="x-a"></polymer-element> | 538 <polymer-element name="x-a"></polymer-element> |
| 551 <div is="x-a"></div> | 539 <div is="x-a"></div> |
| 552 '''.replaceAll(' ', ''), | 540 '''.replaceAll(' ', ''), |
| 553 }, [ | 541 }, [ |
| 554 'warning: custom element "x-a" doesn\'t declare any type ' | 542 'warning: ${BAD_INSTANTIATION_BOGUS_BASE_TAG.create( |
| 555 'extensions. To fix this, either rewrite this tag as ' | 543 {'tag': 'x-a', 'base': 'div'}).snippet} (lib/test.html 2 0)' |
| 556 '<x-a> or add \'extends="div"\' to ' | |
| 557 'the custom element declaration. (lib/test.html 2 0)' | |
| 558 ]); | 544 ]); |
| 559 | 545 |
| 560 _testLinter('used incorrectly, imported def (no base tag)', { | 546 _testLinter('used incorrectly, imported def (no base tag)', { |
| 561 'a|lib/b.html': ''' | 547 'a|lib/b.html': ''' |
| 562 <link rel="import" href="../../packages/polymer/polymer.html"> | 548 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 563 <polymer-element name="x-a"></polymer-element>''', | 549 <polymer-element name="x-a"></polymer-element>''', |
| 564 'a|lib/test.html': ''' | 550 'a|lib/test.html': ''' |
| 565 <link rel="import" href="b.html"> | 551 <link rel="import" href="b.html"> |
| 566 <div is="x-a"></div> | 552 <div is="x-a"></div> |
| 567 '''.replaceAll(' ', ''), | 553 '''.replaceAll(' ', ''), |
| 568 }, [ | 554 }, [ |
| 569 'warning: custom element "x-a" doesn\'t declare any type ' | 555 'warning: ${BAD_INSTANTIATION_BOGUS_BASE_TAG.create( |
| 570 'extensions. To fix this, either rewrite this tag as ' | 556 {'tag': 'x-a', 'base': 'div'}).snippet} (lib/test.html 1 0)' |
| 571 '<x-a> or add \'extends="div"\' to ' | |
| 572 'the custom element declaration. (lib/test.html 1 0)' | |
| 573 ]); | 557 ]); |
| 574 | 558 |
| 575 _testLinter('used correctly (base tag)', { | 559 _testLinter('used correctly (base tag)', { |
| 576 'a|lib/b.html': ''' | 560 'a|lib/b.html': ''' |
| 577 <link rel="import" href="../../packages/polymer/polymer.html"> | 561 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 578 <polymer-element name="x-a" extends="div"> | 562 <polymer-element name="x-a" extends="div"> |
| 579 </polymer-element> | 563 </polymer-element> |
| 580 '''.replaceAll(' ', ''), | 564 '''.replaceAll(' ', ''), |
| 581 'a|lib/test.html': ''' | 565 'a|lib/test.html': ''' |
| 582 <link rel="import" href="b.html"> | 566 <link rel="import" href="b.html"> |
| 583 <div is="x-a"></div> | 567 <div is="x-a"></div> |
| 584 '''.replaceAll(' ', ''), | 568 '''.replaceAll(' ', ''), |
| 585 }, []); | 569 }, []); |
| 586 | 570 |
| 587 _testLinter('used incorrectly (missing base tag)', { | 571 _testLinter('used incorrectly (missing base tag)', { |
| 588 'a|lib/b.html': ''' | 572 'a|lib/b.html': ''' |
| 589 <link rel="import" href="../../packages/polymer/polymer.html"> | 573 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 590 <polymer-element name="x-a" extends="div"> | 574 <polymer-element name="x-a" extends="div"> |
| 591 </polymer-element> | 575 </polymer-element> |
| 592 '''.replaceAll(' ', ''), | 576 '''.replaceAll(' ', ''), |
| 593 'a|lib/test.html': ''' | 577 'a|lib/test.html': ''' |
| 594 <link rel="import" href="b.html"> | 578 <link rel="import" href="b.html"> |
| 595 <x-a></x-a> | 579 <x-a></x-a> |
| 596 '''.replaceAll(' ', ''), | 580 '''.replaceAll(' ', ''), |
| 597 }, [ | 581 }, [ |
| 598 'warning: custom element "x-a" extends from "div", but this tag ' | 582 'warning: ${BAD_INSTANTIATION_MISSING_BASE_TAG.create( |
| 599 'will not include the default properties of "div". To fix this, ' | 583 {'tag': 'x-a', 'base': 'div'}).snippet} (lib/test.html 1 0)' |
| 600 'either write this tag as <div is="x-a"> or remove the "extends" ' | |
| 601 'attribute from the custom element declaration. (lib/test.html 1 0)' | |
| 602 ]); | 584 ]); |
| 603 | 585 |
| 604 _testLinter('used incorrectly (wrong base tag)', { | 586 _testLinter('used incorrectly (wrong base tag)', { |
| 605 'a|lib/b.html': ''' | 587 'a|lib/b.html': ''' |
| 606 <link rel="import" href="../../packages/polymer/polymer.html"> | 588 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 607 <polymer-element name="x-a" extends="div"> | 589 <polymer-element name="x-a" extends="div"> |
| 608 </polymer-element> | 590 </polymer-element> |
| 609 '''.replaceAll(' ', ''), | 591 '''.replaceAll(' ', ''), |
| 610 'a|lib/test.html': ''' | 592 'a|lib/test.html': ''' |
| 611 <link rel="import" href="b.html"> | 593 <link rel="import" href="b.html"> |
| 612 <span is="x-a"></span> | 594 <span is="x-a"></span> |
| 613 '''.replaceAll(' ', ''), | 595 '''.replaceAll(' ', ''), |
| 614 }, [ | 596 }, [ |
| 615 'warning: custom element "x-a" extends from "div". Did you mean ' | 597 'warning: ${BAD_INSTANTIATION_WRONG_BASE_TAG.create( |
| 616 'to write <div is="x-a">? (lib/test.html 1 0)' | 598 {'tag': 'x-a', 'base': 'div'}).snippet} (lib/test.html 1 0)' |
| 617 ]); | 599 ]); |
| 618 | 600 |
| 619 _testLinter('used incorrectly (wrong base tag, transitive)', { | 601 _testLinter('used incorrectly (wrong base tag, transitive)', { |
| 620 'a|lib/c.html': ''' | 602 'a|lib/c.html': ''' |
| 621 <link rel="import" href="../../packages/polymer/polymer.html"> | 603 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 622 <polymer-element name="x-c" extends="li"> | 604 <polymer-element name="x-c" extends="li"> |
| 623 </polymer-element> | 605 </polymer-element> |
| 624 <polymer-element name="x-b" extends="x-c"> | 606 <polymer-element name="x-b" extends="x-c"> |
| 625 </polymer-element> | 607 </polymer-element> |
| 626 '''.replaceAll(' ', ''), | 608 '''.replaceAll(' ', ''), |
| 627 'a|lib/b.html': ''' | 609 'a|lib/b.html': ''' |
| 628 <link rel="import" href="../../packages/polymer/polymer.html"> | 610 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 629 <link rel="import" href="c.html"> | 611 <link rel="import" href="c.html"> |
| 630 <polymer-element name="x-a" extends="x-b"> | 612 <polymer-element name="x-a" extends="x-b"> |
| 631 </polymer-element> | 613 </polymer-element> |
| 632 '''.replaceAll(' ', ''), | 614 '''.replaceAll(' ', ''), |
| 633 'a|lib/test.html': ''' | 615 'a|lib/test.html': ''' |
| 634 <link rel="import" href="../../packages/polymer/polymer.html"> | 616 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 635 <link rel="import" href="b.html"> | 617 <link rel="import" href="b.html"> |
| 636 <span is="x-a"></span> | 618 <span is="x-a"></span> |
| 637 '''.replaceAll(' ', ''), | 619 '''.replaceAll(' ', ''), |
| 638 }, [ | 620 }, [ |
| 639 'warning: custom element "x-a" extends from "li". Did you mean ' | 621 'warning: ${BAD_INSTANTIATION_WRONG_BASE_TAG.create( |
| 640 'to write <li is="x-a">? (lib/test.html 2 0)' | 622 {'tag': 'x-a', 'base': 'li'}).snippet} (lib/test.html 2 0)' |
| 641 ]); | 623 ]); |
| 642 | 624 |
| 643 _testLinter('FOUC warning works', { | 625 _testLinter('FOUC warning works', { |
| 644 'a|lib/a.html': ''' | 626 'a|lib/a.html': ''' |
| 645 <html><body> | 627 <html><body> |
| 646 <link rel="import" href="../../packages/polymer/polymer.html"> | 628 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 647 <polymer-element name="my-element" noscript></polymer-element> | 629 <polymer-element name="my-element" noscript></polymer-element> |
| 648 <my-element>hello!</my-element> | 630 <my-element>hello!</my-element> |
| 649 </body></html> | 631 </body></html> |
| 650 ''', | 632 ''', |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 }); | 685 }); |
| 704 | 686 |
| 705 group('custom attributes', () { | 687 group('custom attributes', () { |
| 706 _testLinter('foo-bar is no longer supported in attributes', { | 688 _testLinter('foo-bar is no longer supported in attributes', { |
| 707 'a|lib/test.html': '''<html><body> | 689 'a|lib/test.html': '''<html><body> |
| 708 <link rel="import" href="../../packages/polymer/polymer.html"> | 690 <link rel="import" href="../../packages/polymer/polymer.html"> |
| 709 <polymer-element name="x-a" attributes="foo-bar"> | 691 <polymer-element name="x-a" attributes="foo-bar"> |
| 710 </polymer-element> | 692 </polymer-element> |
| 711 '''.replaceAll(' ', ''), | 693 '''.replaceAll(' ', ''), |
| 712 }, [ | 694 }, [ |
| 713 'warning: PolymerElement no longer recognizes attribute names with ' | 695 'warning: ${NO_DASHES_IN_CUSTOM_ATTRIBUTES.create( |
| 714 'dashes such as "foo-bar". Use "fooBar" or "foobar" instead (both ' | 696 {'name': 'foo-bar', 'alternative': '"fooBar" or "foobar"'}) |
| 715 'forms are equivalent in HTML). (lib/test.html 2 28)' | 697 .snippet} (lib/test.html 2 28)' |
| 716 ]); | 698 ]); |
| 717 }); | 699 }); |
| 718 | 700 |
| 719 _testLinter("namespaced attributes don't cause an internal error", { | 701 _testLinter("namespaced attributes don't cause an internal error", { |
| 720 'a|lib/test.html': '''<html><body> | 702 'a|lib/test.html': '''<html><body> |
| 721 <svg xmlns="http://www.w3.org/2000/svg" width="520" height="350"> | 703 <svg xmlns="http://www.w3.org/2000/svg" width="520" height="350"> |
| 722 </svg> | 704 </svg> |
| 723 '''.replaceAll(' ', ''), | 705 '''.replaceAll(' ', ''), |
| 724 }, []); | 706 }, []); |
| 725 | 707 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 } | 761 } |
| 780 if (outputMessages.isEmpty) { | 762 if (outputMessages.isEmpty) { |
| 781 var linter = new Linter(new TransformOptions()); | 763 var linter = new Linter(new TransformOptions()); |
| 782 testPhases(name, [[linter]], inputFiles, outputFiles, outputMessages, solo); | 764 testPhases(name, [[linter]], inputFiles, outputFiles, outputMessages, solo); |
| 783 } else { | 765 } else { |
| 784 testLogOutput( | 766 testLogOutput( |
| 785 (options) => new Linter(options), name, inputFiles, outputFiles, | 767 (options) => new Linter(options), name, inputFiles, outputFiles, |
| 786 outputMessages, solo); | 768 outputMessages, solo); |
| 787 } | 769 } |
| 788 } | 770 } |
| OLD | NEW |