Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Description
- I have tried restarting my IDE and the issue persists.
- I haveread the FAQ and my problem is not listed.
- I have updated to the latest version of the packages.
I've update everything but Eslint from 7.32.0 to 8.0.1 because:
@angular-eslint is currently not ready Eslint 8. Seetypescript-eslint issue 4013
Repro
{rules:{'@typescript-eslint/member-ordering':'error',}}
This example angular service validates using@typescript-eslint/eslint-plugin@'^4.28.2':
@Injectable({providedIn:'root'})exportclassCaseService{publicattributes:Session;publiccontractParameters:Record<string,any>;publicpersonParameters:Record<string,any>;publicpackageSession:boolean;publicprefixList:SbiListItem[]=[];publicconsultantViewMode=false;publiceasyOfferViewMode=false;publicgetcontractLength():SbiListItem{returnthis.contractLengths ?this.contractLengths.find(({ id})=>id===this.attributes.vertragsdauer)||this.contractLengths[0] :null;}publiccountries:SbiListItem[];publicsetcountry(value:SbiListItem){this.attributes.postadresse.land=value?.id;this.updateGrenzgaenger();}publicgetzipCode():ZipCode{returnthis.attributes.postadresse?.zipCode ?this.zipCodesService.get(this.attributes.postadresse.zipCode) :null;}publicsetzipCode(value:ZipCode){this.attributes.postadresse.zipCode=value;this.selectedZipCode=value;}publicselectedZipCode:ZipCode;publicgetisRegionSelectRequired():boolean{returnthis.zipCode?.hasMultipleRegions()&&!this.attributes.postadresse.gemeinde_ro;}publicgetregion():Region{returnthis.zipCode&&this.attributes.postadresse.region ?this.zipCode.getRegion(this.attributes.postadresse.region.gemeindeNummer) :this.zipCode?.firstRegion();}privatecurrentPersonSubject:Subject<void>=newReplaySubject(1);privateberaterAttributesSubject:Subject<void>=newReplaySubject(1);constructor(privatelocationService:LocationService){}// snip ... public methods first and private methods last ...
When using `@typescript-eslint/eslint-plugin@'^5.1.0'`` the default rule results like this:
$ yarn eslint --quiet src/app/services/case.service.ts 146:3 error Member countries should be declared before all public instance get definitions @typescript-eslint/member-ordering 166:3 error Member zipCode should be declared before all public instance set definitions @typescript-eslint/member-ordering 184:3 error Member selectedZipCode should be declared before all public instance get definitions @typescript-eslint/member-ordering 186:3 error Member isRegionSelectRequired should be declared before all public instance set definitions @typescript-eslint/member-ordering 193:3 error Member region should be declared before all public instance set definitions @typescript-eslint/member-ordering 210:3 error Member currentPersonSubject should be declared before all public instance get definitions @typescript-eslint/member-ordering 211:3 error Member beraterAttributesSubject should be declared before all public instance get definitions @typescript-eslint/member-ordering 213:3 error Member constructor should be declared before all public instance get definitions @typescript-eslint/member-orderingFair enough. The default rule sais get and set should come after the constructor.
"static-field", // = ["public-static-field", "protected-static-field", "private-static-field"] "instance-field", // = ["public-instance-field", "protected-instance-field", "private-instance-field"] "abstract-field", // = ["public-abstract-field", "protected-abstract-field", "private-abstract-field"] "constructor", // = ["public-constructor", "protected-constructor", "private-constructor"] "static-get", // = ["public-static-get", "protected-static-get", "private-static-get"] "instance-get", // = ["public-instance-get", "protected-instance-get", "private-instance-get"] "abstract-get" // = ["public-abstract-get", "protected-abstract-get", "private-abstract-get"] "static-set", // = ["public-static-set", "protected-static-set", "private-static-set"] "instance-set", // = ["public-instance-set", "protected-instance-set", "private-instance-set"] "abstract-set" // = ["public-abstract-set", "protected-abstract-set", "private-abstract-set"] "static-method", // = ["public-static-method", "protected-static-method", "private-static-method"] "instance-method", // = ["public-instance-method", "protected-instance-method", "private-instance-method"] "abstract-method" // = ["public-abstract-method", "protected-abstract-method", "private-abstract-method"]But for my class this means I have dozens of triplets of field, get and set (which are mostly related between eachother) scattered to three different locations in the file. It could mean that I have to scroll and search even more in that class than I already have to anyway (it is ugly, oversized stuff, but I can't overcome that here and now).
Expected Result
So lets try to reconfigure:
'@typescript-eslint/member-ordering':['error',{default:['public-field','public-get','public-set','protected-field','protected-get','protected-set','private-field','private-get','private-set','constructor','public-method','protected-method','private-method']}],
But that is only slightly better, but still asks me to scatter stuff before the constructor:
146:3 error Member countries should be declared before all public get definitions @typescript-eslint/member-ordering 166:3 error Member zipCode should be declared before all public set definitions @typescript-eslint/member-ordering 184:3 error Member selectedZipCode should be declared before all public get definitions @typescript-eslint/member-ordering 186:3 error Member isRegionSelectRequired should be declared before all public set definitions @typescript-eslint/member-ordering 193:3 error Member region should be declared before all public set definitions @typescript-eslint/member-orderingI actually need field, get and set to be equals.
I could not figure out a config that does fill my requirements and ...
even way more importantly, doesn't ask me to change dozens of thousand lines of codemanually.
Is there no way to configure this?
Currently, I'm only left with the option to completely disable the rule for v5.0+ .
TIA for any hints.
Versions
| package | version |
|---|---|
@typescript-eslint/eslint-plugin | 5.1.0 |
@typescript-eslint/parser | 5.1.0 |
TypeScript | 4.3.5 |
ESLint | 7.32.0 |
node | 14.18.1 |
PS [EDIT]:
It looks like there might be a way to get arround this problem for us:
'@typescript-eslint/member-ordering':['error',{default:['public-field','protected-field','private-field','constructor','public-method','protected-method','private-method']}],
So perhaps in such a manner we can move around our issue. It'd be less of an issue here if that was the case.