bmatcuk / stylelint-lsp

A stylelint Language Server
MIT License
48 stars 4 forks source link

Unknown rules errors with stylelint-config-standard and stylelint-scss #31

Closed TymekDev closed 2 years ago

TymekDev commented 2 years ago

Hello, thanks for creating this package!

I just started configuring it with Neovim built-in LSP and run into a problem. I have installed following packages globally (npm i -g): stylelint-lsp, stylelint-config-standard, and stylelint-scss. I added the following .stylelintrc:

{
  "extends": "stylelint-config-standard",
  "plugins": [
    "stylelint-scss"
  ],
}

After opening a CSS file I receive various Unknown rule errors, e.g. Unknown rule no-invalid-position-at-import-rule. I am no expert in Node world, so I am not sure where it comes from, but if I had to guess it would be that either stylelint-config-standard or stylelint-scss introduces newer rules than the stylelint version required by stylelint-lsp supports.

I would appreciate any pointers on how to solve this issue.

bmatcuk commented 2 years ago

I think your guess is right =) stylelint-lsp will attempt to use whatever version of stylelint you have installed, so, you could try installing a newer version of stylelint globally (ie, npm i -g stylelint). That may fix the problem. Let me know if it doesn't and I'll release a new version of stylelint-lsp with a newer dependency.

TymekDev commented 2 years ago

Thanks for a quick reply! I have installed newest stylelint (14.5.3), but the problem prevails.

bmatcuk commented 2 years ago

Hmm, looks like stylelint 14 changed a whole bunch of stuff... I'm going to have to think about the best way to approach upgrading.

However, based on the .stylelintrc you posted above, it looks like you're actually targeting stylelint v13 (using scss in v14 is a little more involved than just specifying a plugin). Are you trying to use stylelint in a project with a package.json file? Typically, things like stylelint would be added as a dev dependency to your project instead of installed globally. stylelint-lsp should have an easier time finding the installed version of stylelint if it's used in that way.

Another way you could solve this problem is by downgrading stylelint-config-standard... looks like 21.0.0 will work.

TymekDev commented 2 years ago

You are right. Adding a package.json made it apparent that there is a conflict in requested peer dependencies. I have ended up with only stylelint-lsp installed globally, and a following package.json (notice stylelint v13):

{
  "devDependencies": {
    "sass": "^1.49.9",
    "stylelint": "^13.13.1",
    "stylelint-config-standard": "^22.0.0",
    "stylelint-scss": "^3.20.1"
  },
  "stylelint": {
    "extends": "stylelint-config-standard",
    "plugins": [
      "stylelint-scss"
    ]
  }
}

Initially I wanted to stray from adding package.json to not add it to every project as it seemed a bit of an overhead (especially that I aim to write plain HTML + SASS). However, it turns out that adding package.json is the (mostly) hassle-free way of doing things. Thank you for your help and pointing me in the right direction!

bmatcuk commented 2 years ago

Cool, glad you got it working! =)