-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Stylus doesn't throw error at not existed property in json #2629
Comments
Thanks for report. |
It seems I have found out why stylus do this behaviour
But it is so unobviously |
But in this case:
Stylus could throw error that 'red' variable is undefined We have hundreds stylus files in project, and after some refactoring of styles data in json files we can't find all errors |
# e.g add new stylus cli options ?
stylus iChenLei.styl -o iChenLei.css --json-check @groenroos What's your opinion ? |
I don't know if a JSON-specific option like that would have a wide enough audience - but I do think in the wider view, there should be an option on whether to throw errors when any variables (JSON or otherwise) or properties/indices within hash variables don't exist (as per the StackOverflow thread linked above). Some kind of As @mars-abd pointed out above, it would be easy to throw errors when dollar-prefixed variables don't exist - but then this would create a gotcha for people who prefer non-prefixed variables, where they might reasonably expect // would throw an error
div
color $foo
// would not throw an error, but would render as-is
// even though "foo" isn't a valid color
div
color foo So, either;
To put it in context of this issue, for consistency, I would see the missing JSON property error also as part of a |
Having said that, according to the issue description there is a weird inconsistency, where the undefined JSON hash property will be rendered as empty, while other undefined variables get rendered as literals; $colors = json('data.json', { hash: true })
// all the following are undefined
div
color red
background $blue
border-color $colors.gray would according to the above be currently rendered as; div {
color: red;
background: $blue;
border-color: ;
} which is an unexplained inconsistency. I would expect the |
For example
data.json:
styles.styl:
Command:
npx stylus styles.styl
will compile:
without any errors
Json func documentation:
https://stylus-lang.com/docs/bifs.html#jsonpath-options
The text was updated successfully, but these errors were encountered: