Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule probosal: scope disable comments by blocks. #250

Open
seiyab opened this issue Jan 26, 2025 · 1 comment
Open

Rule probosal: scope disable comments by blocks. #250

seiyab opened this issue Jan 26, 2025 · 1 comment

Comments

@seiyab
Copy link

seiyab commented Jan 26, 2025

Proposed rule prevents forgetting to enable eslint rule again after disabling it. I suggest block should be a good boundary to disable / enable rule.

Examples
correct:

function f(x) {
  /* eslint-disable no-unused-vars */
  var a;
  return x * 2;
  /* eslint-enable no-unused-vars */
}

function g(x) {
  return (y) => {
    /* eslint-disable no-unused-vars */
    var a;
    return x + y;
    /* eslint-enable no-unused-vars */
  }
}

incorrect:

function f(x) {
  /* eslint-disable no-unused-vars */
  var a;
  return x * 2;
}

function g(x) {
  return (y) => {
    /* eslint-disable no-unused-vars */
    var a;
    return x + y;
  }
  /* eslint-enable no-unused-vars */
}

autofix:

function f(x) {
  /* eslint-disable no-unused-vars */
  var a;
  return x * 2;
  /* eslint-enable no-unused-vars */
}

function g(x) {
  return (y) => {
    /* eslint-disable no-unused-vars */
    var a;
    return x + y;
    /* eslint-enable no-unused-vars */
  }
  /* eslint-disable no-unused-vars */
}

Object literal and array literal can also be good boundaries.

correct:

const x = {
  /* eslint-disable object-shorthand */
  a: a,
  b: b,
  /* eslint-enable object-shorthand */
}
@seiyab
Copy link
Author

seiyab commented Jan 27, 2025

Adding an option to disable-enable-pair might be better approach than new rule?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant