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

Add function-name-arguments-whitelist #4727

Closed
mockey-jockey opened this issue Apr 29, 2020 · 7 comments
Closed

Add function-name-arguments-whitelist #4727

mockey-jockey opened this issue Apr 29, 2020 · 7 comments

Comments

@mockey-jockey
Copy link

mockey-jockey commented Apr 29, 2020

Clearly describe the bug

Am trying to add the rule for the background-image URL should start with images

background-image: url(ssasimages/dummy.svg);

Which rule, if any, is the bug related to?

"function-url-scheme-whitelist": "/^images/",

What code is needed to reproduce the bug?

image

What stylelint configuration is needed to reproduce the bug?

{
  "rules": {
   "function-url-scheme-whitelist": "/^images/"
  }
}

Which version of stylelint are you using?

9.2.0

How are you running stylelint: CLI, PostCSS plugin, Node.js API?

stylelint app/styles

Does the bug relate to non-standard syntax (e.g. SCSS, Less etc.)?

"Yes, it's related to SCSS nested properties."

What did you expect to happen?

"No warnings to be flagged."

What actually happened (e.g. what warnings or errors did you get)?

"The following warnings were flagged:"

test.css
URL should starts images

image

@jeddy3 jeddy3 changed the title stylelint rule not working for the function URL Add function-name-arguments-whitelist Apr 29, 2020
@jeddy3 jeddy3 added the status: needs discussion triage needs further discussion label Apr 29, 2020
@jeddy3
Copy link
Member

jeddy3 commented Apr 29, 2020

@mockey-jockey Thanks for the report and for using the template.

The rule checks the scheme of the URL. From the docs:

A URL scheme consists of alphanumeric, +, -, and . characters. It can appear at the start of a URL and is followed by :.

i.e, the scheme is the thing up to the :, e.g. http:, https:, data:.

It's not the right rule for the job, but your use case is valid and I think we can add a new rule to stylelint for it.

Unless there are any objections, I think we can add a function-name-arguments-whitelist? From the spec:

The syntax starts with the name of the function immediately followed by a left parenthesis (i.e. a ) followed by the argument(s) to the notation followed by a right parenthesis. [emphasis mine]

The rule would be very similar to declaration-property-value-whitelist but would target function name and arguments rather than properties and values.

@mockey-jockey
Copy link
Author

Thanks, @jeddy3 sounds good. Please let me know once done.

@jeddy3 jeddy3 added good first issue is good for newcomers status: ready to implement is ready to be worked on by someone type: new rule an entirely new rule and removed status: needs discussion triage needs further discussion labels May 10, 2020
@jeddy3
Copy link
Member

jeddy3 commented May 10, 2020

As there are no objections to this rule, I'll label it up as good-to-go.

  • Name: function-name-arguments-whitelist
  • Primary option: object: { "unprefixed-function-name": ["string", "/regex/", /regex/] }
  • Secondary options: None
  • Message: Unexpected arguments "${arguments}" for function "${function}"
  • Description: "Specify a whitelist of allowed name and arguments pairs for functions."
  • Extended description: None
  • Section: "Limit language features" -> "Function"

Please let me know once done.

I've labelled the issue as ready to implement. Please consider contributing if you have time, @mockey-jockey. stylelint is an open-source volunteer project, and it's unlikely the rule will be added unless you contribute it yourself.

There are steps on how to add a new rule in the Developer guide. I suggest using declaration-property-value-whitelist as a blueprint, and then using postcss-value-parser to find and check functions within values.

@mockey-jockey
Copy link
Author

mockey-jockey commented Jun 1, 2020 via email

@hudochenkov
Copy link
Member

@mockey-jockey you need to fork repository, and push to your fork. Then create a draft PR to this repository.

@mockey-jockey
Copy link
Author

#4816 am created draft PR, could some help me to am going correct path or not. sorry am new to open source contributor that's what little bit worried how am doing good or not like that

@jeddy3 jeddy3 added status: wip is being worked on by someone and removed status: ready to implement is ready to be worked on by someone labels Jul 3, 2020
@jeddy3 jeddy3 removed good first issue is good for newcomers status: wip is being worked on by someone type: new rule an entirely new rule labels Aug 10, 2020
@jeddy3
Copy link
Member

jeddy3 commented Aug 10, 2020

It was decided in #4816 that this use case is best handled in a userland plugin.

Closing the issue.

@jeddy3 jeddy3 closed this as completed Aug 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants