From 90fc0bb22670c21b76589c195385e489adf53d3a Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Mon, 12 Dec 2016 11:18:36 +0100 Subject: [PATCH] use Travis to look for spelling errors use silver searcher for faster search (instead of grep) --- .travis.yml | 6 ++ ci/travis/check_spelling.sh | 17 ++++ python/core/qgstaskmanager.sip | 4 +- python/plugins/processing/algs/help/qgis.yaml | 2 +- scripts/.agignore | 38 +++++++++ scripts/chkspelling_ag.sh | 39 +++++++++ scripts/prepare-commit.sh | 80 ++++++++++--------- scripts/spelling.dat | 2 + src/core/qgstaskmanager.cpp | 6 +- src/core/qgstaskmanager.h | 4 +- tests/src/core/testqgstaskmanager.cpp | 10 +-- 11 files changed, 158 insertions(+), 50 deletions(-) create mode 100755 ci/travis/check_spelling.sh create mode 100644 scripts/.agignore create mode 100755 scripts/chkspelling_ag.sh diff --git a/.travis.yml b/.travis.yml index a2151d1d8c3..480f8590df8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,6 +22,7 @@ matrix: - llvm-toolchain-precise-3.8 - ubuntu-toolchain-r-test - george-edison55-precise-backports # doxygen 1.8.3 + # - laurent-boulard-devtools not whitelisted yet https://github.com/travis-ci/apt-source-whitelist/pull/345 packages: - doxygen - bison @@ -36,11 +37,15 @@ matrix: - xvfb - flip - clang-3.8 + # used for spell checks + # - silversearcher-ag not available in precise nor in a white listed ppa (in osgeo4travis as for now) + - expect-dev # unbuffer # OSX based build with QT4 and Python 2 # - os: osx # env: # - BUILD=osx # - IGNORE_BUILD_FAILURES=YES + git: depth: 30 @@ -70,6 +75,7 @@ before_script: script: - ./ci/travis/${TRAVIS_OS_NAME}/script.sh + - ./ci/travis/check_spelling.sh after_script: - ./ci/travis/${TRAVIS_OS_NAME}/after_script.sh diff --git a/ci/travis/check_spelling.sh b/ci/travis/check_spelling.sh new file mode 100755 index 00000000000..10fbca8bb29 --- /dev/null +++ b/ci/travis/check_spelling.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -e + +export PATH=${HOME}/osgeo4travis/bin:${PATH} + + +echo "Spell check" + +if [[ ! -z $TRAVIS_PULL_REQUEST_BRANCH ]]; then + # if on a PR, just analyse the changed files + echo "TRAVIS PR BRANCH: $TRAVIS_PULL_REQUEST_BRANCH" + FILES=$(git diff --name-only HEAD $(git merge-base HEAD master) | tr '\n' ' ' ) +fi + + +CODE=$(./scripts/chkspelling_ag.sh) +exit $CODE diff --git a/python/core/qgstaskmanager.sip b/python/core/qgstaskmanager.sip index 0a41c744978..6ba3e0e824c 100644 --- a/python/core/qgstaskmanager.sip +++ b/python/core/qgstaskmanager.sip @@ -117,7 +117,7 @@ class QgsTask : QObject * Subtasks allow a single task to be created which * consists of multiple smaller tasks. Subtasks are not visible or indepedently * controllable by users. Ownership of the subtask is transferred. - * Subtasks can have an optional list of dependant tasks, which must be completed + * Subtasks can have an optional list of dependent tasks, which must be completed * before the subtask can begin. By default subtasks are considered independent * of the parent task, ie they can be run either before, after, or at the same * time as the parent task. This behaviour can be overriden through the subTaskDependency @@ -286,7 +286,7 @@ class QgsTaskManager : QObject long addTask( QgsTask* task /Transfer/, int priority = 0 ); /** - * Adds a task to the manager, using a full task definition (including dependancy + * Adds a task to the manager, using a full task definition (including dependency * handling). Ownership of the task is transferred to the manager, and the task * manager will be responsible for starting the task. The priority argument can * be used to control the run queue's order of execution. diff --git a/python/plugins/processing/algs/help/qgis.yaml b/python/plugins/processing/algs/help/qgis.yaml index 7b8d386103c..fa950b45a2b 100644 --- a/python/plugins/processing/algs/help/qgis.yaml +++ b/python/plugins/processing/algs/help/qgis.yaml @@ -90,7 +90,7 @@ qgis:countuniquepointsinpolygon: > A new polygons layer is generated, with the exact same content as the input polygons layer, but containing an additional field with the points count corresponding to each polygon. qgis:createattributeindex: > - Creates an index to speed up queries made against a field in a table. Support for index creation is dependant on the layer's data provider and the field type. + Creates an index to speed up queries made against a field in a table. Support for index creation is dependent on the layer's data provider and the field type. qgis:createconstantrasterlayer: > Given an input raster layer an a value, this algorithm generates a new layer with the same extent and cellsize as the input one, and all cells with the specified value. diff --git a/scripts/.agignore b/scripts/.agignore new file mode 100644 index 00000000000..d4a4c1384cd --- /dev/null +++ b/scripts/.agignore @@ -0,0 +1,38 @@ +# Folders +.build*/ +ci/ +debian/build.*/ +debian/build*/ +debian/.*/usr/ +i18n/ +ms-windows/osgeo4w/ +python/ext-libs/ +python/plugins/processing/algs/otb/ +python/plugins/processing/algs/saga/ +python/qsci_apis/ +src/app/dwg/libdxfrw/ +src/app/gps/qwtpolar-1.0/ +src/app/gps/qwtpolar-1.1.1/ +src/plugins/grass/qtermwidget/ + +#Extensions +*.*.orig +*.*.sortinc +*.*.prepare + + +#Specific files +ChangeLog +Exception_to_GPL_for_Qt.txt +images/themes/default/svgbase/hammer.svg +images/themes/default/propertyicons/general.svg +LexerR.py +spelling.dat +resources/cpt-city-qgis-min/fme/metres/DESC.xml +resources/cpt-city-qgis-min/wkp/schwarzwald/COPYING.xml +tests/src/python/test_qgsserver_accesscontrol.py +tests/testdata/qgis_server/ets-wms13/project.qgs +tests/testdata/qgis_server_accesscontrol/project.qgs +tests/testdata/qgis_server_accesscontrol/Hello.qml + + diff --git a/scripts/chkspelling_ag.sh b/scripts/chkspelling_ag.sh new file mode 100755 index 00000000000..395c8b2f490 --- /dev/null +++ b/scripts/chkspelling_ag.sh @@ -0,0 +1,39 @@ +#!/bin/bash +########################################################################### +# chkspelling.sh +# --------------------- +# Date : December 2016 +# Copyright : (C) 2016 by Denis Rouzaud +# Email : denis.rouzaud@gmail.com +########################################################################### +# # +# This program is free software; you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation; either version 2 of the License, or # +# (at your option) any later version. # +# # +########################################################################### + +# optional arguments: files to be checked + + +RE=$(cut -d: -f1 scripts/spelling.dat | tr '\n' '\|' | sed -e 's/|$//') +if [ ! $# -eq 0 ]; then + EXCLUDE=$(cat ci/travis/.agignore | sed -e 's/\s*#.*$//' -e '/^\s*$/d' | tr '\n' '|' | sed -e 's/|$//') + FILES=$(echo $@ | tr -s '[[:blank:]]' '\n' | egrep -iv "$EXCLUDE" | tr '\n' ' ' ) + echo "Running spell check on files: $FILES" +else + FILES="." +fi + + +exec 5>&1 +OUTPUT=$(ag --smart-case --all-text --nopager --numbers --word-regexp --path-to-ignore scripts/.agignore "$RE" $FILES |tee /dev/fd/5) + + +if [[ ! -z $OUTPUT ]]; then + echo "Spelling errors have been found" + exit 1 +else + exit 0 +fi diff --git a/scripts/prepare-commit.sh b/scripts/prepare-commit.sh index 22fc85bbd43..dadde3a7fc6 100755 --- a/scripts/prepare-commit.sh +++ b/scripts/prepare-commit.sh @@ -21,20 +21,20 @@ PATH=$TOPLEVEL/scripts:$PATH cd $TOPLEVEL if ! type -p astyle.sh >/dev/null; then - echo astyle.sh not found - exit 1 + echo astyle.sh not found + exit 1 fi if ! type -p colordiff >/dev/null; then - colordiff() - { - cat "$@" - } + colordiff() + { + cat "$@" + } fi if [ "$1" = "-c" ]; then - echo "Cleaning..." - remove_temporary_files.sh + echo "Cleaning..." + remove_temporary_files.sh fi set -e @@ -42,9 +42,15 @@ set -e # determine changed files MODIFIED=$(git status --porcelain| sed -ne "s/^ *[MA] *//p" | sort -u) +CODE=$(./$TOPLEVEL/scripts/chkspelling_ag.sh $MODIFIED) +if [ code -eq 1]; then + exit 1 +fi + + if [ -z "$MODIFIED" ]; then - echo nothing was modified - exit 0 + echo nothing was modified + exit 0 fi # save original changes @@ -58,42 +64,42 @@ ASTYLEDIFF=astyle.$REV.diff i=0 N=$(echo $MODIFIED | wc -w) for f in $MODIFIED; do - (( i++ )) || true + (( i++ )) || true - case "$f" in - src/core/gps/qextserialport/*|src/plugins/globe/osgEarthQt/*|src/plugins/globe/osgEarthUtil/*) - echo $f skipped - continue - ;; + case "$f" in + src/core/gps/qextserialport/*|src/plugins/globe/osgEarthQt/*|src/plugins/globe/osgEarthUtil/*) + echo $f skipped + continue + ;; - *.cpp|*.c|*.h|*.cxx|*.hxx|*.c++|*.h++|*.cc|*.hh|*.C|*.H|*.sip|*.py) - ;; + *.cpp|*.c|*.h|*.cxx|*.hxx|*.c++|*.h++|*.cc|*.hh|*.C|*.H|*.sip|*.py) + ;; - *) - continue - ;; - esac + *) + continue + ;; + esac - m=$f.$REV.prepare + m=$f.$REV.prepare - cp $f $m - ASTYLEPROGRESS=" [$i/$N]" astyle.sh $f - if diff -u $m $f >>$ASTYLEDIFF; then - # no difference found - rm $m - fi + cp $f $m + ASTYLEPROGRESS=" [$i/$N]" astyle.sh $f + if diff -u $m $f >>$ASTYLEDIFF; then + # no difference found + rm $m + fi done if [ -s "$ASTYLEDIFF" ]; then - if tty -s; then - # review astyle changes - colordiff <$ASTYLEDIFF | less -r - else - echo "Files changed (see $ASTYLEDIFF)" - fi - exit 1 + if tty -s; then + # review astyle changes + colordiff <$ASTYLEDIFF | less -r + else + echo "Files changed (see $ASTYLEDIFF)" + fi + exit 1 else - rm $ASTYLEDIFF + rm $ASTYLEDIFF fi exit 0 diff --git a/scripts/spelling.dat b/scripts/spelling.dat index 6e7135f8fd7..0d29065f793 100644 --- a/scripts/spelling.dat +++ b/scripts/spelling.dat @@ -313,6 +313,8 @@ optionnal:optional optmizations:optimizations orientatied:orientated orientied:oriented +orthagonal:orthogonal +orthagonalize:orthogonalize overaall:overall overidden:overridden overide:override diff --git a/src/core/qgstaskmanager.cpp b/src/core/qgstaskmanager.cpp index 3c28d0177a0..9dc3a2b87c3 100644 --- a/src/core/qgstaskmanager.cpp +++ b/src/core/qgstaskmanager.cpp @@ -626,7 +626,7 @@ void QgsTaskManager::taskStatusChanged( int status ) if ( status == QgsTask::Terminated ) { - //recursively cancel dependant tasks + //recursively cancel dependent tasks cancelDependentTasks( id ); } @@ -790,9 +790,9 @@ void QgsTaskManager::cancelDependentTasks( long taskId ) { if ( it.value().contains( cancelledTask ) ) { - // found task with this dependancy + // found task with this dependency - // cancel it - note that this will be recursive, so any tasks dependant + // cancel it - note that this will be recursive, so any tasks dependent // on this one will also be cancelled QgsTask* dependentTask = task( it.key() ); if ( dependentTask ) diff --git a/src/core/qgstaskmanager.h b/src/core/qgstaskmanager.h index 1d3207d2bab..7cb0064f5aa 100644 --- a/src/core/qgstaskmanager.h +++ b/src/core/qgstaskmanager.h @@ -148,7 +148,7 @@ class CORE_EXPORT QgsTask : public QObject * Subtasks allow a single task to be created which * consists of multiple smaller tasks. Subtasks are not visible or indepedently * controllable by users. Ownership of the subtask is transferred. - * Subtasks can have an optional list of dependant tasks, which must be completed + * Subtasks can have an optional list of dependent tasks, which must be completed * before the subtask can begin. By default subtasks are considered independent * of the parent task, ie they can be run either before, after, or at the same * time as the parent task. This behaviour can be overriden through the subTaskDependency @@ -381,7 +381,7 @@ class CORE_EXPORT QgsTaskManager : public QObject long addTask( QgsTask* task, int priority = 0 ); /** - * Adds a task to the manager, using a full task definition (including dependancy + * Adds a task to the manager, using a full task definition (including dependency * handling). Ownership of the task is transferred to the manager, and the task * manager will be responsible for starting the task. The priority argument can * be used to control the run queue's order of execution, with larger numbers diff --git a/tests/src/core/testqgstaskmanager.cpp b/tests/src/core/testqgstaskmanager.cpp index 6b4a4ce13a3..ca65b8d599d 100644 --- a/tests/src/core/testqgstaskmanager.cpp +++ b/tests/src/core/testqgstaskmanager.cpp @@ -202,7 +202,7 @@ class TestQgsTaskManager : public QObject void allTasksFinished(); void activeTasks(); void holdTask(); - void dependancies(); + void dependencies(); void layerDependencies(); void managerWithSubTasks(); void managerWithSubTasks2(); @@ -923,11 +923,11 @@ void TestQgsTaskManager::holdTask() task->cancel(); } -void TestQgsTaskManager::dependancies() +void TestQgsTaskManager::dependencies() { QgsTaskManager manager; - //test that cancelling tasks cancels all tasks which are dependant on them + //test that cancelling tasks cancels all tasks which are dependent on them CancelableTask* task = new CancelableTask(); task->hold(); CancelableTask* childTask = new CancelableTask(); @@ -952,7 +952,7 @@ void TestQgsTaskManager::dependancies() QCOMPARE( childTask->status(), QgsTask::Terminated ); QCOMPARE( task->status(), QgsTask::Terminated ); - // test that tasks are queued until dependancies are resolved + // test that tasks are queued until dependencies are resolved task = new CancelableTask(); childTask = new CancelableTask(); childTask->hold(); @@ -1023,7 +1023,7 @@ void TestQgsTaskManager::layerDependencies() QgsTaskManager manager; - //test that remove layers cancels all tasks which are dependant on them + //test that remove layers cancels all tasks which are dependent on them TestTask* task = new TestTask(); task->hold(); task->setDependentLayers( QStringList() << layer2->id() << layer3->id() );