Skip to content

Commit c43b63c

Browse files
authored
Do not allow tools to run in compare_output_test (#1853)
* Do not allow tools to run in compare_output_test * Update dev docs
1 parent 855efbb commit c43b63c

File tree

12 files changed

+80
-96
lines changed

12 files changed

+80
-96
lines changed

lib/src/dartdoc_options.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,6 +1286,7 @@ class DartdocOptionContext {
12861286

12871287
// All values defined in createDartdocOptions should be exposed here.
12881288
bool get addCrossdart => optionSet['addCrossdart'].valueAt(context);
1289+
bool get allowTools => optionSet['allowTools'].valueAt(context);
12891290
double get ambiguousReexportScorerMinConfidence =>
12901291
optionSet['ambiguousReexportScorerMinConfidence'].valueAt(context);
12911292
bool get autoIncludeDependencies =>
@@ -1347,6 +1348,9 @@ Future<List<DartdocOption>> createDartdocOptions() async {
13471348
new DartdocOptionArgOnly<bool>('addCrossdart', false,
13481349
help: 'Add Crossdart links to the source code pieces.',
13491350
negatable: true),
1351+
new DartdocOptionArgOnly<bool>('allowTools', true,
1352+
help: 'Execute user-defined tools to fill in @tool directives.',
1353+
negatable: true),
13501354
new DartdocOptionArgFile<double>(
13511355
'ambiguousReexportScorerMinConfidence', 0.1,
13521356
help: 'Minimum scorer confidence to suppress warning on ambiguous '

lib/src/model.dart

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3988,38 +3988,42 @@ abstract class ModelElement extends Canonicalization
39883988
/// ## Content to send to tool.
39893989
/// 2018-09-18T21:15+00:00
39903990
Future<String> _evaluateTools(String rawDocs) async {
3991-
var runner = new ToolRunner(config.tools, (String message) async {
3992-
warn(PackageWarning.toolError, message: message);
3993-
});
3994-
int invocationIndex = 0;
3995-
return await _replaceAllMappedAsync(rawDocs, basicToolRegExp,
3996-
(basicMatch) async {
3997-
List<String> args = _splitUpQuotedArgs(basicMatch[1]).toList();
3998-
// Tool name must come first.
3999-
if (args.isEmpty) {
4000-
warn(PackageWarning.toolError,
4001-
message: 'Must specify a tool to execute for the @tool directive.');
4002-
return Future.value('');
4003-
}
4004-
// Count the number of invocations of tools in this dartdoc block,
4005-
// so that tools can differentiate different blocks from each other.
4006-
invocationIndex++;
4007-
return await runner.run(args,
4008-
content: basicMatch[2],
4009-
environment: {
4010-
'SOURCE_LINE': lineAndColumn?.item1?.toString(),
4011-
'SOURCE_COLUMN': lineAndColumn?.item2?.toString(),
4012-
'SOURCE_PATH': (sourceFileName == null ||
4013-
package?.packagePath == null)
4014-
? null
4015-
: pathLib.relative(sourceFileName, from: package.packagePath),
4016-
'PACKAGE_PATH': package?.packagePath,
4017-
'PACKAGE_NAME': package?.name,
4018-
'LIBRARY_NAME': library?.fullyQualifiedName,
4019-
'ELEMENT_NAME': fullyQualifiedNameWithoutLibrary,
4020-
'INVOCATION_INDEX': invocationIndex.toString(),
4021-
}..removeWhere((key, value) => value == null));
4022-
}).whenComplete(runner.dispose);
3991+
if (config.allowTools) {
3992+
var runner = new ToolRunner(config.tools, (String message) async {
3993+
warn(PackageWarning.toolError, message: message);
3994+
});
3995+
int invocationIndex = 0;
3996+
return await _replaceAllMappedAsync(rawDocs, basicToolRegExp,
3997+
(basicMatch) async {
3998+
List<String> args = _splitUpQuotedArgs(basicMatch[1]).toList();
3999+
// Tool name must come first.
4000+
if (args.isEmpty) {
4001+
warn(PackageWarning.toolError,
4002+
message: 'Must specify a tool to execute for the @tool directive.');
4003+
return Future.value('');
4004+
}
4005+
// Count the number of invocations of tools in this dartdoc block,
4006+
// so that tools can differentiate different blocks from each other.
4007+
invocationIndex++;
4008+
return await runner.run(args,
4009+
content: basicMatch[2],
4010+
environment: {
4011+
'SOURCE_LINE': lineAndColumn?.item1?.toString(),
4012+
'SOURCE_COLUMN': lineAndColumn?.item2?.toString(),
4013+
'SOURCE_PATH': (sourceFileName == null ||
4014+
package?.packagePath == null)
4015+
? null
4016+
: pathLib.relative(sourceFileName, from: package.packagePath),
4017+
'PACKAGE_PATH': package?.packagePath,
4018+
'PACKAGE_NAME': package?.name,
4019+
'LIBRARY_NAME': library?.fullyQualifiedName,
4020+
'ELEMENT_NAME': fullyQualifiedNameWithoutLibrary,
4021+
'INVOCATION_INDEX': invocationIndex.toString(),
4022+
}..removeWhere((key, value) => value == null));
4023+
}).whenComplete(runner.dispose);
4024+
} else {
4025+
return rawDocs;
4026+
}
40234027
}
40244028

40254029
/// Replace &#123;@animation ...&#125; in API comments with some HTML to manage an

test/compare_output_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ void main() {
8989
var args = <String>[
9090
'--enable-asserts',
9191
dartdocBin,
92+
'--no-allow-tools',
9293
'--auto-include-dependencies',
9394
'--example-path-prefix',
9495
'examples',

testing/test_package_docs/ex/HtmlInjection/injectHtmlFromTool.html

Lines changed: 6 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

testing/test_package_docs/ex/ToolUser/invokeTool.html

Lines changed: 4 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

testing/test_package_docs/ex/ToolUser/invokeToolMultipleSections.html

Lines changed: 6 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

testing/test_package_docs/ex/ToolUser/invokeToolNoInput.html

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

testing/test_package_docs_dev/ex/HtmlInjection/injectHtmlFromTool.html

Lines changed: 6 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

testing/test_package_docs_dev/ex/ToolUser/invokeTool.html

Lines changed: 4 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

testing/test_package_docs_dev/ex/ToolUser/invokeToolMultipleSections.html

Lines changed: 6 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)