1 minute read

LGTM is a nice little integration for your GitHub projects that performs code analysis and alerts if any violations are found. And example of what an alert screen looks like on the LGTM site below (using my fluentcpp project as a demonstration).

Example LGTM Alert Screen

You will need to grant the application access to your repositories using their guide Integration with GitHub Apps.

You can then setup badges on your project site that show the status of your code quality.

Code Grade Code Alerts

If more customization is needed, an .lgtml.yml file can be created in the root of the repository per their instructions. You can also download their canonical template too to get started.

Here’s a search of GitHub to look at other example configuration files. For example in my project I needed a more recent version of CMake. This is what mine looks like so it is in the environment before LGTM performs its analysis.

extraction:
  cpp:
    after_prepare:
      - "mkdir custom_cmake"
      # Need later version of CMake than lgtm has.
      - "wget --quiet -O - https://cmake.org/files/v3.16/cmake-3.16.3-Linux-x86_64.tar.gz | tar --strip-components=1 -xz -C custom_cmake"
      - "export PATH=$(pwd)/custom_cmake/bin:${PATH}"
    index:
      build_command:
        - cd $LGTM_SRC
        - mkdir build; cd build
        - cmake .. -DCMAKE_BUILD_TYPE=RELWITHDEBINFO
        - make

Here’s another taken from GitHub that excludes specified directories from analysis.

path_classifiers:
  plugins:
    - plugins/

extraction:
  javascript:
    # https://lgtm.com/help/lgtm/javascript-extraction#customizing-index
    # The `index` step extracts information from the files in the codebase.
    index:
      # Specify a list of files and folders to exclude from extraction.
      exclude:
        - bower_components/
        - docs/assets/js/plugins/
        - plugins/

… or from another repository more simply.

extraction:
  javascript:
    index:
      filters:
        - exclude: "dist"

Here’s yet another repository. This one disables CMake and sets the configuration options before build.

extraction:
  cpp:
    prepare:
      packages: # to avoid confusion with libopenafs-dev which also provides a des.h
        - libssl-dev
    after_prepare: # make sure lgtm.com doesn't use CMake (which generates and runs tests)
      - rm -f CMakeLists.txt
      - ./buildconf
    configure: # enable as many optional features as possible
      command: ./configure --enable-ares --with-libssh2 --with-gssapi --with-librtmp --with-libmetalink --with-libmetalink

I think you get the point. Just give the app permission, customize as needed with the .lgtml.yml and setup your cute badges.

Leave a comment