CorentinDoue / eslint-disable-inserter

Inserts eslint-ignore comments automatically
28 stars 2 forks source link

[idea] filter callback #8

Open dylang opened 2 months ago

dylang commented 2 months ago

I'm using this programmatically, and it would be nice if we had control to sometimes not write the comment.

For example:

eslintDisableInserter(JSON.stringify(results), {
  dryRun: false,
  fixMe: true,
  filter: ({ filename, ruleName }) => {
    // we're always going to want the comments in tests
    if (filename.includes('.test.')) {
      return true;
    }

    // We'll fix these manually.
    if (ruleName === '@typescript-eslint/ban-ts-comment') {
      return false;
    }

    return true;
  }
});
CorentinDoue commented 2 months ago

I suggest adding an optional option:

export type Options = {
  dryRun: boolean;
  fixMe: boolean;
  customCommentCallback?: (args: { filename: string; ruleName: string; }) => string | boolean;
}

Which override the fixMe option per file / rule and enable to use custom comments when returning a string.

I'm not sure to have the time to add this soon, but feel free to contribute

dylang commented 2 months ago

I like that even better, then the FIXME could include a ticket number or developer responsible. 😄

dylang commented 2 months ago

I can look into trying to add this possibly next week.