add missing_whitespace_between_adjacent_strings (#1972)

* add missing_whitespace_between_adjacent_strings

* address review comments
diff --git a/example/all.yaml b/example/all.yaml
index 9578efa..0f8c491 100644
--- a/example/all.yaml
+++ b/example/all.yaml
@@ -71,6 +71,7 @@
     - lines_longer_than_80_chars
     - list_remove_unrelated_type
     - literal_only_boolean_expressions
+    - missing_whitespace_between_adjacent_strings
     - no_adjacent_strings_in_list
     - no_duplicate_case_values
     - no_logic_in_create_state
diff --git a/lib/src/rules.dart b/lib/src/rules.dart
index 57828c5..2f45f5e 100644
--- a/lib/src/rules.dart
+++ b/lib/src/rules.dart
@@ -72,6 +72,7 @@
 import 'rules/lines_longer_than_80_chars.dart';
 import 'rules/list_remove_unrelated_type.dart';
 import 'rules/literal_only_boolean_expressions.dart';
+import 'rules/missing_whitespace_between_adjacent_strings.dart';
 import 'rules/no_adjacent_strings_in_list.dart';
 import 'rules/no_duplicate_case_values.dart';
 import 'rules/no_logic_in_create_state.dart';
@@ -236,6 +237,7 @@
     ..register(LinesLongerThan80Chars())
     ..register(ListRemoveUnrelatedType())
     ..register(LiteralOnlyBooleanExpressions())
+    ..register(MissingWhitespaceBetweenAdjacentStrings())
     ..register(NoAdjacentStringsInList())
     ..register(NoDuplicateCaseValues())
     ..register(NonConstantIdentifierNames())
diff --git a/lib/src/rules/missing_whitespace_between_adjacent_strings.dart b/lib/src/rules/missing_whitespace_between_adjacent_strings.dart
new file mode 100644
index 0000000..93c68b2
--- /dev/null
+++ b/lib/src/rules/missing_whitespace_between_adjacent_strings.dart
@@ -0,0 +1,107 @@
+// Copyright (c) 2020, 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.
+
+import 'package:analyzer/dart/ast/ast.dart';
+import 'package:analyzer/dart/ast/visitor.dart';
+
+import '../analyzer.dart';
+
+const _desc = r'Missing whitespace between adjacent strings.';
+
+const _details = r'''
+
+Add a trailing whitespace to prevent missing whitespace between adjacent
+strings.
+
+With long text split accross adjacent strings it's easy to forget a whitespace
+between strings.
+
+**BAD:**
+```
+var s =
+  'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed'
+  'do eiusmod tempor incididunt ut labore et dolore magna';
+```
+
+**GOOD:**
+```
+var s =
+  'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed '
+  'do eiusmod tempor incididunt ut labore et dolore magna';
+```
+
+''';
+
+class MissingWhitespaceBetweenAdjacentStrings extends LintRule
+    implements NodeLintRule {
+  MissingWhitespaceBetweenAdjacentStrings()
+      : super(
+            name: 'missing_whitespace_between_adjacent_strings',
+            description: _desc,
+            details: _details,
+            group: Group.style);
+
+  @override
+  void registerNodeProcessors(NodeLintRegistry registry,
+      [LinterContext context]) {
+    final visitor = _Visitor(this);
+    registry.addCompilationUnit(this, visitor);
+  }
+}
+
+class _Visitor extends RecursiveAstVisitor<void> {
+  final LintRule rule;
+
+  _Visitor(this.rule);
+
+  @override
+  void visitAdjacentStrings(AdjacentStrings node) {
+    // skip regexp
+    if (node.parent is ArgumentList) {
+      final parentParent = node.parent.parent;
+      if (parentParent is InstanceCreationExpression &&
+              parentParent.staticElement.enclosingElement.name == 'RegExp' ||
+          parentParent is MethodInvocation &&
+              parentParent.realTarget == null &&
+              const ['RegExp', 'matches']
+                  .contains(parentParent.methodName.name)) {
+        return;
+      }
+    }
+
+    for (var i = 0; i < node.strings.length - 1; i++) {
+      final current = node.strings[i];
+      final next = node.strings[i + 1];
+      if (_visit(current, (l) => _endsWithWhitespace(l.last)) ||
+          _visit(next, (l) => _startsWithWhitespace(l.first))) {
+        continue;
+      }
+      if (!_visit(current, (l) => l.any(_hasWhitespace))) {
+        continue;
+      }
+      rule.reportLint(current);
+    }
+
+    return super.visitAdjacentStrings(node);
+  }
+
+  bool _visit(StringLiteral string, bool Function(Iterable<String>) test) {
+    if (string is SimpleStringLiteral) {
+      return test([string.value]);
+    } else if (string is StringInterpolation) {
+      return test(string.elements.map((e) {
+        if (e is InterpolationString) return e.value;
+        return '';
+      }));
+    }
+    throw ArgumentError('${string.runtimeType}: $string');
+  }
+
+  bool _hasWhitespace(String value) => _whitespaces.any(value.contains);
+  bool _endsWithWhitespace(String value) => _whitespaces.any(value.endsWith);
+  bool _startsWithWhitespace(String value) =>
+      _whitespaces.any(value.startsWith);
+}
+
+const _whitespaces = [' ', '\n', '\r', '\t'];
diff --git a/test/rules/missing_whitespace_between_adjacent_strings.dart b/test/rules/missing_whitespace_between_adjacent_strings.dart
new file mode 100644
index 0000000..3c2e48a
--- /dev/null
+++ b/test/rules/missing_whitespace_between_adjacent_strings.dart
@@ -0,0 +1,24 @@
+// Copyright (c) 2020, 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.
+
+// test w/ `pub run test -N missing_whitespace_between_adjacent_strings`
+
+f(o) {
+  f('long line' // LINT
+    'is long');
+  f('long $f line' // LINT
+    'is long');
+  f('long line' ' is long'); // OK
+  f('long line ' 'is long'); // OK
+  f('long $f line ' 'is long'); // OK
+  f('longLineWithoutSpaceCouldBe' 'AnURL'); // OK
+  f('long line\n' 'is long'); // OK
+  f('long line\r' 'is long'); // OK
+  f('long line\t' 'is long'); // OK
+
+  f(RegExp('(\n)+' '(\n)+' '(\n)+')); // OK
+  matches('(\n)+' '(\n)+' '(\n)+'); // OK
+}
+
+void matches(String value){}