Using Stylelint in Your Vue.js Project

Currently, I am in the process of incorporating stylelint into a new Vue project that I have just set up.

Initially, I believed it would be straightforward to utilize the Stylelint Webpack Plugin. However, upon running yarn serve, any encountered errors cause the entire operation to freeze without providing any output. On the other hand, if I execute yarn build, the build process fails as expected but only emits the message "There was a stylelint error".

The contents of my vue.config.js file are outlined below:

const stylelintPlugin = require('stylelint-webpack-plugin');

module.exports = {
  configureWebpack: {
    plugins: [
      new stylelintPlugin({ files: ['**/*.(vue|scss)'] }),
    ],
  },
};

Displayed are the current versions from my package.json:

 "@vue/cli-service": "^3.9.0",
 "stylelint": "^10.1.0",
 "stylelint-config-recommended": "^2.2.0",
 "stylelint-scss": "^3.9.2",

Answer №1

Although it may be overdue, here are effective configurations using

stylelint-config-recommended-scss
.

This is an add-on to the third-party stylelint-scss plugin that must be installed alongside stylelint itself. It appears that stylelint-webpack-plugin was missing from your setup.

To install development dependencies:

# Remove unnecessary dependency (with NPM):
npm uninstall stylelint-config-recommended

# Or with Yarn:
yarn remove stylelint-config-recommended

# Install dev dependencies with NPM:
npm i -D stylelint stylelint-scss stylelint-config-recommended-scss stylelint-webpack-plugin

# Or with Yarn:
yarn add -D stylelint stylelint-scss stylelint-config-recommended-scss stylelint-webpack-plugin

In your vue.config.js:

const StyleLintPlugin = require('stylelint-webpack-plugin');

module.exports = {
  configureWebpack: {
    plugins: [
      new StyleLintPlugin({
        files: ['src/**/*.{vue,scss}'],
      }),
    ],
  },
};

Create a file stylelint.config.js in the root folder of your project:

module.exports = {
  extends: 'stylelint-config-recommended-scss',
  rules: {
    'selector-pseudo-element-no-unknown': [
      true,
      {
        ignorePseudoElements: ['v-deep']
      }
    ]
  }
};

Add this lint:scss command in your package.json file (run with npm run lint:scss). This command attempts to auto-fix all rules, but please note that not all rules can be fixed automatically.

If there are errors that cannot be fixed, the script will display a list of error lines and exit. You will need to manually correct these errors and then rerun the script to ensure they have been resolved:

{
  "scripts": {
    "lint:scss": "stylelint ./src/**/*.{vue,scss} --fix"
  }
}

I hope this information proves helpful! Feel free to leave a comment if anything was overlooked.

Answer №2

My setup mirrors that of a fellow UX engineer, but when attempting to execute the command npm run lint:scss, I encountered an issue.

node_modules/stylelint/node_modules/get-stdin/index.js:13
for await (const chunk of stdin) {
            ^^^^^

SyntaxError: Unexpected reserved word

After investigation, it was discovered that the problem stemmed from using an outdated version of Node.js. It's important to ensure you are using the correct version.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilize React-router to display child components on the webpage

Recently, I've encountered some challenges with this code. I have a component that takes in a child as a prop, which is meant to serve as the foundation for all the pages I am hosting. Base.jsx : import React from 'react'; import PropTypes ...

JavaScript combined with a dynamic menu, a customized current link style using CSS, and a site built on PHP

Here's my current website setup: My website is modular and uses dynamic inclusion. The header is a crucial part of the main page, which is responsible for displaying content from specific links on the site. External links to CSS and js files are incl ...

Chromium browsers exhibit strange behavior with AngularJS orderBy, causing issues with clearing sorting selections

There is a particular issue that is really frustrating me in one of my projects. The code I have is quite similar to this example (I tried to replicate it as closely as possible, but the actual code doesn't seem to be relevant because I can't re ...

Using a Javascript library within an Angular component: A comprehensive guide

I've been working on a Web-Client project that involves visualizing sensor data such as velocity and acceleration within a coordinate system. In order to display this coordinate system, I decided to use the graph.js library from https://github.com/dhu ...

Display a list of errors from an array in JavaScript or jQuery, and output them into a designated <

I need assistance with displaying a list of error messages in a specific div. Within my code, I have a #error-list div and an array called errors that contains various error messages: var errors = ["First name is blank", "Last name is blank", "Company na ...

Updating Options in React JS Material UI Autocomplete

Incorporating an Autocomplete field into my React JS Project is a priority for me. Employing Material UI for the UI design aspect has been immensely beneficial. An example from the documentation showcases how to implement this: <Autocomplete ...

Using TypeScript with Watermelondb

I'm currently developing a React App and I want to implement Watermelondb for Offline Storage, but I'm unsure about using it with TypeScript. I have already set up the database and created Course and Lesson model files from the Watermelondb libra ...

Synchronizing Form Data in Angular 5: Pass and Populate Dropdowns between Components

I have developed a unique form (material dialog modal) that allows users to create an account. When the user clicks on the Register button, their created account should appear in a dropdown menu without redirecting or reloading the current page. I am facin ...

Discover the steps to convert an image to base64 while circumventing the restrictions of the same-origin policy

I've been struggling to convert an image link to base64 in order to store it on the client-side browser (IndexedDB). Despite searching for a solution for days, I have not been able to find one that addresses my issue. While I can successfully convert ...

Adding extra req.body properties to an existing post request in Express and then redirecting it can be done by modifying the req

There are times when I come across a situation where I feel like I'm overlooking something really obvious... On the client side, there is a form that submits to a location like /submit On the server side, I handle it with: app.post('/submit&ap ...

Unforeseen issue encountered while utilizing node proxy

While running the program below, I encountered an error. The application worked fine locally but when I tried to access it in the browser through localhost:3000, this error popped up on the console... **Error: connect ECONNREFUSED** at exports._errnoE ...

The VueJS Chosen directive fails to refresh when new options are selected

Struggling to populate my jQuery Chosen dropdown field with AJAX data using VueJS. Unfortunately, when trying to update the values, the Chosen dropdown does not reflect the changes. I've experimented with different approaches, including manually trig ...

Implementing `block eval() in Content Security Policy header for an Angular 8 project

Is it possible to disable the eval function in CSP-Header for an Angular project, even if it's not being used directly? Are there any potential negative consequences or errors that could occur when deploying the project? Appreciate your insight. ...

Is there a method available to minimize the size of a local storage list containing strings?

Hey there, I am trying to load a large 2.5MB json file in my browser so that I can use it for some typeAhead functions. Unfortunately, I'm facing an issue with my local storage being constantly full. When using Firefox, I receive the following error ...

Mapping an array based on specific conditions

When using my photo gallery app, I faced a challenge in mapping an array of images based on the user-selected album name. The current setup works perfectly for the 'Cambodia' album where all images are correctly logged in the console after mappin ...

What is the best way to eliminate a JSON header?

Here is the JSON data I have: { "folder": [ { "$": { "id": "471841542", "name": "Manajemen Pemasaran", "description": "", "user_id": "186868958", "shared": "1", "shared_l ...

Error: Trying to use 'Player' before it has been initialized

Recently, I have been utilizing ES6 syntax along with import/export on Nodejs using the ESM module loader. Everything was running smoothly until I encountered an error related to imports. Below are the error messages that popped up: joseph@InsaneMachine ...

Executing a series of API calls using Rxjs in Angular that result in a null response

I encountered a situation where I needed to make sequential API calls using RxJs in Angular. However, despite successfully implementing the calls, I am struggling with a null error. In this scenario, the second API call depends on receiving an id from the ...

Is there a way to transform the searchParams function into an object? Changing from URLSearchParams { 'title' => '1' } to { title : 1 }

Is there a way to convert the searchParams function into an object, transforming from URLSearchParams { 'title' => '1' } to { title : 1 }? I need this conversion to be applied for all values in the URLSearchParams, not just one. Cur ...

The Javascript Image() function fails to load or render

I am currently in the process of developing a basic Sprite class for implementation in a canvas game. However, I am encountering an issue where the image specified during the creation of a new instance of the class does not trigger the onload or onerror ev ...