Make the spell checker a bit more conservative.

Reduce the max spell-checking distance for matching words.
"target" will not match "range" anymore.

--
PiperOrigin-RevId: 150638073
MOS_MIGRATED_REVID=150638073
diff --git a/src/main/java/com/google/devtools/build/lib/util/SpellChecker.java b/src/main/java/com/google/devtools/build/lib/util/SpellChecker.java
index 2671a90..ba3ae18 100644
--- a/src/main/java/com/google/devtools/build/lib/util/SpellChecker.java
+++ b/src/main/java/com/google/devtools/build/lib/util/SpellChecker.java
@@ -83,7 +83,7 @@
   public static String suggest(String input, Iterable<String> words) {
     String best = null;
     // Heuristic: the expected number of typos depends on the length of the word.
-    int bestDistance = Math.min(5, input.length() / 2 + 1);
+    int bestDistance = Math.min(5, (input.length() + 1) / 2);
     input = input.toLowerCase();
     for (String candidate : words) {
       int d = editDistance(input, candidate.toLowerCase(), bestDistance);
diff --git a/src/test/java/com/google/devtools/build/lib/util/SpellCheckerTest.java b/src/test/java/com/google/devtools/build/lib/util/SpellCheckerTest.java
index 5b4e55d..5ff97e8 100644
--- a/src/test/java/com/google/devtools/build/lib/util/SpellCheckerTest.java
+++ b/src/test/java/com/google/devtools/build/lib/util/SpellCheckerTest.java
@@ -84,8 +84,9 @@
   @Test
   public void suggest() throws Exception {
     List<String> dict = Lists.newArrayList(
-        "isalnum", "isalpha", "isdigit", "islower", "isupper", "find", "join",
-        "rsplit", "rstrip", "split", "splitlines", "startswith", "strip", "title", "upper");
+        "isalnum", "isalpha", "isdigit", "islower", "isupper", "find", "join", "range",
+        "rsplit", "rstrip", "split", "splitlines", "startswith", "strip", "title", "upper",
+        "x", "xyz");
 
     assertThat(SpellChecker.suggest("isdfit", dict)).isEqualTo("isdigit");
     assertThat(SpellChecker.suggest("rspit", dict)).isEqualTo("rsplit");
@@ -95,12 +96,17 @@
     assertThat(SpellChecker.suggest("fird", dict)).isEqualTo("find");
     assertThat(SpellChecker.suggest("stip", dict)).isEqualTo("strip");
     assertThat(SpellChecker.suggest("isAln", dict)).isEqualTo("isalnum");
+    assertThat(SpellChecker.suggest("targe", dict)).isEqualTo("range");
+    assertThat(SpellChecker.suggest("rarget", dict)).isEqualTo("range");
+    assertThat(SpellChecker.suggest("xyw", dict)).isEqualTo("xyz");
 
-    assertThat(SpellChecker.suggest("isAl", dict)).isEqualTo(null);
-    assertThat(SpellChecker.suggest("", dict)).isEqualTo(null);
-    assertThat(SpellChecker.suggest("f", dict)).isEqualTo(null);
-    assertThat(SpellChecker.suggest("fir", dict)).isEqualTo(null);
-    assertThat(SpellChecker.suggest("wqevxc", dict)).isEqualTo(null);
-    assertThat(SpellChecker.suggest("ialsnuaip", dict)).isEqualTo(null);
+    assertThat(SpellChecker.suggest("target", dict)).isNull();
+    assertThat(SpellChecker.suggest("isAl", dict)).isNull();
+    assertThat(SpellChecker.suggest("", dict)).isNull();
+    assertThat(SpellChecker.suggest("f", dict)).isNull();
+    assertThat(SpellChecker.suggest("fir", dict)).isNull();
+    assertThat(SpellChecker.suggest("wqevxc", dict)).isNull();
+    assertThat(SpellChecker.suggest("ialsnuaip", dict)).isNull();
+    assertThat(SpellChecker.suggest("xy", dict)).isNull();
   }
 }