Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Unified Diff: pkg/polymer/test/build/linter_test.dart

Issue 112843004: Add linter by default for polymer's pub-build, also cleans up the linter code. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/polymer/test/build/linter_test.dart
diff --git a/pkg/polymer/test/build/linter_test.dart b/pkg/polymer/test/build/linter_test.dart
index 46964bed745a847cf4e66b2a4fcdb16dc1552667..22328fe0370601370dfd747d066f61c39bbc40a2 100644
--- a/pkg/polymer/test/build/linter_test.dart
+++ b/pkg/polymer/test/build/linter_test.dart
@@ -16,9 +16,7 @@ void main() {
useCompactVMConfiguration();
_testLinter('nothing to report', {
'a|lib/test.html': '<!DOCTYPE html><html></html>',
- }, {
- 'a|lib/test.html.messages': ''
- });
+ }, []);
group('must have Dart code to invoke initPolymer, dart.js, not boot.js', () {
_testLinter('nothing to report', {
@@ -27,15 +25,13 @@ void main() {
'</script>'
'<script src="packages/browser/dart.js"></script>'
'</html>',
- }, {
- 'a|web/test.html.messages': '',
- });
+ }, []);
_testLinter('missing Dart code and dart.js', {
'a|web/test.html': '<!DOCTYPE html><html></html>',
- }, {
- 'a|web/test.html.messages': 'error: $USE_INIT_DART',
- });
+ }, [
+ 'error: $USE_INIT_DART',
+ ]);
_testLinter('using deprecated boot.js', {
'a|web/test.html': '<!DOCTYPE html><html>\n'
@@ -44,10 +40,9 @@ void main() {
'</script>'
'<script src="packages/browser/dart.js"></script>'
'</html>',
- }, {
- 'a|web/test.html.messages': 'warning: $BOOT_JS_DEPRECATED '
- '(web/test.html 1 0)',
- });
+ }, [
+ 'warning: $BOOT_JS_DEPRECATED (web/test.html 1 0)',
+ ]);
});
group('single script tag per document', () {
_testLinter('two top-level tags', {
@@ -57,11 +52,10 @@ void main() {
'<script type="application/dart" src="b.dart">'
'</script>'
'<script src="packages/browser/dart.js"></script>'
- }, {
- 'a|web/test.html.messages':
- 'warning: Only one "application/dart" script tag per document is'
- ' allowed. (web/test.html 1 0)',
- });
+ }, [
+ 'warning: Only one "application/dart" script tag per document is'
+ ' allowed. (web/test.html 1 0)',
+ ]);
_testLinter('two top-level tags, non entrypoint', {
'a|lib/test.html': '<!DOCTYPE html><html>'
@@ -70,11 +64,10 @@ void main() {
'<script type="application/dart" src="b.dart">'
'</script>'
'<script src="packages/browser/dart.js"></script>'
- }, {
- 'a|lib/test.html.messages':
- 'warning: Only one "application/dart" script tag per document is'
- ' allowed. (lib/test.html 1 0)',
- });
+ }, [
+ 'warning: Only one "application/dart" script tag per document is'
+ ' allowed. (lib/test.html 1 0)',
+ ]);
_testLinter('tags inside elements', {
'a|web/test.html': '<!DOCTYPE html><html>'
@@ -85,28 +78,24 @@ void main() {
'<script type="application/dart" src="b.dart">'
'</script>'
'<script src="packages/browser/dart.js"></script>'
- }, {
- 'a|web/test.html.messages':
- 'warning: Only one "application/dart" script tag per document is'
- ' allowed. (web/test.html 1 0)',
- });
+ }, [
+ 'warning: Only one "application/dart" script tag per document is'
+ ' allowed. (web/test.html 1 0)',
+ ]);
});
group('doctype warning', () {
_testLinter('in web', {
'a|web/test.html': '<html></html>',
- }, {
- 'a|web/test.html.messages':
- 'warning: Unexpected start tag (html). Expected DOCTYPE. '
- '(web/test.html 0 0)\n'
- 'error: $USE_INIT_DART',
- });
+ }, [
+ 'warning: Unexpected start tag (html). Expected DOCTYPE. '
+ '(web/test.html 0 0)',
+ 'error: $USE_INIT_DART',
+ ]);
_testLinter('in lib', {
'a|lib/test.html': '<html></html>',
- }, {
- 'a|lib/test.html.messages': '',
- });
+ }, []);
});
group('duplicate polymer-elements,', () {
@@ -115,13 +104,12 @@ void main() {
<polymer-element name="x-a"></polymer-element>
<polymer-element name="x-a"></polymer-element>
</html>'''.replaceAll(' ', ''),
- }, {
- 'a|lib/test.html.messages':
- 'warning: duplicate definition for custom tag "x-a". '
- '(lib/test.html 1 0)\n'
- 'warning: duplicate definition for custom tag "x-a" '
- '(second definition). (lib/test.html 2 0)'
- });
+ }, [
+ 'warning: duplicate definition for custom tag "x-a". '
+ '(lib/test.html 1 0)',
+ 'warning: duplicate definition for custom tag "x-a" '
+ '(second definition). (lib/test.html 2 0)'
+ ]);
_testLinter('other file', {
'a|lib/b.html': '''<html>
@@ -131,24 +119,22 @@ void main() {
<link rel="import" href="b.html">
<polymer-element name="x-a"></polymer-element>
</html>'''.replaceAll(' ', ''),
- }, {
- 'a|lib/test.html.messages':
- 'warning: duplicate definition for custom tag "x-a". '
- '(lib/b.html 1 0)\n'
- 'warning: duplicate definition for custom tag "x-a" '
- '(second definition). (lib/test.html 2 0)'
- });
+ }, [
+ 'warning: duplicate definition for custom tag "x-a". '
+ '(lib/b.html 1 0)',
+ 'warning: duplicate definition for custom tag "x-a" '
+ '(second definition). (lib/test.html 2 0)'
+ ]);
_testLinter('non existing file', {
'a|lib/test.html': '''<html>
<link rel="import" href="b.html">
<polymer-element name="x-a"></polymer-element>
</html>'''.replaceAll(' ', ''),
- }, {
- 'a|lib/test.html.messages':
- 'error: couldn\'t find imported asset "lib/b.html" in package '
- '"a". (lib/test.html 1 0)'
- });
+ }, [
+ 'error: couldn\'t find imported asset "lib/b.html" in package '
+ '"a". (lib/test.html 1 0)'
+ ]);
_testLinter('other package', {
'b|lib/b.html': '''<html>
@@ -158,13 +144,12 @@ void main() {
<link rel="import" href="../../packages/b/b.html">
<polymer-element name="x-a"></polymer-element>
</html>'''.replaceAll(' ', ''),
- }, {
- 'a|lib/test.html.messages':
- 'warning: duplicate definition for custom tag "x-a". '
- '(package:b/b.html 1 0)\n'
- 'warning: duplicate definition for custom tag "x-a" '
- '(second definition). (lib/test.html 2 0)'
- });
+ }, [
+ 'warning: duplicate definition for custom tag "x-a". '
+ '(package:b/b.html 1 0)',
+ 'warning: duplicate definition for custom tag "x-a" '
+ '(second definition). (lib/test.html 2 0)'
+ ]);
});
_testLinter('bad link-rel tag (href missing)', {
@@ -174,22 +159,20 @@ void main() {
<link rel="foo">
<link rel="import" href="">
</html>'''.replaceAll(' ', ''),
- }, {
- 'a|lib/test.html.messages':
- 'warning: link rel="import" missing href. (lib/test.html 1 0)\n'
- 'warning: link rel="stylesheet" missing href. (lib/test.html 2 0)\n'
- 'warning: link rel="import" missing href. (lib/test.html 4 0)'
- });
+ }, [
+ 'warning: link rel="import" missing href. (lib/test.html 1 0)',
+ 'warning: link rel="stylesheet" missing href. (lib/test.html 2 0)',
+ 'warning: link rel="import" missing href. (lib/test.html 4 0)'
+ ]);
_testLinter('<element> is not supported', {
'a|lib/test.html': '''<html>
<element name="x-a"></element>
</html>'''.replaceAll(' ', ''),
- }, {
- 'a|lib/test.html.messages':
- 'warning: <element> elements are not supported, use <polymer-element>'
- ' instead (lib/test.html 1 0)'
- });
+ }, [
+ 'warning: <element> elements are not supported, use <polymer-element>'
+ ' instead (lib/test.html 1 0)'
+ ]);
_testLinter('do not nest <polymer-element>', {
'a|lib/test.html': '''<html>
@@ -199,51 +182,44 @@ void main() {
</div></template>
</polymer-element>
</html>'''.replaceAll(' ', ''),
- }, {
- 'a|lib/test.html.messages':
- 'error: Nested polymer element definitions are not allowed.'
- ' (lib/test.html 3 4)'
- });
+ }, [
+ 'error: Nested polymer element definitions are not allowed.'
+ ' (lib/test.html 3 4)'
+ ]);
_testLinter('need a name for <polymer-element>', {
'a|lib/test.html': '''<html>
<polymer-element></polymer-element>
</html>'''.replaceAll(' ', ''),
- }, {
- 'a|lib/test.html.messages':
- 'error: Missing tag name of the custom element. Please include an '
- 'attribute like \'name="your-tag-name"\'. (lib/test.html 1 0)'
- });
+ }, [
+ 'error: Missing tag name of the custom element. Please include an '
+ 'attribute like \'name="your-tag-name"\'. (lib/test.html 1 0)'
+ ]);
_testLinter('name for <polymer-element> should have dashes', {
'a|lib/test.html': '''<html>
<polymer-element name="a"></polymer-element>
</html>'''.replaceAll(' ', ''),
- }, {
- 'a|lib/test.html.messages':
- 'error: Invalid name "a". Custom element names must have at least one'
- ' dash and can\'t be any of the following names: annotation-xml, '
- 'color-profile, font-face, font-face-src, font-face-uri, '
- 'font-face-format, font-face-name, missing-glyph. (lib/test.html 1 0)'
- });
+ }, [
+ 'error: Invalid name "a". Custom element names must have at least one'
+ ' dash and can\'t be any of the following names: annotation-xml, '
+ 'color-profile, font-face, font-face-src, font-face-uri, '
+ 'font-face-format, font-face-name, missing-glyph. (lib/test.html 1 0)'
+ ]);
_testLinter('extend is a valid element or existing tag', {
'a|lib/test.html': '''<html>
<polymer-element name="x-a" extends="li"></polymer-element>
</html>'''.replaceAll(' ', ''),
- }, {
- 'a|lib/test.html.messages': ''
- });
+ }, []);
_testLinter('extend is a valid element or existing tag', {
'a|lib/test.html': '''<html>
<polymer-element name="x-a" extends="x-b"></polymer-element>
</html>'''.replaceAll(' ', ''),
- }, {
- 'a|lib/test.html.messages': ''
- 'warning: custom element with name "x-b" not found. '
- '(lib/test.html 1 0)'
- });
+ }, [
+ 'warning: custom element with name "x-b" not found. (lib/test.html 1 0)'
+ ]);
group('script type matches code', () {
@@ -251,11 +227,10 @@ void main() {
'a|lib/test.html': '''<html>
<script src="foo.dart"></script>
</html>'''.replaceAll(' ', ''),
- }, {
- 'a|lib/test.html.messages':
- 'warning: Wrong script type, expected type="application/dart".'
- ' (lib/test.html 1 0)'
- });
+ }, [
+ 'warning: Wrong script type, expected type="application/dart".'
+ ' (lib/test.html 1 0)'
+ ]);
_testLinter('in polymer-element, .dart url', {
'a|lib/test.html': '''<html>
@@ -263,11 +238,10 @@ void main() {
<script src="foo.dart"></script>
</polymer-element>
</html>'''.replaceAll(' ', ''),
- }, {
- 'a|lib/test.html.messages':
- 'warning: Wrong script type, expected type="application/dart".'
- ' (lib/test.html 2 0)'
- });
+ }, [
+ 'warning: Wrong script type, expected type="application/dart".'
+ ' (lib/test.html 2 0)'
+ ]);
_testLinter('in polymer-element, .js url', {
'a|lib/test.html': '''<html>
@@ -275,9 +249,7 @@ void main() {
<script src="foo.js"></script>
</polymer-element>
</html>'''.replaceAll(' ', ''),
- }, {
- 'a|lib/test.html.messages': ''
- });
+ }, []);
_testLinter('in polymer-element, inlined', {
'a|lib/test.html': '''<html>
@@ -285,126 +257,113 @@ void main() {
<script>foo...</script>
</polymer-element>
</html>'''.replaceAll(' ', ''),
- }, {
- 'a|lib/test.html.messages':
- 'warning: script tag in polymer element with no type will '
- 'be treated as JavaScript. Did you forget type="application/dart"?'
- ' (lib/test.html 2 0)'
- });
+ }, [
+ 'warning: script tag in polymer element with no type will '
+ 'be treated as JavaScript. Did you forget type="application/dart"?'
+ ' (lib/test.html 2 0)'
+ ]);
_testLinter('top-level, dart type & .dart url', {
'a|lib/test.html': '''<html>
<script type="application/dart" src="foo.dart"></script>
</html>'''.replaceAll(' ', ''),
- }, {
- 'a|lib/test.html.messages': ''
- });
+ }, []);
_testLinter('top-level, dart type & .js url', {
'a|lib/test.html': '''<html>
<script type="application/dart" src="foo.js"></script>
</html>'''.replaceAll(' ', ''),
- }, {
- 'a|lib/test.html.messages':
- 'warning: "application/dart" scripts should use the .dart file '
- 'extension. (lib/test.html 1 0)'
- });
+ }, [
+ 'warning: "application/dart" scripts should use the .dart file '
+ 'extension. (lib/test.html 1 0)'
+ ]);
});
_testLinter('script tags should have only src url or inline code', {
'a|lib/test.html': '''<html>
<script type="application/dart" src="foo.dart">more</script>
</html>'''.replaceAll(' ', ''),
- }, {
- 'a|lib/test.html.messages':
- 'warning: script tag has "src" attribute and also has script text. '
- '(lib/test.html 1 0)'
- });
+ }, [
+ 'warning: script tag has "src" attribute and also has script text. '
+ '(lib/test.html 1 0)'
+ ]);
group('event handlers', () {
_testLinter('onfoo is not polymer', {
'a|lib/test.html': '''<html><body>
<div onfoo="something"></div>
'''.replaceAll(' ', ''),
- }, {
- 'a|lib/test.html.messages':
- 'warning: Event handler "onfoo" will be interpreted as an inline '
- 'JavaScript event handler. Use the form '
- 'on-event-name="handlerName" if you want a Dart handler '
- 'that will automatically update the UI based on model changes. '
- '(lib/test.html 1 5)'
- });
+ }, [
+ 'warning: Event handler "onfoo" will be interpreted as an inline '
+ 'JavaScript event handler. Use the form '
+ 'on-event-name="handlerName" if you want a Dart handler '
+ 'that will automatically update the UI based on model changes. '
+ '(lib/test.html 1 5)'
+ ]);
_testLinter('on-foo is only supported in polymer elements', {
'a|lib/test.html': '''<html><body>
<div on-foo="something"></div>
'''.replaceAll(' ', ''),
- }, {
- 'a|lib/test.html.messages':
- 'warning: Inline event handlers are only supported inside '
- 'declarations of <polymer-element>. '
- '(lib/test.html 1 5)'
- });
+ }, [
+ 'warning: Inline event handlers are only supported inside '
+ 'declarations of <polymer-element>. '
+ '(lib/test.html 1 5)'
+ ]);
_testLinter('on-foo is not an expression', {
'a|lib/test.html': '''<html><body>
<polymer-element name="x-a"><div on-foo="bar()"></div>
</polymer-element>
'''.replaceAll(' ', ''),
- }, {
- 'a|lib/test.html.messages':
- 'warning: Invalid event handler body "bar()". Declare a method '
- 'in your custom element "void handlerName(event, detail, target)" '
- 'and use the form on-foo="handlerName". '
- '(lib/test.html 1 33)'
- });
+ }, [
+ 'warning: Invalid event handler body "bar()". Declare a method '
+ 'in your custom element "void handlerName(event, detail, target)" '
+ 'and use the form on-foo="handlerName". '
+ '(lib/test.html 1 33)'
+ ]);
_testLinter('on-foo-bar is supported as a custom event name', {
'a|lib/test.html': '''<html><body>
<polymer-element name="x-a"><div on-foo-bar="quux"></div>
</polymer-element>
'''.replaceAll(' ', ''),
- }, {});
+ }, []);
});
group('using custom tags', () {
_testLinter('tag exists (x-tag)', {
'a|lib/test.html': '<x-foo></x-foo>',
- }, {
- 'a|lib/test.html.messages':
- 'warning: definition for Polymer element with tag name "x-foo" not '
- 'found. (lib/test.html 0 0)'
- });
+ }, [
+ 'warning: definition for Polymer element with tag name "x-foo" not '
+ 'found. (lib/test.html 0 0)'
+ ]);
_testLinter('tag exists (type extension)', {
'a|lib/test.html': '<div is="x-foo"></div>',
- }, {
- 'a|lib/test.html.messages':
- 'warning: definition for Polymer element with tag name "x-foo" not '
- 'found. (lib/test.html 0 0)'
- });
+ }, [
+ 'warning: definition for Polymer element with tag name "x-foo" not '
+ 'found. (lib/test.html 0 0)'
+ ]);
_testLinter('used correctly (no base tag)', {
'a|lib/test.html': '''
<polymer-element name="x-a"></polymer-element>
<x-a></x-a>
'''.replaceAll(' ', ''),
- }, {
- 'a|lib/test.html.messages': ''
- });
+ }, []);
_testLinter('used incorrectly (no base tag)', {
'a|lib/test.html': '''
<polymer-element name="x-a"></polymer-element>
<div is="x-a"></div>
'''.replaceAll(' ', ''),
- }, {
- 'a|lib/test.html.messages':
- 'warning: custom element "x-a" doesn\'t declare any type '
- 'extensions. To fix this, either rewrite this tag as '
- '<x-a> or add \'extends="div"\' to '
- 'the custom element declaration. (lib/test.html 1 0)'
- });
+ }, [
+ 'warning: custom element "x-a" doesn\'t declare any type '
+ 'extensions. To fix this, either rewrite this tag as '
+ '<x-a> or add \'extends="div"\' to '
+ 'the custom element declaration. (lib/test.html 1 0)'
+ ]);
_testLinter('used incorrectly, imported def (no base tag)', {
'a|lib/b.html': '<polymer-element name="x-a"></polymer-element>',
@@ -412,13 +371,12 @@ void main() {
<link rel="import" href="b.html">
<div is="x-a"></div>
'''.replaceAll(' ', ''),
- }, {
- 'a|lib/test.html.messages':
- 'warning: custom element "x-a" doesn\'t declare any type '
- 'extensions. To fix this, either rewrite this tag as '
- '<x-a> or add \'extends="div"\' to '
- 'the custom element declaration. (lib/test.html 1 0)'
- });
+ }, [
+ 'warning: custom element "x-a" doesn\'t declare any type '
+ 'extensions. To fix this, either rewrite this tag as '
+ '<x-a> or add \'extends="div"\' to '
+ 'the custom element declaration. (lib/test.html 1 0)'
+ ]);
_testLinter('used correctly (base tag)', {
'a|lib/b.html': '''
@@ -429,9 +387,7 @@ void main() {
<link rel="import" href="b.html">
<div is="x-a"></div>
'''.replaceAll(' ', ''),
- }, {
- 'a|lib/test.html.messages': ''
- });
+ }, []);
_testLinter('used incorrectly (missing base tag)', {
'a|lib/b.html': '''
@@ -442,13 +398,12 @@ void main() {
<link rel="import" href="b.html">
<x-a></x-a>
'''.replaceAll(' ', ''),
- }, {
- 'a|lib/test.html.messages': ''
- 'warning: custom element "x-a" extends from "div", but this tag '
- 'will not include the default properties of "div". To fix this, '
- 'either write this tag as <div is="x-a"> or remove the "extends" '
- 'attribute from the custom element declaration. (lib/test.html 1 0)'
- });
+ }, [
+ 'warning: custom element "x-a" extends from "div", but this tag '
+ 'will not include the default properties of "div". To fix this, '
+ 'either write this tag as <div is="x-a"> or remove the "extends" '
+ 'attribute from the custom element declaration. (lib/test.html 1 0)'
+ ]);
_testLinter('used incorrectly (wrong base tag)', {
'a|lib/b.html': '''
@@ -459,11 +414,10 @@ void main() {
<link rel="import" href="b.html">
<span is="x-a"></span>
'''.replaceAll(' ', ''),
- }, {
- 'a|lib/test.html.messages': ''
- 'warning: custom element "x-a" extends from "div". Did you mean '
- 'to write <div is="x-a">? (lib/test.html 1 0)'
- });
+ }, [
+ 'warning: custom element "x-a" extends from "div". Did you mean '
+ 'to write <div is="x-a">? (lib/test.html 1 0)'
+ ]);
_testLinter('used incorrectly (wrong base tag, transitive)', {
'a|lib/c.html': '''
@@ -481,11 +435,10 @@ void main() {
<link rel="import" href="b.html">
<span is="x-a"></span>
'''.replaceAll(' ', ''),
- }, {
- 'a|lib/test.html.messages': ''
- 'warning: custom element "x-a" extends from "li". Did you mean '
- 'to write <li is="x-a">? (lib/test.html 1 0)'
- });
+ }, [
+ 'warning: custom element "x-a" extends from "li". Did you mean '
+ 'to write <li is="x-a">? (lib/test.html 1 0)'
+ ]);
});
group('custom attributes', () {
@@ -494,32 +447,17 @@ void main() {
<polymer-element name="x-a" attributes="foo-bar">
</polymer-element>
'''.replaceAll(' ', ''),
- }, {
- 'a|lib/test.html.messages':
- 'warning: PolymerElement no longer recognizes attribute names with '
- 'dashes such as "foo-bar". Use "fooBar" or "foobar" instead (both '
- 'forms are equivalent in HTML). (lib/test.html 1 28)'
- });
+ }, [
+ 'warning: PolymerElement no longer recognizes attribute names with '
+ 'dashes such as "foo-bar". Use "fooBar" or "foobar" instead (both '
+ 'forms are equivalent in HTML). (lib/test.html 1 28)'
+ ]);
});
}
-_testLinter(String name, Map inputFiles, Map outputMessages) {
- var linter = new Linter(new TransformOptions(), _testFormatter);
+_testLinter(String name, Map inputFiles, List outputMessages) {
+ var linter = new Linter(new TransformOptions());
var outputFiles = {};
inputFiles.forEach((k, v) => outputFiles[k] = v);
- outputMessages.forEach((k, v) => outputFiles[k] = v);
- var keys = inputFiles.keys.toSet();
- keys.retainAll(outputMessages.keys);
- expect(keys, isEmpty);
- testPhases(name, [[linter]], inputFiles, outputFiles);
-}
-
-
-_testFormatter(String kind, String message, Span span) {
- var formattedMessage = '$kind: $message';
- if (span != null) {
- formattedMessage = '$formattedMessage '
- '(${span.sourceUrl} ${span.start.line} ${span.start.column})';
- }
- return formattedMessage;
+ testPhases(name, [[linter]], inputFiles, outputFiles, outputMessages);
}
« pkg/polymer/lib/src/build/linter.dart ('K') | « pkg/polymer/test/build/common.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698