hundreds-father-404
04/06/2021, 12:50 AM//
comments:hundreds-father-404
04/06/2021, 12:54 AMimport\s*\"(.+?\.proto)\"\s*;
, which captures the filename in import "foo.proto";
for example
I want to improve this so that if there's a preceeding //
before import
, then the regex does not match.
^(?!\/\/).*import\s*\"(.+?\.proto)\"\s*;
does the trick, but it does not handle this edge case:
some proto code; // import "foo.proto";
So, I was thinking to tweak it to put ^[^\/](?!\/\/).*
before the import
part, with the intent that you can have any characters except for /
before that negative lookahead. But that fails if there's a single /
in the prefix, and I only want to do that if there are twohundreds-father-404
04/06/2021, 12:54 AMaverage-vr-56795
04/06/2021, 1:27 AM^\s*import\s*\"(.+?\.proto)\"\s*;
) rather than "look for an import not after //"hundreds-father-404
04/06/2021, 1:30 AM// import "foo.proto";
But not these
some code // import "foo.proto";
// this is now stale code: import "foo.proto";
That sounds sensible, it is an improvement from the status quo even though it's not perfect. Which on that note, I'm making zero attempt to handle /* */
multiline comments - in the worst case, you can use an !
ignore to fix false positiveshundreds-father-404
04/06/2021, 1:30 AMsource
statements: https://github.com/pantsbuild/pants/pull/11844
They share lots of similar code)enough-analyst-54434
04/06/2021, 1:42 AMenough-analyst-54434
04/06/2021, 1:42 AMenough-analyst-54434
04/06/2021, 1:45 AMenough-analyst-54434
04/06/2021, 1:53 AMshellcheck --format=json
gives you everything you need if you look for error code 1091 which is "can''t follow source", It has the line number, start and offset of the token being sourced.enough-analyst-54434
04/06/2021, 1:53 AMenough-analyst-54434
04/06/2021, 1:54 AMhundreds-father-404
04/06/2021, 1:54 AMFear the regexes when you can.I hate regex, so works for me
enough-analyst-54434
04/06/2021, 1:58 AMhappy-kitchen-89482
04/06/2021, 4:23 AMhappy-kitchen-89482
04/06/2021, 4:24 AMhappy-kitchen-89482
04/06/2021, 4:24 AMhundreds-father-404
04/06/2021, 4:25 AM"detect an import only if it's preceded by nothing but whitespace to the beginning of the line" is easy even with a regex,It is easy to implement, indeed. I'll land that as an improvement
I don't recall proto syntax offhand, but can a legitimate import ever be preceded by anything other than whitespace?Yep.
syntax = "proto3"; // We don't use proto2 anymore
happy-kitchen-89482
04/06/2021, 4:25 AMhundreds-father-404
04/06/2021, 4:26 AMhundreds-father-404
04/07/2021, 8:58 AM# shellcheck source=build-support/common.sh
is understood by our dep inference