Skip to content

Commit

Permalink
some updates to vera++ rules
Browse files Browse the repository at this point in the history
  • Loading branch information
yurii-litvinov committed Feb 9, 2015
1 parent 3957b9e commit d27d416
Show file tree
Hide file tree
Showing 54 changed files with 343 additions and 177 deletions.
12 changes: 4 additions & 8 deletions buildScripts/vera++/exclude
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
buildScripts
installer
qrrepo
qrutils
plugins
qrtest
bin
docs
umlDocumentation
qrmc
thirdparty
.moc
.ui
plugins
qrtest
qrutils
qrmc
1 change: 1 addition & 0 deletions buildScripts/vera++/profiles/allRules
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ set rules {
NoSpacesAtTheStart
NoRelativePathsInIncludes
OpeningParethesisForClass
NullsForbidden
}
95 changes: 95 additions & 0 deletions buildScripts/vera++/scripts/rules/Comments.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Copyright 2015 Cybertech Labs Ltd.
#
# 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.

proc ClassSection { old line } {
if { [regexp {public:} $line] || [regexp {public slots:} $line] || [regexp {signals:} $line] } {
return "public"
}

if { [regexp {protected:} $line] || [regexp {protected slots:} $line] } {
return "protected"
}

if { [regexp {private:} $line] || [regexp {private slots:} $line] } {
return "private"
}

return $old
}

proc MayBeMethodDeclaration { line inClass } {
if { ![regexp { \w+\(([\w:]+ [*& ]*\w+.*)?\)} $line] && ![regexp {\t\w+\([\w:]+ [*& ]*\w+.*\)} $line]} {
# Regular method (space before name, name, optional parameters) or constructor (tab before name, name, parameters, since parameterless constructors may be not documented)
return 0
}

if { $inClass == 0 } {
return 0
}

return 1
}

proc ShallHaveComment { line previousComment currentSection inClass } {
if { [string length $previousComment] > 0 } {
return 0
}

if { [string compare $currentSection "private"] == 0 || [string compare $currentSection "protected"] == 0 } {
return 0
}

if { [regexp {override} $line] } {
return 0
}

if { [regexp {^[\t]*///} $line] } {
return 0
}

return 1
}

proc CheckComments { fileName } {
if {![regexp -nocase {.*.h$} $fileName] } { return }
set lineCount 1
set previousComment ""
set currentSection ""
set inClass 0
foreach line [getAllLines $fileName] {
set currentSection [ClassSection $currentSection $line]
if { [regexp {^\t*class[^;]*$} $line] } {
set inClass 1
if { [string length $previousComment] == 0} {
report $fileName $lineCount "Classes must have comments in doxygen style (starting with ///)"
}
}

if { [MayBeMethodDeclaration $line $inClass] && [ShallHaveComment $line $previousComment $currentSection $inClass ] } {
report $fileName $lineCount "Methods must have comments in doxygen style (starting with ///)"
}

if { [regexp {///} $line] } {
set previousComment [concat $previousComment $line]
} else {
set previousComment ""
}

incr lineCount
}
}

foreach fileName [getSourceFileNames] {
CheckComments $fileName
}
27 changes: 27 additions & 0 deletions buildScripts/vera++/scripts/rules/ForeachsForbidden.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2014 Cybertech Labs Ltd.
#
# 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.

proc ForeachsForbidden { fileName } {
set lineCount 1
foreach line [getAllLines $fileName] {
if { [regexp {foreach} $line] } {
report $fileName $lineCount "'foreach' is forbidden, use 'for' range loops instead"
}
incr lineCount
}
}

foreach fileName [getSourceFileNames] {
ForeachsForbidden $fileName
}
4 changes: 2 additions & 2 deletions buildScripts/vera++/scripts/rules/IncludeGuards.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ proc checkGuards { fileName } {
set lineCount 1
set guardFound 0
foreach line [getAllLines $fileName] {
if {[regexp {^[\t ]*#pragma once[\t\r\n ]*} $line] } {
if {[regexp {^#pragma once} $line] } {
set guardFound 1
}
if {[regexp {^[\t ]*#ifn?def .*} $line] } {
Expand All @@ -19,7 +19,7 @@ proc checkGuards { fileName } {
incr lineCount
}
if {![expr $guardFound]} {
report $fileName 1 "No include guard in header file"
report $fileName 1 "No include guard in header file or there is BOM"
}
}

Expand Down
2 changes: 1 addition & 1 deletion buildScripts/vera++/scripts/rules/LineLength.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set maxLength 120
foreach fileName [getSourceFileNames] {
set lineNumber 1
foreach line [getAllLines $fileName] {
# set line [string map {"\t" " "} $line]
set line [string map {"\t" " "} $line]
if {[string length $line] > $maxLength && ![regexp {http://} $line]} {
report $fileName $lineNumber "line is longer than $maxLength characters"
}
Expand Down
27 changes: 27 additions & 0 deletions buildScripts/vera++/scripts/rules/NullsForbidden.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2014 Cybertech Labs Ltd.
#
# 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.

proc NullsForbidden { fileName } {
set lineCount 1
foreach line [getAllLines $fileName] {
if { [regexp {NULL} $line] } {
report $fileName $lineCount "NULL is forbidden, use nullptr instead"
}
incr lineCount
}
}

foreach fileName [getSourceFileNames] {
NullsForbidden $fileName
}
42 changes: 42 additions & 0 deletions buildScripts/vera++/scripts/rules/Ownership.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2015 Cybertech Labs Ltd.
#
# 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.

proc CheckOwnership { fileName } {
if {![regexp -nocase {.*.h$} $fileName] } { return }
set lineCount 1
set previousComment ""
foreach line [getAllLines $fileName] {
if { [regexp {.*\* [\w]*;} $line] } {
report $fileName $lineCount "'*' shall be attached to identifier, not type"
}

if { [regexp {.* \*[\w]*;} $line] } {
if { ![regexp {ownership} [string tolower $line] ] && ![regexp {ownership} [string tolower $previousComment] ] } {
report $fileName $lineCount "Raw pointers must have a comment with ownership information - does object have ownership over pointed object or not (so will it delete pointed object itself or not)"
}
}

if { [regexp {///} $line] } {
set previousComment [concat $previousComment $line]
} else {
set previousComment ""
}

incr lineCount
}
}

foreach fileName [getSourceFileNames] {
CheckOwnership $fileName
}
4 changes: 3 additions & 1 deletion qrealMinimal.pro
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ SUBDIRS = \
qrrepo \
qrkernel \
qrutils \
qrtext \
thirdparty \

qrutils.depends = qrkernel
qrutils.depends = qrkernel qrtext
qrrepo.depends = qrkernel qrutils
qrtext.depends = qrkernel

qrgui.depends = \
qrrepo \
Expand Down
3 changes: 2 additions & 1 deletion qrgui/editor/copyPaste/pasteNodeCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ void PasteNodeCommand::restoreElement()
mScene->models().graphicalModelAssistApi().setProperties(mResult, mNodeData.graphicalProperties);
mScene->models().graphicalModelAssistApi().setPosition(mResult, newGraphicalPos());
if (mCopiedIds->contains(mNodeData.parentId)) {
mScene->models().graphicalModelAssistApi().changeParent(mResult, mCopiedIds->value(mNodeData.parentId), newPos());
mScene->models().graphicalModelAssistApi().changeParent(mResult
, mCopiedIds->value(mNodeData.parentId), newPos());
}

NodeElement *element = mScene->getNodeById(mResult);
Expand Down
4 changes: 3 additions & 1 deletion qrgui/editor/editorViewScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,9 @@ void EditorViewScene::createElement(const QMimeData *mimeData, const QPointF &sc
if (newParent && dynamic_cast<NodeElement*>(newParent)) {
if (!canBeContainedBy(newParent->id(), id)) {
QString text;
text += "Element of type \"" + id.element() + "\" can not be a child of \"" + newParent->id().element() + "\"";
text += "Element of type \"" + id.element() + "\" can not be a child of \""
+ newParent->id().element() + "\"";

QMessageBox::critical(0, "Error!", text);
return;
}
Expand Down
8 changes: 6 additions & 2 deletions qrgui/editor/private/lineHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ void LineHandler::reconnect(bool reconnectSrc, bool reconnectDst)

if (src && reconnectSrc) {
const int targetLinePoint = firstOutsidePoint(true);
const qreal newFrom = src->portId(mEdge->mapToItem(src, mEdge->line()[targetLinePoint]), mEdge->fromPortTypes());
const qreal newFrom = src->portId(mEdge->mapToItem(src, mEdge->line()[targetLinePoint])
, mEdge->fromPortTypes());
mEdge->setFromPort(newFrom);
}

Expand Down Expand Up @@ -312,7 +313,10 @@ bool LineHandler::checkPort(const QPointF &pos, bool isStart) const
return true;
}

const qreal port = node->portId(mEdge->mapToItem(node, pos), isStart ? mEdge->fromPortTypes() : mEdge->toPortTypes());
const qreal port = node->portId(mEdge->mapToItem(node, pos), isStart
? mEdge->fromPortTypes()
: mEdge->toPortTypes());

if (port < 0) {
return true;
}
Expand Down
5 changes: 4 additions & 1 deletion qrgui/editor/private/portHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ QPointF PortHandler::transformPortForNodeSize(const StatPoint * const port) cons
void PortHandler::connectTemporaryRemovedLinksToPort(const IdList &temporaryRemovedLinks, const QString &direction)
{
foreach (const Id &edgeId, temporaryRemovedLinks) {
EdgeElement *edge = dynamic_cast<EdgeElement *>(static_cast<EditorViewScene *>(mNode->scene())->getElem(edgeId));
EdgeElement *edge = dynamic_cast<EdgeElement *>(
static_cast<EditorViewScene *>(mNode->scene())->getElem(edgeId)
);

if (edge == nullptr) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion qrgui/mainWindow/dotRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void DotRunner::parseDOTCoordinates()
{
QString data = QString(mData);
QStringList list = data.split("\n", QString::SkipEmptyParts);
QRegExp regexp("\\s*(\\w+)\\s\\[pos=\"(\\d+\\,\\d+)\"\\,\\swidth=\"(\\d+\\.\\d+)\",\\sheight=\"(\\d+\\.\\d+)\"\\]" );
QRegExp regexp("\\s*(\\w+)\\s\\[pos=\"(\\d+\\,\\d+)\"\\,\\swidth=\"(\\d+\\.\\d+)\",\\sheight=\"(\\d+\\.\\d+)\"\\]");

foreach (const QString &string, list) {
if (string.indexOf(regexp) == -1) {
Expand Down
5 changes: 3 additions & 2 deletions qrgui/mainWindow/mainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ class MainWindow : public QMainWindow
, bool useTypedPorts);
void showAndEditPropertyInTextEditor(const QString &title, const QString &text, const QPersistentModelIndex &index
, const int &role);
void openReferenceList(const QPersistentModelIndex &index, const QString &referenceType, const QString &propertyValue
, int role);
void openReferenceList(const QPersistentModelIndex &index, const QString &referenceType
, const QString &propertyValue, int role);

virtual void openSettingsDialog(const QString &tab);

void showErrors(gui::ErrorReporter *reporter);
Expand Down
3 changes: 2 additions & 1 deletion qrgui/mainWindow/shapeEdit/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class Arch : public Item
virtual void drawScalingRects(QPainter* painter);
virtual void resizeItem(QGraphicsSceneMouseEvent *event);

virtual QPair<QDomElement, Item::DomElementTypes> generateItem(QDomDocument &document, const QPoint &topLeftPicture);
virtual QPair<QDomElement, Item::DomElementTypes> generateItem(QDomDocument &document
, const QPoint &topLeftPicture);

private:
int mStartAngle;
Expand Down
3 changes: 2 additions & 1 deletion qrgui/mainWindow/shapeEdit/curve.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class Curve : public Path
virtual void changeDragState(qreal x, qreal y);
virtual void calcResizeItem(QGraphicsSceneMouseEvent *event);

virtual QPair<QDomElement, Item::DomElementTypes> generateItem(QDomDocument &document, const QPoint &topLeftPicture);
virtual QPair<QDomElement, Item::DomElementTypes> generateItem(QDomDocument &document
, const QPoint &topLeftPicture);

private:
QPointF mC1;
Expand Down
3 changes: 2 additions & 1 deletion qrgui/mainWindow/shapeEdit/ellipse.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class QRealEllipse : public Item
virtual QRectF boundingRect() const;
virtual void drawItem(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);

virtual QPair<QDomElement, Item::DomElementTypes> generateItem(QDomDocument &document, const QPoint &topLeftPicture);
virtual QPair<QDomElement, Item::DomElementTypes> generateItem(QDomDocument &document
, const QPoint &topLeftPicture);

private:
graphicsUtils::RectangleImpl mRectangleImpl;
Expand Down
3 changes: 2 additions & 1 deletion qrgui/mainWindow/shapeEdit/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Image : public Item
virtual void drawItem(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
virtual void setItemZValue(int zValue);

virtual QPair<QDomElement, Item::DomElementTypes> generateItem(QDomDocument &document, const QPoint &topLeftPicture);
virtual QPair<QDomElement, Item::DomElementTypes> generateItem(QDomDocument &document
, const QPoint &topLeftPicture);
private:
QGraphicsPixmapItem* mPixmapItem;
QImage mImage;
Expand Down
3 changes: 2 additions & 1 deletion qrgui/mainWindow/shapeEdit/line.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class Line : public Item

QPair<QPair<QString, QString>, QPair<QString, QString> > setXandYBefore(const QRect &rect);
void setXandY(QDomElement& dom, QPair<QPair<QString, QString>, QPair<QString, QString> > pair);
virtual QPair<QDomElement, Item::DomElementTypes> generateItem(QDomDocument &document, const QPoint &topLeftPicture);
virtual QPair<QDomElement, Item::DomElementTypes> generateItem(QDomDocument &document
, const QPoint &topLeftPicture);

private:
graphicsUtils::LineImpl mLineImpl;
Expand Down
Loading

0 comments on commit d27d416

Please sign in to comment.