question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow an `/* eslint */` alternative to apply until overridden by another such directive (or if disabled)

See original GitHub issue

Hi,

I sometimes have need for a rule to have different configuration within a single file. The inline /* eslint */ directive is close to what I want as it allows defining a rule inline, but doesn’t seem to allow changing within a file.

I do not wish to use /* eslint-disable */ directives as I want the rule to apply at different points, just with different options.

For example, in one file, I want to add:

  /* eslint 'jsdoc/require-jsdoc':
    ['error', {contexts: ['Property']}] */

…preceding an object whose properties I want to be forced to have a jsdoc description.

But I don’t want properties everywhere in the document to be forced to have jsdoc blocks as this would be very cumbersome for our project, yet it appears to be the case when I use the directive as above.

I see that adding a subsequent /* eslint */ directive will override the previous one, but the overriding directive will then apply (retroactively) to the whole file and not only to the content following it.

I’d therefore like to have a directive which can add or change a rule and later change the options for that rule (and ideally also be able to revert to the default, especially since some rules configuration can be very verbose).

Note that I do not wish to entirely disable the rule, so having, for example, an overrides specific to this file and then using disable/enable directives does not suffice for my use case.

(Also, if I can ask, as I assume it has been considered, why single-line comments are not supported, e.g., // eslint-disable doesn’t work though /* eslint-disable */ does?)

Update: Note that the proposed directive would need to be disabled when running no-inline-config.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
mysticateacommented, Mar 5, 2020

In common, rules use information from the whole code in order to report errors, therefore I think that context.getOptions(loc) will introduce huge complexity to the ecosystem. I can’t think it’s good.

Instead, maybe, linter can make multiple instances of a rule for each option if option’s changes existed in the code, then ignore errors outside of valid ranges. In that case, I think that the ecosystem doesn’t need to fix their rules except for the rules that use global state.

1reaction
mdjermanoviccommented, Mar 4, 2020

This makes sense, but it looks like a serious breaking change for rules (core rules and plugins).

In order to support this, context.options should be removed from the API and replaced with something like context.getOptions(loc) where loc is the location that would be reported.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rules - ESLint - Pluggable JavaScript Linter
Rules are the core building block of ESLint. A rule validates if your code meets a certain expectation, and what to do if...
Read more >
Turning off eslint rule for a specific file - Stack Overflow
1) Disabling "All rules"​​ Two ways you can do this: Put /* eslint-disable-line */ at the end of the line(s), or /* eslint-disable-next-line...
Read more >
angular-eslint/README.md at main - GitHub
@angular-eslint/builder - An Angular CLI Builder which is used to execute ESLint on your Angular projects using standard commands such as ng lint....
Read more >
Migrating and configuring Eslint with Angular 11
It allows for plugins, different parsers, overrides, ... but a brief explanation is that eslint:recommended adds some basic rules such as no ...
Read more >
eslint-plugin-disable - npm Package Health Analysis - Snyk
To disable plugins for file paths use new ESLint 6+ Overrides feature in config (.eslintrc). It has many different configurations for glob path...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found