GithubHelp home page GithubHelp logo

Comments (9)

jeddy3 avatar jeddy3 commented on July 18, 2024

There's a PR/discussion over at eslint about this (with links to two issues where it is discussed further). Perhaps we can take a page out of their book?

Looks like they're going for some sort of schema validation approach. Rules throwing errors seems to have been ruled at because:

Having rules validate options will significantly complicate rules implementation. Rules are currently responsible only for one thing, validating AST and reporting errors.

So, shall we park this issue for now and milestone it for way into the future?

from stylelint.

davidtheclark avatar davidtheclark commented on July 18, 2024

I'm in agreement. It will be nicer if we build this as a separate component of the architecture.

from stylelint.

MoOx avatar MoOx commented on July 18, 2024

It will be nicer if we build this as a separate component of the architecture.

+1. KISS for now :)

from stylelint.

davidtheclark avatar davidtheclark commented on July 18, 2024

Does anybody have an example of an application that they think does this really well?

from stylelint.

jeddy3 avatar jeddy3 commented on July 18, 2024

The only one I know of is the aforementioned one in eslint (but that's probably due to that fact I don't have much experience with tooling). Looking back through their issues and pull requests, it looks like it was a heavily debated and discussed topic. So, one can only assume that what they have in place is well reasoned.

It seems they had to juggle a few things though, including how plugin rules and the rule-tester both work with the validator.

from stylelint.

davidtheclark avatar davidtheclark commented on July 18, 2024

Here's what I'm thinking might work:

  • We create two util functions validatePrimaryOptions(result, ruleName, possible, actual) and validateSecondaryOptions(result, ruleName, schema, actual). Our rule signature includes two possible option-places: the primary options, which should always be a single value, and secondary options, which should always be an object. Maybe we blend those into a single function -- whatever turns out simplest. Either way, the idea would be that each plugin calls this for each of its options arguments.
  • possible is an array of possibilities. Each possibility is either a value (e.g. "always") or a function that returns true to say that the actual value is acceptable (e.g. check if it's an integer or "tab" for indentation)
  • schema is just an object whose keys correspond to secondary options and values are possible arrays.
  • All the validate functions do is check whether the option is valid; and if not, attach a warning to result.

That's the simplest solution I can think of, though it may not be the best. Any thoughts?

from stylelint.

jeddy3 avatar jeddy3 commented on July 18, 2024

Seems like a sensible approach to me :)

Is there something in there to check that *-no-* rules, which have no options, would attach a warning if any options are supplied e.g. is can validatePrimaryOptions accept something like null for possible instead of an array?

Or is overloading that function not the best approach, and instead we have a 3rd function called something like validateNoOptions?

from stylelint.

davidtheclark avatar davidtheclark commented on July 18, 2024

Sure, we could make the possibilities an empty array, so anything entered there comes up wrong.

For warning messages, I was just thinking Invalid option "x" for rule "y", e.g. Invalid option "alwars" for rule "block-opening-brace-space-before". Check documentation. That seem ok?

from stylelint.

jeddy3 avatar jeddy3 commented on July 18, 2024

Invalid option "x" for rule "y"

Spot on :)

from stylelint.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.