dprint-plugin-typescript icon indicating copy to clipboard operation
dprint-plugin-typescript copied to clipboard

eslint next-line directives are broken on format

Open joscha opened this issue 4 years ago • 0 comments

Not a bug but something to consider. I am not sure if this just needs to be handled manually, maybe?

Example:

// eslint-disable-next-line no-restricted-properties
getNavigateToHelpTroubleshootingArticle = makeActionGetter(this.navigateToHelpTroubleshootingArticle.bind(this));

formats to:

// eslint-disable-next-line no-restricted-properties
getNavigateToHelpTroubleshootingArticle = makeActionGetter(
  this.navigateToHelpTroubleshootingArticle.bind(this),
);

now the forbidden property is .bind, and because of the reformat, the eslint-disable-next-line is now pointing to a line that does no longer have the property.

Ideally (this would need semantic understanding of the rule and is quite tricky) this would reformat to:

getNavigateToHelpTroubleshootingArticle = makeActionGetter(
  // eslint-disable-next-line no-restricted-properties
  this.navigateToHelpTroubleshootingArticle.bind(this),
);

There are two simpler alternatives:

  1. Do not break lines up that follow an // <some-tool>-disable-next-line directive, e.g. just leave the next line unformatted
  2. transform the one liner into:
    /* eslint-disable no-restricted-properties */
    getNavigateToHelpTroubleshootingArticle = makeActionGetter(
      this.navigateToHelpTroubleshootingArticle.bind(this),
    );
    /* eslint-enable no-restricted-properties */
    
  1. is simple but not ideal
  2. is a bit more tricky and requires maybe some keyword formatting, but because before the rule was applied to the whole next line, it is safe to split it and mark the block as such.

joscha avatar Aug 26 '21 15:08 joscha