selaux/eslint-plugin-filenames

Multiple match-regex / match-exported rules (based on file extension)

Closed this issue · 8 comments

My helpers are named and exported using normal camelCase:

// helperFunction.js

const helperFunction = () {
  ...
}

export default helperFunction;

However, my React components use PascalCase:

// SomeComponent.jsx.js

class SomeComponent extends Component {
  ...
}

export default SomeComponent;

Lastly, my tests use a dual extension:

// SomeComponent.tests.js
describe('SomeComponent', function() {
  ...
});

Right now, there doesn't seem to be a way to specify multiple rules based on these file types. Any ideas on how to configure multiple styles for different parts of the same project?

I see it as a two-fold problem:

  1. PascalCase is not supported as a transform, would be great to add it
  2. Being able to set the transform based on the file extension.

I.e., all js files -> camelCase and all jsx.js files -> PascalCase

So, adding PascalCase would not be a problem. For the extensions I want to refer to eslint/eslint#3611 and hope that that will be implemented soon.

@selaux cool. Would it be possible to specify an array of transforms? I.e. ['camel', 'pascal'] to let the plugin know that we're cool with either one? Some of my files, such as components, are Pascal case per react best practices, but most others are normal camel per generic javascript best practices.

I think there is one additional (related) problem. Filenames that have dual suffixes, such as:

componentName.jsx.js
componentName.styles.js
componentName.tests.js

These all get flagged, even though the core name is indeed camelCase. Is there a way around this?

I was able to selectively disable this plugin based on the file path / name using https://github.com/mradionov/eslint-plugin-disable#file-paths

To address your other problems, you can use a custom regex, something like (untested) "([A-Za-z][a-z0-9]+)([A-Z][a-z0-9]+)+(\.styles|\.test)*"

@joncursi Can you have a look at #17 to see whether this improves things (PascalCase and multiple transforms now supported)?

👍