I am using VS code for a project using CSS Grid and CSS Modules. However when I try something like this
.loginRegisterDiv {
composes: loginDiv;
margin: 0px;
width: 100%;
}
I get an error saying composes "unknown property" for composes. Plus I am using css grid and there does not seem to be any intellisense for this in VS code. Do I need to install an extension?
I am using rallycoding rulesets.
You can add to the VSC CSS linter an exception to the rule css.lint.unknownProperties
(or set this to ignore). Open the VSC settings, search for css.lint.validProperties
and add 'composes' to the list. The error/warning will go away.
To make the VS Code recognise these custom CSS directive/properties, you can provide custom data for VS Code's CSS Language Service as mentioned here - https://github.com/Microsoft/vscode-css-languageservice/blob/master/docs/customData.md.
Create a CSS custom data set file with the following info. Place it at location .vscode/custom.css-data.json
relative to the project root.
{
"version": 1.1,
"properties": [
{
"name": "composes",
"description": "css modules compose"
}
],
"atDirectives": [
{
"name": "@value",
"description": "css modules value import"
}
],
"pseudoClasses": [],
"pseudoElements": []
}
Now, if you don't have already, create a .vscode\settings.json
file relative to project root. Add a field with key "css.customData" and value as the path to custom data set. For example,
{
"css.customData": ["./.vscode/custom.css-data.json"]
}
Now, you will no longer get "Unknown property" warning. When you hover over "composes", you will see the description you set for it in custom.css-data.json
This works to me, in your settings.json
file add "css.lint.validProperties": ["composes"],
I use extensions to help with this particular problem. The extension system is excellent in VS Code, and there are a lot of really high quality extensions built by the community that greatly improve the quality and feature set of the editor.
Here are a few extensions that I use for writing SASS in VS Code. One or a couple of these should fix the problems you are having (and maybe even a few you didn't know you were having).
CSS Modules Syntax Highlighter by Andrew Leedham
SCSS IntelliSense by mrmlnc
Install one or several of those in VS Code, restart the editor, and then let me know if that doesn't fix your issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With