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 no-unknown-custom-properties #6361

Closed
jeddy3 opened this issue Sep 26, 2022 · 12 comments
Closed

Add no-unknown-custom-properties #6361

jeddy3 opened this issue Sep 26, 2022 · 12 comments
Labels
status: wip is being worked on by someone type: new rule an entirely new rule

Comments

@jeddy3
Copy link
Member

jeddy3 commented Sep 26, 2022

What is the problem you're trying to solve?

I'd like to disallow unknown custom properties. For example:

:root {
  --foo: 1px;
}

a {
  top: var(--bar);
}

What solution would you like to see?

A new rule to catch this. It's currently available as a plugin but it meets our criteria to be a built-in rule.

Prior art for user-defined unknowns is no-unknown-animations.

Also, see this Twitter thread.

We'd need to address #4088 first, and work out how best to add imports & resolvers to configuration files. Is standardised importForm and resolver secondary options on each of these types of rules the way to go?

  • Name: no-unknown-custom-properties
  • Primary option: true
  • Secondary options: importForm & resolver?
  • Autofixable: No
  • Message: - Unexpected unknown custom property
  • Description: "Disallow unknown custom properties."
  • Extended description: "This rule considers custom properties defined within the same source to be known. Use the importForm secondary option to specify more sources."
  • Section: "Avoid errors" -> "General"

Like no-unknown-animations, we won't turn the rule on in the recommended config and we'll want to update the recommended config to reflect this.

Any thoughts?

@jeddy3 jeddy3 added the status: needs discussion triage needs further discussion label Sep 26, 2022
@ybiquitous
Copy link
Member

@jeddy3 Thanks for the proposal. I see it as very interesting, and it seems that this feature should be so valuable for many people.

However, as we mentioned many times, how to resolve other files is stuff to be discussed well. It would be good if we could have a PoC that should be the basis of the discussion.

By the way, is importForm a typo of importFrom?

@ybiquitous
Copy link
Member

It would be good if we could have a PoC that should be the basis of the discussion.

We may implement such a resolving mechanism as an experimental feature by borrowing code from the existing plugin.

@jeddy3
Copy link
Member Author

jeddy3 commented Sep 27, 2022

By the way, is importForm a typo of importFrom?

Oops, yes it is.

We may implement such a resolving mechanism as an experimental feature by borrowing code from the existing plugin.

That sounds like a sensible approach. And I agree we can flag as experimental for now.

I suggest we start by only supporting .css imports, i.e. importFrom accepts an array of paths to CSS files. Other features like a resolver and supporting other files types, e.g. .html and .scss, can happen later down the line. The latter would likely involve custom syntaxes like we do with overrides. (The existing plugin supports JSON, JS and object imports but let's not go there yet.)

We'd want to author the importFrom option is a way that makes it easier for other rules and plugins to implement.

Do you think there's value in something like a defaultImportFrom configuration property, which would (like defaultSeverity) would sit at the top-level of the configuration object or shall we just go with importFrom as a secondary option on the rule for now?

@ybiquitous
Copy link
Member

I suggest we start by only supporting .css imports,

I agree with the idea.

Do you think there's value in something like a defaultImportFrom configuration property

Indeed, there may be a helpful case if defaultImportFrom is supported. But I'm not sure whether it is necessary for the first step. If it is easy to implement defaultImportFrom and importFrom simultaneously, I agree with adding both.

@jeddy3
Copy link
Member Author

jeddy3 commented Sep 28, 2022

Indeed, there may be a helpful case if defaultImportFrom is supported. But I'm not sure whether it is necessary for the first step. If it is easy to implement defaultImportFrom and importFrom simultaneously, I agree with adding both.

I agree.

I'll label this as ready to implement.

  • Name: no-unknown-custom-properties
  • Primary option: true
  • Secondary options: importFrom: [] - array of glob paths to .css files
  • Autofixable: No
  • Message: - Unexpected unknown custom property
  • Description: "Disallow unknown custom properties."
  • Extended description: "This rule considers custom properties defined within the same source to be known. You can use the importFrom secondary option to specify more sources."
  • Section: "Avoid errors" -> "Unknown"

If anyone fancies contributing this rule, there are steps on how to add a new rule in the Developer guide.

@jeddy3 jeddy3 added 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 Sep 28, 2022
@jeddy3 jeddy3 changed the title Add no-unknown-custom-properties Add no-unknown-custom-properties Sep 28, 2022
@silverwind
Copy link

Regarding importFrom: Yes, sounds sensible to start off with only supporting manually declared CSS sources.

If a flat config is implemented, variable declarations could be automatically extracted from all files in the same "job", which then should be able to rely on user-provided customSyntax parsers for HTML/SCSS etc.

@jameschensmith
Copy link
Contributor

jameschensmith commented Mar 20, 2023

Thanks @silverwind for connecting the tickets together, which helped get my attention. I'm totally on board with this, and will be happy to implement this here (this will be my first PR in this repository, so I'll be following the developer guide @jeddy3 mentioned). I have one question, though. Why not just implement it without secondary options for now, and POC the importFrom option separately? I'm fine implementing it either with/without the second option. I just think if we iterate on this rule, we can deliver value much more quickly.

Once I hear back on what y'all think, I can start iterating on it.

@ybiquitous
Copy link
Member

Why not just implement it without secondary options for now, and POC the importFrom option separately?

Sounds good. I welcome a pull request to implement the new rule without the secondary option.

@jameschensmith
Copy link
Contributor

PR for initial implementation can be found here.

@ybiquitous ybiquitous added status: wip is being worked on by someone and removed status: ready to implement is ready to be worked on by someone labels Mar 27, 2023
@silverwind
Copy link

silverwind commented Mar 29, 2023

Implementation was merged, so I assume we can close this one.

Should we make a separate issue for the feature request for a importFrom option?

@ybiquitous
Copy link
Member

Should we make a separate issue for the feature request for a importFrom option?

Surely, leaving this issue title as-is may confuse people. Let's close this after we open a new follow-up issue.

@ybiquitous
Copy link
Member

I just opened #6746. This can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: wip is being worked on by someone type: new rule an entirely new rule
Development

No branches or pull requests

4 participants