What rule do you want to change?
max-classes-per-file
What change do you want to make?
Generate fewer warnings
How do you think the change should be implemented?
A new default behavior
Example code
/*eslint max-classes-per-file: "error"*/
class Foo {}
class Bar {}
What does the rule currently do for this code?
Currently, the rule reports on the Program node, so editors will highlight the entire file. This is noisy because the violation is caused by the presence of an additional class, not by every line in the file.
What will the rule do after it's changed?
Ideally, the rule would report on a smaller, more precise location, such as the class head for the class that exceeds the configured limit. For example, in the code above, the violation could be reported on class B.
Another alternative would be to keep reporting from Program:exit, but use the same effective range that Program had before the v10 range change:
loc: {
start: node.body[0].loc.start,
end: node.body.at(-1).loc.end,
}
This would not be as precise as reporting on the class that exceeds the limit, because it would still cover the program body. However, it would avoid including leading/trailing comments in the reported range and would restore behavior closer to v9. For example:
/* leading file comment */
/* eslint-disable max-classes-per-file */
class A {}
class B {}
In v9, this disable comment suppresses the violation. In v10, it does not.
Participation
AI acknowledgment
Additional comments
No response
What rule do you want to change?
max-classes-per-file
What change do you want to make?
Generate fewer warnings
How do you think the change should be implemented?
A new default behavior
Example code
What does the rule currently do for this code?
Currently, the rule reports on the
Programnode, so editors will highlight the entire file. This is noisy because the violation is caused by the presence of an additional class, not by every line in the file.What will the rule do after it's changed?
Ideally, the rule would report on a smaller, more precise location, such as the class head for the class that exceeds the configured limit. For example, in the code above, the violation could be reported on
class B.Another alternative would be to keep reporting from
Program:exit, but use the same effective range thatProgramhad before the v10 range change:This would not be as precise as reporting on the class that exceeds the limit, because it would still cover the program body. However, it would avoid including leading/trailing comments in the reported range and would restore behavior closer to v9. For example:
In v9, this disable comment suppresses the violation. In v10, it does not.
Participation
AI acknowledgment
Additional comments
No response