willofindie / vscode-cssvar

VSCode extension to support CSS Variables Intellisense
https://marketplace.visualstudio.com/items?itemName=phoenisx.cssvar
MIT License
243 stars 4 forks source link

[Feat] Allow users to enable/disable css variable linting #75

Closed phoenisx closed 1 year ago

phoenisx commented 1 year ago

Closes #73

Changes:

Notes:

Since CSS variables are global in nature by default and can be used even without them being declared, an ideal CSS linter for CSS variables might not exist. This feature enables strict checks for undeclared variables, thus variables which are undeclared or dynamically created will be considered as lint warn/errors.

For e.g. all the following CSS examples are valid:

body {
  /* The following `--undeclared` variable does not exist */
  /* but its usage is completely valid, even though this extension */
  /* shows it as an error after enabling this feature */
  color: var(--undeclared, #333);
}
// source.js
const foo = (index, value) => (
  css`
    --color-${index}: ${value};
  `
);
/* index.css */
body {
  color: var(--color-1);
}

To fix the above cases, you can pass a list of variable names in the extension settings to ignore them, as follows:

// settings.json
{
  "cssvar.mode": ["warn", {
    "ignore": [
      "^--undeclared",
      "--color-\\w+?"
    ]
  }]
}

For details check the examples folder