Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

[Feature Request] Custom Rule: Require new line after import statements. #4052

Closed
lucasklaassen opened this issue Jul 17, 2018 · 5 comments
Closed
Labels
Formatting rule Relates to a rule which enforces code formatting and likely overlaps with prettier Resolution: Declined Type: Rule Suggestion

Comments

@lucasklaassen
Copy link

lucasklaassen commented Jul 17, 2018

Bug Report

  • TSLint version:5.9.1
  • TypeScript version:2.7.2
  • Running TSLint via: (pick one) VSCode

TypeScript code being linted

import { NgModule } from '@angular/core';
import { NgbModule } from '../../../../node_modules/@ng-bootstrap/ng-bootstrap';
import { SharedModule } from '../../shared/shared.module';
import { ClubMembersRoutingModule } from './club-members-routing.module';
import { ClubMembersComponent } from './club-members.component';
@NgModule({
  imports: [
    SharedModule,
    ClubMembersRoutingModule,
    NgbModule
  ],
  declarations: [
    ClubMembersComponent
  ]
})
export class ClubMembersModule {}

with tslint.json configuration:

"new-line-after-imports": true

Actual behavior

Right now there's no rule to require a new line to be included after the import statements in a typescript file. Below in the expected behavior, I've listed how the code sample above should be linted.

Expected behavior

import { NgModule } from '@angular/core';
import { NgbModule } from '../../../../node_modules/@ng-bootstrap/ng-bootstrap';
import { SharedModule } from '../../shared/shared.module';
import { ClubMembersRoutingModule } from './club-members-routing.module';
import { ClubMembersComponent } from './club-members.component';
// New Line Required Here
@NgModule({
  imports: [
    SharedModule,
    ClubMembersRoutingModule,
    NgbModule
  ],
  declarations: [
    ClubMembersComponent
  ]
})
export class ClubMembersModule {}
@rafaelss95
Copy link
Contributor

What if imports doesn't come at the top of file (btw this could be another good rule)? How can we handle this case?

@stocksr
Copy link

stocksr commented Oct 5, 2018

I would also like a rule (option on this rule) to prevent extra newlines inside the import block.

@omniscient
Copy link

@stocksr : This should be a separate request since there is already "import-spacing": true rule in place.

@amazzoccone
Copy link

Maybe we should think in rules for Typescript Decorators, because the package doesn't have any about it. Something like "newline-before-decorator"?

For example, in Stencil, you could have the following code:

  @State() device: IDevice;
  constructor() {
    ..
  }

and there is no rule to force a line between decorator and method.

@adidahiya adidahiya added Formatting rule Relates to a rule which enforces code formatting and likely overlaps with prettier Resolution: Declined and removed Status: Accepting PRs labels Feb 27, 2019
@adidahiya
Copy link
Contributor

adidahiya commented Feb 27, 2019

Sorry, I don't think we will add new formatting rules at this point. See #4534. You can maintain this rule in a custom rule set package if you'd like.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Formatting rule Relates to a rule which enforces code formatting and likely overlaps with prettier Resolution: Declined Type: Rule Suggestion
Projects
None yet
Development

No branches or pull requests

7 participants