Check out a free preview of the full Code Transformation and Linting with ASTs course
The "Challenge 3: Schema Property" Lesson is part of the full, Code Transformation and Linting with ASTs course featured in this preview video. Here's what you'd learn in this lesson:
In this challenge, students learn about using the JSON schema property.
Transcript from the "Challenge 3: Schema Property" Lesson
[00:00:00]
>> Kent C. Dodds: We're gonna round npm start exercise ES Lint two. So now you should have that looks like function in here, and your plugin should look similar to what we just solved for.
>> Kent C. Dodds: And then your test should be failing. So if we run npm start to start up our test again,
[00:00:27]
>> Kent C. Dodds: Your test should fail because,
>> Kent C. Dodds: Your console.1 up here in the valid is specifying some options saying that one is okay, but we're saying there's an error. So this is where you need to learn about the schema property in our configuration and I'll just show you that here.
[00:00:54]
Schema is pretty much all you do. Provide an array and what you need to do is provide an object in that schema. So this is JSON schema, I'll show you the docs to go look that up. But you need to fill this in with a JSON schema object with a property that is called allowedMethods, that accepts any of the console log methods as an array, okay?
[00:01:32]
Cool, so the docs for this, I'll paste this in the chat. Lives in options schemas and there's a link to JSON schema. If you're not familiar with JSON schema, don't worry. I wasn't either when I made this exercise and it's fairly straightforward. I'll just give you a little pro tip that there's these examples in JSON schema's website.
[00:01:59]
And let's see, the simple example is pretty useful. You can look at some of these examples to see what your schema should look like. After you've defined your schema, then you can start accepting the options that have been provided. And you get those from the context. So it would be context.options, and that'll be an array of the options that you're passed.
[00:02:32]
So I'll leave this up so everybody can see this. Here I'll even paste a link to this example right here, so you can look at that.
Learn Straight from the Experts Who Shape the Modern Web
- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops