-
-
Notifications
You must be signed in to change notification settings - Fork 934
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-missing-generic-family-keyword #2930
Conversation
This addresses issue stylelint#2929 ran $ npm test lib/rules/font-family-generic-fallback/__tests__/ Not sure how to improve the coverage of the tests. Results: Test Suites: 1 passed, 1 total Tests: 22 passed, 22 total Snapshots: 0 total Time: 2.609s Ran all test suites matching /lib\/rules\/font-family-generic-fallback\/__tests__\//i. =============================== Coverage summary =============================== Statements : 36.9% ( 2955/8008 ) Branches : 4.85% ( 184/3794 ) Functions : 5.15% ( 72/1398 ) Lines : 37.12% ( 2950/7947 ) ================================================================================ Jest: Coverage for statements (36.9%) does not meet global threshold (75%) Jest: Coverage for branches (4.85%) does not meet global threshold (75%) Jest: Coverage for lines (37.12%) does not meet global threshold (75%) Jest: Coverage for functions (5.15%) does not meet global threshold (75%) npm ERR! Test failed. See above for more details.
Hey thanks for your idea and your work. It's often a good idea to leave your issue up for a bit and see if there is any discussion ... the core is quite lively with hashing out issues and often things will be spotted that can avoid a chunk of work. Having said that your tests do pass and your code runs fine: I don't think our coverage suite is really set up to report on one file at a time? If run I'll take a look at the code itself depending on the discussion surrounding the feature request. |
Thanks! Yeah, I poked around the code, and then read up on the procedures for pull request. My bad :) |
NP. I like the idea and think this will get merged eventually. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stoyan Thanks! This does look good.
Once we settle on the the rule name, we can amend the rule description etc accordingly.
In the meantime, I've just some initial minor requests.
|
||
```css | ||
a { font-family: Arial, sans-serif; } | ||
/** ↑ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Align the arrow to the start of the generic family
The following patterns are *not* considered violations: | ||
|
||
```css | ||
a { font-family: Times, serif; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's match these first two examples to the violations above, but fixed. I think that'll make it clearer.
return; | ||
} | ||
|
||
complain( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for separate out the report into a complain
function when it is only called once.
|
||
const isFamilyNameKeyword = node => | ||
!node.quote && keywordSets.fontFamilyKeywords.has(node.value.toLowerCase()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does !node.quote
mean anything in quotes will NOT be seen as a generic family name? I would have assumed that font-family: Times, "serif"
, is perfectly valid and should pass, although it is slightly weird.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the spec, generic font families must be unquoted:
The following generic family keywords are defined: ‘serif’, ‘sans-serif’, ‘cursive’, ‘fantasy’, and ‘monospace’. These keywords can be used as a general fallback mechanism when an author's desired font choices are not available. As keywords, they must not be quoted. Authors are encouraged to append a generic font family as a last alternative for improved robustness.
So, the code as it is LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I stand corrected ... agreed.
@@ -0,0 +1,39 @@ | |||
# font-family-generic-fallback | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As described in the associated issue, please change all references to the rule name to font-family-no-missing-generic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM. As there seems to be no objections to the name proposal, @stoyan can you rename this font-family-no-missing-generic
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stoyan Thanks again for starting this. I believe its a rule all stylelint users will find useful. Also, thank you for your patience with the review. We've all been busy with other things.
There doesn't appear to be any objections to the naming proposal. Therefore, I've added some further requests to make the rule consistent with the conventions in stylelint. With 150 rules in stylelint we endeavour to be consistent, to help both the users and maintainers of stylelint. Thanks for your understanding.
The final step is to wire-up-the-rule. Can you add the rule to the example config please and to the list of rules (under possible errors -> font family)
@@ -0,0 +1,39 @@ | |||
# font-family-generic-fallback | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM. As there seems to be no objections to the name proposal, @stoyan can you rename this font-family-no-missing-generic
.
@@ -0,0 +1,39 @@ | |||
# font-family-generic-fallback | |||
|
|||
Require a generic fallback to any font-family declaration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change this to the following, as this is now a no
rules:
Disallow missing generic families in lists of font family names.
const ruleName = "font-family-generic-fallback"; | ||
|
||
const messages = ruleMessages(ruleName, { | ||
generic: () => "Missing generic font family, e.g. serif" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For no
rules, the convention is to use rejected
. A simple string would suffice too. Can you please use:
rejected: "Unexpected missing generic font family"
You'll need to update your tests accordingly too.
lib/rules/index.js
Outdated
@@ -52,6 +52,7 @@ const declarationPropertyUnitBlacklist = require("./declaration-property-unit-bl | |||
const declarationPropertyUnitWhitelist = require("./declaration-property-unit-whitelist"); | |||
const declarationPropertyValueBlacklist = require("./declaration-property-value-blacklist"); | |||
const declarationPropertyValueWhitelist = require("./declaration-property-value-whitelist"); | |||
const fontFamilyGenericFallback = require("./font-family-generic-fallback"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update the rule name.
font-family-generic-fallback
Thanks folks, this is awesome! I'll work on it as soon as I can. |
... and other assorted review feedback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stoyan Thanks! This looks great.
As a "possible errors" rule, it'll also be included in config-recommended
(and config-standard
), which means quite a few people will be using it from the get-go.
Changelog:
|
This addresses issue (feature request) #2929. I mostly copied
font-family-no-duplicate-names
and tweaked accordingly.To test I ran:
$ npm test lib/rules/font-family-generic-fallback/tests/
Not sure how to improve the coverage of the tests. Results:
Test Suites: 1 passed, 1 total
Tests: 22 passed, 22 total
Snapshots: 0 total
Time: 2.609s
Ran all test suites matching /lib/rules/font-family-generic-fallback/tests//i.
=============================== Coverage summary ===============================
Statements : 36.9% ( 2955/8008 )
Branches : 4.85% ( 184/3794 )
Functions : 5.15% ( 72/1398 )
Lines : 37.12% ( 2950/7947 )
Jest: Coverage for statements (36.9%) does not meet global threshold (75%)
Jest: Coverage for branches (4.85%) does not meet global threshold (75%)
Jest: Coverage for lines (37.12%) does not meet global threshold (75%)
Jest: Coverage for functions (5.15%) does not meet global threshold (75%)
npm ERR! Test failed. See above for more details.
#2929
I don't think so