Skip to content

Fix performance of constructor parsing rules #6869

Open
@romainmenke

Description

Recommended config:

  • annotation-no-unknown
  • color-no-invalid-hex
  • custom-property-no-missing-var-function
  • declaration-block-no-duplicate-properties
  • font-family-no-duplicate-names
  • font-family-no-missing-generic-family-keyword
  • function-calc-no-unspaced-operator
  • function-linear-gradient-no-nonstandard-direction
  • function-no-unknown
  • media-feature-name-no-unknown
  • named-grid-areas-no-invalid
  • no-descending-specificity (1687)
  • no-duplicate-at-import-rules
  • no-duplicate-selectors (363)
  • selector-anb-no-unmatchable
  • selector-pseudo-class-no-unknown (153)
  • selector-pseudo-element-no-unknown
  • selector-type-no-unknown
  • string-no-newline
  • unit-no-unknown

Standard config:

  • alpha-value-notation
  • color-function-notation
  • color-hex-length
  • custom-property-pattern
  • font-family-name-quotes
  • function-name-case
  • function-url-quotes
  • hue-degree-notation
  • import-notation
  • length-zero-no-unit
  • media-feature-range-notation
  • selector-attribute-quotes
  • selector-class-pattern (342)
  • selector-id-pattern
  • selector-no-vendor-prefix
  • selector-not-notation
  • selector-pseudo-element-colon-notation
  • selector-type-case
  • shorthand-property-no-redundant-values
  • value-keyword-case
  • value-no-vendor-prefix

Selector rules:

  • selector-attribute-name-disallowed-list
  • selector-attribute-operator-allowed-list
  • selector-attribute-operator-disallowed-list
  • selector-combinator-allowed-list
  • selector-combinator-disallowed-list
  • selector-max-attribute
  • selector-max-class
  • selector-max-combinators
  • selector-max-compound-selectors
  • selector-max-id
  • selector-max-pseudo-class
  • selector-max-specificity
  • selector-max-type
  • selector-max-universal
  • selector-no-qualifying-type
  • selector-pseudo-class-allowed-list
  • selector-pseudo-class-disallowed-list
  • selector-pseudo-element-allowed-list
  • selector-pseudo-element-disallowed-list

Other rules:

  • color-hex-alpha
  • color-named
  • color-no-hex
  • declaration-block-no-redundant-longhand-properties
  • declaration-property-max-values
  • declaration-property-unit-allowed-list
  • declaration-property-unit-disallowed-list
  • declaration-property-value-no-unknown
  • font-weight-notation
  • function-allowed-list
  • function-disallowed-list
  • max-nesting-depth
  • media-feature-name-unit-allowed-list
  • media-feature-name-value-allowed-list
  • no-unknown-custom-properties
  • number-max-precision
  • time-min-milliseconds
  • unit-allowed-list
  • unit-disallowed-list

List created with :

find ./lib/rules -type f -print0 | xargs -0 grep -l "parse"

Some rules may not have any issues. Maybe they just contain the word "parse" in a comment.


In stylelint/css-parser#2 performance was discussed in the context of CSS parsers.

This made me curious about the current state of Stylelint.
Is it fast, slow, ... ?

This issue doesn't say anything about stylelint/css-parser#2.
The other issue was merely inspiration for this one.


Especially for Stylelint performance is an interesting subject because by it's very nature Stylelint runs should gravitate towards becoming a noop.

In a codebase with many linter errors it's logical to do a lot of work to compute what the issues are and where they are.

However in a codebase that is already "healthy", Stylelint should be able to skip a lot of work.
Optimizing for codebases that are already free of issues means that users will have a fast experience most of the time.

Even in a codebase that is full of errors, there is a lot parsing and processing done that can be eliminated. Most parts of a CSS codebase do not apply to most Stylelint rules.

A low effort and low complexity way to make Stylelint faster is to add one or two types of fast aborts :

  1. the rule doesn't apply to the CSS source
  2. the rule does apply but it will definitely pass with a given config

Example of 1 :
color-function-notation where the CSS source doesn't contain rgb|rgba|hsl|hsla

Example of 2 :
color-function-notation with option modern where the CSS source doesn't contain any comma's.

These checks will typically be regexp's that are to broad to know if the issue is real and where it is, but are specific enough to know that there can not be an issue.

i.e. they can have false negatives, but not false positives.


I've already explored some rules for low hanging fruit and I think reviewing all (non deprecated) rules and making improvements to them will be good for users of Stylelint.

Metadata

Assignees

No one assigned

    Labels

    status: ask to implementask before implementing as may no longer be relevant

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions