Is it possible to enable an eslint rule for only a section of code and have it disabled for all other code?
In our case, we have a class:
export class HeaderWidget extends AbstractWidget implements HeaderWidget.State {
// tslint:disable-next-line:variable-name
public readonly widget_type: WidgetType = WidgetType.Header;
public text!: string;
public image_data!: string;
public image_data_alt!: string;
public hide_on_mobile!: boolean;
...
}
We want to make sure that any properties added to this class are snake_case. I found the naming-convention rule that I can enable with:
"@typescript-eslint/naming-convention": [
"error",
{
"format": ["snake_case"],
"selector": "classProperty"
}
]
but that enables the rule for all the code in the project. I just want to enable for properties in that specific class (or even better would be anything that extends AbstractWidget). I see additional config options like filter, custom and suffix but the docs say they apply to the identifier which leads me to believe they can't be used to pick properties within a certain class.
So I'm looking for a way to configure a rule and have it disabled by default but then enable it for a specific section of code without having to add /* eslint-disable naming-convention */ to every file.