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-missing-generic-family-keyword #2930

Merged
merged 2 commits into from
Oct 22, 2017

Conversation

stoyan
Copy link
Contributor

@stoyan stoyan commented Sep 28, 2017

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.

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

#2929

Is there anything in the PR that needs further explanation?

I don't think so

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.
@CAYdenberg
Copy link
Contributor

CAYdenberg commented Sep 29, 2017

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 npm test everything looks good (takes about 96 sec) ... while working you can use npm run watch, hit the p key, and then zero in on your test file using a regular expression.

I'll take a look at the code itself depending on the discussion surrounding the feature request.

@stoyan
Copy link
Contributor Author

stoyan commented Sep 30, 2017

Thanks! Yeah, I poked around the code, and then read up on the procedures for pull request. My bad :)

@CAYdenberg
Copy link
Contributor

NP. I like the idea and think this will get merged eventually.

Copy link
Member

@jeddy3 jeddy3 left a 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; }
/** ↑
Copy link
Member

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; }
Copy link
Member

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(
Copy link
Member

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());

Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Member

@jeddy3 jeddy3 left a 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

Copy link
Member

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.
Copy link
Member

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"
Copy link
Member

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.

@@ -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");
Copy link
Member

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.

@jeddy3 jeddy3 changed the title new rule font-family-generic-fallback Add font-family-no-missing-generic Oct 3, 2017
@stoyan
Copy link
Contributor Author

stoyan commented Oct 4, 2017

Thanks folks, this is awesome! I'll work on it as soon as I can.

... and other assorted review feedback
Copy link
Member

@jeddy3 jeddy3 left a 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.

@jeddy3 jeddy3 changed the title Add font-family-no-missing-generic Add font-family-no-missing-generic-family-keyword Oct 22, 2017
@jeddy3 jeddy3 merged commit 3df2f61 into stylelint:master Oct 22, 2017
@jeddy3
Copy link
Member

jeddy3 commented Oct 22, 2017

Changelog:

  • Added: font-family-no-missing-generic-family-keyword rule (#2930).

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.

3 participants