Differing preferences for indentation styles can lead to conflicting prett

My eslint setup is as follows:

{
  "env": {
    "es2020": true,
    "jest": true
  },
  "extends": [
    "eslint:recommended",
    "plugin:react/recommended",
    "plugin:import/recommended",
    "plugin:import/typescript",
    "plugin:prettier/recommended",
    "plugin:@typescript-eslint/recommended"
  ],
  "parser": "@typescript-eslint/parser",
  "plugins": ["@typescript-eslint", "prettier"],
  "settings": {
    "import/resolver": {
      "typescript": true,
      "node": true
    }
  },
  "overrides": [
    {
      "files": ["*.ts", "*.tsx"],
      "parserOptions": {
        "project": ["./tsconfig.json"]
      },
      "rules": {
        "@typescript-eslint/consistent-type-imports": [
          "error",
          {
            "fixStyle": "inline-type-imports"
          }
        ],
        "@typescript-eslint/member-ordering": "error",
        "@typescript-eslint/consistent-type-exports": "error",
        "@typescript-eslint/method-signature-style": "error",
        "@typescript-eslint/prefer-ts-expect-error": "error",
        "@typescript-eslint/consistent-generic-constructors": ["error", "constructor"],
        "@typescript-eslint/consistent-type-definitions": ["error", "type"],
        "@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }]
      }
    }
  ],
  "rules": {
    "indent": "off",
    "max-len": [
      "error",
      {
        "code": 88,
        "ignoreRegExpLiterals": true
      }
    ],
    "no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
    "semi": ["error", "always"],
    "arrow-parens": ["error", "as-needed"],
    "prefer-const": ["error"],
    "react/require-default-props": "off",
    "import/order": [
      "error",
      {
        "newlines-between": "always",
        "groups": ["builtin", "external", "parent", "sibling", "index", "type"]
      }
    ]
  }
}

This is my prettier configuration:

{
  "semi": true,
  "tabWidth": 2,
  "printWidth": 88,
  "singleQuote": true,
  "trailingComma": "none",
  "jsxBracketSameLine": true,
  "endOfLine": "auto",
  "arrowParens": "avoid"
}

I have a typescript file with the following code snippet:

import { createRoot } from 'react-dom/client';

export const mount = (el: HTMLElement) => {
    const root = createRoot(el);
};

An eslint error occurs:

Delete ".." eslint(prettier/prettier)
. Deleting 2 spaces resolves it temporarily, but reformatting adds the spaces back and triggers the same error.

The conflicting eslint rules are puzzling, especially considering I've set the tabWidth to 2. What could be causing this issue? Thank you!

Answer №1

It seems like you might be relying on the wrong formatter, specifically the default Typescript one.

To resolve this, try pressing CtrlShiftP and selecting "format document with..." then set the default formatter to either ESLint or Prettier.
Make sure that the ESLint formatter is enabled in your settings, as it may not be activated by default.

Answer №2

There appears to be a clash between ESLint and prettier in your code. Consider utilizing the eslint-config-prettier package to disable any conflicting Linter rules with prettier.

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

Having trouble removing objects from a map results in having to invoke the function three times

I am facing an issue with the function findPrice where I need to call it multiple times to delete objects that match a specific price. The problem arises when dealing with large maps and two functions. Here is the JSON format: [ { _id: 5c6c408dbec3ab457c ...

Error: The next.config.js file contains invalid options - The root value includes an unexpected property

I recently updated my next version from 10 to 12, and when I run the local development server, I encounter the following error in the terminal. As a result, the code fails to compile. How can I fix this issue? Invalid next.config.js options have been iden ...

Discovering the power of chaining operators in RxJS 6 by encapsulating .map within

I am in the process of updating my Observable code from RXJS 5 to version 6. import { Injectable } from '@angular/core'; import { Observable } from 'rxjs' import { AppConfig } from '../config/app-config'; import { Xapi } from ...

How can a child component trigger an event in its parent component?

Currently, I have tabs implemented with a form and a button in tab1. In the parent component, there is an event that deactivates the current tab and activates the next one. Can anyone advise on how to call this event from the child component? gotosecond ...

Can the tiles in a grid-list be organized in a specific order?

I am facing an issue with a class named 'scenario' that has properties such as 'id', 'name', and 'number' among others. In the HTML, scenarios are displayed in this format: <mat-grid-list [cols]="breakpoint" r ...

Steps for incorporating a new element in Reactjs

While attempting to insert a new element into a React object, I encountered the following issue: const isAdmin = true let schema = { fname: Yup.string().required('Required'), lname: Yup.string().required('Required&apo ...

When considering Angular directives, which is more suitable for this scenario: structural or attribute?

In the process of developing an Angular 5 directive, I aim to incorporate various host views (generated from a component) into the viewContainer. However, I find myself at a crossroads as to whether I should opt for an attribute directive or a structural ...

Make sure to always utilize an alias when setting up automatic imports

Is there a method to ensure that autoimport always utilizes the alias for importing modules in a project with VSCode? I want to consistently use the alias, even when it's a sibling component, without any exceptions. Instead of import { Navbar } from ...

When a property is removed from a variable in an Angular Component, it can impact another variable

During the iteration of the results property, I am assigning its value to another property called moreResults. After this assignment, I proceed to remove array elements from the testDetails within the moreResults property. However, it seems that the remova ...

Type-constrained generic key access for enhanced security

While attempting to create a versatile function that retrieves the value of a boolean property using a type-safe approach, I encountered an issue with the compiler not recognizing the type of my value. type KeyOfType<T, V> = keyof { [P in keyof T a ...

An issue occurred at line 2, character 16 in the generateReport.service.ts file: TypeScript error TS2580 - The term 'require' is not recognized

I have a requirement in my app to generate a report in the form of a Word document with just a click of a button. Previously, I successfully accomplished this using the "officeGen" module in a separate project. You can find more information about the modul ...

Exploring the power of RxJs through chaining observers

In my Angular application, I am utilizing Observables to set up a WebSocket service. Currently, I have the following implementation: readwrite(commands: command[]) : Observable<response[]>{ const observable = new Observable((observer)=>{ ...

An effective way to extract targeted information from an array of objects using Typescript

I'm having trouble extracting the IDs from the selected items in my PrimeNG DataTable. Despite searching on Google, I couldn't find much information about the error I'm encountering... ERROR in C:/Users/*****/Documents/Octopus/Octopus 2.0/s ...

Example of TypeScript Ambient Namespace Usage

The Namespaces chapter provides an example involving D3.d.ts that I find puzzling. Here is the complete example: declare namespace D3 { export interface Selectors { select: { (selector: string): Selection; (element: ...

Having difficulty transferring navigation props between screens using react-navigation

Within my ContactList component, I have utilized a map to render various items. Each item includes a thumbnail and the desired functionality is that upon clicking on the thumbnail, the user should be directed to a new screen referred to as UserDetailsScree ...

Operating on Javascript Objects with Randomized Keys

Once I retrieve my data from firebase, the result is an object containing multiple child objects. myObj = { "J251525" : { "email" : "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6c3823212 ...

Tips for picking out a particular item from a list of child elements

When I select the first parent's children array, it ends up selecting every other parent's children as well. This is due to index 0 remaining the same for all of them. How can I specify and highlight a specific child? Link: Check out the stackb ...

Guide on properly specifying mapDispatchToProps in a component's props interface

In my project, I have a connected component utilizing mapStateToProps and mapDispatchToProps along with the connect HOC from react-redux. My goal is to create concise and future-proof type definitions for this component. When it comes to defining types fo ...

Pressing a button that appears multiple times and is also embedded within layers

I am facing an issue where I need to interact with a button that appears multiple times on the website within nested cards. Specifically, I am trying to locate the card containing a pet named Bala, as shown in the attachment below, and click on the Detail ...

Creating a dynamic multi-line list in Ionic application is a breeze!

I'm a beginner in Ionic and I am interested in creating a Multi-line List similar to how we generate list-views in Android with custom views and using an Array of custom objects programmatically. Can Multi-line Lists be generated with data from an Ar ...