Skip to content
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

Compiler should verify correct usage of builtin functions #2502

Open
Aran-Fey opened this issue Oct 29, 2019 · 1 comment
Open

Compiler should verify correct usage of builtin functions #2502

Aran-Fey opened this issue Oct 29, 2019 · 1 comment

Comments

@Aran-Fey
Copy link

I'd like builtin functions to verify that they were called with the correct number of arguments, and that the function's return value makes sense in context. Silently ignoring these two problems can make debugging incredibly difficult.

Real world example: Being used to LESS, I tried to use the contrast function like this:

background-color: contrast(#111, #222, #333)

Obviously, this is wrong in stylus - contrast accepts at most 2 arguments, and it doesn't return a color. But the compiler silently ignores both of these problems, outputting

background-color: {"ratio":"1.2","error":"0","min":"1.2","max":"1.2"};

I was using the Stylus browser addon and never got to see the compiled CSS, so all I had to figure out the problem was a weird error message complaining about unexpected {.

Ideally, I'd like to receive two error messages:

  1. Function 'contrast' accepts at most 2 arguments, but received 3.
    Line 1:
        background-color: contrast(#111, #222, #333)
    
  2. 'background-color' requires a value of type 'color', but received 'object'.
    Line 1:
        background-color: contrast(#111, #222, #333)
    
@MoussaAdam
Copy link

i agree to

Function 'contrast' accepts at most 2 arguments, but received 3.
Line 1:
background-color: contrast(#111, #222, #333)

but not to

'background-color' requires a value of type 'color', but received 'object'.
Line 1:
background-color: contrast(#111, #222, #333)

this is the work of a linter, not of a preprocessor like stylus, also it will be hard to know what every property expected value is, and making it flexible enough for properties like font, not to mention the changes of the properties and the fact that new properties get added by time, its not the responsibility of stylus to track that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants