What is the process for integrating prettier configuration into the eslint configuration?

Just a heads up, I prefer to avoid using semicolons in my JavaScript project.

Check out this YouTube video

I attempted to turn off the semicolon rule in the .eslintrc.cjs file but it was strange that setting semi: 0 didn't work to suppress the warnings for missing ;. Surprisingly, semi: false did disable the warnings in VScode.

However, it turned out my issue was related to Prettier. So, I included the Prettier config in my ESLint file and used semi: false there which actually worked. But running npm run lint threw an error:

https://i.sstatic.net/S8gmg.png

This is how my configuration looks like:

/* eslint-env node */
require("@rushstack/eslint-patch/modern-module-resolution")

module.exports = {
  root: true,
  extends: [
    "plugin:vue/vue3-essential",
    "eslint:recommended",
    "@vue/eslint-config-prettier",
  ],
  rules: {
    semi: 0,
  },
  prettier: {
    rules: {
      semi: false
    },
  },
  overrides: [
    {
      files: ["cypress/e2e/**.{cy,spec}.{js,ts,jsx,tsx}"],
      extends: ["plugin:cypress/recommended"],
    },
  ],
};

If I remove the Prettier block, the warnings will start appearing again in my code:

https://i.sstatic.net/iNrzX.png

This is how my package.json file (created by Vue) looks like:

{
  "name": "moonholdings.xyz",
  "version": "0.0.0",
  "scripts": {
    "dev": "vite",
    "build": "run-p type-check build-only",
    "preview": "vite preview --port 4173",
    "test:unit": "vitest --environment jsdom",
    "test:e2e": "start-server-and-test preview http://127.0.0.1:4173/ 'cypress open --e2e'",
    "test:e2e:ci": "start-server-and-test preview http://127.0.0.1:4173/ 'cypress run --e2e'",
    "build-only": "vite build",
    "prettier": "prettier --write .",
    "lint": "eslint . && prettier --check ."
  },
  "dependencies": {
    "pinia": "^2.0.14",
    "vue": "^3.2.36",
    "vue-router": "^4.0.15"
  },
  "devDependencies": {
    "@rushstack/eslint-patch": "^1.1.0",
    "@vitejs/plugin-vue": "^2.3.3",
    "@vitejs/plugin-vue-jsx": "^1.3.10",
    "@vue/eslint-config-prettier": "^7.0.0",
    "@vue/test-utils": "^2.0.0",
    "cypress": "^10.0.2",
    "eslint": "^8.5.0",
    "eslint-plugin-cypress": "^2.12.1",
    "eslint-plugin-vue": "^9.0.0",
    "jsdom": "^19.0.0",
    "npm-run-all": "^4.1.5",
    "prettier": "^2.5.1",
    "sass": "^1.53.0",
    "start-server-and-test": "^1.14.0",
    "vite": "^2.9.9",
    "vitest": "^0.13.0",
    "vue-tsc": "^0.35.2"
  }
}

Answer №1

Solved the problem by deactivating the ESlint plugin in VScode, as it was conflicting with my configuration files. Turns out, this plugin was unnecessary.

https://i.sstatic.net/AYId3.png

Answer №2

Make sure to update your .eslintrc file to include the following prettier rule:

"rules": {
        "react/react-in-jsx-scope": "off",
        "prettier/prettier": [
            "error",
            {
              "trailingComma": "all",
              "tabWidth": 12,
              "semi": false,
              "singleQuote": true,
              "bracketSpacing": true,
              "eslintIntegration": true,
              "printWidth": 120
            }
          ]
    }

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

Custom attribute with ng-options in AngularJS

I am currently working with the following directive in my select. ng-options="option.value as option.title for option in exportTypes" The array $scope.exportTypes contains objects with attributes title, value, and generatesFile. I would like to include t ...

Leveraging AJAX with React Router

Currently tackling a project utilizing React Router, encountering some challenges with data flow. Each page triggers an AJAX call to fetch data for the component. These calls have been placed within componentDidMount: // The following code is in ES6 comp ...

Is it possible to encounter a MongoDB error for the $or operator in a correctly formatted query?

Here is the problem I am facing: const users = this.mongo.db.collection('Users') let query = { '$or': [ { "email": {'$eq': req.body.email }}, {"username": {'$eq': req.body.username }} ] } users.fi ...

Is there a way to showcase the generated results on a graph after the user presses the submit button?

I've been working with to generate a bar chart. Currently, when the user clicks 'submit', the input numbers are shown in a graph on http://jsfiddle.net/jx9sJ/5/. Now, I want to make some changes. I am attempting to send the input numbers t ...

What is the reason behind material-ui's decision to invoke their dialogs twice?

After attempting to implement a modal and realizing the strange behavior, I switched to using a dialog instead. To my surprise, the issue persisted. This is how I approached it: import Dialog, { DialogProps } from '@material-ui/core/Dialog'; imp ...

Prevent the line break from going beneath the ::before pseudo element

p::before { content: "1. "; } p { width: 200px; } <p>This is an example of a long text that requires a line break: Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam ...

What is the best way to retrieve a FireStore document ID from an object?

I'm in the process of trying to reference an auto-generated firestore document ID in order to create a subcollection within it. The issue I'm facing is that although I can locate the document ID, I'm struggling to save it to a variable in a ...

JQuery GET brings back unnecessary HTML content

Currently utilizing a PHP cart class and implementing some jQuery to dynamically update a div when users add products. The issue I'm encountering is that upon adding a product, the list of products on the HTML page gets duplicated (see screenshot) ev ...

The functionality for navigating the Angular uib-dropdown using the keyboard is currently experiencing issues

I am currently utilizing Angular Bootstrap 2.2.0 in conjunction with Angular 1.5. Despite enabling the keyboard-nav option, I am experiencing issues with keyboard navigation on UIB dropdowns. Below is the snippet of my code: <div class="btn-group" ...

having trouble transferring the password field in PHP to phpMyAdmin

My HTML form collects the user's first name, last name, username, and password. I am trying to upload this data to my local phpMyAdmin, but I'm facing an issue with storing the password in the database. Below is my HTML code: <input type="te ...

What is the procedure for eliminating a cookie with Javascript?

Is there a way to delete the cookie set by javascript:void(document.cookie=”PREF=ID=20b6e4c2f44943bb:U=4bf292d46faad806:TM=1249677602:LM=1257919388:S=odm0Ys-53ZueXfZG;path=/; domain=.google.com”); The code below fails to do so. javascript:void(docum ...

Instructions for creating a dynamic Google map based on an address

Specifics I am aiming to generate a map based on any address stored within my <span> The address in question is : 410 walker street Lowell MA 01851 The <span> containing the address reads as follows: Address: <span id="address" > 410 w ...

"Exploring the Mini Drawer feature on Material UI brings up a whole new page for the Link

Currently, I am working on a project that involves updating stocks using Material UI. I have implemented a mini drawer from Material UI, but when I click on the menu link, it routes to a new page instead of rendering on the homepage itself. In my App.JS f ...

The issue of Rails 4 serving JavaScript as plain text instead of executing it when attempting to utilize AJAX

I am in the process of constructing a basic page layout featuring two side-by-side columns. The left column is intended for user input via a form submission. Upon submitting the form, I want the right column to dynamically update (using AJAX) and display a ...

Is there a way for me to display the output within the component rather than using console log?

I created a simple app.js file in React that continuously checks if a number is prime or not and logs the result in the console every second. Now, I am looking to display this information on my homepage instead of in the console. Any suggestions on how I ...

The never-ending loading animation in Jquery ajax search is relentless

In my quest to create an efficient search functionality using ajax, I have written the code below. The idea is that when a user presses a key and then stops for 500ms, an ajax request is triggered to perform the search operation. However, there seems to be ...

The JavaScript function on the master page is not being triggered by the code behind

Two pages are named: Abc.aspx and popupAbc.aspx On the Abc.aspx page, there is a button that opens popupAbc.aspx as a pop-up: <asp:Button ID="btnOpenChildAbcPopup" runat="server" Text="Open" UseSubmitBehavior="false" CausesValidation="False" OnClick=" ...

Receiving a notification when attempting to log in with incorrect credentials

I am currently working on an Angular login page implementation using a username and password setup. When the user enters incorrect credentials, I want to display an alert message indicating the same. Here is the HTML code snippet for the form: <form [f ...

Loop fails to collect all values from the array

I am attempting to create two consecutive loops that will iterate through an array of customers and extract all the fruits from each customer's list. I initially tried using nested for loops, but this only provided me with the first fruit from each cu ...

An error will occur if you try to use $.ajax inside a function

I am facing an issue with a function that utilizes jquery's ajax to check an API for the success status of a variable. The goal is to return true if the "success" variable is true and false if it is false. Below is the code snippet: function checkLo ...