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

Side by Side Diff: pkg/polymer/lib/src/build/common.dart

Issue 648883002: Add more options to configure the linter. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 2 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/polymer/lib/deploy.dart ('k') | pkg/polymer/lib/src/build/linter.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 /// Common methods used by transfomers. 5 /// Common methods used by transfomers.
6 library polymer.src.build.common; 6 library polymer.src.build.common;
7 7
8 import 'dart:async'; 8 import 'dart:async';
9 9
10 import 'package:analyzer/src/generated/ast.dart'; 10 import 'package:analyzer/src/generated/ast.dart';
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 final bool directlyIncludeJS; 81 final bool directlyIncludeJS;
82 82
83 /// Run transformers to create a releasable app. For example, include the 83 /// Run transformers to create a releasable app. For example, include the
84 /// minified versions of the polyfills rather than the debug versions. 84 /// minified versions of the polyfills rather than the debug versions.
85 final bool releaseMode; 85 final bool releaseMode;
86 86
87 /// This will make a physical element appear on the page showing build logs. 87 /// This will make a physical element appear on the page showing build logs.
88 /// It will only appear when ![releaseMode] even if this is true. 88 /// It will only appear when ![releaseMode] even if this is true.
89 final bool injectBuildLogsInOutput; 89 final bool injectBuildLogsInOutput;
90 90
91 /// True to run liner on all html files before starting other phases. 91 /// Rules to determine whether to run liner on an html file.
92 // TODO(jmesserly): instead of this flag, we should only run linter on 92 // TODO(jmesserly): instead of this flag, we should only run linter on
93 // reachable (entry point+imported) html if deploying. See dartbug.com/17199. 93 // reachable (entry point+imported) html if deploying. See dartbug.com/17199.
94 final bool lint; 94 final LintOptions lint;
95 95
96 /// This will automatically inject `platform.js` from the `web_components` 96 /// This will automatically inject `platform.js` from the `web_components`
97 /// package in all entry points, if it is not already included. 97 /// package in all entry points, if it is not already included.
98 final bool injectPlatformJs; 98 final bool injectPlatformJs;
99 99
100 TransformOptions({entryPoints, this.inlineStylesheets, 100 TransformOptions({entryPoints, this.inlineStylesheets,
101 this.contentSecurityPolicy: false, this.directlyIncludeJS: true, 101 this.contentSecurityPolicy: false, this.directlyIncludeJS: true,
102 this.releaseMode: true, this.lint: true, 102 this.releaseMode: true, this.lint: const LintOptions(),
103 this.injectBuildLogsInOutput: false, this.injectPlatformJs: true}) 103 this.injectBuildLogsInOutput: false, this.injectPlatformJs: true})
104 : entryPoints = entryPoints == null ? null 104 : entryPoints = entryPoints == null ? null
105 : entryPoints.map(systemToAssetPath).toList(); 105 : entryPoints.map(systemToAssetPath).toList();
106 106
107 /// Whether an asset with [id] is an entry point HTML file. 107 /// Whether an asset with [id] is an entry point HTML file.
108 bool isHtmlEntryPoint(AssetId id) { 108 bool isHtmlEntryPoint(AssetId id) {
109 if (id.extension != '.html') return false; 109 if (id.extension != '.html') return false;
110 110
111 // Note: [id.path] is a relative path from the root of a package. 111 // Note: [id.path] is a relative path from the root of a package.
112 if (entryPoints == null) { 112 if (entryPoints == null) {
(...skipping 20 matching lines...) Expand all
133 } 133 }
134 134
135 // Whether a stylesheet with [id] has an overriden inlining setting. 135 // Whether a stylesheet with [id] has an overriden inlining setting.
136 bool stylesheetInliningIsOverridden(AssetId id) { 136 bool stylesheetInliningIsOverridden(AssetId id) {
137 return inlineStylesheets != null && 137 return inlineStylesheets != null &&
138 (inlineStylesheets.containsKey(id.toString()) 138 (inlineStylesheets.containsKey(id.toString())
139 || inlineStylesheets.containsKey(id.path)); 139 || inlineStylesheets.containsKey(id.path));
140 } 140 }
141 } 141 }
142 142
143 class LintOptions {
144 /// Whether lint is enabled.
145 final bool enabled;
146
147 /// Patterns explicitly included/excluded from linting (if any).
148 final List<RegExp> patterns;
149
150 /// When [patterns] is not null, whether they denote inclusion or exclusion.
151 final bool isInclude;
152
153 const LintOptions()
154 : enabled = true, patterns = null, isInclude = true;
155 const LintOptions.disabled()
156 : enabled = false, patterns = null, isInclude = true;
157
158 LintOptions.include(List<String> patterns)
159 : enabled = true,
160 isInclude = true,
161 patterns = patterns.map((s) => new RegExp(s)).toList();
162
163 LintOptions.exclude(List<String> patterns)
164 : enabled = true,
165 isInclude = false,
166 patterns = patterns.map((s) => new RegExp(s)).toList();
167
168 bool shouldLint(String fileName) {
169 if (!enabled) return false;
170 if (patterns == null) return isInclude;
171 for (var pattern in patterns) {
172 if (pattern.hasMatch(fileName)) return isInclude;
173 }
174 return !isInclude;
175 }
176 }
177
143 /// Mixin for polymer transformers. 178 /// Mixin for polymer transformers.
144 abstract class PolymerTransformer { 179 abstract class PolymerTransformer {
145 TransformOptions get options; 180 TransformOptions get options;
146 181
147 Future<Document> readPrimaryAsHtml(Transform transform, BuildLogger logger) { 182 Future<Document> readPrimaryAsHtml(Transform transform, BuildLogger logger) {
148 var asset = transform.primaryInput; 183 var asset = transform.primaryInput;
149 var id = asset.id; 184 var id = asset.id;
150 return asset.readAsString().then((content) { 185 return asset.readAsString().then((content) {
151 return _parseHtml(content, id.path, logger, 186 return _parseHtml(content, id.path, logger,
152 checkDocType: options.isHtmlEntryPoint(id)); 187 checkDocType: options.isHtmlEntryPoint(id));
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 /// Returns true if this is a valid custom element name. See: 269 /// Returns true if this is a valid custom element name. See:
235 /// <http://w3c.github.io/webcomponents/spec/custom/#dfn-custom-element-type> 270 /// <http://w3c.github.io/webcomponents/spec/custom/#dfn-custom-element-type>
236 bool isCustomTagName(String name) { 271 bool isCustomTagName(String name) {
237 if (name == null || !name.contains('-')) return false; 272 if (name == null || !name.contains('-')) return false;
238 return !invalidTagNames.containsKey(name); 273 return !invalidTagNames.containsKey(name);
239 } 274 }
240 275
241 /// Regex to split names in the 'attributes' attribute, which supports 'a b c', 276 /// Regex to split names in the 'attributes' attribute, which supports 'a b c',
242 /// 'a,b,c', or even 'a b,c'. This is the same as in `lib/src/declaration.dart`. 277 /// 'a,b,c', or even 'a b,c'. This is the same as in `lib/src/declaration.dart`.
243 final ATTRIBUTES_REGEX = new RegExp(r'\s|,'); 278 final ATTRIBUTES_REGEX = new RegExp(r'\s|,');
OLDNEW
« no previous file with comments | « pkg/polymer/lib/deploy.dart ('k') | pkg/polymer/lib/src/build/linter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698