Skip to content

Commit

Permalink
dtslint (#56)
Browse files Browse the repository at this point in the history
* dtslint

* Add some expect errors
  • Loading branch information
jscheiny authored Aug 13, 2018
1 parent 1ad2a43 commit 8559c4b
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 3 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"compile:src": "tsc -p src",
"lint:codegen": "tslint -p codegen/tsconfig.json -c tslint.json",
"lint:src": "tslint -p src/tsconfig.json -c tslint.json",
"lint": "npm-run-all -p lint:codegen lint:src",
"lint:types": "dtslint test/types",
"lint": "npm-run-all -p lint:codegen lint:src lint:types",
"node:codegen": "node codegen/dist/emit",
"test": "jest --config jest.config.json",
"prepack": "yarn build",
Expand All @@ -35,6 +36,7 @@
"devDependencies": {
"@types/jest": "^22.2.3",
"@types/node": "^8.10.16",
"dtslint": "^0.3.0",
"jest": "^22.4.3",
"npm-run-all": "^4.1.3",
"prettier": "^1.12.1",
Expand Down
1 change: 1 addition & 0 deletions test/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// TypeScript Version: 2.8
70 changes: 70 additions & 0 deletions test/types/measureTypeTests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { Measure, seconds, liters, speedOfLight, square } from "safe-units";
import { acres } from "../../src/unit/common";
import { newtons } from "../../src/unit/metric";
import { cubic } from "../../src/measure/measure";

// ExpectType Measure<{ data: 1; }>
Measure.dimension("data");

// $ExpectType Measure<{ time: 1; }>
const time = Measure.of(10, seconds);

// $ExpectType Measure<Pick<{ length: 3; }, "length">>
const volume = Measure.of(500, liters);

// $ExpectType Measure<Pick<{ length: 2; }, "length">>
const area = Measure.of(20, acres);

// $ExpectType Measure<Pick<{ time: -1; length: 0; mass: 1; }, "time" | "mass">>
Measure.of(1000, newtons).over(Measure.of(0.3, speedOfLight));

// $ExpectType Measure<Pick<{ time: 1; length: 3; }, "time" | "length">>
volume.times(time);

// $ExpectError
volume.times(volume);

// $ExpectError
volume.over(volume.inverse());

// $ExpectType Measure<Pick<{ time: -1; length: 3; }, "time" | "length">>
volume.over(time);

// $ExpectType Measure<Pick<{ length: 1; }, "length">>
volume.over(area);

// $ExpectType Measure<Pick<{ length: -3; }, "length">>
volume.inverse();

// $ExpectType never
volume.squared;

// $ExpectError
square(volume);

// $ExpectType never
volume.cubed;

// $ExpectError
cubic(volume);

// $ExpectType () => Measure<Pick<{ time: 2; }, "time">>
time.squared;

square(time);

// $ExpectType () => Measure<Pick<{ time: 3; }, "time">>
time.cubed;

cubic(time);

// $ExpectType () => Measure<Pick<{ length: 4; }, "length">>
area.squared;

square(area);

// $ExpectType never
area.cubed;

// $ExpectError
cubic(area);
16 changes: 16 additions & 0 deletions test/types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"declaration": true,
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": false,
"lib": ["es5"],
"baseUrl": ".",
"paths": { "safe-units": ["../../src"] }
}
}
6 changes: 6 additions & 0 deletions test/types/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "dtslint/dtslint.json",
"rules": {
"no-useless-files": false
}
}
102 changes: 100 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
version "8.10.16"
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.10.16.tgz#96fadb371748845a0c8ea970a565330efb0a67d5"

"@types/parsimmon@^1.3.0":
version "1.10.0"
resolved "https://registry.yarnpkg.com/@types/parsimmon/-/parsimmon-1.10.0.tgz#ffb81cb023ff435a41d4710a29ab23c561dc9fdf"

abab@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/abab/-/abab-1.0.4.tgz#5faad9c2c07f60dd76770f71cf025b62a63cfd4e"
Expand Down Expand Up @@ -85,6 +89,10 @@ ansi-styles@^3.2.0, ansi-styles@^3.2.1:
dependencies:
color-convert "^1.9.0"

any-promise@^1.0.0, any-promise@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/any-promise/-/any-promise-1.3.0.tgz#abc6afeedcea52e809cdc0376aed3ce39635d17f"

anymatch@^1.3.0:
version "1.3.2"
resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-1.3.2.tgz#553dcb8f91e3c889845dfdba34c77721b90b9d7a"
Expand Down Expand Up @@ -771,6 +779,13 @@ define-property@^2.0.2:
is-descriptor "^1.0.2"
isobject "^3.0.1"

"definitelytyped-header-parser@github:Microsoft/definitelytyped-header-parser#production":
version "0.0.0"
resolved "https://codeload.github.com/Microsoft/definitelytyped-header-parser/tar.gz/a485d0e3f394da4d8628f36bf5b9700102f6b014"
dependencies:
"@types/parsimmon" "^1.3.0"
parsimmon "^1.2.0"

delayed-stream@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
Expand Down Expand Up @@ -810,6 +825,16 @@ domexception@^1.0.0:
dependencies:
webidl-conversions "^4.0.2"

dtslint@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/dtslint/-/dtslint-0.3.0.tgz#918e664a6f7e1f54ba22088daa2bc6e64a6001c1"
dependencies:
definitelytyped-header-parser Microsoft/definitelytyped-header-parser#production
fs-promise "^2.0.0"
strip-json-comments "^2.0.1"
tslint "^5.9.1"
typescript next

duplexer@^0.1.1, duplexer@~0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/duplexer/-/duplexer-0.1.1.tgz#ace6ff808c1ce66b57d1ebf97977acb02334cfc1"
Expand Down Expand Up @@ -1112,12 +1137,28 @@ [email protected]:
jsonfile "^4.0.0"
universalify "^0.1.0"

fs-extra@^2.0.0:
version "2.1.2"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-2.1.2.tgz#046c70163cef9aad46b0e4a7fa467fb22d71de35"
dependencies:
graceful-fs "^4.1.2"
jsonfile "^2.1.0"

fs-minipass@^1.2.5:
version "1.2.5"
resolved "https://registry.yarnpkg.com/fs-minipass/-/fs-minipass-1.2.5.tgz#06c277218454ec288df77ada54a03b8702aacb9d"
dependencies:
minipass "^2.2.1"

fs-promise@^2.0.0:
version "2.0.3"
resolved "https://registry.yarnpkg.com/fs-promise/-/fs-promise-2.0.3.tgz#f64e4f854bcf689aa8bddcba268916db3db46854"
dependencies:
any-promise "^1.3.0"
fs-extra "^2.0.0"
mz "^2.6.0"
thenify-all "^1.6.0"

fs.realpath@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
Expand Down Expand Up @@ -1983,6 +2024,12 @@ json5@^0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/json5/-/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821"

jsonfile@^2.1.0:
version "2.4.0"
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-2.4.0.tgz#3736a2b428b87bbda0cc83b53fa3d633a35c2ae8"
optionalDependencies:
graceful-fs "^4.1.6"

jsonfile@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb"
Expand Down Expand Up @@ -2244,6 +2291,14 @@ [email protected]:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"

mz@^2.6.0:
version "2.7.0"
resolved "https://registry.yarnpkg.com/mz/-/mz-2.7.0.tgz#95008057a56cafadc2bc63dde7f9ff6955948e32"
dependencies:
any-promise "^1.0.0"
object-assign "^4.0.1"
thenify-all "^1.0.0"

nan@^2.9.2:
version "2.10.0"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.10.0.tgz#96d0cd610ebd58d4b4de9cc0c6828cda99c7548f"
Expand Down Expand Up @@ -2383,7 +2438,7 @@ oauth-sign@~0.8.2:
version "0.8.2"
resolved "https://registry.yarnpkg.com/oauth-sign/-/oauth-sign-0.8.2.tgz#46a6ab7f0aead8deae9ec0565780b7d4efeb9d43"

object-assign@^4.1.0:
object-assign@^4.0.1, object-assign@^4.1.0:
version "4.1.1"
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"

Expand Down Expand Up @@ -2518,6 +2573,10 @@ [email protected]:
version "4.0.0"
resolved "https://registry.yarnpkg.com/parse5/-/parse5-4.0.0.tgz#6d78656e3da8d78b4ec0b906f7c08ef1dfe3f608"

parsimmon@^1.2.0:
version "1.12.0"
resolved "https://registry.yarnpkg.com/parsimmon/-/parsimmon-1.12.0.tgz#886a442fb30b5fc3c8e7c4994050f5cdcfe0ea90"

pascalcase@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/pascalcase/-/pascalcase-0.1.1.tgz#b363e55e8006ca6fe21784d2db22bd15d7917f14"
Expand Down Expand Up @@ -3158,7 +3217,7 @@ strip-eof@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/strip-eof/-/strip-eof-1.0.0.tgz#bb43ff5598a6eb05d89b59fcd129c983313606bf"

strip-json-comments@~2.0.1:
strip-json-comments@^2.0.1, strip-json-comments@~2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"

Expand Down Expand Up @@ -3210,6 +3269,18 @@ test-exclude@^4.2.1:
read-pkg-up "^1.0.1"
require-main-filename "^1.0.1"

thenify-all@^1.0.0, thenify-all@^1.6.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/thenify-all/-/thenify-all-1.6.0.tgz#1a1918d402d8fc3f98fbf234db0bcc8cc10e9726"
dependencies:
thenify ">= 3.1.0 < 4"

"thenify@>= 3.1.0 < 4":
version "3.3.0"
resolved "https://registry.yarnpkg.com/thenify/-/thenify-3.3.0.tgz#e69e38a1babe969b0108207978b9f62b88604839"
dependencies:
any-promise "^1.0.0"

throat@^4.0.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/throat/-/throat-4.1.0.tgz#89037cbc92c56ab18926e6ba4cbb200e15672a6a"
Expand Down Expand Up @@ -3343,6 +3414,23 @@ tslint@^5.10.0:
tslib "^1.8.0"
tsutils "^2.12.1"

tslint@^5.9.1:
version "5.11.0"
resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.11.0.tgz#98f30c02eae3cde7006201e4c33cb08b48581eed"
dependencies:
babel-code-frame "^6.22.0"
builtin-modules "^1.1.1"
chalk "^2.3.0"
commander "^2.12.1"
diff "^3.2.0"
glob "^7.1.1"
js-yaml "^3.7.0"
minimatch "^3.0.4"
resolve "^1.3.2"
semver "^5.3.0"
tslib "^1.8.0"
tsutils "^2.27.2"

tsutils@^1.4.0:
version "1.9.1"
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-1.9.1.tgz#b9f9ab44e55af9681831d5f28d0aeeaf5c750cb0"
Expand All @@ -3353,6 +3441,12 @@ tsutils@^2.12.1:
dependencies:
tslib "^1.8.1"

tsutils@^2.27.2:
version "2.29.0"
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-2.29.0.tgz#32b488501467acbedd4b85498673a0812aca0b99"
dependencies:
tslib "^1.8.1"

tunnel-agent@^0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/tunnel-agent/-/tunnel-agent-0.6.0.tgz#27a5dea06b36b04a0a9966774b290868f0fc40fd"
Expand All @@ -3369,6 +3463,10 @@ type-check@~0.3.2:
dependencies:
prelude-ls "~1.1.2"

typescript@next:
version "3.1.0-dev.20180810"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.1.0-dev.20180810.tgz#4e3c194fd3c1e87dd7c91f9ad63494fa835952c7"

typescript@~2.9.1:
version "2.9.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.9.2.tgz#1cbf61d05d6b96269244eb6a3bce4bd914e0f00c"
Expand Down

0 comments on commit 8559c4b

Please sign in to comment.