Suggested expansion of the "Default export names and file names should match" rule

In JavaScript, there is the code smell rule “Default export names and file names should match”. This is a good rule, but a frustration that we have had is that we often use extra extensions in our file names, like MyComponent.form.js or login.service.js.

So we end up with:

// file path: MyComponent.form.jsx
class MyComponentForm {
  // ...
}
export default MyComponentForm;  // currently noncompliant

Of course, we can’t name the variable “MyComponent.form” so we just turn it into Pascal case.

We could just stop using those extra extension, but we think that it adds clarity. In the meantime we’ve just written a custom linter rule to catch this at development time so we can turn off the SonarQube rule. But I think this would be an enhancement to the existing rule.

My suggestion is that the functionality of this rule should stay the same except that if there is an “extra extension” in the file name, that those should be appended to the expected filename with the first letter capitalized. So, for MyComponent.form.js it would expect “MyComponentForm” as the default export name, and similarly, login.service.js would expect “loginService”. I think this would allow people to use this pattern and still be in the spirit of the underlying principle.