bmatcuk/coc-stylelintplus

Not working coc-stylelintplus in neovim

mr-scrpt opened this issue · 6 comments

Hi all. My coc-stylelintplus is not working.Please help me find the cause
Here are my configs:

coc-settings.json

{
  "stylelintplus.enable": true,
  "stylelintplus.filetypes": [
    "css",
    "less",
    "postcss",
    "sass",
    "scss",
    "sugarss",
    "vue"
  ],
  "stylelintplus.validateOnSave": true,
  "stylelintplus.validateOnType": true,
  "css.validate": false,
  "less.validate": false,
  "scss.validate": false,
  "eslint.autoFixOnSave": true,
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    "typescript",
    "typescriptreact"
  ],
  "eslint.probe": [
    "javascript",
    "javascriptreact",
    "typescript",
    "typescriptreact"
  ],
  "coc.preferences.formatOnSave": true,
  "emmet.includeLanguages": {
    "htmldjango": "html",
    "njk": "html",
    "nunjucks": "html",
    "html": "njk"
  }
}

coc.lua

vim.g.coc_global_extensions =  { 
    'coc-tag', 
    'coc-css',
    'coc-htmldjango',
    'coc-html', 
    'coc-json', 
    'coc-prettier', 
    'coc-vimlsp', 
    'coc-pairs', 
    'coc-eslint', 
    'coc-tsserver', 
    'coc-emmet', 
    'coc-stylelintplus'
} 

vim.cmd(" let g:coc_user_config = { 'suggest.enablePreview': v:true,  'prettier.disableSuccessMessage': v:true, 'suggest.maxPreviewWidth': 100, 'diagnostic.checkCurrentLine': v:true, 'diagnostic.maxWindowHeight': 20, 'diagnostic.errorSign': '✖', 'diagnostic.warningSign': '⚠', 'diagnostic.infoSign': '●', 'diagnostic.hintSign': '○'}")

Here are the project configurations:
packege.json

{
  "name": "workflow_standart",
  "version": "1.0.0",
  "description": "",
  "main": "gulpfile.js",
  "type": "module",
  "scripts": {
    "dev": "gulp watch",
    "build": "gulp build --build",
    "zip": "gulp deployZIP --build",
    "deploy": "gulp deployFTP --build",
    "svgSprive": "gulp svgSprive"
  },
  "author": "FLS",
  "license": "ISC",
  "dependencies": {
    "aos": "^2.3.4",
    "css-loader": "^6.7.1",
    "css-minimizer-webpack-plugin": "^4.0.0",
    "gulp-cli": "^2.3.0",
    "jquery": "^3.6.0",
    "mini-css-extract-plugin": "^2.6.1",
    "showctrl": "^1.0.2",
    "style-loader": "^3.3.1"
  },
  "devDependencies": {
    "browser-sync": "latest",
    "del": "latest",
    "eslint": "^8.22.0",
    "eslint-config-prettier": "^8.5.0",
    "eslint-plugin-import": "^2.26.0",
    "eslint-plugin-prettier": "^4.2.1",
    "gulp": "latest",
    "gulp-autoprefixer": "latest",
    "gulp-clean-css": "latest",
    "gulp-data": "^1.3.1",
    "gulp-file-include": "latest",
    "gulp-fonter-2": "^0.3.0",
    "gulp-group-css-media-queries": "latest",
    "gulp-if": "latest",
    "gulp-imagemin": "latest",
    "gulp-newer": "latest",
    "gulp-notify": "latest",
    "gulp-nunjucks-render": "^2.2.3",
    "gulp-plumber": "latest",
    "gulp-pug": "latest",
    "gulp-rename": "latest",
    "gulp-replace": "latest",
    "gulp-sass": "latest",
    "gulp-svg-sprite": "latest",
    "gulp-ttf2woff2": "latest",
    "gulp-util": "latest",
    "gulp-version-number": "latest",
    "gulp-webp": "latest",
    "gulp-webp-html-nosvg": "latest",
    "gulp-webpcss": "latest",
    "gulp-zip": "latest",
    "htmlhint": "^1.1.4",
    "prettier": "^2.8.3",
    "sass": "latest",
    "smart-grid": "^2.1.2",
    "stylelint": "^14.16.1",
    "stylelint-config-prettier-scss": "^0.0.1",
    "stylelint-config-standard-scss": "^6.1.0",
    "swiper": "latest",
    "vinyl-ftp": "latest",
    "webp-converter": "2.2.3",
    "webpack": "latest",
    "webpack-stream": "latest"
  }
}

stylelintrc.json

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

When I run npx stylelint ./src/style/base/button.scss
Validation works correctly
image

If I open the project in VSCode, it also works correctly

image

But nvim does not show errors
image

If I run :CocList extensions , I see that coc-stylelintplus is enabled
image

But if I try to access a command with stylelintplus, I only see one command in the tooltip, but there should be more as I understand it
image

If I enter the command :CocCommand workspace.showOutput and select stylelintplus in the list, I get a configuration error.

[Info  - 14:34:59.120] stylelint running in node v16.19.0
Error when trying to validate file:///home/mr/project/maksim/ukrgumbat/template/src/style/base/button.scss Error: No rules found within configuration. Have you provided a "rules" property?
    at configurationError (/home/mr/project/maksim/ukrgumbat/template/node_modules/stylelint/lib/utils/configurationError.js:11:49)
    at augmentConfigFull (/home/mr/project/maksim/ukrgumbat/template/node_modules/stylelint/lib/augmentConfig.js:119:9)
    at async isPathIgnored (/home/mr/project/maksim/ukrgumbat/template/node_modules/stylelint/lib/isPathIgnored.js:27:17)
    at async lintSource (/home/mr/project/maksim/ukrgumbat/template/node_modules/stylelint/lib/lintSource.js:41:20)
    at async Function.standalone [as lint] (/home/mr/project/maksim/ukrgumbat/template/node_modules/stylelint/lib/standalone.js:129:26)
    at async Object.lint (/home/mr/.config/coc/extensions/node_modules/coc-stylelintplus/node_modules/stylelint-lsp/dist/settings.js:68:28)
    at async validate (/home/mr/.config/coc/extensions/node_modules/coc-stylelintplus/node_modules/stylelint-lsp/dist/validate.js:37:36)
    at async /home/mr/.config/coc/extensions/node_modules/coc-stylelintplus/node_modules/stylelint-lsp/dist/validate.js:116:13 {
  code: 78
}

I think stylelintplus can't see my .stylelintrc.json file. Although this file is in the root of my project
image

See #35, as this issue has already been reported there.

fffed commented

The issue is created by returned null value for config field as stylelint-lsp expects undefined instead.

The issue is created by returned null value for config field as stylelint-lsp expects undefined instead.

Thank you for your reply. Can you tell me how this can be fixed?

fffed commented

@mr-scrpt, you can localy (~/.config/coc/extensions/node_modules/coc-stylelintplus) remove

"stylelintplus.config": {
          "description": "Stylelint config. If config and configFile are unset, stylelint will automatically look for a config file.",
          "scope": "resource",
          "type": "object"
        },

from package.json.

@mr-scrpt, you can localy (~/.config/coc/extensions/node_modules/coc-stylelintplus) remove

@mr-scrpt This was a big clue, but unfortunately does not work b/c it does not result in an undefined value for stylelintplus.config. It actually results in a {} value instead.

I think this bug actually lives (and was introduced) inside the coc.nvim package and changes made to the getConfiguration function. Instead of returning undefined for configuration properties with no default key, it always returns an empty {} instead based on its type: object.

I found no way in coc-stylelintplus to get around this, and there is unfortunately no way to explicitly declare an undefined default value within the package.json.

I ended up digging into my local coc-stylelintplus/node_modules/stylelint-lsp package and updating this particular file and line.

Added this mutation to the settings.stylelintplus object to essentially clear out these props:

        const promise = this.connection.workspace
            .getConfiguration({ scopeUri: uri, section: "" })
            .then((settings) => {
            // NOTE: Make sure config props not defined.
            settings.stylelintplus.config = undefined;
            settings.stylelintplus.configOverrides = undefined;
            console.log('---', settings.stylelintplus);

            const stylelint = this.resolveStylelint(uri);
            ...

Hope this helps y'all. And if anyone can help getting this fixed up in stylelint-lsp, that would probably be good.

Tuch commented

@dannobytes thanks, works for me