Fix a few more lints, no longer ignore line length (dart-lang/markdown#552)
diff --git a/pkgs/markdown/analysis_options.yaml b/pkgs/markdown/analysis_options.yaml index afb26cd..124348f 100644 --- a/pkgs/markdown/analysis_options.yaml +++ b/pkgs/markdown/analysis_options.yaml
@@ -1,4 +1,4 @@ -# https://dart.dev/guides/language/analysis-options +# https://dart.dev/tools/analysis include: package:dart_flutter_team_lints/analysis_options.yaml analyzer: @@ -8,8 +8,6 @@ strict-raw-types: true errors: - # 41 cases to clean up - lines_longer_than_80_chars: ignore # The example app explicitly takes a String of user-generated HTML and # inserts it straight into a <div> using innerHtml. unsafe_html: ignore @@ -30,6 +28,7 @@ - prefer_const_constructors - prefer_const_declarations - prefer_final_locals + - prefer_final_in_for_each - prefer_relative_imports - test_types_in_equals - unnecessary_await_in_return
diff --git a/pkgs/markdown/lib/markdown.dart b/pkgs/markdown/lib/markdown.dart index 99a85de..409baaf 100644 --- a/pkgs/markdown/lib/markdown.dart +++ b/pkgs/markdown/lib/markdown.dart
@@ -7,32 +7,36 @@ /// that can then be rendered to HTML. /// /// If you are only interested in rendering Markdown to HTML please refer -/// to the [README](../index.html) which explains the use of [markdownToHtml()]. +/// to the [README](../index.html) which explains the use of [markdownToHtml]. /// -/// The main entrypoint to the library is the [Document] which encapsulates the -/// parsing process converting a Markdown text into a tree of [Node] (`List<Node>`). +/// The main entrypoint to the library is the [Document] which +/// encapsulates the parsing process converting a Markdown text into +/// a tree of [Node] (`List<Node>`). /// -/// Two main parsing mechanics are used: +/// The two main parsing mechanics used are: /// -/// - Blocks, representing top level elements like: headers, paragraphs, blockquotes, -/// code blocks, ... implemented via [BlockSyntax] subclasses. -/// - Inlines, representing chunks of text within a block with special meaning, like: -/// links, emphasis, inlined code, ... implemented via [InlineSyntax] subclasses. +/// - Blocks, representing top-level elements +/// implemented via [BlockSyntax] subclasses, +/// such as headers, paragraphs, blockquotes, and code blocks. +/// - Inlines, representing chunks of text within a block with special meaning, +/// implemented via [InlineSyntax] subclasses, +/// such as links, emphasis, and inlined code. /// -/// Looking closely at [Document.new()] a few other concepts merit a mention: +/// Looking closely at [Document.new] a few other concepts merit a mention: /// /// - [ExtensionSet] that provide configurations for common Markdown flavors /// - [Resolver] which aid in resolving links and images /// /// If you are looking at extending the library to support custom formatting -/// what you may want is to: +/// what you might want is to: /// /// - Implement your own [InlineSyntax] subclasses /// - Implement your own [BlockSyntax] subclasses /// - Instruct the library to use those by: -/// - Creating a new [ExtensionSet] from one of the existing flavors adding your syntaxes -/// - Passing your syntaxes to [Document] or [markdownToHtml()] as parameters. -library markdown; +/// - Creating a new [ExtensionSet] from one of the existing flavors +/// and adding your syntaxes. +/// - Passing your syntaxes to [Document] or [markdownToHtml] as parameters. +library; import 'src/version.dart';
diff --git a/pkgs/markdown/lib/src/ast.dart b/pkgs/markdown/lib/src/ast.dart index 13490d0..e5530cb 100644 --- a/pkgs/markdown/lib/src/ast.dart +++ b/pkgs/markdown/lib/src/ast.dart
@@ -46,7 +46,7 @@ void accept(NodeVisitor visitor) { if (visitor.visitElementBefore(this)) { if (children != null) { - for (var child in children!) { + for (final child in children!) { child.accept(visitor); } }
diff --git a/pkgs/markdown/lib/src/block_syntaxes/code_block_syntax.dart b/pkgs/markdown/lib/src/block_syntaxes/code_block_syntax.dart index 38c9951..1d30667 100644 --- a/pkgs/markdown/lib/src/block_syntaxes/code_block_syntax.dart +++ b/pkgs/markdown/lib/src/block_syntaxes/code_block_syntax.dart
@@ -31,7 +31,7 @@ if (!isBlankLine && childLines.isNotEmpty && - pattern.hasMatch(parser.current.content) != true) { + !pattern.hasMatch(parser.current.content)) { break; } @@ -79,7 +79,7 @@ continue; } - return pattern.hasMatch(nextLine.content) == false; + return !pattern.hasMatch(nextLine.content); } } }
diff --git a/pkgs/markdown/lib/src/block_syntaxes/footnote_def_syntax.dart b/pkgs/markdown/lib/src/block_syntaxes/footnote_def_syntax.dart index 7b959ff..3e59dcf 100644 --- a/pkgs/markdown/lib/src/block_syntaxes/footnote_def_syntax.dart +++ b/pkgs/markdown/lib/src/block_syntaxes/footnote_def_syntax.dart
@@ -74,7 +74,8 @@ dummyPattern, }; - /// Whether this line is one kind of block, if true footnotes block should end. + /// Whether this line is any kind of block. + /// If `true`, the footnote block should end. static bool _isBlock(Iterable<BlockSyntax> syntaxList, String line) { return syntaxList.any((s) => s.pattern.hasMatch(line)); }
diff --git a/pkgs/markdown/lib/src/document.dart b/pkgs/markdown/lib/src/document.dart index b04fa07..f33ff33 100644 --- a/pkgs/markdown/lib/src/document.dart +++ b/pkgs/markdown/lib/src/document.dart
@@ -18,7 +18,9 @@ /// Footnote ref count, keys are case-sensitive and added by define syntax. final footnoteReferences = <String, int>{}; - /// Footnotes labels by appearing order, are case-insensitive and added by ref syntax. + /// Footnote labels by appearing order. + /// + /// They are case-insensitive and added by ref syntax. final footnoteLabels = <String>[]; final Resolver? linkResolver; final Resolver? imageLinkResolver; @@ -182,7 +184,8 @@ if (i > 0) Element('sup', [Text(num)])..attributes['class'] = 'footnote-ref', ]) - // Ignore GFM's attributes: <data-footnote-backref aria-label="Back to content">. + // Ignore GFM's attributes: + // <data-footnote-backref aria-label="Back to content">. ..attributes['href'] = '#fnref-$ref$suffix' ..attributes['class'] = 'footnote-backref'; }
diff --git a/pkgs/markdown/lib/src/inline_syntaxes/autolink_extension_syntax.dart b/pkgs/markdown/lib/src/inline_syntaxes/autolink_extension_syntax.dart index a7f174f..85773dc 100644 --- a/pkgs/markdown/lib/src/inline_syntaxes/autolink_extension_syntax.dart +++ b/pkgs/markdown/lib/src/inline_syntaxes/autolink_extension_syntax.dart
@@ -66,7 +66,7 @@ if (startMatch[1] != null && parser.pos > 0) { final precededBy = String.fromCharCode(parser.charAt(parser.pos - 1)); const validPrecedingChars = {' ', '*', '_', '~', '(', '>'}; - if (validPrecedingChars.contains(precededBy) == false) { + if (!validPrecedingChars.contains(precededBy)) { return false; } }
diff --git a/pkgs/markdown/lib/src/inline_syntaxes/footnote_ref_syntax.dart b/pkgs/markdown/lib/src/inline_syntaxes/footnote_ref_syntax.dart index 32a1eec..155fd74 100644 --- a/pkgs/markdown/lib/src/inline_syntaxes/footnote_ref_syntax.dart +++ b/pkgs/markdown/lib/src/inline_syntaxes/footnote_ref_syntax.dart
@@ -2,10 +2,13 @@ import '../charcode.dart'; import 'link_syntax.dart' show LinkContext; -/// The spec of GFM about footnotes is [missing](https://github.com/github/cmark-gfm/issues/283#issuecomment-1378868725). -/// For source code of cmark-gfm, See [noMatch] label of [handle_close_bracket] function in [master@c32ef78](https://github.com/github/cmark-gfm/blob/c32ef78/src/inlines.c#L1236). +/// The spec of GFM about footnotes is +/// [missing](https://github.com/github/cmark-gfm/issues/283#issuecomment-1378868725). +/// For source code of cmark-gfm, see the `noMatch` label of the +/// `handle_close_bracket` function in [master@c32ef78](https://github.com/github/cmark-gfm/blob/c32ef78/src/inlines.c#L1236). /// A Rust implementation is also [available](https://github.com/wooorm/markdown-rs/blob/2498e31eecead798efc649502bbf5f86feaa94be/src/construct/gfm_label_start_footnote.rs). -/// Footnote shares the same syntax with [LinkSyntax], but goes a different branch of handling close bracket. +/// Footnotes shares the same syntax with [LinkSyntax], +/// but have a different branch of handling the close bracket. class FootnoteRefSyntax { static String? _footnoteLabel(String key) { if (key.isEmpty || key.codeUnitAt(0) != $caret) {
diff --git a/pkgs/markdown/lib/src/patterns.dart b/pkgs/markdown/lib/src/patterns.dart index 967434a..c75838f 100644 --- a/pkgs/markdown/lib/src/patterns.dart +++ b/pkgs/markdown/lib/src/patterns.dart
@@ -23,7 +23,8 @@ /// Fenced code block. final codeFencePattern = RegExp( - r'^([ ]{0,3})(?:(?<backtick>`{3,})(?<backtickInfo>[^`]*)|(?<tilde>~{3,})(?<tildeInfo>.*))$', + '^([ ]{0,3})(?:(?<backtick>`{3,})(?<backtickInfo>[^`]*)|' + r'(?<tilde>~{3,})(?<tildeInfo>.*))$', ); /// Fenced blockquotes. @@ -102,35 +103,36 @@ /// The 7 conditions here correspond to the 7 start conditions in the Commonmark /// specification one by one: https://spec.commonmark.org/0.30/#html-block. final htmlBlockPattern = RegExp( - '^ {0,3}(?:' - '<(?<condition_1>pre|script|style|textarea)' - r'(?:\s|>|$)' - '|' - '(?<condition_2><!--)' - '|' - r'(?<condition_3><\?)' - '|' - '(?<condition_4><![a-z])' - '|' - r'(?<condition_5><!\[CDATA\[)' - '|' - '</?(?<condition_6>address|article|aside|base|basefont|blockquote|body|' - 'caption|center|col|colgroup|dd|details|dialog|dir|DIV|dl|dt|fieldset|' - 'figcaption|figure|footer|form|frame|frameset|h1|h2|h3|h4|h5|h6|head|' - 'header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|' - 'optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|' - 'thead|title|tr|track|ul)' - r'(?:\s|>|/>|$)' - '|' + '^ {0,3}(?:' + '<(?<condition_1>pre|script|style|textarea)' + r'(?:\s|>|$)' + '|' + '(?<condition_2><!--)' + '|' + r'(?<condition_3><\?)' + '|' + '(?<condition_4><![a-z])' + '|' + r'(?<condition_5><!\[CDATA\[)' + '|' + '</?(?<condition_6>address|article|aside|base|basefont|blockquote|body|' + 'caption|center|col|colgroup|dd|details|dialog|dir|DIV|dl|dt|fieldset|' + 'figcaption|figure|footer|form|frame|frameset|h1|h2|h3|h4|h5|h6|head|' + 'header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|' + 'optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|' + 'thead|title|tr|track|ul)' + r'(?:\s|>|/>|$)' + '|' - // Here we are more restrictive than the Commonmark definition (Rule #7). - // Otherwise some raw HTML test cases will fail, for example: - // https://spec.commonmark.org/0.30/#example-618. - // Because if a line is treated as an HTML block, it will output as Text node - // directly, the RawHtmlSyntax does not have a chance to validate if this - // HTML tag is legal or not. - '(?<condition_7>(?:$namedTagDefinition)\\s*\$))', - caseSensitive: false); + // Here we are more restrictive than the Commonmark definition (Rule #7). + // Otherwise some raw HTML test cases will fail, for example: + // https://spec.commonmark.org/0.30/#example-618. + // Because if a line is treated as an HTML block, it will output as a + // Text node directly, and the RawHtmlSyntax will not have a chance to + // validate if this HTML tag is legal or not. + '(?<condition_7>(?:$namedTagDefinition)\\s*\$))', + caseSensitive: false, +); /// ASCII punctuation characters. // See https://spec.commonmark.org/0.30/#unicode-whitespace-character.
diff --git a/pkgs/markdown/lib/src/text_parser.dart b/pkgs/markdown/lib/src/text_parser.dart index 1492268..2f696de 100644 --- a/pkgs/markdown/lib/src/text_parser.dart +++ b/pkgs/markdown/lib/src/text_parser.dart
@@ -32,7 +32,7 @@ char != $vt && char != $cr && char != $ff && - !(multiLine == true && char == $lf)) { + !(multiLine && char == $lf)) { return i; }
diff --git a/pkgs/markdown/test/blns.dart b/pkgs/markdown/test/blns.dart index a649c3a..4f06115 100644 --- a/pkgs/markdown/test/blns.dart +++ b/pkgs/markdown/test/blns.dart
@@ -2,9 +2,10 @@ // // This file was generated from big-list-of-naughty-strings's JSON file: // https://github.com/minimaxir/big-list-of-naughty-strings/raw/master/blns.json -// at 2022-04-16 22:37:54.467197 by the script, tool/update_blns.dart. +// at 2023-08-26 16:34:37.127975 by the script, tool/update_blns.dart. // ignore_for_file: text_direction_code_point_in_literal, use_raw_strings +// ignore_for_file: lines_longer_than_80_chars const blns = <String>[ '',
diff --git a/pkgs/markdown/tool/dartdoc_compare.dart b/pkgs/markdown/tool/dartdoc_compare.dart index 05e3fd7..e6100ee 100644 --- a/pkgs/markdown/tool/dartdoc_compare.dart +++ b/pkgs/markdown/tool/dartdoc_compare.dart
@@ -40,7 +40,9 @@ } if (options[_dartdocDir] == null || options[_markdownBefore] == null) { print( - 'Invalid arguments: Options --$_dartdocDir and --$_markdownBefore must be specified'); + 'Invalid arguments: Options --$_dartdocDir and --$_markdownBefore ' + 'must be specified', + ); print(parser.usage); exitCode = 1; return;
diff --git a/pkgs/markdown/tool/update_blns.dart b/pkgs/markdown/tool/update_blns.dart index e2b5c62..fbdabca 100644 --- a/pkgs/markdown/tool/update_blns.dart +++ b/pkgs/markdown/tool/update_blns.dart
@@ -17,6 +17,7 @@ // at ${DateTime.now()} by the script, tool/update_blns.dart. // ignore_for_file: text_direction_code_point_in_literal, use_raw_strings +// ignore_for_file: lines_longer_than_80_chars '''); blnsContent.writeln('const blns = <String>[');
diff --git a/pkgs/markdown/tool/update_emojis.dart b/pkgs/markdown/tool/update_emojis.dart index dad59c7..0b2b8a9 100644 --- a/pkgs/markdown/tool/update_emojis.dart +++ b/pkgs/markdown/tool/update_emojis.dart
@@ -44,8 +44,13 @@ } emojisContent.writeln('};'); File(_emojisFilePath).writeAsStringSync(emojisContent.toString()); - print('WARNING: This updates only the LEGACY emoji - to update the active\n' - 'emoji recognized by the markdown package, execute `update_github_emojis.dart`.\n'); - print('Wrote data to $_emojisFilePath for $emojiCount emoji, ' - 'ignoring ${ignored.length}: ${ignored.join(', ')}.'); + print( + 'WARNING: This updates only the LEGACY emoji - to update the active ' + 'emoji recognized by the markdown package, ' + 'execute `update_github_emojis.dart`.', + ); + print( + 'Wrote data to $_emojisFilePath for $emojiCount emoji, ' + 'ignoring ${ignored.length}: ${ignored.join(', ')}.', + ); }
diff --git a/pkgs/markdown/tool/update_entities.dart b/pkgs/markdown/tool/update_entities.dart index 2026ebc..2d114bd 100644 --- a/pkgs/markdown/tool/update_entities.dart +++ b/pkgs/markdown/tool/update_entities.dart
@@ -14,7 +14,7 @@ final map = Map<String, Map<String, dynamic>>.from(jsonDecode(json) as Map); final result = <String, String>{}; - for (var name in map.keys) { + for (final name in map.keys) { if (name.endsWith(';')) { final value = map[name]!['characters'] as String; result[name] = value;
diff --git a/pkgs/markdown/tool/update_github_emojis.dart b/pkgs/markdown/tool/update_github_emojis.dart index ea429d3..33751ec 100644 --- a/pkgs/markdown/tool/update_github_emojis.dart +++ b/pkgs/markdown/tool/update_github_emojis.dart
@@ -18,8 +18,10 @@ /// we don't change or break anything. /// There are essentially only TWO (2) emoji that change and the /// legacy emoji is still available with an alternate name. -/// The 'beetle' emoji changes from `🐞` to `🪲`, legacy available as 'lady_beetle'. -/// The 'cricket' emoji changes from `🏏` to `🦗`, legacy available as 'cricket_game'. +/// The 'beetle' emoji changes from `🐞` to `🪲`, +/// legacy available as 'lady_beetle'. +/// The 'cricket' emoji changes from `🏏` to `🦗`, +/// legacy available as 'cricket_game'. /// (if the -g flag us used to force using the GitHub Unicode sequences for the /// emoji then additionally the 'email' emoji changes from '✉️' to '📧'). const _emojisJsonRawUrl = 'https://api.github.com/emojis'; @@ -125,10 +127,11 @@ /// - "https://github.githubassets.com/images/icons/emoji/unicode/1f643.png?v8" /// - "https://github.githubassets.com/images/icons/emoji/unicode/1f1fa-1f1fe.png?v8" /// - "https://github.githubassets.com/images/icons/emoji/unicode/1f469-1f469-1f467-1f466.png?v8" -/// NOTE: Some filenames will be GitHub 'custom' emoji that have no Unicode -/// equivalent and these will not have hex codepoints, only the GitHub custom name. -/// We will ingore these (there are only a 19 and they are mostly pixel art from -/// the old Doom game). +/// NOTE: Some filenames will be GitHub 'custom' emoji that have +/// no Unicode equivalent and these will not have hex codepoints, +/// only the GitHub custom name. +/// We will ignore these (there are only a 19 and they are mostly pixel art +/// from the old Doom game). /// Example GitHub custom emoji filename: /// - "https://github.githubassets.com/images/icons/emoji/godmode.png?v8", String parseGitHubFilenameIntoUnicodeString(String emojiFilename) { @@ -140,8 +143,8 @@ .firstMatch(emojiFilename) ?.group(1); if (rawHexList == null) { - // This is a GitHub custom emoji and it is represented by a PNG image only and - // there is no equivalent Unicode. We have to ingore. + // This is a GitHub custom emoji and it is represented by a PNG image only + // and there is no equivalent Unicode. We have to ignore. return ''; } var legacyUsedVariationCode = false; @@ -159,7 +162,8 @@ codePointsHex.addAll(rawCodePointsHex); codePointsHex.add(variationSelector); } else { - // Now insert the join zero width and variation select modifying Unicode chars. + // Now insert the join zero width and + // variation select modifying Unicode chars. for (var i = 0; i < rawCodePointsHex.length; i++) { final codePointAtIndex = rawCodePointsHex[i]; codePointsHex.add(codePointAtIndex); @@ -204,8 +208,8 @@ 'tooltip': '(shortcode with a link to provide emoji name in tooltips)', }, - help: - 'Outputs all emoji shortcodes to stdout which can be used in markdown to show and tests all emoji.'); + help: 'Outputs all emoji shortcodes to stdout which can be used ' + 'in markdown to show and tests all emoji.'); late final ArgResults results; try { @@ -231,12 +235,15 @@ final dumpMarkdownToolTipShortCodes = shortCodes == 'tooltip'; if (!useLegacyUnicodeSequences) { - // Issue warning of the implications of using full GitHub emjoi Unicode sequences. + // Issue warning of the implications of using + // full GitHub emoji Unicode sequences. print(useOfGitHubUnicodeSequencesWarning); } if (visualizeUnicodeDiffs) { print( - 'The following emoji have different Unicode sequences from those of legacy versions:'); + 'The following emoji have different Unicode sequences ' + 'from those of legacy versions:', + ); } final shortcodeToEmoji = (await downloadJson(_emojisJsonRawUrl) as Map<String, dynamic>).map( @@ -246,8 +253,8 @@ ), ); - // Now before we proceed we need to 'mix in' any legacy emoji alias shortcodes that - // are missing from the GitHub emoji list. + // Now before we proceed we need to 'mix in' any legacy emoji alias shortcodes + // that are missing from the GitHub emoji list. legacyEmojis.forEach((String shortCodeAlias, String emojiUnicode) { if (!shortcodeToEmoji.containsKey(shortCodeAlias)) { shortcodeToEmoji[shortCodeAlias] = emojiUnicode; @@ -282,7 +289,9 @@ totalEmojiWithDifferentUnicodeSequences++; if (visualizeUnicodeDiffs) { print( - '$emojiUnicode was ${legacyEmojis[shortCodeAlias]} :$shortCodeAlias:'); + '$emojiUnicode was ${legacyEmojis[shortCodeAlias]} ' + ':$shortCodeAlias:', + ); } } if (emojiUnicode != errorSpecialReplacement && emojiUnicode.isNotEmpty) {