fi3ework / vite-plugin-checker

💬 Vite plugin that provide checks of TypeScript, ESLint, vue-tsc, Stylelint and more.
https://vite-plugin-checker.netlify.app
MIT License
973 stars 84 forks source link

Stylelint report throws when `stylelint-ignore` is used #272

Open amiller-gh opened 1 year ago

amiller-gh commented 1 year ago

Describe the bug

When /* stylelint-ignore */ is added to the top of a file, the module throws with:

TypeError: Cannot read properties of undefined (reading 'css')
    at /node_modules/vite-plugin-checker/dist/esm/logger.js:283:41
    at Array.map (<anonymous>)
    at normalizeStylelintDiagnostic (/node_modules/vite-plugin-checker/dist/esm/logger.js:258:30)
    at /node_modules/vite-plugin-checker/dist/esm/checkers/stylelint/main.js:91:47
    at Array.map (<anonymous>)
    at Object.configureServer (/node_modules/vite-plugin-checker/dist/esm/checkers/stylelint/main.js:91:36)

Reproduction

Add /* stylelint-ignore */ to the top of any file, observe the error.

Expected behavior

The process doesn't crash! ;)

System Info

System:
    OS: macOS 13.2.1
    CPU: (10) arm64 Apple M2 Pro
    Memory: 49.84 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v18.16.0/bin/yarn
    npm: 9.5.1 - ~/.nvm/versions/node/v18.16.0/bin/npm
  Browsers:
    Chrome: 115.0.5790.170
    Safari: 16.3


### Additional context

Offending line is here: https://github.com/fi3ework/vite-plugin-checker/blob/e564641ac312eba95286b717177af27eb48bcf07/packages/vite-plugin-checker/src/logger.ts#L427C28-L427C28

Updating with optional chaining to `diagnostic?._postcssResult?.css ?? ''` fixes the issue!

### Validations

- [X] Read the [docs](https://github.com/fi3ework/vite-plugin-checker#readme).
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
liukonghe commented 10 months ago

I've encountered a similar issue and have been working on a fix for it. You can check out my Pull Request #284 to see if it addresses your problem.