LGTM/fr

Vue d'ensemble
LGTM est un outil d'analyse de code pouvant être intégré à plusieurs systèmes de contrôle de version de logiciel en ligne et prenant en charge plusieurs langues. C'est un excellent vérificateur de la qualité du code, identifiant les problèmes de code qui sont souvent oubliés par les autres vérificateurs de code et les linters.

LGTM convient parfaitement comme outil d’analyse de code pour le développement d’ateliers en Python de FreeCAD et d’autres projets de petite et moyenne taille. Cette page fournit un aperçu de la mise en route de LGTM avec un atelier Python pour FreeCAD.

Commencer
La prise en main de LGTM dépend de la plate-forme de contrôle de version en ligne que vous utilisez. La documentation LGTM pour automated code review fournit un bon aperçu de la façon d'intégrer LGTM à votre projet pour plusieurs plates-formes.

En outre, il est possible d'effectuer une large gamme d'analyses approfondies du code sur LGTM, ce qui dépasse le cadre de ce tutoriel. Vous pouvez en savoir plus à ce sujet dans la documentation de LGTM sur configuring code analysis.

Getting Results
Once you've set up LGTM and provided access to your code repositories, analyses are typically done daily on the repository. So, pushed changes will not yeild results immediately. It is possible to have LGTM analyze pull requests when they are submitted, as described in the LGTM documentation.

Reviewing the results simply requires logging in to your LGTM dashboard and selecting the desired project. From there, code analyses will provide a list of issues (like bugs, bad coding practices, useless/irrelevant/unused code, etc.) for your perusal. In addition LGTM provides overall code 'ratings' (A, B, C, D) depending on the number of issue you have compared to the overall size of your project.

Probably, the most useful, immediate way to manage the results of your code analysis is simply filtering out files in your project that you don't want analyzed. That is, suppose you're developing new code that is incomplete, keeping around legacy code that is otherwise unused, or have a good deal of testing code that doesn't need analysis. LGTM provides file classification, an easy way to filter those files so they don't pollute your analysis results.

To enable file classification, first create a file named ".lgtm.yml" in your projects top-most directory. Then, in that file, add some classifications.

Below is an example from the FreeCAD Trails Python workbench:

Note that indent levels are important in LGTM. Incorrect indenting will result in failed file classification.

Also, some classifications (like 'template' and 'test') are used by LGTM for queries and other analysis components. You may also define your own custom tags, which will filter code and provide additional queryable results.