Socket
Socket
Sign inDemoInstall

cr2checkstyle

Package Overview
Dependencies
67
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.3 to 1.0.0

.travis.yml

27

index.js

@@ -9,12 +9,21 @@ #!/usr/bin/env node

require('./src/cr2checkstyle')(process.stdin, process.stdout, {
module: {
maintainability: argv['module-maintainability'],
cyclomatic: argv['module-cyclomatic-complexity'],
halsteadDifficulty: argv['module-halstead-difficulty']
require('./src/cr2checkstyle')(
process.stdin,
process.stdout,
{
module: {
maintainability: argv['module-maintainability'],
cyclomatic: argv['module-cyclomatic-complexity'],
halsteadDifficulty: argv['module-halstead-difficulty']
},
function: {
cyclomatic: argv['function-cyclomatic-complexity'],
halsteadDifficulty: argv['function-halstead-difficulty']
}
},
function: {
cyclomatic: argv['function-cyclomatic-complexity'],
halsteadDifficulty: argv['function-halstead-difficulty']
function (errorCount) {
if (argv.exitCode) {
process.exitCode = errorCount === 0 ? 0 : 1;
}
}
});
);
{
"name": "cr2checkstyle",
"version": "0.0.3",
"version": "1.0.0",
"description": "Convert complexity-report data to Checkstyle XML",
"main": "index.js",
"homepage": "https://github.com/Finanzchef24-GmbH/cr2checkstyle",
"keywords": [
"complexity-report",
"complexity",
"checkstyle",
"xml"
],
"repository": {

@@ -33,3 +39,3 @@ "type": "git",

"dependencies": {
"JSONStream": "1.1.2",
"JSONStream": "1.1.3",
"event-stream": "3.3.3",

@@ -44,8 +50,8 @@ "xml-escape": "1.1.0",

"eslint": "2.13.1",
"eslint-config-four66": "1.0.0",
"eslint-config-four66": "1.0.1",
"libxmljs": "0.18.0",
"mocha": "2.5.3",
"nsp": "2.4.0",
"nsp": "2.5.0",
"stream-buffers": "3.0.0"
}
}
# cr2checkstyle
[![npm](https://img.shields.io/npm/v/cr2checkstyle.svg?style=flat-square)](https://www.npmjs.com/package/cr2checkstyle)
![Codeship](https://img.shields.io/codeship/227f5300-f7f2-0133-0bf6-2eb9f408a9c3.svg?style=flat-square)
[![Travis CI](https://img.shields.io/travis/Finanzchef24-GmbH/cr2checkstyle/master.svg?maxAge=2592000&style=flat-square)](https://travis-ci.org/Finanzchef24-GmbH/cr2checkstyle)
[![Dependency Status](https://img.shields.io/david/Finanzchef24-GmbH/cr2checkstyle.svg?style=flat-square)](https://david-dm.org/Finanzchef24-GmbH/cr2checkstyle)

@@ -26,2 +26,4 @@ [![devDependency Status](https://img.shields.io/david/dev/Finanzchef24-GmbH/cr2checkstyle.svg?style=flat-square)](https://david-dm.org/Finanzchef24-GmbH/cr2checkstyle)

cr2checkstyle always terminates with an exit code of 0 (unless an internal error occurred), even if the generated checkstyle report contains items with severity "error". To change this behaviour use the `--exit-code` option.
## Configuration

@@ -28,0 +30,0 @@ By default, cr2checkstyle has no thresholds set so it will not generate any warnings or errors. Currently supported metrics are [cyclomatic complexity](https://en.wikipedia.org/wiki/Cyclomatic_complexity), [halstead difficulty](https://en.wikipedia.org/wiki/Halstead_complexity_measures) and the maintainability index. The corresponding command line options are:

@@ -160,7 +160,13 @@ 'use strict';

* @param {cr2cs.Thresholds} thresholds
* @param {function=} callback
*/
module.exports = function (stdin, stdout, thresholds) {
module.exports = function (stdin, stdout, thresholds, callback) {
let errorCount = 0;
stdout.write(`<?xml version="1.0" encoding="UTF-8" ?>${EOL}`);
stdout.write(`<checkstyle>${EOL}`);
stdin.on('end', () => stdout.write(`${EOL}</checkstyle>`));
stdin.on('end', function () {
stdout.write(`${EOL}</checkstyle>`);
return callback ? callback(errorCount) : undefined;
});

@@ -171,2 +177,4 @@ stdin

.pipe(es.mapSync(function (result) {
errorCount += result.messages.filter(message => message.severity === 'error').length;
return [

@@ -173,0 +181,0 @@ ` <file name="${escape(result.file)}">`,

@@ -7,2 +7,7 @@ 'use strict';

const OPTIONS = {
'exit-code': {
type: 'boolean',
describe: 'Terminate with non-zero exit code if an error was generated',
default: false
},
'module-maintainability': {

@@ -72,2 +77,3 @@ type: 'string',

.config('config', path => JSON.parse(fs.readFileSync(path)))
.group(['exit-code'], 'miscellaneous')
.group(['module-maintainability', 'module-halstead-difficulty', 'module-cyclomatic-complexity'], 'Per-module metrics')

@@ -74,0 +80,0 @@ .group(['function-halstead-difficulty', 'function-cyclomatic-complexity'], 'Per-function metrics')

@@ -46,10 +46,16 @@ 'use strict';

describe('cr2checkstyle', function () {
function run(moduleThresholds, fnThresholds) {
function run(moduleThresholds, fnThresholds, options) {
const stdin = new streamBuffers.ReadableStreamBuffer();
const stdout = new streamBuffers.WritableStreamBuffer();
let errorCount;
cr2cs(stdin, stdout, {
module: moduleThresholds || {},
function: fnThresholds || {}
});
cr2cs(
stdin,
stdout,
{
module: moduleThresholds || {},
function: fnThresholds || {}
},
count => (errorCount = count)
);

@@ -62,3 +68,3 @@ stdin.put(JSON.stringify(output));

stdout.on('finish', () => resolve(stdout.getContentsAsString()));
}).then(contents => libxmljs.parseXmlString(contents));
}).then(contents => [libxmljs.parseXmlString(contents), errorCount]);
}

@@ -68,3 +74,4 @@

return run({})
.then(function (xml) {
.spread(function (xml, errorCount) {
expect(errorCount).to.equal(0);
expect(xml.find('/checkstyle/file')).to.have.length(0);

@@ -77,3 +84,4 @@ });

return run({ maintainability: [80, 110] })
.then(function (xml) {
.spread(function (xml, errorCount) {
expect(errorCount).to.equal(0);
expect(xml.find('/checkstyle/file')).to.have.length(0);

@@ -86,13 +94,14 @@ expect(xml.find('/checkstyle/file/error')).to.have.length(0);

return run({ maintainability: [80, 120] })
.then(function (xml) {
.spread(function (xml, errorCount) {
const files = xml.find('/checkstyle/file');
const errors = xml.find('/checkstyle/file/error');
const errorsAndWarnings = xml.find('/checkstyle/file/error');
expect(errors).to.have.length(1);
expect(errorCount).to.equal(0);
expect(errorsAndWarnings).to.have.length(1);
expect(files).to.have.length(1);
expect(files[0].attr('name').value()).to.equal('/home/user/project/some-file.js');
expect(errors[0].attr('severity').value()).to.equal('warning');
expect(errors[0].attr('line').value()).to.equal('0');
expect(errors[0].attr('message').value())
expect(errorsAndWarnings[0].attr('severity').value()).to.equal('warning');
expect(errorsAndWarnings[0].attr('line').value()).to.equal('0');
expect(errorsAndWarnings[0].attr('message').value())
.to.equal('Maintainability of 115.7 is low for a module');

@@ -104,10 +113,11 @@ });

return run({ maintainability: [120, 150] })
.then(function (xml) {
const errors = xml.find('/checkstyle/file/error');
.spread(function (xml, errorCount) {
const errorsAndWarnings = xml.find('/checkstyle/file/error');
expect(errors).to.have.length(1);
expect(errorCount).to.equal(1);
expect(errorsAndWarnings).to.have.length(1);
expect(errors[0].attr('severity').value()).to.equal('error');
expect(errors[0].attr('line').value()).to.equal('0');
expect(errors[0].attr('message').value())
expect(errorsAndWarnings[0].attr('severity').value()).to.equal('error');
expect(errorsAndWarnings[0].attr('line').value()).to.equal('0');
expect(errorsAndWarnings[0].attr('message').value())
.to.equal('Maintainability of 115.7 is too low for a module');

@@ -121,3 +131,3 @@ });

return run(null, { halsteadDifficulty: [15, 20] })
.then(function (xml) {
.spread(function (xml) {
expect(xml.find('/checkstyle/file')).to.have.length(0);

@@ -130,4 +140,4 @@ expect(xml.find('/checkstyle/file/error')).to.have.length(0);

return run(null, { halsteadDifficulty: [11, 14] })
.then(function (xml) {
const errors = xml.find('/checkstyle/file/error');
.spread(function (xml, errorCount) {
const errorsAndWarnings = xml.find('/checkstyle/file/error');
const expected = [

@@ -146,5 +156,6 @@ {

expect(errors).to.have.length(2);
expect(errorCount).to.equal(1);
expect(errorsAndWarnings).to.have.length(2);
errors.forEach(function (error, index) {
errorsAndWarnings.forEach(function (error, index) {
expect(error.attr('line').value()).to.equal(expected[index].line);

@@ -151,0 +162,0 @@ expect(error.attr('severity').value()).to.equal(expected[index].severity);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc