The Typescript ESLint Indent rule seems to struggle with properly indenting multi-line object parameters

I'm facing an issue with my code block that appears like this:

this.$api
  .get<AxiosResponse<Resource>>('/resources/', {
    params: {
      pageNumber: 1,
      pageLength: 10,
    }
  });

For some reason, my typescript ESLint is automatically formatting the codeblock as shown below:

this.$api
  .get<AxiosResponse<Resource>>('/resources/', {
  params: {
    pageNumber: 1,
    pageLength: 10,
  }
});

This formatting is causing confusion and I don't find it ideal. A similar issue has been discussed for @typescript-eslint here.

What steps can I take to update my ESLint configuration to prevent this behavior?

Here's my current ESLint configuration:

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

module.exports = {
  root: true,
  extends: [
    'plugin:vue/vue3-essential',
    'eslint:recommended',
    '@vue/eslint-config-typescript/recommended',
  ],
  env: {
    'vue/setup-compiler-macros': true,
  },
  overrides: [
    {
      files: ['cypress/integration/**.spec.{js,ts,jsx,tsx}'],
      extends: ['plugin:cypress/recommended'],
    },
  ],
  rules: {
    quotes: [2, 'single', { avoidEscape: true }],
    indent: 'off',
    '@typescript-eslint/no-unused-vars': 'off',
    ... (Remaining content abbreviated for brevity)
    }
};

Answer №1

After exploring various threads with closed issues and no answers, I finally uncovered the solution to this problem. The key is to instruct Typescript ESLint to disregard the arguments in a call expression. Additionally, I configured the @typescript-eslint/indent rule to ignore several other node types using the ignoredNodes property.

Remember, it is crucial to also disable the default indent rule.

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

module.exports = {
  root: true,
  extends: [
    'plugin:vue/vue3-essential',
    'eslint:recommended',
    '@vue/eslint-config-typescript/recommended',
  ],
  env: {
    'vue/setup-compiler-macros': true,
  },
  overrides: [
    {
      files: ['cypress/integration/**.spec.{js,ts,jsx,tsx}'],
      extends: ['plugin:cypress/recommended'],
    },
  ],
  rules: {
    quotes: [2, 'single', { avoidEscape: true }],
    indent: 'off',                                  // !!!! VERY IMPORTANT !!!!
    '@typescript-eslint/no-unused-vars': 'off',
    'vue/max-attributes-per-line': [
      'error',
      {
        singleline: {
          max: 1,
        },
        multiline: {
          max: 1,
        },
      },
    ],
    'vue/html-indent': [
      'error',
      2,
      {
        attribute: 1,
        baseIndent: 1,
        closeBracket: 0,
        alignAttributesVertically: false,
        ignores: [],
      },
    ],
    'vue/html-closing-bracket-newline': [
      'error',
      {
        singleline: 'never',
        multiline: 'always',
      },
    ],
    'vue/script-indent': [
      'error',
      2,
      {
        baseIndent: 0,
        switchCase: 1,
        ignores: [],
      },
    ],
    'vue/attributes-order': [
      'error',
      {
        order: [
          'DEFINITION',
          'LIST_RENDERING',
          'CONDITIONALS',
          'RENDER_MODIFIERS',
          'GLOBAL',
          ['UNIQUE', 'SLOT'],
          'TWO_WAY_BINDING',
          'OTHER_DIRECTIVES',
          'OTHER_ATTR',
          'EVENTS',
          'CONTENT'
        ],
        'alphabetical': false
      }
    ],
    '@typescript-eslint/indent': [
      'error',
      2,
      {
        SwitchCase: 1,
        ObjectExpression: 1,
        MemberExpression: 1,
        CallExpression: {
          arguments: 1,
        },
        'ignoredNodes': [
          'PropertyDefinition[decorators]',
          'TSUnionType',
          'FunctionExpression[params]',
          'CallExpression[arguments]',              // !!!! VERY IMPORTANT !!!!
        ],
      }
    ]
  },
};


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

What exactly do the values 0, 1, and 2 represent in an eslintrc configuration file?

"react/jsx-uses-vars": 2, Within the rules object of my .eslintrc file, I have set this property along with others to values of 0, 1, and 2. Can you explain what each of these values signifies? ...

Ensure that the dynamically inserted <title> tag remains intact in Angular even when the page is re

Can the dynamic title tag be preserved when the page is refreshed? When I refresh the page, the title tag reverts back to the original one specified in the index.html temporarily before switching back to the dynamically added one. I want the title tag to ...

Is it possible in TypeScript to change a string literal type into a number type?

Would it be feasible to develop a utility type Number<T> that can take a string literal type and convert it into a number? If conversion is not possible, should the utility return a never type? type Five = Number<'5'> // `Five` is con ...

What is the method for utilizing enum values as options for a variable's available values?

I'm curious about using enum values in TypeScript to restrict the possible values for a variable. For example, I have an enum named FormType with Create and Update options. Is there a way to ensure that only these enum values are used? enum FormType { ...

What are the steps to restrict a user from accessing a specific website?

In my Vue.js project, I've implemented a function that hides a specific menu item for users with insufficient permissions: <a :href="href" @click="navigate" v-if="hideMenuItem()"> // some code </a> hideMe ...

Binding iframes in Angular 6

Is there a way to display iframe code stored in a variable within a div? Here's the HTML code: <div class="top-image" [innerHTML]="yt"></div> And here's the TypeScript code: yt = '<iframe class="w-100" src="https://www.you ...

Navigate using history.push with user Logout Icon

Currently, I am utilizing a Material UI icon as a logout button in my project. Here is how I have implemented it: function logout(props:any){ localStorage.removeItem("token"); return( <Redirect to="/login" /> ) //props.history.push("/log ...

Is there a way to implement a pipe function in TypeScript?

Introducing a unique pipe function implemented in plain JavaScript: const customPipe = (f, ...fs) => x => f === undefined ? x : customPipe(...fs)(f(x)) const exampleFunction = customPipe( x => x + 1, x => `wow ${x * 2} this is an amaz ...

Can someone explain the meaning of these AngularCli errors, especially when no issues are detected in VsCode?

Following up on my previous question posted here: Additionally, I am encountering these errors specifically in the Terminal. While I am not new to Angular, I am fairly new to FireStore and Firebase :) After setting up a Firebase account for the first tim ...

Is it not allowed to use the '<>' type assertion, you should use 'as' instead?

Below is a test scenario present in my spec file, it (should create,()=>{ const url = (<jasmine.spy> http.get).calls.args(0)[0] expect(url).toBe('/api/get') }); Upon execution, I encounter the following linting issue. Type ...

The term 'string' is typically employed as a data type, yet in this instance it is being utilized as an actual value

Just started working with TypeScript and encountered an issue while trying to set the state. Encountered this error message: 'string' is a type and cannot be used as a value here. const state = reactive({ user: { uid: "", ...

Is there a way to programmatically add a timestamp to a form in Angular6?

Is there a way to automatically populate new forms with the current datetime value? this.editForm.patchValue({ id: chatRoom.id, creationDate: chatRoom.creationDate != null ? chatRoom.creationDate.format(DATE_TIME_FORMAT) : null, roo ...

Retrieve the object from the data received from the HTTP GET API call

I have a question that has been asked before, but I am unable to achieve the desired result with my current approach. When my service retrieves data from an API, it returns results in the following format: { "nhits": 581, "paramete ...

What is the reason for Jest attempting to resolve all components in my index.ts file?

Having a bit of trouble while using Jest (with Enzyme) to test my Typescript-React project due to an issue with an alias module. The module is being found correctly, but I believe the problem may lie in the structure of one of my files. In my jest.config ...

ability to reach the sub-element dictionaries in typescript

class ProvinciaComponent extends CatalogoGenerico implements OnInit, AfterViewInit { page: Page = new Page({sort: {field: 'description', dir: 'asc'}}); dataSource: ProvinciaDataSource; columns = ['codprovi ...

React 18 update causes malfunctioning of react-switch-selector component

I'm facing an issue where the component is not rendering. I attempted to start a new project but it still didn't work. Is there a solution to fix this problem or should I just wait for an update from the original repository? Encountered Error: ...

Transforming an object in TypeScript to another object while retaining the properties of the original type

Issue Struggling with TypeScript type casting here. Trying to convert an object of type B to type A, but without carrying over the properties from type B. Inquiry Is there a way to achieve this conversion without explicitly mentioning the otherName prop ...

Difficulty with index.html file in Crypto-JS (Angular 2 app)

After successfully installing crypto-js in my node_modules folder using the command npm install crypto-js, I included the following script in my index.html file so that I could use the CryptoJS.SHA256() method: <html> <head> <script s ...

What is the best way to update the image source in Angular 2?

Learn How to Get a Directive's Reference in Angular 2 Looking to swap image src on hover? Check out this helpful link for guidance:-- ...

ways to insert a fresh value into a recently instantiated object in typescript

I am currently using Angular 6 and dealing with arrays. I have an array along with a model. Here is the Array: let array = [ { id: 1, value: "Some Value", description: "Some Description" }, { id: 2, va ...