Ensuring compatibility between prettier and eslint for consistent brace style and indentation

For my new project, I have set up prettier and eslint to automatically convert the indentation and brace styles to the correct format. However, I am facing an issue with the following code block:

export default class BaseTextMixin
  implements BaseTextMixinType
{
  readTextFile(this: BaseType, link: string): string {
    return (
      this.text_mesh.get(link) ?? fs.readFileSync(link, 'utf-8')
    )
  }
}

When I check it, I see:

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

The first error message states:

Expected indentation of 0 spaces but found 2. eslint indent

The second error message is:

Opening curly brace does not appear on the same line as controlling statement. eslint brace-style

In my .eslintrc.json, I have the following configurations:

"rules": {
  "curly": 2,
  "brace-style": ["error", "1tbs"],
  "indent": ["error", 2, { "SwitchCase": 1 }]
  // ...
}

And in my .prettierrc.json, these are the settings:

{
  "semi": false,
  "trailingComma": "all",
  "singleQuote": true,
  "printWidth": 64,
  "tabWidth": 2,
  "useTabs": false,
  "arrowParens": "avoid",
  "quoteProps": "as-needed",
  "bracketSpacing": true,
  "proseWrap": "always",
  "endOfLine": "lf",
  "singleAttributePerLine": true,
  "prettierPath": "./node_modules/prettier"
}

How can I make it accept this format, knowing that the line length exceeds the limit (following prettier's rule)? Specifically, how can I allow the indentation like:

export default class BaseTextMixin
  implements BaseTextMixinType
{

Should I make changes to prettier or eslint?

Answer №1

To optimize your code formatting, it is crucial to set up the eslint-config-prettier extension for eslint. This will override all formatting rules from other eslint plugins.

In addition, delete any eslint regulations related to formatting and allow prettier to manage it completely.

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

The impact of redefining TypeScript constructor parameter properties when inheriting classes

Exploring the inner workings of TypeScript from a more theoretical perspective. Referencing this particular discussion and drawing from personal experiences, it appears that there are two distinct methods for handling constructor parameter properties when ...

The 'clientX' property is not recognized on the 'Event' type in Angular2 Directive

When attempting to retrieve the X position of my mouse in an Angular2 Directive using the following code: @HostListener('mousemove', ['$event']) onMousemove(event: Event): void { console.log(event.clientX) } I encountered an error ...

Troubleshooting Angular 14 Custom Form Control Display Issue

I'm facing an issue while attempting to develop a custom form control in Angular 14. Despite no errors showing up in the console, my custom control is not rendering as expected. When inspecting the Elements tab in the console, I can see the parent com ...

The error message "Property 'DecalGeometry' is not found in the type 'typeof "..node_modules/@types/three/index"'."

Within my Angular6 application, I am utilizing 'three.js' and 'three-decal-geometry'. Here is a snippet of the necessary imports: import * as THREE from 'three'; import * as OBJLoader from 'three-obj-loader'; import ...

Launching a React project on GitHub Pages

I am facing an issue while trying to deploy my react application on Github Pages. The 'npm run deploy' command is not executing as expected. This project file serves as a test application for a new React App. Here's a screenshot of my vscod ...

What could be the reason for React failing to compile my local module that includes an Interface?

I've created a shared module that is utilized by both a React and Backend module. This module consists of two essential files: index.ts and package.json. The content of package.json is as follows: { "name": "app-shared", " ...

Determining the generic data type without an actual instance of the generic

Is it possible to determine the generic type without having an instance of it? For example: doThing<T extends Foo | Bar>(someArg: string): T { if (T extends Foo) return functionThatReturnsFoo(someArg); else return functionThatReturnsBar(someArg ...

Having trouble importing the hash-set module in TypeScript/SystemJS?

In the midst of developing an Aurelia project with TypeScript to generate JavaScript, I decided to incorporate another custom library called 'hash-set' (installed using jspm install npm:hash-set --save). However, I encountered difficulties in act ...

Is Angular 2 Really Suitable for Multi-Page Applications?

I am currently working on a multi-page app using Angular2 and have noticed that the load times are slower than desired when in development mode. While searching for solutions, I came across a thread on stackoverflow that explains how to set up Angular2 fo ...

Changing the Date Format in Reactive Forms: A Guide

I need to update the date format displayed in my field within Reactive forms. Currently, it shows as "16-03-1999" but I want it to display as "March 16, 1999." Here is the relevant code: In my TypeScript file: this.companyForms = this.fb.group({ }) I a ...

Using TypeScript to create enumerations that contain both strings and numbers

I am working on an interface that includes a property named mathAction, which should only have specific values from the MathActionEnum below. interface mathTest { mathAction: MathActionEnum; } The MathActionEnum consists of the following values: enum M ...

Angular4 allows for the creation of a div that can horizontally scroll

Below is the HTML code I am working with: <div class="card-deck" fxLayout.xs="row" style="overflow: scroll; height:100%"> <md-card style="width:10rem" *ngFor="let make of filteredMakes" (click)="goToModels(make.niceName)" class=" ...

Utilize object destructuring in React when implementing pagination functionality and incrementing the page by one

Whenever the bottom of this div is reached, I want to add one to the page. However, I keep getting an error saying "use object destructuring" and I'm not sure how to resolve it. Below is the code snippet: const vendorContainer = documen ...

Set up eslint to utilize the standard import configuration

Having some trouble setting up eslint for @material-ui in this specific scenario: I want to import like this: import Typography from '@material-ui/core/Typography'; and not import like this: import { Typography } from '@material-ui/core&ap ...

What is the best approach to have a method in the parent class identify the type based on a method in the child class using TypeScript?

I'm faced with a code snippet that looks like this. class Base{ private getData(): Data | undefined{ return undefined } public get output(): Data | undefined { return { data: this.getData() } } } class ...

Determine the return type of a related function

My goal is to achieve the following functionality: const columns: ColumnDefinition<Pair>[] = [ { label: 'Pair', value: pair => (all ? pair.code : pair.second.code), format: result => result.toUpperCase() }, { label: 'P ...

Broadcasting events across the entire system

I'm trying to accomplish something specific in Angular2 - emitting a custom event globally and having multiple components listen to it, not just following the parent-child pattern. Within my event source component, I have: export class EventSourceCo ...

Create a fake version of ElementRef and simulate the getBoundingClientRect() function

Looking to simulate ElementRef and access getBoundingClientRect() I experimented with the code below, but it didn't yield the expected results. const mockHostRef = { nativeElement: { getBoundingClientRect: {top: 10, left: 10} } } {pr ...

Error: The variable "document" is not defined in the context of NextJS TypeScript

Here is the import trace for the requested module: ./app/StarrySky.tsx ./app/resume/page.tsx ✓ Compiled in 425ms (711 modules) ⨯ app\StarrySky.tsx (9:4) @ document ⨯ ReferenceError: document is not defined Trying to set const vw equal to the ma ...

What are the steps to set up eslint-airbnb on your development environment

After successfully running the command ( export PKG=eslint-config-airbnb; npm info "$PKG@latest" peerDependencies --json | command sed 's/[\{\},]//g ; s/: /@/g' | xargs npm install --save-dev "$PKG@latest" ), I proceeded to run esl ...