Formatting linter/parser be applied to snippets before they are copied to the clipboard

Idea created by Matt.Wilkie.Yukon on Aug 15, 2019
    Reviewed
    Score30
    • KDHL-GIS
    • Jamal432@gmail.com
    • Matt.Wilkie.Yukon

    ArcGIS Pro 2.4.1:  When using “Copy Python Command” from context menu in Geoprocessing History the resultant code uses inconsistent formatting, mixing single and double quotes for parameters. While technically it’s not wrong, it goes against best practice and sets the stage for making mistakes later. Arguments should be all single or all double quoted.

     

    Example raw clipboard contents:

     

    arcpy.management.MakeImageServerLayer("https://services.example.ca/imagery/services/Elevation/Elevation/ImageServer", "AOI - from elev svc", "299910.08935875 848995.617035001 304601.63344125 853442.221065001", None, "Seamline", '', "0", '', 1, "LowPS = 1", "None")

     

    Reformatted using a font which carefully distinguishes quote types and inconsistent quoting highlighted:

     

    arcpy.management.MakeImageServerLayer(

        "https://services.example.ca/imagery/services/Elevation/Elevation/ImageServer",

        "AOI - from elev svc",

        "299910.08935875 848995.617035001 304601.63344125 853442.221065001",

        None,

        "Seamline",

        '',

        "0",

        '',

        1,

        "LowPS = 1",

        "None")

     

    For example in this screenshot the user is invited to interpret Seamline as one parameter and comma  as the next parameter “,” when it’s actually ((( Seamline – comma – empty-single-quotes – comma ))).

     

    It’s not until carefully reformatting the code snippet that the real structure becomes apparent. An enhancement I recommend is that a python formatting linter/parser be applied to snippets before they are copied to the clipboard.

     

    (Black would be an excellent choice: https://black.readthedocs.io/en/stable/)