Skip to content

Commit

Permalink
Fix a few more lints, no longer ignore line length (#552)
Browse files Browse the repository at this point in the history
  • Loading branch information
parlough authored Aug 30, 2023
1 parent 56e75df commit 52be591
Show file tree
Hide file tree
Showing 16 changed files with 110 additions and 80 deletions.
5 changes: 2 additions & 3 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -8,8 +8,6 @@ analyzer:
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
Expand All @@ -30,6 +28,7 @@ linter:
- 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
Expand Down
30 changes: 17 additions & 13 deletions lib/markdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion lib/src/ast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Element implements Node {
void accept(NodeVisitor visitor) {
if (visitor.visitElementBefore(this)) {
if (children != null) {
for (var child in children!) {
for (final child in children!) {
child.accept(visitor);
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/block_syntaxes/code_block_syntax.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CodeBlockSyntax extends BlockSyntax {

if (!isBlankLine &&
childLines.isNotEmpty &&
pattern.hasMatch(parser.current.content) != true) {
!pattern.hasMatch(parser.current.content)) {
break;
}

Expand Down Expand Up @@ -79,7 +79,7 @@ class CodeBlockSyntax extends BlockSyntax {
continue;
}

return pattern.hasMatch(nextLine.content) == false;
return !pattern.hasMatch(nextLine.content);
}
}
}
3 changes: 2 additions & 1 deletion lib/src/block_syntaxes/footnote_def_syntax.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ class FootnoteDefSyntax extends BlockSyntax {
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));
}
Expand Down
7 changes: 5 additions & 2 deletions lib/src/document.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ class Document {
/// 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;
Expand Down Expand Up @@ -182,7 +184,8 @@ extension _ElementExt on Element {
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';
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/inline_syntaxes/autolink_extension_syntax.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class AutolinkExtensionSyntax extends InlineSyntax {
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;
}
}
Expand Down
9 changes: 6 additions & 3 deletions lib/src/inline_syntaxes/footnote_ref_syntax.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import '../ast.dart' show Element, Node, Text;
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) {
Expand Down
62 changes: 32 additions & 30 deletions lib/src/patterns.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ final indentPattern = RegExp(r'^(?: | {0,3}\t)(.*)$');

/// 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.
Expand Down Expand Up @@ -102,35 +103,36 @@ const namedTagDefinition =
/// 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|>|/>|$)'
'|'

// 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);
'^ {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 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.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/text_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class TextParser {
char != $vt &&
char != $cr &&
char != $ff &&
!(multiLine == true && char == $lf)) {
!(multiLine && char == $lf)) {
return i;
}

Expand Down
3 changes: 2 additions & 1 deletion test/blns.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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>[
'',
Expand Down
4 changes: 3 additions & 1 deletion tool/dartdoc_compare.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ void main(List<String> arguments) {
}
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;
Expand Down
1 change: 1 addition & 0 deletions tool/update_blns.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Future<void> main() async {
// 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>[');
Expand Down
13 changes: 9 additions & 4 deletions tool/update_emojis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,13 @@ Future<void> main() async {
}
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(', ')}.',
);
}
2 changes: 1 addition & 1 deletion tool/update_entities.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void main() {
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;
Expand Down
Loading

0 comments on commit 52be591

Please sign in to comment.