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

Text spacing not !important [78fd32, 24afc2, 9e45ec]: Consider actual font size and ignore empty text #1804

Closed
wants to merge 19 commits into from

Conversation

Jym77
Copy link
Collaborator

@Jym77 Jym77 commented Mar 3, 2022

Superceded by #1923

Currently updating only "Line height is not !important" to check whether that solution works or not.

The second and third condition where about the test target, which is incorrect since both the font-size or the text spacing property can be updated before the actual text. This replaces them with a condition that look at these properties on the parent of each text node inside the test target.

Closes issue(s):

Need for Call for Review:
This will require a 2 weeks Call for Review (big change to expectation reworking the logic significantly)


Pull Request Etiquette

When creating PR:

  • Make sure you're requesting to pull a branch (right side) to the develop branch (left side).
  • Make sure you do not remove the "How to Review and Approve" section in your pull request description

After creating PR:

  • Add yourself (and co-authors) as "Assignees" for PR.
  • Add label to indicate if it's a Rule, Definition or Chore.
  • Link the PR to any issue it solves. This will be done automatically by referencing the issue at the top of this comment in the indicated place.
  • Optionally request feedback from anyone in particular by assigning them as "Reviewers".

When merging a PR:

  • Close any issue that the PR resolves. This will happen automatically upon merging if the PR was correctly linked to the issue, e.g. by referencing the issue at the top of this comment.

How to Review And Approve

  • Go to the “Files changed” tab
  • Here you will have the option to leave comments on different lines.
  • Once the review is completed, find the “Review changes” button in the top right, select “Approve” (if you are really confident in the rule) or "Request changes" and click “Submit review”.
  • Make sure to also review the proposed Call for Review period. In case of disagreement, the longer period wins.

@Jym77 Jym77 added Rule Update Use this label for an existing rule that is being updated reviewers wanted labels Mar 3, 2022
@Jym77 Jym77 self-assigned this Mar 3, 2022
@WilcoFiers WilcoFiers requested a review from tbostic32 March 24, 2022 14:17
- <dfn id="24afc2:wide-enough-cond">wide enough</dfn>: the parent of the text node has [wide enough letter spacing](#24afc2:wide-enough-def); or
- <dfn id="24afc2:cascade">cascade</dfn>: the parent of the text node has a [cascaded][] [letter-spacing][] property which is not the one [declared][] in the `style` attribute of the target.

An element has a <dfn id="24afc2:wide-enough-def">wide enough letter spacing</dfn> if the computed value of its [letter-spacing][] property is at least 0.12 times the computed value of its [font-size][] property.
Copy link
Collaborator

Choose a reason for hiding this comment

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

To mirror what we did with the line height we might want to make this the used value instead of the computed value.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fair point. It is not really needed for letter-spacing and word-spacing since the used value and computed value should be equal. But alignment is a good idea…

_rules/letter-spacing-not-important-24afc2.md Show resolved Hide resolved
@Jym77 Jym77 requested a review from tbostic32 March 31, 2022 11:20
tbostic32
tbostic32 previously approved these changes Apr 7, 2022
- <dfn id="24afc2:spaced-text">spaced text</dfn>: for each text node descendant of this target, one of the following is true:
- <dfn id="24afc2:empty">empty</dfn>: the text node is only [whitespace][]; or
- <dfn id="24afc2:wide-enough-cond">wide enough</dfn>: the parent of the text node has [wide enough letter spacing](#24afc2:wide-enough-def); or
- <dfn id="24afc2:cascade">cascade</dfn>: the parent of the text node has a [cascaded][] [letter-spacing][] property which is not the one [declared][] in the `style` attribute of the target.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I've been wrestling with this definition a bit. I finally understand it, but it seems weird since it feels like it is almost defining an inapplicable case and then calling it a pass (e.g., the text node doesn't use the target elements style which results in a pass). I'm not sure I have a suggestion for this, but figured I'd leave my thoughts in case it helps to figure out how to clarify this language somehow.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, the problem is that a single target can have all three cases (or more), something like:

<div style="letter-spacing: 2.4 px !important; font-size: 30px">
  <span>&nbsp;</span> <!-- OK because too small but only whitespace -->
  <span style="font-size: 20px">Lorem</span> <!-- OK because font-size has changed -->
  <span style="letter-spacing: 3.6px !important">ipsum</span> <!-- OK because letter-spacing has changed -->
  <span>dolor sit amet</span> <!-- bad -->
</div>

The 4th case totally only fails because of the div, so we do want the div as a target.

We could update applicability to say something like "…and has at least one text node descendant which is not only whitespace and whose parent's cascaded letter-spacing is not the one declared here". That would make cases with only the first or third case Inapplicable, which is quite good (these are cases where the !important declaration does not affect anything. But we would still need to keep the "empty" and "cascade" exceptions in the Expectation due to the possibility of mixing things up, as here. Hence, I feel that doing so would result in complicating the Applicability without simplifying the Expectation, and duplicating some condition (making maintenance harder).

Another solution could be to target the text nodes (which are not empty and whose parent's cascaded letter-spacing is !important and declared in a style attribute), but that would result in failing the text nodes rather than the (element with the) bad declaration, so it is not that good for reporting. This would result in only targeting "Lorem" (pass) and "dolor sit amet" (fail).

Comment on lines +107 to +114
if (stripRefNamesAndURLs) {
// Start of line, Opening [, no ] (repeated), closing ], /[[][^\]]*]: [^ ]*/ => matches "[name]: url"
// => the leftover bit is the title, which should be spellchecked.
// The name is only spellchecked if it appears in text, which is OK.
// 'm' flag checks in multiline mode, aka each line is matched separately.
const refListRegex = /^\[[^\]]*]: [^ ]*/gm
body = body.replace(refListRegex, "")
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Adding code to ignore the names and URL parts of reference list items when spellchecking, i.e. in

`[name]: url 'title'

only the title needs to be spellchecked (the name being spellchecked if it appears in the text). This became useful here with all the #xxxxxx:anchor links in the reference list.

@Jym77 Jym77 marked this pull request as ready for review July 7, 2022 13:39
@WilcoFiers WilcoFiers requested a review from colabottles July 14, 2022 13:21
@Jym77 Jym77 dismissed tbostic32’s stale review July 14, 2022 14:09

Added changes for all rules

@Jym77 Jym77 requested a review from tbostic32 July 14, 2022 14:09
Copy link
Member

@carlosapaduarte carlosapaduarte left a comment

Choose a reason for hiding this comment

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

Good job with the updated expectations. I've made some changes towards clarifying example descriptions.


#### Passed Example 13

This `p` element has three text node descendants. The first one is [empty](#24afc2:empty); the second one is [wide enough][] because of the smaller `font-size` on its parent; and the last one is [wide enough][] because of the `letter-spacing` specified on its parent. The third `span` element has a [wide enough][] text node descendant.
Copy link
Member

Choose a reason for hiding this comment

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

I feel like it would be good to specifically highlight there are two test targets in this example. Also, added the reference to the cascade condition.

Suggested change
This `p` element has three text node descendants. The first one is [empty](#24afc2:empty); the second one is [wide enough][] because of the smaller `font-size` on its parent; and the last one is [wide enough][] because of the `letter-spacing` specified on its parent. The third `span` element has a [wide enough][] text node descendant.
This `p` element has three text node descendants. The first one is [empty](#24afc2:empty); the second one is [wide enough][] because of the smaller `font-size` on its parent; and the last one is [wide enough][] because of the `letter-spacing` specified on its parent, meeting the [cascade](#24afc2:cascade) condition. The third `span` element, which is also applicable, has a [wide enough][] text node descendant.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For the p target, the text inside the third span is actually meeting both the "cascade" condition and the "wide enough" one (because the parent of this text node, the span, has a used letter-spacing of 3.6px, and a computed font-size of 30px; and 30×1.2 ⩽ 3.6).
I felt that "wide enough" is easier to understand 😅 But I guess we can keep both…


#### Passed Example 13

Both this `p` and `span` elements have a single text node descendant, whose parent (the `span` element) is [large enough][].
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't the description here mention that the p passes because of the cascade condition? The large enough condition is only relevant for the span

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Here also, the large enough condition is relevant for both 🤷

_rules/line-height-not-important-78fd32.md Outdated Show resolved Hide resolved
_rules/word-spacing-not-important-9e45ec.md Outdated Show resolved Hide resolved
_rules/word-spacing-not-important-9e45ec.md Outdated Show resolved Hide resolved
_rules/word-spacing-not-important-9e45ec.md Outdated Show resolved Hide resolved
@Jym77 Jym77 dismissed carlosapaduarte’s stale review August 4, 2022 08:49

Improved descriptions

@Jym77 Jym77 requested a review from carlosapaduarte August 4, 2022 08:49
carlosapaduarte
carlosapaduarte previously approved these changes Aug 5, 2022
Copy link
Member

@WilcoFiers WilcoFiers left a comment

Choose a reason for hiding this comment

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

This is getting really very complicated. I'm not sure this is actually necessary. To be honest I'd much rather we do this by just adding an assumption. Previously the rule of thumb has been that if we have no real-world examples of a problem, we're can use those. WDYT?

@Jym77
Copy link
Collaborator Author

Jym77 commented Sep 8, 2022

This is getting really very complicated. I'm not sure this is actually necessary. To be honest I'd much rather we do this by just adding an assumption. Previously the rule of thumb has been that if we have no real-world examples of a problem, we're can use those. WDYT?

I'm not sure how much of an actual problem the full rule detects in the first place 😅

Thus said, I feel the way to simplicity would be to move focus of the rule from the element to the text node (so from where the problem is created to where it actually occurs):

Applicability: any (parent of a) (non-whitespace) text node.

Expectation: either (i) specified letter-spacing is not declared in a style attribute; or (ii) specified letter-spacing is not !important; or (iii) computed letter-spacing is larger than X times computed font-size.

This immediately rules out the corner cases where a definition is not affecting any text, and freely handle the cases where the properties get changed. Maybe that would need to deprecate these rules and create new ones since it is a significant change 🤔

@WilcoFiers what do you think about this?

@Jym77 Jym77 requested a review from WilcoFiers September 8, 2022 13:26
@Jym77 Jym77 dismissed WilcoFiers’s stale review September 8, 2022 13:27

Further discussion

@Jym77 Jym77 dismissed carlosapaduarte’s stale review September 8, 2022 13:27

Opinion wanted on latest discussion.

@WilcoFiers
Copy link
Member

WilcoFiers commented Sep 13, 2022

@Jym77 Just for how much that changes these rules, I'd rather not. If we wanted to fix this (and I'm not convinced we need to) perhaps the way to do it would be by doing this:

- **wide enough**: the [computed][] [letter-spacing][] is at least 0.12 times the [computed][] [font-size][] of all descending text node in the flat tree; or

@Jym77
Copy link
Collaborator Author

Jym77 commented Sep 13, 2022

@Jym77 Just for how much that changes these rules, I'd rather not. If we wanted to fix this (and I'm not convinced we need to) perhaps the way to do it would be by doing this:

- **wide enough**: the [computed][] [letter-spacing][] is at least 0.12 times the [computed][] [font-size][] of all descending text node in the flat tree; or

That fixes #1688 (font-size changes), but not #1687 (letter-spacing change) where in the second example the div would still incorrectly fail the rule.

@Jym77 Jym77 mentioned this pull request Sep 15, 2022
7 tasks
@dd8
Copy link
Collaborator

dd8 commented Oct 6, 2022

How about wording like this:

Applicability

Elements where the computed value of the letter-spacing: property was assigned from a letter-spacing: declared as !important in a style attribute.

Expectation

For each test target, at least one of the following is true:

  • only whitespace: the element contains only whitespace text nodes; or
  • wide enough: the element has wide enough letter spacing

The avoids having to embed details of how the CSS the cascade works in the rule, and lets implementors choose how they implement this (looking at cascaded value, looking at specificity, calling an API, etc)

The definition above seems to work for all these cases:

<div style="letter-spacing: 2.4px !important; font-size: 30px">
  <span>&nbsp;</span> <!-- OK because too small but only whitespace -->
  <span style="font-size: 20px">Lorem</span> <!-- OK letter-spacing assigned from div, but font-size is smaller -->
  <span style="letter-spacing: 3.6px !important">ipsum <!-- OK letter-spacing assigned from span --></span> 
  <span style="letter-spacing: 4.6px">ipsum <!-- OK letter-spacing assigned from span, and doesn't inherit from div --></span> 
  <span>dolor sit amet </span> <!-- Bad: letter-spacing assigned from div via implicit inheritance -->
  <span style="letter-spacing: inherit">ipsum <!-- Bad: letter-spacing assigned from div via explicit inheritance --></span> 
  
 Also bad <!-- Bad: letter-spacing assigned from div -->
</div>

@Jym77
Copy link
Collaborator Author

Jym77 commented Oct 7, 2022

How about wording like this:

Applicability

Elements where the computed value of the letter-spacing: property was assigned from a letter-spacing: declared as !important in a style attribute.

I'm not sure what "the computed value was assigned from" means. I guess i will boil down to something like "the specified value was declared in" (an !important style attribute) 🤔 In any case we'll need to define it since it doesn't refer to any existing term as far as I can tell.

@dd8
Copy link
Collaborator

dd8 commented Oct 7, 2022

assign comes from here:

Once a user agent has parsed a document and constructed a document tree, it must assign, to every element in the tree, and correspondingly to every box in the formatting structure, a value to every property that applies to the target media type

https://www.w3.org/TR/css-cascade-3/#value-stages

Here's a tweaked version with a link to the definition:

Applicability

Elements where the computed value of the letter-spacing: property was assigned from a letter-spacing: declaration marked as as !important in an HTML style attribute.

@Jym77
Copy link
Collaborator Author

Jym77 commented Oct 13, 2023

Closed by #1923

@Jym77 Jym77 closed this Oct 13, 2023
@WilcoFiers WilcoFiers deleted the style-not-important-fixes branch December 12, 2023 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Rule Update Use this label for an existing rule that is being updated
Projects
None yet
6 participants