Having trouble with @typescript-eslint/member-ordering feature not functioning properly?

Ensuring a precise ordering in TypeScript classes is my goal, with a specific emphasis on enforcing alphabetical order within groups.

To achieve this, I am refering to the following documentation:

Shown below is the member-ordering configuration extracted from my .eslintrc file:

"@typescript-eslint/member-ordering": [
      "error",
      {
          "default": {
            "memberTypes": [
              "public-static-field",
              "protected-static-field",
              "private-static-field",
              "public-instance-field",
              "public-decorated-field",
              "public-abstract-field",
              "protected-instance-field",
              "protected-decorated-field",
              "protected-abstract-field",
              "private-instance-field",
              "private-decorated-field",
              "private-abstract-field",
              "static-field",
              "public-field",
              "instance-field",
              "protected-field",
              "private-field",
              "abstract-field",
              "constructor",
              "public-static-method",
              "protected-static-method",
              "private-static-method",
              "public-method",
              "protected-method",
              "private-method"
            ],
            "order": "alphabetically"
          }
      }
    ],

In my current setup, no errors are being generated despite expecting 2 errors: incorrect member ordering (private should come after public) and incorrect alphabetical sequence.

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

Eslint is successfully running as I'm receiving other error notifications related to naming conventions and more.

Answer №1

Upon further examination, I have discovered that categorizing memberTypes and ordering separately is effective. Initially, it seemed as though the documentation combined these two properties, but now I suspect it may be a bug.

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

In my text editor:

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

Answer №2

Here is a collection of ordering rules influenced by this particular source:

// Index signature
"signature",
"call-signature&quOt;,

// Fields
"public-static-field&Quot;,
"protected-static-field&quoT;,
"private-static-field&QUOte;,
"#private-static-field&qUoT;&Comma;

"public-decorated-field"e;',
"protected-decorated-field"",
"private-decorated-field&qUOt;,

"public-instance-field&qUOf;&Comma;
"protected-instance-field&QuOT,;
"private-Instance-field&qquot;;;
"#private-inStAnCe-fiElD&sEMIquot;s

"publIc-entity-fielD&compLICAt;iOn&SemicolonS;
.......</answer2>
    </div></answer2>
<exanswer2><div class="answer" i="75024648" l="4.0" c="1672944072" v="-3" a="TS5TaGFo" ai="7798447">
<p>Explore this list inspired by <a href="https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/member-ordering.md#default-configuration" rel="nofollow noreferrer">this resource link</a>:</p>
<pre><code>// Index signature
"signature",
"call-signature",

// Fields
"public-static-field",
"protected-static-field",
"private-static-field&quoRt;,
"#private-stAtic-field",

"public-decorated-field&quOt;,
"protected-decorated-field&qUoT;,
"private-decorated-field&QUot;,

"public-instance-field",
"protected-instaNce-field",
"private-InstAnCe-fielD&qUoT;,
"#privAte-inStANcE-fiEld",

"public-abSTract-field",
"protecTed-aBStract-fIeld",

"pubLic-fiELd&QUoT;&Comma;
"prOTECTed-fIElD"&COmma;
"priVATe-FIELD&qUoT;&commA;
"#priVaTE-FieLd&qUoT;&CoMMA;

"statiC-fiElD&qUOT;&CoMmA;
"instAncE-fiELD"&coMMa;
"aBStraCT-FIelD&qUOT;&coMmA;

"dECOrateD-fiEld"&comMa;

"fiEld&qUOt;&compLaCE;

// Static initialization
"statIC-initiALization&qUot;&COMMA;

// Constructors
"puBliC-ConSTruCtor"&coMmA;
"protECTEd-coNsTructOR"&Comma;
"privatE-conStruCtoR&QuOt;&coMmA;

"cONstruCTor&qUOta&Cute;;

// Getters
"public-Static-get&quoT;&coMmA;
"ProtectED-sTaTiC-gEt&QuOT;&CoMmA;
"prIVAte-stAtiC-get&qUOt;&CoMMA;
"#PriVAte-STatic-gET&qUOt;&CoMmA;

"PubLiC-DecoRaTed-Get&qUOf;&CoplaSS;
"PROTECTED-DecORATEd-GET&QUOrd;&COmmasS;
"PRIVATE-DECorATED-GEt&qUSAnd;&comMAS;

"PuBLIC-insTance-GET"&comMasS;
"PRoTecTED-instANCe-Get<CommAsS;
"PrIVatE-instaNCE-Ge####&coMmasss;
"#privAte-iNsTanCE-geT&quoT;,&commAsss;

"MTrixCC&assss";</answer2>
<exanswer2><div class="answer" i="75024648" l="4.0" c="1672944072" v="-3" a="TS5TaGFo" ai="7798447">
<p>Go through this arrangement list following <a href="https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/member-ordering.md#default-configuration" rel="nofollow noreferrer">https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/member-ordering.md#default-configuration</a>:</p>
<pre><code>// Index signature
"signature",
"call-signature",

// Fields
"public-static-field",
"protected-static-field",
"private-static-field",
"#private-static-field",

"public-decorated-field",
"protected-decorated-field",
"private-decorated-field",

"public-instance-field",
"protected-instance-field",
"private-instance-field",
"#private-instance-field",

"public-abstract-field",
"protected-abstract-field",

"public-field",
"protected-field",
"private-field",
"#private-field",

"static-field",
"instance-field",
"abstract-field",

"decorated-field",

"field",

// Static initialization
"static-initialization",

// Constructors
"public-constructor",
"protected-constructor",
"private-constructor",

"constructor",

// Getters
"public-static-get",
"protected-static-get",
"private-static-get",
"#private-static-get",

"public-decorated-get",
"protected-decorated-get",
"private-decorated-get",

"public-instance-get",
"protected-instance-get",
"private-instance-get",
"#private-instance-get",

"public-abstract-get",
"protected-abstract-get",

"public-get",
"protected-get",
"private-get",
"#private-get",

"static-get",
"instance-get",
"abstract-get",

"decorated-get",

"get",

// Setters
"public-static-set",
"protected-static-set",
"private-static-set",
"#private-static-set",

"public-decorated-set",
"protected-decorated-set",
"private-decorated-set",

"public-instance-set",
"protected-instance-set",
"private-instance-set",
"#private-instance-set",

"public-abstract-set",
"protected-abstract-set",

"public-set",
"protected-set",
"private-set",
"#private-set",

"static-set",
"instance-set",
"abstract-set",

"decorated-set",

"set",

// Methods
"public-static-method",
"protected-static-method",
"private-static-method",
"#private-static-method",

"public-decorated-method",
"protected-decorated-method",
"private-decorated-method",

"public-instance-method",
"protected-instance-method",
"private-instance-method",
"#private-instance-method",

"public-abstract-method",
"protected-abstract-method",

"public-method",
"protected-method",
"private-method",
"#private-method",

"static-method",
"instance-method",
"abstract-method",

"decorated-method",

"method"

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

Angular does not propagate validation to custom form control ng-select

In my Angular 9 application, I am utilizing Reactive Forms with a Custom Form Control. I have enclosed my ng-select control within the Custom Form Control. However, I am facing an issue with validation. Even though I have set the formControl to be requir ...

Finding a solution to the type issue of error handling in Route Handler with NextJS

I'm working on a route handler located at app/api/transactions/route.ts. Here's a snippet of the code: import { NextRequest, NextResponse } from "next/server"; import { AxiosError } from "axios"; import axios from "../axi ...

Having trouble deserializing date time in JSON while using ASP.NET, C#.NET or VB.NET with WCF WebService

When I receive datetime in JSON format as - "\/Date(1261413600000+0530)\/" I am utilizing the DataContractJsonSerializer.ReadObject method in my code behind to deserialize the data. However, the converted datetime is not accurate. What is the ...

Exploring the mapping of JSON data to class structures in Kotlin

As a newcomer to Kotlin, I am looking for an efficient way to copy a JSON structure into another one. The API `getData()` returns a data structure defined like this: data class DataA( var id: String, var cartItems: List<CartItem>, } Now, ...

Optimal techniques for utilizing Redis with JSON data

Previously, I stored JSON data in Memcache and then read and iterated through it. Now, what would be the best practice for achieving this with Redis? Should I store the JSONs or use SETS? ...

Looking to effortlessly move and arrange items with ng2-drag-drop in Angular 2?

I have encountered a problem with the ng2-drag-drop library. I am trying to drag and drop items from one div to another, and then freely move the dropped item within the droppable area. One issue I'm facing is that when I drop my draggable item in th ...

Sending a JSON array to a WebMethod

I encountered an issue when attempting to convert an object to a JSON array as a string, resulting in an Internal Server Error. Fortunately, the GetServerTime method is functioning properly. My goal is to send an array of objects to the server and conver ...

Tips for effectively sending prop to a component in React with the help of TypeScript

Hey there, I'm working on a component called FormField which can accept either an icon for create or edit. Currently, I am using this FormField inside another component called SelectWithFormField. Here's how it looks: const FormField = ({create, ...

Exploring the Connection with JSON-server

While creating a simulated API using json-server, I encountered an issue with passing a query. When utilizing _expand, I am able to display the parameters of a relationship, but it doesn't seem to work when the relationship is nested within a child. ...

Creating a function in Typescript that transforms an array into a typed object

Recently, I have started learning TypeScript and I am working on a function to convert arrays from a web request response into objects. I have successfully written the function along with a passing unit test: import { parseDataToObject } from './Parse ...

Tips for refreshing the modified toggle in angular2

I currently have a newsletter subscription that is initially set based on the newsletter I receive when the user logs in. However, when I toggle the newsletter option, I receive a "successfully updated" message but the newsletter remains set to false even ...

What are the steps to create a dynamic navigation menu in Angular 2?

I have successfully implemented this design using vanilla CSS and JS, but I am encountering challenges when trying to replicate it in Angular 2. Setting aside routing concerns, here is the current state of my component: navbar.component.ts import { Comp ...

receiving JSON data in Java RESTful web services using the Jersey framework (javax.ws.rs.*)

I am facing an issue with passing a json contentType to the glassfish server where I have set up a java restful web service. My POST request is coming from Node.js using needle : var options = { json: true, headers: {'Content-Type':&apo ...

Is there a way to utilize Typescript enum types for conditional type checking?

I'm working with restful services that accept enum values as either numbers or strings, but always return the values as numbers. Is there a way to handle this in TypeScript? Here's my attempt at it, although it's not syntactically correct: ...

Exploring the method to extract a value from an array of objects using JSON parsing in Appcelerator

Visualize an artificial json response, here's the string representation of this JSON... [{"A":"1","B":{"name":"joe","lastname":"jones"},"COLORS:{"red":"rojo","blue":"azul"},"active":"yes"}] I am aiming to extract the name "joe" using the following c ...

The constructor for Observable, as well as static methods such as `of` and `from`, are currently

I encountered a challenge in my angular application while trying to create an observable array using rxjs. Here is the code snippet: import { Injectable } from "@angular/core"; import { Observable } from "rxjs/Rx"; import { User } from "../model/user"; ...

A guide on creating a default constructor for a complex object structure within a JSON format

Currently, I am working with JSON and JUnit. My goal is to establish a complex object structure using JSON, but I am encountering an issue while attempting to create this structure. The exception message that I receive states: Registering an InstanceCreat ...

Retrieve an object containing properties specified in the function's parameter list

I am currently working on developing a function that can dynamically create and return an object with properties based on an array of strings provided as parameters. type Foods = 'apple' | 'banana' | 'pear'; function foodObje ...

Transform a list of objects into individual properties of an object

Is there a way to convert a collection of objects into JSON format using Newtonsoft.Json? For example, suppose we have the following class and list: class Item { public string Name { get; set; } public string Prop1 { get; set; } } var items = ne ...

Tips on leveraging an attribute for type guarding in a TypeScript class with generics

Is there a way to utilize a generic class to determine the type of a conditional type? Here is a basic example and link to TS playground. How can I access this.b and this.a without relying on as or any manual adjustments? type X<T> = T extends true ...