Coder Social home page Coder Social logo

ceedling-cppcheck-plugin's Introduction

Cppcheck Ceedling Plugin

Add Ceedling task for analyzing code with Cppcheck.

Contents

Installation

Clone this into Ceedling's plugin folder of your current project.

$ cd <your-project>/vendor/ceedling/plugins
$ git clone https://github.com/deltalejo/cppcheck-ceedling-plugin.git cppcheck

Enable the plugin

Add the plugins path to your project.yml if you have not done it yet. Then add cppcheck plugin to the enabled plugins list:

:plugins:
  :load_paths:
    - vendor/ceedling/plugins
  :enabled:
    - cppcheck

Configuration

Add cppcheck section to your project.yml specifying configuration options. e.g:

:cppcheck:
  :reports:
    - html
  :addons:
    - misra

Reports

Three types of reports are available:

  • text
  • xml
  • html

They can be enabled by listing them on the :reports list:

:cppcheck:
  :reports:
    - text
    - html

Text

Artifact file and output format can be configured:

:cppcheck:
  :text_artifact_filename: path/to/CppcheckResults.txt
  :template: gcc

:template can be any of the ones included with Cppcheck or custom format string.

XML

Artifact file can be configured:

:cppcheck:
  :xml_artifact_filename: path/to/CppcheckResults.xml

HTML

Artifact directory and HTML title can be configured:

:cppcheck:
  :html_artifact_dirname: path/to/CppcheckHtml
  :html_title: Awesome Project

Notes:

  • This report requires the cppcheck-htmlreport tool to be available.
  • This report implies the xml report.

Preprocessor defines

Define

:cppcheck:
  :defines:
    - A
    - B
    - C=1

Undefine

:cppcheck:
  :undefines:
    - A
    - B
    - C

Note: By default TEST is undefined so the analysis is performed against production code.

Includes

Force inclusion of files before checked files.

:cppcheck:
  :includes:
    - file1.h
    - file2.h

Excludes

Exclude files from the analysis.

:cppcheck:
  :excludes:
    - file1.c
    - file2.c

Platform

Specify platform to use for the analysis, can be any of the ones included with Cppcheck, e.g.: unix64, or the path of the platform XML file.

:cppcheck:
  :platform: unix64

Standard

Specify C/C++ language standard.

:cppcheck:
  :standard: c99

Check Level

Specify the check level to be used for whole project analysis.

  • normal
  • exhaustive

By default exhaustive will be used.

:cppcheck:
  :check_level: normal

Single file analysis uses Cppcheck's default. i.e. normal.

Addons

Addons to be run.

:cppcheck:
  :addons:
    - misra
    - path/to/addon.py

MISRA with rule texts file

Locate your rules text file or copy it to your project. e.g.: <your-project>/misra.txt and create the addon file misra.json inside your project:

misra.json
{
	"script": "misra",
	"args": ["--rule-texts=misra.txt"]
}

Enable the addon:

:cppcheck:
  :addons:
    - misra.json

Checks

Enable additional checks:

:cppcheck:
  :enable_checks:
    - performance
    - portability

Note: These are only enabled for single file analysis. Whole project analysis always enable all checks.

Disable individual checks:

:cppcheck:
  :disable_checks:
    - style
    - information

Suppressions

Inline

Inline suppressions are disabled by default, they can be enabled with:

:cppcheck:
  :inline_suppressions: true

List Files

Suppressions files can be used by giving the search paths and/or files in the :paths and :files sections of your project.yml respectively. e.g.:

:paths:
  :cppcheck:
    - suppressions/
    - source/*/suppressions/

:files:
  :cppcheck:
    - suppressions.xml

Both XML and text files are supported, and for the latter, the file extension can be configured. The default is .txt. e.g.:

:extension:
  :cppcheck: .txt

The files that will ultimately be used can be verified with:

ceedling files:cppcheck

Command Line

Command line suppressions can also be added:

:cppcheck:
  :suppressions:
    - memleak:src/file1.cpp
    - exceptNew:src/file1.cpp

Library configuration

Add library configuration files:

:cppcheck:
  :libraries:
    - lib1.cfg
    - lib2.cfg

Rules

Regular expression rules:

:cppcheck:
  :rules:
    - if \( p \) { free \( p \) ; }

Extra options

For things not covered above, add extra command line options:

:cppcheck:
  :options:
    - --max-configs=<limit>
    - --suppressions-list=<file>

Usage

Analyze whole project

Run analysis for all project sources:

$ ceedling cppcheck:all

Note: Analysis is run with all checks enabled.

Analyze single file

Run analysis for single source file:

$ ceedling cppcheck:<filename>

Note: Analysis will run with the checks in :enable_checks list enabled or with style check if none given.

ceedling-cppcheck-plugin's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

ceedling-cppcheck-plugin's Issues

Platform

Hi @deltalejo, sorry for bugging you in the wrong repository, but since the platform plugin has been archived, this is where I can post any issues for you.

I use the platform plugin a lot in ceedling in v0.31.1, I'm trying to do the same but in v0.32.0, I know the tags are still pre-candidates, but I've already tried to adapt, but it's messing up with the gcov plugin . Everything works fine with the ceedling platform:something release and ceedling platform:something test:all tasks.
But with ceedling platform:something gcov:all an error occurs.

I think it's a platform plugin because it didn't happen when I just used project.yml. May you help me?

platform fork
gcov error

NOTE: I don't have any Ruby or Rake skills, nor do I know how I could debug the error.

Ceedling 0.32 Prerelease Error

When trying to current version with the prerelease of Ceedling 0.32, I'm getting the following error. I believe it is because file_system_utils doesn't exist anymore in 0.32.

๐Ÿšง Loaded project configuration at default location using ./project.yml
Exception raised while trying to load plugin: cppcheck

๐Ÿงจ EXCEPTION: Failed to construct 'file_system_utils'
  ...caused by:
  >>> No object definition for 'file_system_utils'

I believe that

@ceedling[:file_system_utils].revise_file_list( all_suppressions, in_hash[:files_cppcheck] )

just needs to be changed to

@ceedling[:file_path_collection_utils].revise_filelist( all_suppressions, in_hash[:files_cppcheck] )

EDIT:
Also getting this error after the change above

๐Ÿšง Loaded project configuration at default location using ./project.yml
Exception raised while trying to load plugin: cppcheck

๐Ÿงจ EXCEPTION: uninitialized constant Cppcheck::PROJECT_ROOT
Did you mean?  Projectinator

Ceedling 0.32: "support paths" causing plugin to get stuck.

I found another "error", but it's something that only partially affects me. With the new :paths: changes in Ceedling 0.32, locations that I define in :support: seem to result in cppcheck getting stuck at Creating Cppcheck xml report... . It only partially affects me though because for my project I am able to just move the :support: paths to :include: and it doesn't get stuck. I can't share many details of the project I'm working on so the most explanation I can give is that this:

:paths:
  :test:
    - +:test/**
    - -:support
  :source:
    - ../Lib/**
  :include:
    - ../Lib/**
    - ../Startup/**
    - ../Src/**
    - ../Inc/**
    - ../Drivers/CMSIS/**
  :support:
    - support
    - ../Drivers/STM32G0xx_HAL_Driver/Inc/**
  :libraries: []

doesn't work and causes it to get stuck. However this:

:paths:
  :test:
    - +:test/**
    - -:support
  :source:
    - ../Lib/**
  :include:
    - ../Lib/**
    - ../Startup/**
    - ../Src/**
    - ../Inc/**
    - ../Drivers/CMSIS/**
    - ../Drivers/STM32G0xx_HAL_Driver/Inc/**
  :support:
    - support
  :libraries: []

works just fine.

In case it is relevant, I want to also note that I'm using CppCheck in WSL, installing it via snap, then downloading the cppcheck-htmlreport separately to my /usr/local/bin.

#!/bin/bash

# Set noninteractive to avoid prompts during installation
export DEBIAN_FRONTEND=noninteractive

CPPCHECK_HTMLREPORT_INSTALL_DIR="/usr/local/bin"

# Install CppCheck
sudo snap install cppcheck
sudo curl -o "$CPPCHECK_HTMLREPORT_INSTALL_DIR/cppcheck-htmlreport" "https://raw.githubusercontent.com/danmar/cppcheck/main/htmlreport/cppcheck-htmlreport"
sudo chmod +x "$CPPCHECK_HTMLREPORT_INSTALL_DIR/cppcheck-htmlreport"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.