From 846647436e829c34e4f67edb9c4ce2df4abe7aab Mon Sep 17 00:00:00 2001 From: Spencer Date: Tue, 1 Sep 2020 10:33:28 -0700 Subject: [PATCH] [yarn] remove typings-tester, use @ts-expect-error (#76341) Co-authored-by: spalger --- package.json | 2 - .../public/lib/aeroelastic/tsconfig.json | 21 --- .../typespec_tests.ts => typespec.test.ts} | 172 +++++++++--------- .../scripts/optimize_tsconfig/tsconfig.json | 3 +- x-pack/tsconfig.json | 3 +- yarn.lock | 9 +- 6 files changed, 94 insertions(+), 116 deletions(-) delete mode 100644 x-pack/plugins/canvas/public/lib/aeroelastic/tsconfig.json rename x-pack/plugins/canvas/public/lib/aeroelastic/{__fixtures__/typescript/typespec_tests.ts => typespec.test.ts} (67%) diff --git a/package.json b/package.json index 5c95f538a00e1..3485ce5d7a7fc 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,6 @@ "test:ftr:server": "node scripts/functional_tests_server", "test:ftr:runner": "node scripts/functional_test_runner", "test:coverage": "grunt test:coverage", - "typespec": "typings-tester --config x-pack/plugins/canvas/public/lib/aeroelastic/tsconfig.json x-pack/plugins/canvas/public/lib/aeroelastic/__fixtures__/typescript/typespec_tests.ts", "checkLicenses": "node scripts/check_licenses --dev", "build": "node scripts/build --all-platforms", "start": "node scripts/kibana --dev", @@ -473,7 +472,6 @@ "topojson-client": "3.0.0", "tree-kill": "^1.2.2", "typescript": "4.0.2", - "typings-tester": "^0.3.2", "ui-select": "0.19.8", "vega": "^5.13.0", "vega-lite": "^4.13.1", diff --git a/x-pack/plugins/canvas/public/lib/aeroelastic/tsconfig.json b/x-pack/plugins/canvas/public/lib/aeroelastic/tsconfig.json deleted file mode 100644 index 3b61e4b414626..0000000000000 --- a/x-pack/plugins/canvas/public/lib/aeroelastic/tsconfig.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "extends": "../../../../../tsconfig", - "compilerOptions": { - "module": "commonjs", - "lib": ["es2018", "dom"], - "noImplicitAny": true, - "strictNullChecks": true, - "strictFunctionTypes": false, - "strictPropertyInitialization": true, - "noImplicitThis": true, - "noImplicitReturns": true, - "forceConsistentCasingInFileNames": true, - "noEmit": true, - "baseUrl": ".", - "paths": { - "layout/*": ["aeroelastic/*"] - }, - "types": ["@kbn/x-pack/plugins/canvas/public/lib/aeroelastic"] - }, - "exclude": ["node_modules", "**/*.spec.ts", "node_modules/@types/mocha"] -} diff --git a/x-pack/plugins/canvas/public/lib/aeroelastic/__fixtures__/typescript/typespec_tests.ts b/x-pack/plugins/canvas/public/lib/aeroelastic/typespec.test.ts similarity index 67% rename from x-pack/plugins/canvas/public/lib/aeroelastic/__fixtures__/typescript/typespec_tests.ts rename to x-pack/plugins/canvas/public/lib/aeroelastic/typespec.test.ts index cb46a3d6be402..3b1fde12edcc4 100644 --- a/x-pack/plugins/canvas/public/lib/aeroelastic/__fixtures__/typescript/typespec_tests.ts +++ b/x-pack/plugins/canvas/public/lib/aeroelastic/typespec.test.ts @@ -4,49 +4,47 @@ * you may not use this file except in compliance with the Elastic License. */ -import { select } from '../../select'; -import { Json, Selector, Vector2d, Vector3d, TransformMatrix2d, TransformMatrix3d } from '../..'; +import { select } from './select'; +import { Json, Selector, Vector2d, Vector3d, TransformMatrix2d, TransformMatrix3d } from './index'; import { mvMultiply as mult2d, ORIGIN as UNIT2D, UNITMATRIX as UNITMATRIX2D, add as add2d, -} from '../../matrix2d'; +} from './matrix2d'; import { mvMultiply as mult3d, ORIGIN as UNIT3D, NANMATRIX as NANMATRIX3D, add as add3d, -} from '../../matrix'; +} from './matrix'; -/* +// helper to mark variables as "used" so they don't trigger errors +const use = (...vars: any[]) => vars.includes(null); +/* Type checking isn't too useful if future commits can accidentally weaken the type constraints, because a TypeScript linter will not complain - everything that passed before will continue to pass. The coder will not have feedback that the original intent with the typing got compromised. To declare the intent via passing and failing type checks, test cases are needed, some of which designed to expect a TS pass, some of them to expect a TS complaint. It documents intent for peers too, as type specs are a tough read. - Run compile-time type specification tests in the `kibana` root with: - - yarn typespec - Test "cases" expecting to pass TS checks are not annotated, while ones we want TS to complain about are prepended with the comment - - // typings:expect-error + + // @ts-expect-error The test "suite" and "cases" are wrapped in IIFEs to prevent linters from complaining about the unused binding. It can be structured internally as desired. - */ -((): void => { - /** - * TYPE TEST SUITE - */ +describe('vector array creation', () => { + it('passes typechecking', () => { + let vec2d: Vector2d = UNIT2D; + let vec3d: Vector3d = UNIT3D; + + use(vec2d, vec3d); - (function vectorArrayCreationTests(vec2d: Vector2d, vec3d: Vector3d): void { // 2D vector OK vec2d = [0, 0, 0] as Vector2d; // OK vec2d = [-0, NaN, -Infinity] as Vector2d; // IEEE 754 values are OK @@ -57,30 +55,35 @@ import { // 2D vector not OK - // typings:expect-error + // @ts-expect-error vec2d = 3; // not even an array - // typings:expect-error + // @ts-expect-error vec2d = [] as Vector2d; // no elements - // typings:expect-error + // @ts-expect-error vec2d = [0, 0] as Vector2d; // too few elements - // typings:expect-error + // @ts-expect-error vec2d = [0, 0, 0, 0] as Vector2d; // too many elements // 3D vector not OK - // typings:expect-error + // @ts-expect-error vec3d = 3; // not even an array - // typings:expect-error + // @ts-expect-error vec3d = [] as Vector3d; // no elements - // typings:expect-error + // @ts-expect-error vec3d = [0, 0, 0] as Vector3d; // too few elements - // typings:expect-error + // @ts-expect-error vec3d = [0, 0, 0, 0, 0] as Vector3d; // too many elements + }); +}); + +describe('matrix array creation', () => { + it('passes typechecking', () => { + let mat2d: TransformMatrix2d = UNITMATRIX2D; + let mat3d: TransformMatrix3d = NANMATRIX3D; - return; // arrayCreationTests - })(UNIT2D, UNIT3D); + use(mat2d, mat3d); - (function matrixArrayCreationTests(mat2d: TransformMatrix2d, mat3d: TransformMatrix3d): void { // 2D matrix OK mat2d = [0, 1, 2, 3, 4, 5, 6, 7, 8] as TransformMatrix2d; // OK mat2d = [-0, NaN, -Infinity, 3, 4, 5, 6, 7, 8] as TransformMatrix2d; // IEEE 754 values are OK @@ -91,80 +94,87 @@ import { // 2D matrix not OK - // typings:expect-error + // @ts-expect-error mat2d = 3; // not even an array - // typings:expect-error + // @ts-expect-error mat2d = [] as TransformMatrix2d; // no elements - // typings:expect-error + // @ts-expect-error mat2d = [0, 1, 2, 3, 4, 5, 6, 7] as TransformMatrix2d; // too few elements - // typings:expect-error + // @ts-expect-error mat2d = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] as TransformMatrix2d; // too many elements // 3D vector not OK - // typings:expect-error + // @ts-expect-error mat3d = 3; // not even an array - // typings:expect-error + // @ts-expect-error mat3d = [] as TransformMatrix3d; // no elements - // typings:expect-error + // @ts-expect-error mat3d = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] as TransformMatrix3d; // too few elements - // typings:expect-error + // @ts-expect-error mat3d = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] as TransformMatrix3d; // too many elements - // Matrix modification should NOT be OK - mat3d[3] = 100; // too bad the ReadOnly part appears not to be enforced so can't precede it with typings:expect-error + // @ts-expect-error + mat3d[3] = 100; // Matrix modification is NOT OK + }); +}); - return; // arrayCreationTests - })(UNITMATRIX2D, NANMATRIX3D); +describe('matrix addition', () => { + it('passes typecheck', () => { + const mat2d: TransformMatrix2d = UNITMATRIX2D; + const mat3d: TransformMatrix3d = NANMATRIX3D; - (function matrixMatrixAdditionTests(mat2d: TransformMatrix2d, mat3d: TransformMatrix3d): void { add2d(mat2d, mat2d); // OK add3d(mat3d, mat3d); // OK - // typings:expect-error + // @ts-expect-error add2d(mat2d, mat3d); // at least one arg doesn't comply - // typings:expect-error + // @ts-expect-error add2d(mat3d, mat2d); // at least one arg doesn't comply - // typings:expect-error + // @ts-expect-error add2d(mat3d, mat3d); // at least one arg doesn't comply - // typings:expect-error + // @ts-expect-error add3d(mat2d, mat3d); // at least one arg doesn't comply - // typings:expect-error + // @ts-expect-error add3d(mat3d, mat2d); // at least one arg doesn't comply - // typings:expect-error + // @ts-expect-error add3d(mat2d, mat2d); // at least one arg doesn't comply + }); +}); - return; // matrixMatrixAdditionTests - })(UNITMATRIX2D, NANMATRIX3D); +describe('matric vector multiplication', () => { + it('passes typecheck', () => { + const vec2d: Vector2d = UNIT2D; + const mat2d: TransformMatrix2d = UNITMATRIX2D; + const vec3d: Vector3d = UNIT3D; + const mat3d: TransformMatrix3d = NANMATRIX3D; - (function matrixVectorMultiplicationTests( - vec2d: Vector2d, - mat2d: TransformMatrix2d, - vec3d: Vector3d, - mat3d: TransformMatrix3d - ): void { mult2d(mat2d, vec2d); // OK mult3d(mat3d, vec3d); // OK - // typings:expect-error + // @ts-expect-error mult3d(mat2d, vec2d); // trying to use a 3d fun for 2d args - // typings:expect-error + // @ts-expect-error mult2d(mat3d, vec3d); // trying to use a 2d fun for 3d args - // typings:expect-error + // @ts-expect-error mult2d(mat3d, vec2d); // 1st arg is a mismatch - // typings:expect-error + // @ts-expect-error mult2d(mat2d, vec3d); // 2nd arg is a mismatch - // typings:expect-error + // @ts-expect-error mult3d(mat2d, vec3d); // 1st arg is a mismatch - // typings:expect-error + // @ts-expect-error mult3d(mat3d, vec2d); // 2nd arg is a mismatch + }); +}); - return; // matrixVectorTests - })(UNIT2D, UNITMATRIX2D, UNIT3D, NANMATRIX3D); +describe('json', () => { + it('passes typecheck', () => { + let plain: Json = null; + + use(plain); - (function jsonTests(plain: Json): void { // numbers are OK plain = 1; plain = NaN; @@ -182,37 +192,37 @@ import { plain = [0, null, false, NaN, 3.14, 'one more']; plain = { a: { b: 5, c: { d: [1, 'a', -Infinity, null], e: -1 }, f: 'b' }, g: false }; - // typings:expect-error + // @ts-expect-error plain = undefined; // it's undefined - // typings:expect-error + // @ts-expect-error plain = (a) => a; // it's a function - // typings:expect-error + // @ts-expect-error plain = [new Date()]; // it's a time - // typings:expect-error + // @ts-expect-error plain = { a: Symbol('haha') }; // symbol isn't permitted either - // typings:expect-error + // @ts-expect-error plain = window || void 0; - // typings:expect-error + // @ts-expect-error plain = { a: { b: 5, c: { d: [1, 'a', undefined, null] } } }; // going deep into the structure + }); +}); - return; // jsonTests - })(null); +describe('select', () => { + it('passes typecheck', () => { + let selector: Selector; - (function selectTests(selector: Selector): void { selector = select((a: Json) => a); // one arg selector = select((a: Json, b: Json): Json => `${a} and ${b}`); // more args selector = select(() => 1); // zero arg selector = select((...args: Json[]) => args); // variadic - // typings:expect-error + // @ts-expect-error selector = (a: Json) => a; // not a selector - // typings:expect-error + // @ts-expect-error selector = select(() => {}); // should yield a JSON value, but it returns void - // typings:expect-error + // @ts-expect-error selector = select((x: Json) => ({ a: x, b: undefined })); // should return a Json - return; // selectTests - })(select((a: Json) => a)); - - return; // test suite -})(); + use(selector); + }); +}); diff --git a/x-pack/plugins/security_solution/scripts/optimize_tsconfig/tsconfig.json b/x-pack/plugins/security_solution/scripts/optimize_tsconfig/tsconfig.json index ea7a11b89dab2..ac56a6af31c72 100644 --- a/x-pack/plugins/security_solution/scripts/optimize_tsconfig/tsconfig.json +++ b/x-pack/plugins/security_solution/scripts/optimize_tsconfig/tsconfig.json @@ -10,7 +10,6 @@ "exclude": [ "test/**/*", "**/__fixtures__/**/*", - "plugins/security_solution/cypress/**/*", - "**/typespec_tests.ts" + "plugins/security_solution/cypress/**/*" ] } diff --git a/x-pack/tsconfig.json b/x-pack/tsconfig.json index 35e1800c6fbd1..7c6210bb9ce19 100644 --- a/x-pack/tsconfig.json +++ b/x-pack/tsconfig.json @@ -14,8 +14,7 @@ "test/**/*", "plugins/security_solution/cypress/**/*", "plugins/apm/e2e/cypress/**/*", - "plugins/apm/scripts/**/*", - "**/typespec_tests.ts" + "plugins/apm/scripts/**/*" ], "compilerOptions": { "outDir": ".", diff --git a/yarn.lock b/yarn.lock index c0c2305609f58..3be2599c64201 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9035,7 +9035,7 @@ comma-separated-tokens@^1.0.1: resolved "https://registry.yarnpkg.com/comma-separated-tokens/-/comma-separated-tokens-1.0.8.tgz#632b80b6117867a158f1080ad498b2fbe7e3f5ea" integrity sha512-GHuDRO12Sypu2cV70d1dkA2EUmXHgntrzbpvOB+Qy+49ypNfGgFQIC2fhhXbnyrJRynDCAARsT7Ou0M6hirpfw== -commander@2, commander@2.19.0, commander@^2.11.0, commander@^2.12.2: +commander@2, commander@2.19.0, commander@^2.11.0: version "2.19.0" resolved "https://registry.yarnpkg.com/commander/-/commander-2.19.0.tgz#f6198aa84e5b83c46054b94ddedbfed5ee9ff12a" integrity sha512-6tvAOO+D6OENvRAh524Dh9jcfKTYDQAqvqezbCW82xj5X0pSrcpxtvRKHLG0yBY6SD7PSDrJaj+0AiOcKVd1Xg== @@ -28423,13 +28423,6 @@ typescript@4.0.2, typescript@^3.0.1, typescript@^3.0.3, typescript@^3.2.2, types resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.2.tgz#7ea7c88777c723c681e33bf7988be5d008d05ac2" integrity sha512-e4ERvRV2wb+rRZ/IQeb3jm2VxBsirQLpQhdxplZ2MEzGvDkkMmPglecnNDfSUBivMjP93vRbngYYDQqQ/78bcQ== -typings-tester@^0.3.2: - version "0.3.2" - resolved "https://registry.yarnpkg.com/typings-tester/-/typings-tester-0.3.2.tgz#04cc499d15ab1d8b2d14dd48415a13d01333bc5b" - integrity sha512-HjGoAM2UoGhmSKKy23TYEKkxlphdJFdix5VvqWFLzH1BJVnnwG38tpC6SXPgqhfFGfHY77RlN1K8ts0dbWBQ7A== - dependencies: - commander "^2.12.2" - ua-parser-js@^0.7.18: version "0.7.21" resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.21.tgz#853cf9ce93f642f67174273cc34565ae6f308777"