misc/chrome/gophertool/gopher.js JAVASCRIPT 42 lines View on github.com → Search inside
1// Copyright 2011 The Go Authors. All rights reserved.2// Use of this source code is governed by a BSD-style3// license that can be found in the LICENSE file.45var numericRE = /^\d+$/;6var commitRE = /^(?:\d+:)?([0-9a-f]{6,40})$/; // e.g "8486:ab29d2698a47" or "ab29d2698a47"7var gerritChangeIdRE = /^I[0-9a-f]{4,40}$/; // e.g. Id69c00d908d18151486007ec03da5495b34b05f58var pkgRE = /^[a-z0-9_\/]+$/;910function urlForInput(t) {11    if (!t) {12        return null;13    }1415    if (numericRE.test(t)) {16        if (t < 150000) {17            // We could use the golang.org/cl/ handler here, but18            // avoid some redirect latency and go right there, since19            // one is easy. (no server-side mapping)20            return "https://github.com/golang/go/issues/" + t;21        }22        return "https://golang.org/cl/" + t;23    }2425    if (gerritChangeIdRE.test(t)) {26        return "https://golang.org/cl/" + t;27    }2829    var match = commitRE.exec(t);30    if (match) {31        return "https://golang.org/change/" + match[1];32    }3334    if (pkgRE.test(t)) {35        // TODO: make this smarter, using a list of packages + substring matches.36        // Get the list from godoc itself in JSON format?37        return "https://golang.org/pkg/" + t;38    }3940    return null;41}

Code quality findings 5

Use let or const to avoid scope issues and hoisting
info correctness var-declaration
var numericRE = /^\d+$/;
Use let or const to avoid scope issues and hoisting
info correctness var-declaration
var commitRE = /^(?:\d+:)?([0-9a-f]{6,40})$/; // e.g "8486:ab29d2698a47" or "ab29d2698a47"
Use let or const to avoid scope issues and hoisting
info correctness var-declaration
var gerritChangeIdRE = /^I[0-9a-f]{4,40}$/; // e.g. Id69c00d908d18151486007ec03da5495b34b05f5
Use let or const to avoid scope issues and hoisting
info correctness var-declaration
var pkgRE = /^[a-z0-9_\/]+$/;
Use let or const to avoid scope issues and hoisting
info correctness var-declaration
var match = commitRE.exec(t);

Get this view in your editor

Same data, no extra tab — call code_get_file + code_get_findings over MCP from Claude/Cursor/Copilot.