Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] Lint typescript definitions #12637

Merged
merged 29 commits into from Aug 24, 2018

Conversation

eps1lon
Copy link
Member

@eps1lon eps1lon commented Aug 24, 2018

While trying to to run all the *.tsx? files through the compiler might show the correct usage of this package with typescript it does not provide a complete test suite for the definitons i.e. we only have positive assertions but no negative.

This PR is the first step for providing negative assertions to the typescript tests. By adding dtslint to the CI pipeline we enable linting for the definition and test files and follow the standard for definition files set by DefinitelyTyped. I deliberately added not more than one rule per commit to make review easier. If we decide against certain rules we can just remove the commit from this PR. If we decided on a ruleset I would squash the rules into a single extends: ["dtslint/dtslint.json"] and leave only our exceptions in the tslint.json.

I disabled no-unnecessary-generics because most cases are not that obvious in my opinion and without good test coverage might break things if we'd remove the generics.

This PR also enables strict mode in typescript and removes the suppressImplicitAnyIndexErrors option. Both changes did not cause any errors and I think strict mode should be our goal.

The next step should be to improve typescript tests by adding $ExpectType and $ExpectError throughout the component test. I'd suggest adding the tests next to the file as is already done with the js tests. The single component test file in material-ui/test/typescript is very unwieldy. I actually like the FILE.spec.ts schema. It makes a clearer distinction between js and ts tests i.e. run time vs compile time test.

The issues with dtslint originally described in #12332 were mostly resolved with the switch to typescript@3.0. Per package tsconfig support is still poor with dtslint because it does not respect extends properties. I'm working on a fix for that.

/cc @pelotom

While trying to to run all the *.tsx? files might show the correct usage
of this package with typescript it does not provide a complete test
suite for the definitons i.e. we cannot write tests that expect an
error.

The longterm goal is to fully extends dtslint rules and make use of
the $Expect* helpers to display where typescript can help us avoid
errors at compile time. It will also enable linting for our definitons
files.
Started incrementally adding rules to tslint until we ideally
satisfy dtslint and tslint-react
Flow got introduced accidentally while rebasing
Seems like a yarn issue were adding a dependency includes the github
libk but running yarn again causes yarn to remove the github prefix.
Copy link
Member

@pelotom pelotom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is a great step forward!

@@ -49,7 +49,7 @@
"test:coverage:html": "cross-env NODE_ENV=test BABEL_ENV=coverage nyc mocha packages/material-ui/test/**/*.test.js packages/material-ui/src/{,**/}*.test.js && nyc report --reporter=html",
"test:karma": "cross-env NODE_ENV=test karma start test/karma.conf.js --single-run",
"test:regressions": "webpack --config test/regressions/webpack.config.js && rimraf test/regressions/screenshots/chrome/* && vrtest run --config test/vrtest.config.js --record",
"typescript": "tsc -p tsconfig.json",
"typescript": "tslint -p tsconfig.json \"packages/*/{src,test}/**/*.{ts,tsx}\"",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it intentional that you're not actually using dtslint yet?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of by accident if that makes sense. This just means that we are only using the rules from dtslint.

dtslint requires some extra setup because it can't run on more than one package on its own. I was wondering why this worked so seamless all of the sudden.

I guess this is good for now since we do not use $ExpectError and target multiple typescript versions which does require dtslint.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it as an explicit dependency for now to avoid further confusion.

Since we are using tslint as the lint runner we should list it
explicitly.
@pelotom pelotom merged commit 570377d into mui:master Aug 24, 2018
@eps1lon eps1lon mentioned this pull request Sep 5, 2018
@eps1lon eps1lon deleted the typescript-test-definitions branch September 22, 2018 21:31
marcelpanse pushed a commit to marcelpanse/material-ui that referenced this pull request Oct 2, 2018
* [test] Use tslint instead of typescript to test definitions

While trying to to run all the *.tsx? files might show the correct usage
of this package with typescript it does not provide a complete test
suite for the definitons i.e. we cannot write tests that expect an
error.

The longterm goal is to fully extends dtslint rules and make use of
the $Expect* helpers to display where typescript can help us avoid
errors at compile time. It will also enable linting for our definitons
files.

* [tslint] Enable no-unnecessary-type-assertion rule

Started incrementally adding rules to tslint until we ideally
satisfy dtslint and tslint-react

* [tslint] Enable no-unnecessary-callback-wrapper rule

* [tslint] Enable member-access rule

* [tslint] Enable space-within-parens rule

* [tslint] Enable file-name-casing rule

* [tslint] Enable comment-format rule

* [tslint] Enable semicolon rule

* [tslint] Enable interface-name rule

* [tslint] Fix errors reintroduced when rebasing

* [tslint] Enable strict-export-declare-modifiers rule

* [tslint] Enable no-relative-import-in-test rule

* [tslint] Enable use-default-type-parameter rule

* [tslint] Disable no-unnecessary-generics rule

* [tslint] Enable prefer-declare-function rule

* [tslint] Enable interface-over-type-literal rule

* [tslint] Enable array-type rule

* [tslint] Enforce ban-types rule

* [tslint] Enable no-duplicate-imports rule

* [tslint] Enable callable-types rule

* [test] Use tslint from project root

* [test] Move lint to typescript test command

* [test] Use typescript test in CI

Flow got introduced accidentally while rebasing

* [tslint] Enable strict mode

* [tslint] Remove unused suppressImplicitAnyIndexErrors

* [test] Run prettier

* [core] Run yarn

Seems like a yarn issue were adding a dependency includes the github
libk but running yarn again causes yarn to remove the github prefix.

* [test] Add tslint as an explicit dependency

Since we are using tslint as the lint runner we should list it
explicitly.

* [tslint] Squash rules that are already set in dtslint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants