airbnb / javascript

JavaScript Style Guide
MIT License
144.66k stars 26.45k forks source link

max-classes-per-file enabled in code but not in docs #2143

Open SeanOfTheHillPeople opened 4 years ago

SeanOfTheHillPeople commented 4 years ago

The max-classes-per-file rule is enabled in rules/best-practices.js but there is no mention of this requirement in the docs. If this is a best practice, I'd like to know why.

ljharb commented 4 years ago

The same rationale that applies to https://github.com/airbnb/javascript/tree/master/react#basic-rules (but also appears not to be documented): the whole point of modules is to make them as small and atomic and reusable as possible, which means splitting things up as much as possible.

Is there a specific use case where you think this rule shouldn't apply?

SeanOfTheHillPeople commented 4 years ago

Thanks! I'll have a look at our offending modules with the team to see if there's a case for keeping them together.

SteveThorpe commented 4 years ago

I would advocate for the use of a single module for model and controller classes for the same 'component' (in non-React ES6)

ljharb commented 4 years ago

@SteveThorpe that presumes the MVC pattern is an ideal one to be following for the frontend, react or otherwise :-)

SteveThorpe commented 4 years ago

@ljharb MVC is far from ideal (IMO), even for our codebase. But if you are starting out with a codebase that is 'sort-of' MVC and, have a directive to impose AirBnb style on it, then the max-classes-per-file rule makes things worse (again, IMO)

SteveThorpe commented 4 years ago

@ljharb So would you agree that if you are stuck with the MVC pattern then you could be justified in turning off the max-classes-per-file rule? ;)

ljharb commented 4 years ago

You can always turn off any rules that aren't a good fit for your use case - the Airbnb config assumes you're using Babel, targeting both web and node, using React, etc.

ghost commented 4 years ago

i rendered a repository from json after reciving a web token from releasing my notes curious to know what all it is. can anyone help?

ljharb commented 4 years ago

@clout4sad this seems pretty unrelated to this repo, which is a javascript style guide. I'd suggest IRC or stack overflow.