Skip to content

Commit

Permalink
Add use of 'cc' to improve C++ code style linting
Browse files Browse the repository at this point in the history
  • Loading branch information
lovell committed Feb 11, 2017
1 parent 04f5c88 commit 81f5589
Show file tree
Hide file tree
Showing 13 changed files with 279 additions and 210 deletions.
18 changes: 13 additions & 5 deletions package.json
@@ -1,8 +1,9 @@
{
"name": "sharp",
"description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP and TIFF images",
"version": "0.17.1",
"version": "0.17.2",
"author": "Lovell Fuller <npm@lovell.info>",
"homepage": "https://github.com/lovell/sharp",
"contributors": [
"Pierre Inglebert <pierre.inglebert@gmail.com>",
"Jonathan Ong <jonathanrichardong@gmail.com>",
Expand Down Expand Up @@ -35,7 +36,7 @@
],
"scripts": {
"clean": "rm -rf node_modules/ build/ vendor/ coverage/ test/fixtures/output.*",
"test": "semistandard && cross-env VIPS_WARNING=0 nyc --reporter=lcov --branches=99 mocha --slow=5000 --timeout=60000 ./test/unit/*.js",
"test": "semistandard && cc && cross-env VIPS_WARNING=0 nyc --reporter=lcov --branches=99 mocha --slow=5000 --timeout=60000 ./test/unit/*.js",
"test-leak": "./test/leak/leak.sh",
"test-packaging": "./packaging/test-linux-x64.sh",
"docs": "for m in constructor input resize composite operation colour channel output utility; do documentation build --shallow --format=md lib/$m.js >docs/api-$m.md; done"
Expand Down Expand Up @@ -64,19 +65,19 @@
"caw": "^2.0.0",
"color": "^1.0.3",
"got": "^6.7.1",
"nan": "^2.5.0",
"nan": "^2.5.1",
"semver": "^5.3.0",
"tar": "^2.2.1"
},
"devDependencies": {
"async": "^2.1.4",
"bufferutil": "^1.3.0",
"bufferutil": "^2.0.1",
"cc": "^1.0.0",
"cross-env": "^3.1.4",
"documentation": "^4.0.0-beta.18",
"exif-reader": "^1.0.2",
"icc": "^1.0.0",
"mocha": "^3.2.0",
"node-cpplint": "^0.4.0",
"nyc": "^10.1.2",
"rimraf": "^2.5.4",
"semistandard": "^9.2.1",
Expand All @@ -93,5 +94,12 @@
"env": [
"mocha"
]
},
"cc": {
"linelength": "120",
"filter": [
"build/include",
"runtime/indentation_namespace"
]
}
}
38 changes: 25 additions & 13 deletions src/common.cc
@@ -1,12 +1,27 @@
// Copyright 2013, 2014, 2015, 2016, 2017 Lovell Fuller and contributors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <cstdlib>
#include <string>
#include <string.h>
#include <vector>

#include <node.h>
#include <node_buffer.h>
#include <nan.h>
#include <vips/vips8>

#include "nan.h"
#include "common.h"

using vips::VImage;
Expand Down Expand Up @@ -254,8 +269,7 @@ namespace sharp {
return (
(bands == 2 && interpretation == VIPS_INTERPRETATION_B_W) ||
(bands == 4 && interpretation != VIPS_INTERPRETATION_CMYK) ||
(bands == 5 && interpretation == VIPS_INTERPRETATION_CMYK)
);
(bands == 5 && interpretation == VIPS_INTERPRETATION_CMYK));
}

/*
Expand Down Expand Up @@ -378,23 +392,23 @@ namespace sharp {
int top = 0;

// assign only if valid
if(x >= 0 && x < (inWidth - outWidth)) {
if (x >= 0 && x < (inWidth - outWidth)) {
left = x;
} else if(x >= (inWidth - outWidth)) {
} else if (x >= (inWidth - outWidth)) {
left = inWidth - outWidth;
}

if(y >= 0 && y < (inHeight - outHeight)) {
if (y >= 0 && y < (inHeight - outHeight)) {
top = y;
} else if(y >= (inHeight - outHeight)) {
} else if (y >= (inHeight - outHeight)) {
top = inHeight - outHeight;
}

// the resulting left and top could have been outside the image after calculation from bottom/right edges
if(left < 0) {
if (left < 0) {
left = 0;
}
if(top < 0) {
if (top < 0) {
top = 0;
}

Expand All @@ -421,17 +435,15 @@ namespace sharp {
*/
VipsOperationBoolean GetBooleanOperation(std::string const opStr) {
return static_cast<VipsOperationBoolean>(
vips_enum_from_nick(nullptr, VIPS_TYPE_OPERATION_BOOLEAN, opStr.data())
);
vips_enum_from_nick(nullptr, VIPS_TYPE_OPERATION_BOOLEAN, opStr.data()));
}

/*
Get interpretation type from string
*/
VipsInterpretation GetInterpretation(std::string const typeStr) {
return static_cast<VipsInterpretation>(
vips_enum_from_nick(nullptr, VIPS_TYPE_INTERPRETATION, typeStr.data())
);
vips_enum_from_nick(nullptr, VIPS_TYPE_INTERPRETATION, typeStr.data()));
}

/*
Expand Down
21 changes: 17 additions & 4 deletions src/common.h
@@ -1,14 +1,28 @@
// Copyright 2013, 2014, 2015, 2016, 2017 Lovell Fuller and contributors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef SRC_COMMON_H_
#define SRC_COMMON_H_

#include <string>
#include <tuple>
#include <vector>

#include <node.h>
#include <nan.h>
#include <vips/vips8>

#include "nan.h"

// Verify platform and compiler compatibility

#if (VIPS_MAJOR_VERSION < 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION < 4))
Expand Down Expand Up @@ -63,8 +77,7 @@ namespace sharp {

// Create an InputDescriptor instance from a v8::Object describing an input image
InputDescriptor* CreateInputDescriptor(
v8::Handle<v8::Object> input, std::vector<v8::Local<v8::Object>> buffersToPersist
);
v8::Handle<v8::Object> input, std::vector<v8::Local<v8::Object>> buffersToPersist);

enum class ImageType {
JPEG,
Expand Down
35 changes: 23 additions & 12 deletions src/metadata.cc
@@ -1,25 +1,39 @@
// Copyright 2013, 2014, 2015, 2016, 2017 Lovell Fuller and contributors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <numeric>
#include <vector>

#include <node.h>
#include <nan.h>
#include <vips/vips8>

#include "nan.h"
#include "common.h"
#include "metadata.h"

class MetadataWorker : public Nan::AsyncWorker {
public:
MetadataWorker(
Nan::Callback *callback, MetadataBaton *baton,
std::vector<v8::Local<v8::Object>> const buffersToPersist
) : Nan::AsyncWorker(callback), baton(baton), buffersToPersist(buffersToPersist) {
std::vector<v8::Local<v8::Object>> const buffersToPersist)
: Nan::AsyncWorker(callback), baton(baton), buffersToPersist(buffersToPersist) {
// Protect Buffer objects from GC, keyed on index
std::accumulate(buffersToPersist.begin(), buffersToPersist.end(), 0,
[this](uint32_t index, v8::Local<v8::Object> const buffer) -> uint32_t {
SaveToPersistent(index, buffer);
return index + 1;
}
);
});
}
~MetadataWorker() {}

Expand Down Expand Up @@ -72,7 +86,7 @@ class MetadataWorker : public Nan::AsyncWorker {
vips_thread_shutdown();
}

void HandleOKCallback () {
void HandleOKCallback() {
using Nan::New;
using Nan::Set;
Nan::HandleScope();
Expand All @@ -99,14 +113,12 @@ class MetadataWorker : public Nan::AsyncWorker {
if (baton->exifLength > 0) {
Set(info,
New("exif").ToLocalChecked(),
Nan::NewBuffer(baton->exif, baton->exifLength, sharp::FreeCallback, nullptr).ToLocalChecked()
);
Nan::NewBuffer(baton->exif, baton->exifLength, sharp::FreeCallback, nullptr).ToLocalChecked());
}
if (baton->iccLength > 0) {
Set(info,
New("icc").ToLocalChecked(),
Nan::NewBuffer(baton->icc, baton->iccLength, sharp::FreeCallback, nullptr).ToLocalChecked()
);
Nan::NewBuffer(baton->icc, baton->iccLength, sharp::FreeCallback, nullptr).ToLocalChecked());
}
argv[1] = info;
}
Expand All @@ -116,8 +128,7 @@ class MetadataWorker : public Nan::AsyncWorker {
[this](uint32_t index, v8::Local<v8::Object> const buffer) -> uint32_t {
GetFromPersistent(index);
return index + 1;
}
);
});
delete baton->input;
delete baton;

Expand Down
20 changes: 18 additions & 2 deletions src/metadata.h
@@ -1,8 +1,24 @@
// Copyright 2013, 2014, 2015, 2016, 2017 Lovell Fuller and contributors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef SRC_METADATA_H_
#define SRC_METADATA_H_

#include "nan.h"
#include "common.h"
#include <string>
#include <nan.h>

#include "./common.h"

struct MetadataBaton {
// Input
Expand Down

0 comments on commit 81f5589

Please sign in to comment.