Skip to content
This repository has been archived by the owner on Feb 27, 2019. It is now read-only.

Commit

Permalink
Initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
biffen committed Dec 12, 2015
0 parents commit 18eb934
Show file tree
Hide file tree
Showing 7 changed files with 294 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
node_modules
npm-debug.log
20 changes: 20 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2015 Theo Willows

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
linter-cppcheck
===============

A [linter] for [Atom] using [Cppcheck].

## Requirements ##

[Cppcheck] needs to be installed (or at least available). Its path can be
configured.

Without [Linter] this package is rather useless.

## Acknowledgements ##

This package is really a tiny amount of glue between other great pieces of
software, namely the [Linter] package, the [atom-linter] module and — of course —
[Cppcheck].

[Atom]: https://atom.io

[atom-linter]: https://www.npmjs.com/package/atom-linter

[Cppcheck]: http://cppcheck.sourceforge.net

[Linter]: https://atom.io/packages/linter
166 changes: 166 additions & 0 deletions lib/linter-cppcheck.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
'use babel';
'use strict';

import {
exec,
parse,
}
from 'atom-linter';

import {
XRegExp
}
from 'xregexp';

export default {

activate: (state) => {},

config: {
enableInformation: {
description: 'Enable information messages.',
default: true,
type: 'boolean',
},
enableMissingInclude: {
description: 'Warn if there are missing includes.',
default: false,
type: 'boolean',
},
enablePerformance: {
description: 'Enable performance messages.',
default: true,
type: 'boolean',
},
enablePortability: {
description: 'Enable portability messages.',
default: true,
type: 'boolean',
},
enableStyle: {
description: 'Enable all coding style checks. All messages with the severities *style*, *performance* and *portability* are enabled.',
default: true,
type: 'boolean',
},
enableUnusedFunction: {
description: 'Check for unused functions.',
default: false,
type: 'boolean',
},
enableWarning: {
description: 'Enable warning messages.',
default: true,
type: 'boolean',
},
executable: {
default: 'cppcheck',
type: 'string',
},
force: {
description: '`--force`',
default: false,
type: 'boolean',
},
inconclusive: {
default: false,
description: 'Include inconclusive warnings. (`--inconclusive`)',
type: 'boolean',
},
inlineSuppressions: {
default: false,
description: 'Enable inline suppressions. (`--inline-suppr`)',
type: 'boolean',
},
suppress: {
description: 'Suppress specific warnings. See Cppcheck\'s documentation for details on the format. (`--suppress`)',
type: 'array',
items: {
type: 'string',
},
},
},

provideLinter: () => {
const regex =
'\\[(?<file>.+?):(?:(?<line>\\d+)\\]|(?<lineStart>\\d+)\\] -> \\[.+?:(?<lineEnd>\\d+)\\]): \\((?<type>\\w+)\\) (?<message>.*)';

const lint = (textEditor) => {
const args = [];

// --enable
const enables = [];
for (const enable of 'Information,MissingInclude,Performance,Portability,Style,UnusedFunction,Warning'
.split(',')) {
if (atom.config.get(`linter-cppcheck.enable${enable}`)) {
enables.push(enable.toLowerCase());
}
}
if (enables.length) {
args.push('--enable=' + enables.join(','));
}

// --force
if (atom.config.get('linter-cppcheck.force')) {
args.push('--force');
}

// --inconclusive
if (atom.config.get('linter-cppcheck.inconclusive')) {
args.push('--inconclusive');
}

// --inline-suppr
if (atom.config.get('linter-cppcheck.inlineSuppressions')) {
args.push('--inline-suppr');
}

// --language
const grammar = textEditor.getGrammar().name;
switch (grammar) {
case 'C':
args.push('--language=c');
break;

case 'C++':
args.push('--language=c++');
break;

default:
console.warn(
`[linter-cppcheck] Unrecognised grammar ‘${grammar}’`
);
break;
}

// --suppress
for (const suppress of atom.config.get('linter-cppcheck.suppress') || []) {
args.push(`--suppress=${suppress}`);
}

// <file>
args.push(textEditor.getPath());

return exec(
atom.config.get('linter-cppcheck.executable'),
args, {
'stream': 'stderr'
}
).then((output) => {
return parse(output, regex);
});
};

const provider = {
grammarScopes: ['source.c', 'source.cpp'],
lint: lint,
lintOnFly: false,
name: 'Cppcheck',
scope: 'file',
}

return provider;
},

serialize: () => {},

}
40 changes: 40 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"activationCommands": {},
"author": {
"name": "Theo Willows",
"email": "[email protected]"
},
"bugs": {
"url": "https://github.com/Munkei/atom-linter-cppcheck/issues"
},
"contributors": [],
"dependencies": {
"atom-linter": "^4.1.1",
"xregexp": "^3.0.0"
},
"description": "A linter for Atom using Cppcheck",
"engines": {
"atom": ">=1.0.0 <2.0.0"
},
"homepage": "https://github.com/Munkei/atom-linter-cppcheck",
"keywords": [
"c",
"c++",
"linter"
],
"license": "MIT",
"main": "./lib/linter-cppcheck",
"name": "linter-cppcheck",
"providedServices": {
"linter": {
"versions": {
"1.0.0": "provideLinter"
}
}
},
"repository": {
"type": "git",
"url": "https://github.com/Munkei/atom-linter-cppcheck"
},
"version": "0.0.0"
}
4 changes: 4 additions & 0 deletions project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "linter-cppcheck",
"type": "atom-package"
}
36 changes: 36 additions & 0 deletions styles/linter-cppcheck.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@import "ui-variables";

atom-text-editor::shadow .linter-highlight,
.linter-highlight {
&.information {
&:not(.line-number) {
background-color: @background-color-info;
color : white;
}

.linter-gutter {
color: @background-color-info;
}

.region {
border-bottom: 1px dashed @background-color-info;
}
}

&.performance,
&.portability,
&.style {
&:not(.line-number) {
background-color: @background-color-warning;
color : white;
}

.linter-gutter {
color: @background-color-warning;
}

.region {
border-bottom: 1px dashed @background-color-warning;
}
}
}

0 comments on commit 18eb934

Please sign in to comment.