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

Add runtime validation for options #468

Merged
merged 1 commit into from Aug 26, 2019
Merged

Conversation

alangpierce
Copy link
Owner

Fixes #467

This uses the libraries ts-interface-builder and ts-interface-checker to codegen
a data structure of the options TS type and then check it on every transform
invocation.

I tried a few approaches here, including generating JSON schema and then
validating that, but that this seemed to be pretty smooth from a build system
standpoint.

I timed this on 1000 compilations of a large file and any difference was well
within the time variability, so it seems fine to run this type validation on
every transform invocation. It could potentially be moved out into a separate
routine if perf is ever an issue, though.

Fixes #467

This uses the libraries ts-interface-builder and ts-interface-checker to codegen
a data structure of the options TS type and then check it on every `transform`
invocation.

I tried a few approaches here, including generating JSON schema and then
validating that, but that this seemed to be pretty smooth from a build system
standpoint.

I timed this on 1000 compilations of a large file and any difference was well
within the time variability, so it seems fine to run this type validation on
every `transform` invocation. It could potentially be moved out into a separate
routine if perf is ever an issue, though.
@codecov-io
Copy link

Codecov Report

Merging #468 into master will increase coverage by 0.05%.
The diff coverage is 75%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #468      +/-   ##
==========================================
+ Coverage   81.42%   81.48%   +0.05%     
==========================================
  Files          50       52       +2     
  Lines        5180     5200      +20     
  Branches     1208     1208              
==========================================
+ Hits         4218     4237      +19     
- Misses        669      671       +2     
+ Partials      293      292       -1
Impacted Files Coverage Δ
src/index.ts 89.79% <100%> (+6.93%) ⬆️
src/Options.ts 100% <100%> (ø)
src/Options-gen-types.ts 50% <50%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5ae23c8...3b7b5b6. Read the comment docs.

@alangpierce alangpierce merged commit fff991e into master Aug 26, 2019
@alangpierce alangpierce deleted the add-options-validation branch August 26, 2019 00:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clarifying error messages when incorrect options are passed
2 participants