Comments (9)
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.
I'm in agreement. It will be nicer if we build this as a separate component of the architecture.
from stylelint.
It will be nicer if we build this as a separate component of the architecture.
+1. KISS for now :)
from stylelint.
Does anybody have an example of an application that they think does this really well?
from stylelint.
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.
Here's what I'm thinking might work:
- We create two util functions
validatePrimaryOptions(result, ruleName, possible, actual)
andvalidateSecondaryOptions(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"
forindentation
)schema
is just an object whose keys correspond to secondary options and values arepossible
arrays.- All the
validate
functions do is check whether the option is valid; and if not, attach a warning toresult
.
That's the simplest solution I can think of, though it may not be the best. Any thoughts?
from stylelint.
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.
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.
Invalid option "x" for rule "y"
Spot on :)
from stylelint.
Related Issues (20)
- Rule idea: `declaration-prefer-shorthand` HOT 2
- Fix `selector-type-no-unknown` false positive for `model`
- Release 16.6.0 HOT 11
- Missing semicolon in JSON file HOT 5
- Fix `no-descending-specificity` false positives for nested selectors HOT 2
- Release 16.6.1 HOT 5
- breaking changes for `property-no-vendor-prefix` HOT 6
- New rule: identifier-pattern HOT 12
- Remove `postcssResult.stylelint.disableWritingFix` HOT 7
- Unknown rule no-extra-semicolons. HOT 3
- `block-no-empty` false `needless-disable` in blocks with comments. HOT 2
- New rule: Disallow unconstrained `:has()` for performance reasons HOT 3
- `at-rule-no-unknown` false positive for `@view-transition` HOT 2
- `property-no-unknown` false positive for descriptor `navigation` HOT 1
- Add `junit` as a core formatter HOT 3
- Update the documentation of `isAutoprefixable` util
- Address potentially breaking changes in #7769 HOT 5
- Autofix refactors HOT 40
- Make fixer data testable
- Ranges of fixes HOT 14
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stylelint.