Enable raw strings lint rules (#418)
* Enable use_raw_strings lint rule
* Enable unnecessary_raw_strings lint rule
Co-authored-by: Sam Rawlins <srawlins@google.com>
diff --git a/analysis_options.yaml b/analysis_options.yaml
index 18598d8..92ca266 100644
--- a/analysis_options.yaml
+++ b/analysis_options.yaml
@@ -33,4 +33,6 @@
- throw_in_finally
- prefer_final_locals
- use_if_null_to_convert_nulls_to_bools
+ - use_raw_strings
+ - unnecessary_raw_strings
- prefer_interpolation_to_compose_strings
diff --git a/example/app.dart b/example/app.dart
index f9556c2..78da8a3 100644
--- a/example/app.dart
+++ b/example/app.dart
@@ -14,7 +14,7 @@
final nullSanitizer = NullTreeSanitizer();
const typing = Duration(milliseconds: 150);
-final introText = r'''Markdown is the **best**!
+final introText = '''Markdown is the **best**!
* It has lists.
* It has [links](https://dart.dev).
diff --git a/lib/src/block_parser.dart b/lib/src/block_parser.dart
index b54fce7..17a7739 100644
--- a/lib/src/block_parser.dart
+++ b/lib/src/block_parser.dart
@@ -88,9 +88,9 @@
LongBlockHtmlSyntax(r'^ {0,3}<script(?:\s|>|$)', '</script>'),
LongBlockHtmlSyntax(r'^ {0,3}<style(?:\s|>|$)', '</style>'),
LongBlockHtmlSyntax('^ {0,3}<!--', '-->'),
- LongBlockHtmlSyntax('^ {0,3}<\\?', '\\?>'),
+ LongBlockHtmlSyntax(r'^ {0,3}<\?', r'\?>'),
LongBlockHtmlSyntax('^ {0,3}<![A-Z]', '>'),
- LongBlockHtmlSyntax('^ {0,3}<!\\[CDATA\\[', '\\]\\]>'),
+ LongBlockHtmlSyntax(r'^ {0,3}<!\[CDATA\[', r'\]\]>'),
const OtherTagBlockHtmlSyntax(),
const SetextHeaderSyntax(),
const HeaderSyntax(),
@@ -211,7 +211,7 @@
element.children!.first.textContent
.toLowerCase()
.trim()
- .replaceAll(RegExp(r'[^a-z0-9 _-]'), '')
+ .replaceAll(RegExp('[^a-z0-9 _-]'), '')
.replaceAll(RegExp(r'\s'), '-');
}
@@ -591,19 +591,19 @@
class BlockTagBlockHtmlSyntax extends BlockHtmlSyntax {
static final _pattern = RegExp(
- r'^ {0,3}</?(?:address|article|aside|base|basefont|blockquote|body|'
- r'caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|'
- r'figcaption|figure|footer|form|frame|frameset|h1|head|header|hr|html|'
- r'iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|'
- r'option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|'
- r'title|tr|track|ul)'
+ '^ {0,3}</?(?: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|head|header|hr|html|'
+ 'iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|'
+ 'option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|'
+ 'title|tr|track|ul)'
r'(?:\s|>|/>|$)');
/// The [_pattern] regular expression above is very expensive, even on
/// paragraphs of Markdown with no HTML. This regular expression can be used
/// first as a basic check that the input might possibly be an HTML block
/// tag, which occur very rarely in typical Markdown.
- static final _openBracketPattern = RegExp(r'^ {0,3}<');
+ static final _openBracketPattern = RegExp('^ {0,3}<');
@override
RegExp get pattern => _pattern;
@@ -1238,7 +1238,7 @@
bool _parseReflinkDefinition(BlockParser parser, String contents) {
final pattern = RegExp(
// Leading indentation.
- r'''^[ ]{0,3}'''
+ '''^[ ]{0,3}'''
// Reference id in brackets, and URL.
r'''\[((?:\\\]|[^\]])+)\]:\s*(?:<(\S+)>|(\S+))\s*'''
// Title in double or single quotes, or parens.
diff --git a/lib/src/inline_parser.dart b/lib/src/inline_parser.dart
index 29b09b3..ac0cc73 100644
--- a/lib/src/inline_parser.dart
+++ b/lib/src/inline_parser.dart
@@ -22,7 +22,7 @@
// "*" surrounded by spaces is left alone.
TextSyntax(r' \* ', startCharacter: $space),
// "_" surrounded by spaces is left alone.
- TextSyntax(r' _ ', startCharacter: $space),
+ TextSyntax(' _ ', startCharacter: $space),
// Parse "**strong**" and "*emphasis*" tags.
EmphasisSyntax.asterisk(),
// Parse "__strong__" and "_emphasis_" tags.
@@ -35,13 +35,13 @@
List<InlineSyntax>.unmodifiable(<InlineSyntax>[
// Leave already-encoded HTML entities alone. Ensures we don't turn
// "&" into "&amp;"
- TextSyntax(r'&[#a-zA-Z0-9]*;', startCharacter: $ampersand),
+ TextSyntax('&[#a-zA-Z0-9]*;', startCharacter: $ampersand),
// Encode "&".
- TextSyntax(r'&', sub: '&', startCharacter: $ampersand),
+ TextSyntax('&', sub: '&', startCharacter: $ampersand),
// Encode "<".
- TextSyntax(r'<', sub: '<', startCharacter: $lt),
+ TextSyntax('<', sub: '<', startCharacter: $lt),
// Encode ">".
- TextSyntax(r'>', sub: '>', startCharacter: $gt),
+ TextSyntax('>', sub: '>', startCharacter: $gt),
]);
/// The string of Markdown being parsed.
@@ -549,7 +549,7 @@
// Trailing punctuation (specifically, ?, !, ., ,, :, *, _, and ~) will not
// be considered part of the autolink
- static const truncatingPunctuationPositive = r'[?!.,:*_~]';
+ static const truncatingPunctuationPositive = '[?!.,:*_~]';
static final regExpTrailingPunc = RegExp('$truncatingPunctuationPositive*\$');
static final regExpEndsWithColon = RegExp(r'\&[a-zA-Z0-9]+;$');
@@ -742,7 +742,7 @@
// This RegExp is inspired by
// https://github.com/commonmark/commonmark.js/blob/1f7d09099c20d7861a674674a5a88733f55ff729/lib/inlines.js#L39.
// I don't know if there is any way to simplify it or maintain it.
- static final RegExp punctuation = RegExp(r'['
+ static final RegExp punctuation = RegExp('['
r'''!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~'''
r'\xA1\xA7\xAB\xB6\xB7\xBB\xBF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE'
r'\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061E'
diff --git a/test/blns.dart b/test/blns.dart
index f059f6d..a649c3a 100644
--- a/test/blns.dart
+++ b/test/blns.dart
@@ -2,9 +2,9 @@
//
// 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 2021-11-14 15:03:54.726971 by the script, tool/update_blns.dart.
+// at 2022-04-16 22:37:54.467197 by the script, tool/update_blns.dart.
-// ignore_for_file: text_direction_code_point_in_literal
+// ignore_for_file: text_direction_code_point_in_literal, use_raw_strings
const blns = <String>[
'',
diff --git a/test/markdown_test.dart b/test/markdown_test.dart
index 539c397..827a696 100644
--- a/test/markdown_test.dart
+++ b/test/markdown_test.dart
@@ -106,7 +106,7 @@
validateCore(
'can choose to _not_ resolve something, like an empty link',
- r'''
+ '''
resolve [[]] thing
''',
'''
diff --git a/tool/stats.dart b/tool/stats.dart
index 55ec4ca..55f05b8 100644
--- a/tool/stats.dart
+++ b/tool/stats.dart
@@ -81,7 +81,7 @@
}
}
-final _sectionNameReplace = RegExp('[ \\)\\(]+');
+final _sectionNameReplace = RegExp(r'[ \)\(]+');
String _unitOutput(Iterable<DataCase> cases) => cases.map((dataCase) => '''
>>> ${dataCase.front_matter}
diff --git a/tool/update_blns.dart b/tool/update_blns.dart
index 589b52f..7491470 100644
--- a/tool/update_blns.dart
+++ b/tool/update_blns.dart
@@ -27,7 +27,7 @@
// $_blnsJsonRawUrl
// at ${DateTime.now()} by the script, tool/update_blns.dart.
-// ignore_for_file: text_direction_code_point_in_literal
+// ignore_for_file: text_direction_code_point_in_literal, use_raw_strings
''');
blnsContent.writeln('const blns = <String>[');