linaria icon indicating copy to clipboard operation
linaria copied to clipboard

Stylelint 14 rules do not work because during traversal, node parent `lang` is undefined and not `template-literal`

Open ShayDavidson opened this issue 2 years ago • 1 comments

Environment

  • Node.js version: 18.16.0
  • Stylelint version: 14.16.1
  • @linaria/core version: 4.2.10
  • @linaria/stylelint-config-standard-linaria: 4.1.5
  • @linaria/postcss-linaria: 4.1.5

Stylelint config:

{
  "ignoreFiles": ["**/*"],
  "extends": ["@linaria/stylelint-config-standard-linaria"],
}

Description

I integrated stylelint into our Linaria project, yet figured that most of the rules do not work. e.g. property-no-unknown doesn't report unknown properties, yet string-quotes worked.

Considering I couldn't figure what's wrong, I literally debugged the property-no-unknown rule in Stylelint. This pointed me to this line in one of the checks: https://github.com/stylelint/stylelint/blob/main/lib/rules/property-no-unknown/index.js#L64

!isStandardSyntaxLang((parent.source).lang)

Yet the "parent" of my unknown property was the actual wrapping TS file my Linaria declaration is present in. e.g. if this is the traversed declaration in test.ts:

const ResponsiveWidth = css`
  test: 1px;
`;

Then the parent became:

import { css } from '@linaria/core';

Considering this is no CSS, stylelint fails to recognize this is CSS hence the check passes.

I guess I'm doing something wrong, but can't figure what. I thought it's related to PostCSS missing as an actual dependency, but even after installing it the rules fail to work.

ShayDavidson avatar Jun 29 '23 12:06 ShayDavidson

I think this is the problem: https://github.com/stylelint/stylelint/pull/6553

Stylelint 15 fixes the problem, and no longer checks the for parent rule. Once I upgraded, the problem got solved. However, the Linaria documentation and code doesn't seem to officially support Stylelint 15, so I can't be sure it actually works well.

ShayDavidson avatar Jun 30 '23 04:06 ShayDavidson