Commit 755f01c1 authored by Stefan Cameron's avatar Stefan Cameron

Get publishing-ready, remove dist from git, add pre-commit hooks

With this commit, the built distro is no longer committed to the
repo. It's generated post-install and pre-publish with the
npm 'prepare' script. Tests are run pre-publish. Linting and API
documentation are run pre-commit. API docs have moved to API.md
in the repo root so that they're available online. They are also
included in the distro that will be published to npm sometime in
the near future.

Also, I discovered that test code wasn't being linted! So I added
those source files and got rid of the accumulated lint.
parent 18c8f730
......@@ -60,7 +60,8 @@ typings/
# IDE files
.vscode/
# Tools Builds
# Builds
dist/
dist_tools/
# OS files
......
......@@ -1209,7 +1209,7 @@ The following values __are considered__ any objects:
- `{}`
- `new Object()`
- `new (function() {}) | new (class {})` (class instance) (also see
- `new (function() {}) | new (class {})()` (class instance) (also see
[CLASS_OBJECT](#rtvref.types.CLASS_OBJECT))
- `new String('')`
- `new Boolean(true)`
......@@ -1273,7 +1273,7 @@ The following values are considered objects:
- `{}`
- `new Object()`
- `new (function() {}) | new (class {})` (class instance) (also see
- `new (function() {}) | new (class {})()` (class instance) (also see
[CLASS_OBJECT](#rtvref.types.CLASS_OBJECT))
The following values __are not__ considered objects:
......@@ -1328,7 +1328,7 @@ The following values are considered plain objects:
The following values __are not__ considered plain objects:
- `new (function() {}) | new (class {})` (class instance) (also see
- `new (function() {}) | new (class {})()` (class instance) (also see
[CLASS_OBJECT](#rtvref.types.CLASS_OBJECT))
- `new String('')`
- `new Boolean(true)`
......@@ -1378,7 +1378,7 @@ A _class_ object is one that is created by invoking the `new` operator on a
The following values are considered class objects:
- `new (function() {}) | new (class {})` (tip: use the `ctr`
- `new (function() {}) | new (class {})()` (tip: use the `ctr`
[argument](#rtvref.types.CLASS_OBJECT_args) to test for a specific class)
The following values __are not__ considered class objects:
......
......@@ -15,7 +15,7 @@ Shapes must be:
# Documentation
[Documentation](dist/rtv.js.md)
[API](API.md)
# Changes
......@@ -27,7 +27,7 @@ Shapes must be:
# License
[MIT](LICENSE.md)
[MIT](LICENSE)
# TODO
......
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -2556,6 +2556,18 @@
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
},
"concat-stream": {
"version": "1.6.2",
"resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz",
"integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==",
"dev": true,
"requires": {
"buffer-from": "^1.0.0",
"inherits": "^2.0.3",
"readable-stream": "^2.2.2",
"typedarray": "^0.0.6"
}
},
"config-master": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/config-master/-/config-master-3.1.0.tgz",
......@@ -3478,8 +3490,7 @@
"isexe": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
"integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=",
"optional": true
"integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA="
},
"isobject": {
"version": "2.1.0",
......@@ -3768,6 +3779,16 @@
"js-tokens": "^3.0.0"
}
},
"lru-cache": {
"version": "4.1.3",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.3.tgz",
"integrity": "sha512-fFEhvcgzuIoJVUF8fYr5KR0YqxD238zgObTps31YdADwPPAp82a4M8TrckkWyx7ekNlf9aBcVn81cFwwXngrJA==",
"dev": true,
"requires": {
"pseudomap": "^1.0.2",
"yallist": "^2.1.2"
}
},
"magic-string": {
"version": "0.22.5",
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.22.5.tgz",
......@@ -5131,6 +5152,12 @@
}
}
},
"os-shim": {
"version": "0.1.3",
"resolved": "https://registry.npmjs.org/os-shim/-/os-shim-0.1.3.tgz",
"integrity": "sha1-a2LDeRz3kJ6jXtRuF2WLtBfLORc=",
"dev": true
},
"os-tmpdir": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz",
......@@ -5326,6 +5353,39 @@
"integrity": "sha512-ARhBOdzS3e41FbkW/XWrTEtukqqLoK5+Z/4UeDaLuSW+39JPeFgs4gCGqsrJHVZX0fUrx//4OF0K1CUGwlIFow==",
"optional": true
},
"pre-commit": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/pre-commit/-/pre-commit-1.2.2.tgz",
"integrity": "sha1-287g7p3nI15X95xW186UZBpp7sY=",
"dev": true,
"requires": {
"cross-spawn": "^5.0.1",
"spawn-sync": "^1.0.15",
"which": "1.2.x"
},
"dependencies": {
"cross-spawn": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz",
"integrity": "sha1-6L0O/uWPz/b4+UUQoKVUu/ojVEk=",
"dev": true,
"requires": {
"lru-cache": "^4.0.1",
"shebang-command": "^1.2.0",
"which": "^1.2.9"
}
},
"which": {
"version": "1.2.14",
"resolved": "https://registry.npmjs.org/which/-/which-1.2.14.tgz",
"integrity": "sha1-mofEN48D6CfOyvGs31bHNsAcFOU=",
"dev": true,
"requires": {
"isexe": "^2.0.0"
}
}
}
},
"prelude-ls": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz",
......@@ -5355,6 +5415,12 @@
"integrity": "sha1-ihvjZr+Pwj2yvSPxDG/pILQ4nR8=",
"optional": true
},
"pseudomap": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz",
"integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM=",
"dev": true
},
"punycode": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz",
......@@ -5792,7 +5858,6 @@
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz",
"integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=",
"optional": true,
"requires": {
"shebang-regex": "^1.0.0"
}
......@@ -5800,8 +5865,7 @@
"shebang-regex": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz",
"integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=",
"optional": true
"integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM="
},
"signal-exit": {
"version": "3.0.2",
......@@ -5884,6 +5948,16 @@
"source-map": "^0.6.0"
}
},
"spawn-sync": {
"version": "1.0.15",
"resolved": "https://registry.npmjs.org/spawn-sync/-/spawn-sync-1.0.15.tgz",
"integrity": "sha1-sAeZVX63+wyDdsKdROih6mfldHY=",
"dev": true,
"requires": {
"concat-stream": "^1.4.7",
"os-shim": "^0.1.2"
}
},
"spdx-correct": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.0.0.tgz",
......@@ -6149,6 +6223,12 @@
"resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz",
"integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g=="
},
"typedarray": {
"version": "0.0.6",
"resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz",
"integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=",
"dev": true
},
"typical": {
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/typical/-/typical-2.6.1.tgz",
......@@ -6311,6 +6391,12 @@
"integrity": "sha1-+mv3YqYKQT+z3Y9LA8WyaSONMI8=",
"dev": true
},
"yallist": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz",
"integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=",
"dev": true
},
"yargs": {
"version": "3.10.0",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-3.10.0.tgz",
......
......@@ -31,21 +31,26 @@
"html"
]
},
"pre-commit": ["precommit:msg", "lint", "docs", "precommit:docs"],
"scripts": {
"precommit:msg": "echo 'Running pre-commit checks...'",
"precommit:docs": "git add API.md",
"clean": "rm -rf ./build",
"start": "npm run build:lib && npm run node",
"node": "node -r ./tools/node.js --inspect",
"node:build": "npm run build:lib && npm run node",
"node:internals": "rollup -c tools/rollup.internals.js && node -r ./dist_tools/internals.js --inspect",
"build:docs": "jsdoc2md -f \"src/**/*.js\" -f \"src/**/*.jsdoc\" --separators > dist/rtv.js.md",
"build:lib": "BABEL_ENV=build rollup -c",
"build": "npm run clean && npm run build:lib && npm run build:docs",
"lint": "eslint rollup.config.js \"src/**/*.js\" \"tools/**/*.js\"",
"build": "npm run clean && npm run build:lib",
"docs": "jsdoc2md -f \"src/**/*.js\" -f \"src/**/*.jsdoc\" --separators > API.md",
"lint": "eslint ./*.js \"src/**/*.js\" \"test/**/*.js\" \"tools/**/*.js\"",
"test:unit": "BABEL_ENV=test mocha -c -r mocha-setup.js \"./test/**/*.test.js\"",
"test:unit:watch": "npm run test:unit -- -w",
"test:unit:debug": "npm run test:unit -- --inspect-brk",
"test:coverage": "nyc npm run test:unit",
"test": "npm run lint && npm run test:coverage"
"test": "npm run lint && npm run test:coverage",
"prepare": "npm run build && npm run docs",
"prepublishOnly": "npm test"
},
"repository": {
"type": "git",
......@@ -71,14 +76,23 @@
"url": "https://gitlab.com/stefcameron/rtvjs/issues"
},
"homepage": "https://gitlab.com/stefcameron/rtvjs#README",
"dependencies": {
"lodash": "^4.17.10"
},
"files": [
"API.md",
"CHANGELOG.md",
"LICENSE",
"package-lock.json",
"package.json",
"README.md",
"dist/"
],
"dependencies": {},
"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/register": "^7.0.0",
"jsdoc-to-markdown": "^4.0.1",
"lodash": "^4.17.10",
"pre-commit": "^1.2.2",
"rollup": "^0.65.2",
"rollup-plugin-babel": "^4.0.3",
"rollup-plugin-commonjs": "^9.1.6",
......
......@@ -767,7 +767,7 @@ const defs = {
*
* - `{}`
* - `new Object()`
* - `new (function() {}) | new (class {})` (class instance) (also see
* - `new (function() {}) | new (class {})()` (class instance) (also see
* {@link rtvref.types.CLASS_OBJECT CLASS_OBJECT})
* - `new String('')`
* - `new Boolean(true)`
......@@ -827,7 +827,7 @@ const defs = {
*
* - `{}`
* - `new Object()`
* - `new (function() {}) | new (class {})` (class instance) (also see
* - `new (function() {}) | new (class {})()` (class instance) (also see
* {@link rtvref.types.CLASS_OBJECT CLASS_OBJECT})
*
* The following values __are not__ considered objects:
......@@ -878,7 +878,7 @@ const defs = {
*
* The following values __are not__ considered plain objects:
*
* - `new (function() {}) | new (class {})` (class instance) (also see
* - `new (function() {}) | new (class {})()` (class instance) (also see
* {@link rtvref.types.CLASS_OBJECT CLASS_OBJECT})
* - `new String('')`
* - `new Boolean(true)`
......@@ -936,7 +936,7 @@ const defs = {
*
* The following values are considered class objects:
*
* - `new (function() {}) | new (class {})` (tip: use the `ctr`
* - `new (function() {}) | new (class {})()` (tip: use the `ctr`
* {@link rtvref.types.CLASS_OBJECT_args argument} to test for a specific class)
*
* The following values __are not__ considered class objects:
......
import {expect} from 'chai';
import _ from 'lodash';
import types from '../../src/lib/types';
import qualifiers from '../../src/lib/qualifiers';
......@@ -133,7 +132,7 @@ describe('module: lib/RtvError', function() {
const path = [];
const cause = [qualifiers.REQUIRED, types.STRING];
const err = new RtvError(value, typeset, path, cause);
expect(err.message).to.contain(`path="/"`);
expect(err.message).to.contain('path="/"');
});
it('should extend Error', function() {
......@@ -198,7 +197,7 @@ describe('module: lib/RtvError', function() {
const path = ['the', 'path'];
const err = new RtvError(value, types.STRING, path, [qualifiers.REQUIRED, types.STRING]);
const str = err + '';
expect(str.match(/^Error\: /)).to.equal(null); // not the default serialization
expect(str.match(/^Error: /)).to.equal(null); // not the default serialization
expect(str).to.contain('RtvError');
expect(str).to.contain(`value=${value}`);
expect(str).to.contain(`path="/${path.join('/')}"`);
......
import {expect} from 'chai';
import _ from 'lodash';
import types from '../../src/lib/types';
import qualifiers from '../../src/lib/qualifiers';
......
......@@ -376,7 +376,7 @@ describe('module: lib/impl', function() {
expect(impl.fullyQualify(types.STRING, qualifiers.EXPECTED))
.to.eql([qualifiers.EXPECTED, types.STRING]);
const shape = {foo: 1}
const shape = {foo: 1};
expect(impl.fullyQualify(shape, qualifiers.OPTIONAL))
.to.eql([qualifiers.OPTIONAL, DEFAULT_OBJECT_TYPE, shape]);
......@@ -423,7 +423,6 @@ describe('module: lib/impl', function() {
expect(nextType).to.eql([types.STRING]);
const args = {};
const arr = [];
const val = function() {};
typeset = [types.ARRAY, args, val];
......
import {expect} from 'chai';
import _ from 'lodash';
import * as mod from '../../src/lib/qualifiers';
import Enumeration from '../../src/lib/Enumeration';
......
......@@ -42,7 +42,7 @@ describe('module: lib/validation/isPlainObject', function() {
new Boolean(true),
new Boolean(false),
new Number(1),
new (class {})
new (class {})()
]);
// nothing should pass
......
......@@ -5,6 +5,8 @@ import * as vtu from '../validationTestUtil';
import types from '../../../src/lib/types';
import * as val from '../../../src/lib/validation/isShape';
/* eslint-disable no-new-wrappers */
describe('module: lib/validation/isShape', function() {
it('#type', function() {
expect(val.type).to.equal(undefined);
......
......@@ -5,6 +5,8 @@ import * as vtu from '../validationTestUtil';
import types from '../../../src/lib/types';
import * as val from '../../../src/lib/validation/isTypeArgs';
/* eslint-disable no-new-wrappers */
describe('module: lib/validation/isTypeArgs', function() {
it('#type', function() {
expect(val.type).to.equal(undefined);
......
......@@ -136,7 +136,8 @@ describe('module: lib/validation/isTypeset', function() {
goodValues[15].unshift(DEFAULT_QUALIFIER);
goodValues[16] = [DEFAULT_QUALIFIER, types.ARRAY, {typeset: goodValues[16][0]}];
goodValues[17] = [DEFAULT_QUALIFIER, types.ARRAY, {typeset: goodValues[17][0]}];
goodValues[18] = [DEFAULT_QUALIFIER, goodValues[18][0], types.ARRAY, {typeset: goodValues[18][1]}];
goodValues[18] = [DEFAULT_QUALIFIER, goodValues[18][0], types.ARRAY,
{typeset: goodValues[18][1]}];
let results = vtu.testValues('isTypeset', isTypeset, goodValues, {fullyQualified: true});
expect(results.failures).to.eql([]);
......@@ -181,8 +182,7 @@ describe('module: lib/validation/isTypeset', function() {
const shapeWithProtoProp = Object.create({
invalid: null // invalid typeset, but on prototype so shouldn't cause failure
})
.foo = types.JSON;
}).foo = types.JSON;
goodValues = [
{foo: types.FINITE},
......@@ -230,7 +230,7 @@ describe('module: lib/validation/isTypeset', function() {
{foo: {bar: ['invalid-type']}},
// validator is not last element in deep-nested typeset
[{foo: [{bar: [{baz: [types.STRING, function() {}, types.REGEXP]}] }] }],
[{foo: [{bar: [{baz: [types.STRING, function() {}, types.REGEXP]}] }] }], // eslint-disable-line object-curly-spacing
// for class object, we should be going deep into the shape property of
// the args object and finding the invalid typeset
......@@ -362,9 +362,11 @@ describe('module: lib/validation/isTypeset', function() {
expect(isTypeset([function() {}, function() {}])).to.be.false;
expect(isTypeset([types.STRING, function() {}, function() {}])).to.be.false;
expect(isTypeset([types.STRING, [function() {}, function() {}]], {deep: true})).to.be.false;
expect(isTypeset([DEFAULT_QUALIFIER, types.STRING,
[DEFAULT_QUALIFIER, function() {}, function() {}]],
{deep: true, fullyQualified: true})).to.be.false;
expect(isTypeset([
DEFAULT_QUALIFIER,
types.STRING,
[DEFAULT_QUALIFIER, function() {}, function() {}]
], {deep: true, fullyQualified: true})).to.be.false;
});
it('should not validate with only the qualifier', function() {
......
......@@ -6,6 +6,8 @@ import types from '../../../src/lib/types';
import qualifiers from '../../../src/lib/qualifiers';
import * as val from '../../../src/lib/validator/valHashMap';
/* eslint-disable no-new-wrappers */
describe('module: lib/validator/valHashMap', function() {
describe('validator', function() { // module, and value only
it('#type', function() {
......@@ -119,7 +121,7 @@ describe('module: lib/validator/valHashMap', function() {
});
it('checks for string keys that match a pattern', function() {
map = {'key1': 1, 'key2': 2};
map = {key1: 1, key2: 2};
vtu.expectValidatorSuccess(val, map, undefined, {
keyExp: 'key\\d'
......@@ -178,9 +180,9 @@ describe('module: lib/validator/valHashMap', function() {
});
it('checks for keys and values with specified typeset', function() {
map[1] = {'a': true};
map[2] = {'b': false};
map[3] = {'c': true};
map[1] = {a: true};
map[2] = {b: false};
map[3] = {c: true};
vtu.expectValidatorSuccess(val, map, undefined, {
keyExp: '\\d',
......
......@@ -117,13 +117,13 @@ export const getValidValues = function(type) {
}()),
[types.REGEXP]: [/regexp/, new RegExp('regexp')],
[types.DATE]: [new Date()],
[types.ERROR]: [new Error(), new TypeError(), new URIError(), new ReferenceError(), new RangeError(),
new EvalError(), new SyntaxError()],
[types.ERROR]: [new Error(), new TypeError(), new URIError(), new ReferenceError(),
new RangeError(), new EvalError(), new SyntaxError()],
[types.PROMISE]: [new Promise(function() {})],
[types.FUNCTION]: [function() {}, new Function('a', 'b', 'return a + b;')],
[types.FUNCTION]: [function() {}, new Function('a', 'b', 'return a + b;')], // eslint-disable-line no-new-func
// while the JS type is objects, it's not an object type in this library
[types.HASH_MAP]: [new Object(), {}, new (class {})],
[types.HASH_MAP]: [new Object(), {}, new (class {})()],
//
// object types
......@@ -137,13 +137,13 @@ export const getValidValues = function(type) {
new Object(),
Object.create(null),
{},
new (class {})
new (class {})()
],
[types.OBJECT]: [
new Object(),
Object.create(null),
{},
new (class {})
new (class {})()
],
[types.PLAIN_OBJECT]: [
new Object(),
......@@ -151,7 +151,7 @@ export const getValidValues = function(type) {
{}
],
[types.CLASS_OBJECT]: [
new (class {})
new (class {})()
]
};
......@@ -210,7 +210,7 @@ export const getInvalidJsonValues = function() {
new Boolean(true),
new Boolean(false),
new Number(1),
new (class {})
new (class {})()
];
invalidValues = invalidValues.concat(
......
......@@ -7,6 +7,8 @@ import types from '../../../src/lib/types';
import qualifiers from '../../../src/lib/qualifiers';
import * as val from '../../../src/lib/validator/valClassObject';
/* eslint-disable no-new-wrappers */
class Shape {
constructor(name = 'shape') {
this.name = name;
......@@ -161,7 +163,7 @@ describe('module: lib/validator/valClassObject', function() {
it('should not check args.shape if not an instanceof args.ctr', function() {
vtu.expectValidatorError(val, classObject, undefined, {
ctr: class{}, // this will fail
ctr: class {}, // this will fail
shape: {name: types.STRING} // shape would match
});
expect(checkStub.called).to.be.false;
......
import {expect} from 'chai';
import sinon from 'sinon';
import * as vtu from '../validationTestUtil';
import types from '../../../src/lib/types';
......
......@@ -7,6 +7,8 @@ import types from '../../../src/lib/types';
import qualifiers from '../../../src/lib/qualifiers';
import * as val from '../../../src/lib/validator/valObject';
/* eslint-disable no-new-wrappers */
describe('module: lib/validator/valObject', function() {
describe('validator', function() { // module, and value only
it('#type', function() {
......
......@@ -7,6 +7,8 @@ import types from '../../../src/lib/types';
import qualifiers from '../../../src/lib/qualifiers';
import * as val from '../../../src/lib/validator/valPlainObject';
/* eslint-disable no-new-wrappers */
describe('module: lib/validator/valPlainObject', function() {
describe('validator', function() { // module, and value only
it('#type', function() {
......@@ -46,7 +48,7 @@ describe('module: lib/validator/valPlainObject', function() {
new Boolean(true),
new Boolean(false),
new Number(1),
new (class {})
new (class {})()
]);
// nothing should pass
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment