mirror of
https://github.com/dart-lang/sdk
synced 2024-10-06 14:07:57 +00:00
linter: Move tests for two lint rules
* lines_longer_than_80_chars * unnecessary_brace_in_string_interps Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try Change-Id: I75b5a5feeb863cb7463467d96ad751d6334e7cfd Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371940 Auto-Submit: Sam Rawlins <srawlins@google.com> Commit-Queue: Phil Quitslund <pquitslund@google.com> Reviewed-by: Phil Quitslund <pquitslund@google.com>
This commit is contained in:
parent
80b0bda3de
commit
39497e46fc
|
@ -86,6 +86,29 @@ class LinesLongerThan80CharsTest extends LintRuleTest {
|
|||
);
|
||||
}
|
||||
|
||||
test_exactly80Characters() async {
|
||||
await assertNoDiagnostics(r'''
|
||||
var p =
|
||||
' ';
|
||||
''');
|
||||
}
|
||||
|
||||
test_lineEndsWithCrlf() async {
|
||||
await assertNoDiagnostics('''
|
||||
var p =
|
||||
' ';\r\n
|
||||
''');
|
||||
}
|
||||
|
||||
test_longerThan80Characters() async {
|
||||
await assertDiagnostics(r'''
|
||||
var p =
|
||||
' ';
|
||||
''', [
|
||||
lint(88, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
test_multilineBlockComment_noSpaceAfter80() async {
|
||||
await assertNoDiagnostics(
|
||||
'/*\n'
|
||||
|
@ -123,4 +146,32 @@ class LinesLongerThan80CharsTest extends LintRuleTest {
|
|||
],
|
||||
);
|
||||
}
|
||||
|
||||
test_multilineString() async {
|
||||
await assertNoDiagnostics(r'''
|
||||
var p = """
|
||||
This line is a long, very long, very very long, very very very long, very very very very long
|
||||
""";
|
||||
''');
|
||||
}
|
||||
|
||||
test_shorterThan80Characters() async {
|
||||
await assertNoDiagnostics(r'''
|
||||
var short = 'This is a short line';
|
||||
''');
|
||||
}
|
||||
|
||||
test_stringContainsBackslash() async {
|
||||
await assertNoDiagnostics(r'''
|
||||
var p =
|
||||
r'C:\home\dart.dev\guides\language\effective-dart\style\avoid-lines-longer-than-80-characters';
|
||||
''');
|
||||
}
|
||||
|
||||
test_stringContainsForwardSlash() async {
|
||||
await assertNoDiagnostics(r'''
|
||||
var p =
|
||||
'/home/dart.dev/guides/language/effective-dart/style#avoid-lines-longer-than-80-characters'; // OK
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,83 @@ class UnnecessaryBraceInStringInterpsTest extends LintRuleTest {
|
|||
@override
|
||||
String get lintRule => 'unnecessary_brace_in_string_interps';
|
||||
|
||||
test_braces_bangAfter() async {
|
||||
await assertDiagnostics(r'''
|
||||
void f() {
|
||||
print('hello ${int}!');
|
||||
}
|
||||
''', [
|
||||
lint(26, 6),
|
||||
]);
|
||||
}
|
||||
|
||||
test_braces_nonSimpleIdentifier() async {
|
||||
await assertNoDiagnostics(r'''
|
||||
void f(int p) {
|
||||
print('hello ${p.hashCode}');
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_braces_precededByDollar() async {
|
||||
await assertNoDiagnostics(r'''
|
||||
void f() {
|
||||
var $int = 7;
|
||||
print('Value is: ${$int}');
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_braces_simpleIdentifier() async {
|
||||
await assertDiagnostics(r'''
|
||||
void f() {
|
||||
print('hello ${int}');
|
||||
}
|
||||
''', [
|
||||
lint(26, 6),
|
||||
]);
|
||||
}
|
||||
|
||||
test_braces_simpleIdentifier_numberAfter() async {
|
||||
await assertNoDiagnostics(r'''
|
||||
void f() {
|
||||
print('hello ${int}1');
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_braces_surroundedByUnderscores() async {
|
||||
await assertNoDiagnostics(r'''
|
||||
void f() {
|
||||
print('hello _${int}_');
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_noBraces() async {
|
||||
await assertNoDiagnostics(r'''
|
||||
void f() {
|
||||
print('hello $int');
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_noBraces_bangAfter() async {
|
||||
await assertNoDiagnostics(r'''
|
||||
void f() {
|
||||
print('hello $int!');
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_noInterpolation() async {
|
||||
await assertNoDiagnostics(r'''
|
||||
void f() {
|
||||
print('hello');
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_simpleIdentifier() async {
|
||||
await assertDiagnostics(r'''
|
||||
void hi(String name) {
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
|
||||
// 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.
|
||||
|
||||
var short = 'This is a short line'; // OK
|
||||
var line80 =
|
||||
' '; // OK
|
||||
var line81 =
|
||||
' '; // LINT
|
||||
var long =
|
||||
'This line is a long, very long, very very long, very very very long, very very very very long'; // LINT
|
||||
|
||||
var uriIsOk =
|
||||
'https://dart.dev/guides/language/effective-dart/style#avoid-lines-longer-than-80-characters'; // OK
|
||||
|
||||
var posixPathIsOk =
|
||||
'/home/dart.dev/guides/language/effective-dart/style#avoid-lines-longer-than-80-characters'; // OK
|
||||
|
||||
var windowsPathIsOk =
|
||||
r'C:\home\dart.dev\guides\language\effective-dart\style\avoid-lines-longer-than-80-characters'; // OK
|
||||
|
||||
var multilinesOK = '''
|
||||
This line is a long, very long, very very long, very very very long, very very very very long
|
||||
''';
|
||||
|
||||
var interpolated = 'this $uriIsOk that';
|
||||
|
||||
var line80EndingWithCRLF =
|
||||
' '; // OK
|
|
@ -1,16 +0,0 @@
|
|||
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
|
||||
// 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.
|
||||
|
||||
main(args) {
|
||||
print('hello');
|
||||
print('hello $args');
|
||||
print('hello $args!');
|
||||
print('hello ${args}1');
|
||||
print('hello ${args}'); //LINT [16:7]
|
||||
print('hello ${args}!'); //LINT
|
||||
print('hello ${args.length}');
|
||||
print('hello _${args}_');
|
||||
var $someString = 'Some Value';
|
||||
print('Value is: ${$someString}'); //OK
|
||||
}
|
Loading…
Reference in a new issue