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 font-family-no-duplicate-names rule #2020

Merged
merged 1 commit into from Nov 1, 2016

Conversation

gaidarenko
Copy link
Contributor

Which issue, if any, is this issue related to?

Closes #1284

Is there anything in the PR that needs further explanation?

e.g. "No, it's self explanatory."

}
else {
familyNames.add(family)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the only difference between these two blocks is the value assigned to family. The code could probably be simplified significantly, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidtheclark Not only family but also different Sets to store already found font family names. I use keywords to store found font family keywords (e.g. sans-serif, cursive, monospace ...). And I use familyNames to store other font family names. All this done in order to allow a { font-family: "sans-serif", sans-serif; } and don't throw an error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I guess I wasn't looking closely enough. I still think this code can be simplified, though. Please try to match the conventions in other parts of the codebase for brace spacing and early returns, and see if you can this up a little.


This rule ignores `$sass`, `@less`, and `var(--custom-property)` variable syntaxes.

**Caveat:** This rule does not currently understand escape sequences. If you want to use the font family name "Hawaii 5-0" you will need to wrap it in quotes, instead of escaping it as `Hawaii \35 -0` or `Hawaii\ 5-0`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to use ...

This is inaccurate, right? You do not need to wrap it in quotes to use it. What is the actual consequence related to this rule of not wrapping the name in quotes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not using quotes brings up a lot of ambiguity. For example,

 Lucida      Grande
and
Lucida Grande
are one and the same valid family font name from CSS point of view. But this rule will treat these fonts as different font names. On the other hand,
"Lucida     Grande"
and
"Lucida Grande"
are different font names from both CSS and this rule point of view.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so it sounds like the caveat is not about "escape sequences" but about quotation marks around multi-word font names?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One can say so. The main idea - Please use quotation marks around multi-word font names or around font names containing disallowed symbols. Rather than use escape sequences in unquoted font family names. Because this rule does not currently support escape sequences.

Here some quotes from w3.org site:

Font family names other than generic families must either be given quoted as strings, or unquoted as a sequence of one or more identifiers. This means most punctuation characters and digits at the start of each token must be escaped in unquoted font family names.

To avoid mistakes in escaping, it is recommended to quote font family names that contain white space, digits, or punctuation characters other than hyphens

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rule will stumble on unquoted multi-word font names and unquoted font names containing escape sequences. Wrap these font names in quotation marks, and everything should be fine.

How about ^^?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Should I keep Caveat word?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, to match the format from other docs.

}
else {
familyNames.add(family)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I guess I wasn't looking closely enough. I still think this code can be simplified, though. Please try to match the conventions in other parts of the codebase for brace spacing and early returns, and see if you can this up a little.

@gaidarenko
Copy link
Contributor Author

I have simplified the code to use early returns.

}

keywords.add(family)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can return early here instead of the else statement below.

@gaidarenko
Copy link
Contributor Author

Done.

@davidtheclark
Copy link
Contributor

👍 from me. @jeddy3 any input, or should we merge?

@alexander-akait
Copy link
Member

@davidtheclark what about add option ignore, sometimes we need this https://github.com/necolas/normalize.css/blob/master/normalize.css#L93

Disallow duplicate font family names.

```css
a { font-family: "Times New Roman", serif; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a { font-family: serif, serif; }
/**              ↑      ↑
 * These font family names */

import {
messages,
ruleName,
} from ".."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

} should be flush to the left.

@jeddy3
Copy link
Member

jeddy3 commented Nov 1, 2016

@jeddy3 any input, or should we merge?

Two very minor requests. Otherwise, looks good to me. @gaidarenko Thanks for yet another rule! :)

what about add option ignore, sometimes we need this

This is what the disable comment are for i.e. one-off instances (e.g. hacks or workarounds). The ignore option is there for repeating patterns that occur more than once within a codebase.

@alexander-akait
Copy link
Member

@jeddy3 agree

@gaidarenko
Copy link
Contributor Author

Done.

@jeddy3 jeddy3 merged commit b45e095 into stylelint:master Nov 1, 2016
@jeddy3
Copy link
Member

jeddy3 commented Nov 1, 2016

  • Added: font-family-no-duplicate-names rule.

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

Successfully merging this pull request may close these issues.

None yet

4 participants