From 29c8107808b3984ca651a89daa749316bc3e82ab Mon Sep 17 00:00:00 2001 From: Bjorn Stromberg Date: Sat, 15 Aug 2020 10:32:59 +0900 Subject: [PATCH] Fix array sort test failure (#64) * Fix array sort test failure * Remove Makefile and associated scripts * Test on node 14, 12, and 10 * Fix markdown of README --- .travis.yml | 8 ++--- Makefile | 35 --------------------- README.md | 60 ++++++++++++++++++------------------ package.json | 14 ++++++--- scripts/git-setup.sh | 57 ---------------------------------- scripts/jshint.cfg | 70 ------------------------------------------ scripts/lint-all.sh | 26 ---------------- scripts/lint-staged.sh | 45 --------------------------- test/modules/array.js | 8 ++--- 9 files changed, 47 insertions(+), 276 deletions(-) delete mode 100644 Makefile delete mode 100755 scripts/git-setup.sh delete mode 100644 scripts/jshint.cfg delete mode 100755 scripts/lint-all.sh delete mode 100755 scripts/lint-staged.sh diff --git a/.travis.yml b/.travis.yml index 3a688c5..5afe061 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ language: - node_js node_js: - - "0.11" - - "0.10" - - "0.8" + - "14" + - "12" + - "10" before_install: - - npm install -g npm \ No newline at end of file + - npm install -g npm diff --git a/Makefile b/Makefile deleted file mode 100644 index 931c181..0000000 --- a/Makefile +++ /dev/null @@ -1,35 +0,0 @@ -# target: help, Display callable targets. -help: - egrep "^# target:" [Mm]akefile - -# target: setup, Do a full setup (currently an alias for git-setup). -setup: git-setup - -# target: clean, Cleans the NPM cache. -clean: - npm cache clean - -# target: install, Installs all Node.js dependencies. -install: - npm install - -# target: test, Runs all tests. -test: - npm test - -# target: lint, Lints every JavaScript file in the project that is staged to be comitted. -lint: - ./scripts/lint-staged.sh - -# target: lint-all, Lints every JavaScript file in the project. -lint-all: - ./scripts/lint-all.sh - -# target: commit-test, Runs all tests and lints every JavaScript file in the project that is staged to be comitted.. -commit-test: test lint - -# target: git-setup, Sets up git hooks. -git-setup: - ./scripts/git-setup.sh - -.PHONY: test diff --git a/README.md b/README.md index 30f9fb6..a23112e 100644 --- a/README.md +++ b/README.md @@ -39,12 +39,12 @@ reservoirDogs.cast[1].ears.pop(); Tomes API ========= -##Tome +## Tome -###Tome.conjure( *data* ) +### Tome.conjure( *data* ) Returns a new Tome containing your data. -###Tome.typeOf( *data* ) +### Tome.typeOf( *data* ) Returns data's type as a string. Tomes has types that exist in JSON which are: - array - boolean @@ -55,13 +55,13 @@ Returns data's type as a string. Tomes has types that exist in JSON which are: As well as: - undefined -###Tome.isTome( *data* ) +### Tome.isTome( *data* ) Returns a boolean indicating whether data is a Tome or not. -###Tome.unTome( *tome* ) +### Tome.unTome( *tome* ) Returns a regular JavaScript version of your Tome. -##TomeTypes +## TomeTypes - ArrayTome - BooleanTome - NullTome @@ -70,72 +70,72 @@ Returns a regular JavaScript version of your Tome. - StringTome - UndefinedTome -###Tome.destroy( *tome* ) +### Tome.destroy( *tome* ) Make a tome and all of it's sub-tomes emit destroy. This will not delete anything. -##Methods +## Methods -###assign( *data* ) +### assign( *data* ) Assign data to a Tome. -###set( *key*, *data* ) +### set( *key*, *data* ) Assign data to key on a Tome. Set will create a Tome on the key if it does not exist. -###del( *key* ) +### del( *key* ) Delete a key from a Tome. -###swap( *key*, *tome* ) +### swap( *key*, *tome* ) Swap key with tome. -###rename( *key*, *newkey* ) +### rename( *key*, *newkey* ) Rename key to newkey. -###move( *key*, *tome*, [ *newkey* ] ) +### move( *key*, *tome*, [ *newkey* ] ) Move key to tome. Optionally call it newkey on that tome. -###read( ) +### read( ) Get a single change operation from the root Tome, removing it in the process. Returns null if there are no changes. -###readAll( ) +### readAll( ) Get all change operations from the Tome -###merge( *diff* ) +### merge( *diff* ) Applies a change operation or an array of change operations to a Tome. -###destroy( ) +### destroy( ) Makes the tome and all of it's sub-tomes emit destroy. Does not delete anything. -###unTome( ) +### unTome( ) Returns a regular javascript version of your Tome. -###getKey( ) +### getKey( ) Returns a Tome's key. -###getParent( ) +### getParent( ) Returns a Tome's parent Tome. -###getVersion( ) +### getVersion( ) Returns a Tome's version. -###is( *value* ) +### is( *value* ) Returns a boolean value indicating whether or not the Tome is observably indistinguishable from value ([ref](http://wiki.ecmascript.org/doku.php?id=harmony:egal)). If no value is given, returns whether or not the Tome's value is truthy. -###isDirty( ) +### isDirty( ) Returns whether a Tome has been changed, but the change has not been read. -##Events +## Events -###add( *key* ) +### add( *key* ) Emitted when a Tome receives a new key. -###del( *key* ) +### del( *key* ) Emitted when a key is deleted from a Tome. -###destroy( ) +### destroy( ) Emitted when a Tome is deleted. Removes all event listeners for this Tome. -###readable( *was* ) +### readable( *was* ) Emitted every time a Tome or any of its child Tomes are altered. If the Tome was a primitive (ie. string, number, or boolean) the previous value will be emitted as well, but only if it did not change types. -###typeChange( *tome*, *oldType*, *newType* ) +### typeChange( *tome*, *oldType*, *newType* ) Emitted by the root tome when a Tome changes type. diff --git a/package.json b/package.json index ad42672..67bde59 100644 --- a/package.json +++ b/package.json @@ -2,12 +2,16 @@ "name": "@bjornstar/tomes", "description": "Evented Storage Agnostic Data API", "version": "1.0.0", - "author": "Bjorn Stromberg ", + "author": "Bjorn Stromberg ", "maintainers": [ - { "name": "Bjorn Stromberg", "email": "bjornstar@gmail.com" } + { + "name": "Bjorn Stromberg", + "email": "bjorn@bjornstar.com" + } ], "scripts": { - "test": "jshint index.js && node test" + "lint": "jshint index.js", + "test": "node test" }, "main": "index.js", "devDependencies": { @@ -20,7 +24,7 @@ "type": "git", "url": "https://github.com/bjornstar/tomes.git" }, - "bugs" : { - "url" : "http://github.com/bjornstar/tomes/issues" + "bugs": { + "url": "http://github.com/bjornstar/tomes/issues" } } diff --git a/scripts/git-setup.sh b/scripts/git-setup.sh deleted file mode 100755 index 6ba2a4a..0000000 --- a/scripts/git-setup.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/sh - -echo Detecting git repository root... - -PROJECTPATH=`git rev-parse --show-toplevel` -if [[ $? != 0 ]] -then - echo "Error: failed to detect git repository root (is this a repository?)" - exit 1 -fi - -GITPATH="$PROJECTPATH/.git" - -echo "Making sure $GITPATH exists..." - -if [[ ! -d "$GITPATH" ]] -then - echo "Error: directory $GITPATH not found." - exit 1 -else - echo "$GITPATH found." -fi - - -# set up git hooks - -HOOKSPATH="$GITPATH/hooks" - -if [[ ! -d "$HOOKSPATH" ]] -then - echo "Directory $HOOKSPATH not found, creating..." - mkdir -p "$HOOKSPATH" -fi - - -# pre-commit hook - -PRECOMMITPATH="$HOOKSPATH/pre-commit" -MODE=775 - -echo -n "Make command to run before commit (default: commit-test): " -read INP - -if [[ -z "$INP" ]] -then - INP="commit-test" -fi - -echo "Make command that will be run on commit: $INP" -echo "Creating pre-commit script..." - -echo "#!/bin/sh" > "$PRECOMMITPATH" -echo "make -C \"$PROJECTPATH\" $INP" >> "$PRECOMMITPATH" - -echo "Setting $PRECOMMITPATH to be executable ($MODE)" -chmod $MODE "$PRECOMMITPATH" - diff --git a/scripts/jshint.cfg b/scripts/jshint.cfg deleted file mode 100644 index 3f7c749..0000000 --- a/scripts/jshint.cfg +++ /dev/null @@ -1,70 +0,0 @@ -{ - "predef" : [ // Custom globals. - - ], - - // Settings - "passfail" : false, // Stop on first error. - "maxerr" : 100, // Maximum error before stopping. - - // Predefined globals whom JSHint will ignore. - "browser" : true, // Standard browser globals e.g. `window`, `document`. - - "node" : true, - "rhino" : false, - "couch" : false, - "wsh" : false, // Windows Scripting Host. - - "jquery" : false, - "prototypejs" : false, - "mootools" : false, - "dojo" : false, - - // Development. - "debug" : false, // Allow debugger statements e.g. browser breakpoints. - "devel" : true, // Allow developments statements e.g. `console.log();`. - - - // ECMAScript 5. - "strict" : false, // Require `use strict` pragma in every file. - "globalstrict" : true, // Allow global "use strict" (also enables 'strict'). - - - // The Good Parts. - "asi" : false, // Tolerate Automatic Semicolon Insertion (no semicolons). - "laxbreak" : true, // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons. - "bitwise" : false, // Prohibit bitwise operators (&, |, ^, etc.). - "boss" : false, // Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments. - "curly" : true, // Require {} for every new block or scope. - "eqeqeq" : true, // Require triple equals i.e. `===`. - "eqnull" : false, // Tolerate use of `== null`. - "evil" : false, // Tolerate use of `eval`. - "expr" : false, // Tolerate `ExpressionStatement` as Programs. - "forin" : false, // Tolerate `for in` loops without `hasOwnPrototype`. - "immed" : true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );` - "latedef" : true, // Prohibit variable use before definition. - "loopfunc" : false, // Allow functions to be defined within loops. - "noarg" : true, // Prohibit use of `arguments.caller` and `arguments.callee`. - "regexp" : false, // Prohibit `.` and `[^...]` in regular expressions. - "regexdash" : false, // Tolerate unescaped last dash i.e. `[-...]`. - "scripturl" : false, // Tolerate script-targeted URLs. - "shadow" : false, // Allows re-define variables later in code e.g. `var x=1; x=2;`. - "supernew" : false, // Tolerate `new function () { ... };` and `new Object;`. - "undef" : true, // Require all non-global variables be declared before they are used. - "camelcase" : false, // Require camelCase or ALL_CAPS. - "unused" : true, // Prohibit unused variables. - "proto" : true, // Tolerate use of the __proto__ property. - - // Personal styling prefeirences. - "newcap" : true, // Require capitalization of all constructor functions e.g. `new F()`. - "noempty" : true, // Prohibit use of empty blocks. - "nonew" : true, // Prohibit use of constructors for side-effects. - "nomen" : false, // Prohibit use of initial or trailing underbars in names. - "onevar" : false, // Allow only one `var` statement per function. - "plusplus" : true, // Prohibit use of `++` & `--`. - "sub" : false, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`. - "trailing" : true, // Prohibit trailing whitespaces. - "white" : true, // Check against strict whitespace and indentation rules. - "indent" : 4 // Specify indentation spacing -} - diff --git a/scripts/lint-all.sh b/scripts/lint-all.sh deleted file mode 100755 index 60b21fa..0000000 --- a/scripts/lint-all.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -# this script requires: -# - the user to be in a git repo -# - git to be installed -# - jshint to be installed - - -path=`pwd` -cd `git rev-parse --show-toplevel` - -files=`find . ! -wholename '*/node_modules/*' -name '*.js'` - -if [[ -z "$files" ]] -then - echo No JavaScript files to lint. - exit 0 -fi - -node_modules/.bin/jshint $files --config ./scripts/jshint.cfg -exitCode=$? - -cd "$path" - -exit $exitCode - diff --git a/scripts/lint-staged.sh b/scripts/lint-staged.sh deleted file mode 100755 index 55ac719..0000000 --- a/scripts/lint-staged.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash - -# this script requires: -# - the user to be in a git repo -# - git to be installed -# - jshint to be installed - - -path=`pwd` -cd `git rev-parse --show-toplevel` - -staged=`git diff --name-only --cached |grep -e '\.js$'` -if [[ -z "$staged" ]] -then - echo No staged JavaScript files to lint. - exit 0 -fi - -exitCode=0 -let success=0 -let failures=0 - -for file in $staged -do - # ignore non-existing files (caused by renames or removal) - if [[ -e $file ]] - then - node_modules/.bin/jshint $file --config ./scripts/jshint.cfg - if [[ $? != 0 ]] - then - exitCode=1 - let failures=$failures+1 - else - let success=$success+1 - fi - fi -done - -echo "LINT failures: $failures" -echo "LINT successes: $success" - -cd "$path" - -exit $exitCode - diff --git a/test/modules/array.js b/test/modules/array.js index 9739f4b..fc4bcb0 100755 --- a/test/modules/array.js +++ b/test/modules/array.js @@ -451,8 +451,8 @@ exports.testArraySort = function (test) { test.strictEqual(JSON.stringify(a), JSON.stringify(b)); }); - a.sort(function (a, b) { return a.valueOf() - b.valueOf(); }); - b.sort(function (a, b) { return a.valueOf() - b.valueOf(); }); + a.sort(); + b.sort(); // 2 test.strictEqual(a.length, b.length); @@ -462,8 +462,8 @@ exports.testArraySort = function (test) { a.push('asdf', 'foo', 'bar', 'zebra', 'banana', 'kangaroo'); b.push('asdf', 'foo', 'bar', 'zebra', 'banana', 'kangaroo'); - a.sort(function (a, b) { return a.valueOf() - b.valueOf(); }); - b.sort(function (a, b) { return a.valueOf() - b.valueOf(); }); + a.sort(); + b.sort(); // 6 test.strictEqual(JSON.stringify(a), JSON.stringify(b));