Code Transformation and Linting with ASTs

Challenge 3: Schema Property

Kent C. Dodds

Kent C. Dodds

Professional Trainer
Code Transformation and Linting with ASTs

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

>> 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,

>> 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.

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?

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.

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.

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
Get Unlimited Access Now