Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate the missingCodeBlockLanguage warning. #3743

Merged
merged 5 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/src/model/documentation_comment.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
kallentu marked this conversation as resolved.
Show resolved Hide resolved
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:analyzer/dart/element/element.dart';
import 'package:args/args.dart';
import 'package:crypto/crypto.dart' as crypto;
Expand Down
31 changes: 23 additions & 8 deletions lib/src/warnings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -279,16 +279,19 @@ enum PackageWarning implements Comparable<PackageWarning> {
'deprecated dartdoc usage: {0}',
shortHelp: 'A dartdoc directive has a deprecated format.',
),
// TODO(kallentu): Remove this warning.
missingCodeBlockLanguage(
'missing-code-block-language',
'missing code block language: {0}',
shortHelp: 'A fenced code block is missing a specified language.',
longHelp:
'To enable proper syntax highlighting of Markdown code blocks, Dartdoc '
'requires code blocks to specify the language used after the initial '
'declaration. As an example, to specify Dart you would open the '
'Markdown code block with ```dart or ~~~dart.',
shortHelp: '(Deprecated: Use `missing_code_block_language_in_doc_comment` '
'lint) A fenced code block is missing a specified language.',
longHelp: '(Deprecated: Use `missing_code_block_language_in_doc_comment` '
'lint) To enable proper syntax highlighting of Markdown code blocks, '
'Dartdoc requires code blocks to specify the language used after the '
'initial declaration. As an example, to specify Dart you would open '
'the Markdown code block with ```dart or ~~~dart.',
defaultWarningMode: PackageWarningMode.ignore,
isDeprecated: true,
);

/// The name which can be used at the command line to enable this warning.
Expand All @@ -305,6 +308,8 @@ enum PackageWarning implements Comparable<PackageWarning> {

final String _longHelp;

final bool _isDeprecated;

final PackageWarningMode _defaultWarningMode;

const PackageWarning(
Expand All @@ -314,11 +319,13 @@ enum PackageWarning implements Comparable<PackageWarning> {
String longHelp = '',
String warnablePrefix = 'from',
String referredFromPrefix = 'referred to by',
bool isDeprecated = false,
PackageWarningMode defaultWarningMode = PackageWarningMode.warn,
}) : _shortHelp = shortHelp,
_longHelp = longHelp,
_warnablePrefix = warnablePrefix,
_referredFromPrefix = referredFromPrefix,
_isDeprecated = isDeprecated,
_defaultWarningMode = defaultWarningMode;

static PackageWarning? _byName(String name) =>
Expand Down Expand Up @@ -402,6 +409,7 @@ class PackageWarningOptions {
for (var warningName in errorsForDir) {
var packageWarning = PackageWarning._byName(warningName);
if (packageWarning != null) {
newOptions.writeErrorOnDeprecation(packageWarning);
newOptions.error(packageWarning);
}
}
Expand All @@ -410,6 +418,7 @@ class PackageWarningOptions {
for (var warningName in warningsForDir) {
var packageWarning = PackageWarning._byName(warningName);
if (packageWarning != null) {
newOptions.writeErrorOnDeprecation(packageWarning);
newOptions.warn(packageWarning);
}
}
Expand Down Expand Up @@ -455,14 +464,20 @@ class PackageWarningOptions {
return newOptions;
}

void error(PackageWarning kind) =>
warningModes[kind] = PackageWarningMode.error;

void ignore(PackageWarning kind) =>
warningModes[kind] = PackageWarningMode.ignore;

void warn(PackageWarning kind) =>
warningModes[kind] = PackageWarningMode.warn;

void error(PackageWarning kind) =>
warningModes[kind] = PackageWarningMode.error;
void writeErrorOnDeprecation(PackageWarning warning) {
if (warning._isDeprecated) {
stderr.writeln("The warning '${warning._flagName}' is deprecated.");
}
}

PackageWarningMode getMode(PackageWarning kind) => warningModes[kind]!;
}
Expand Down
Loading