New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[camelcase] Remove rule from recommended config #1358
Comments
As mentioned in #651 (comment)
camelcase has been in recommended config since the recommended config was added for this plugin. I put forward that comment for commenting, and nobody suggested directly the rule be removed, just that stylistic rules be removed in general. We removed the majority of the stylistic ones in #729, but I chose to leave a few of the less opinionated ones in. I'm happy going a bit more opinionated with the recommended set, considering it only takes a single line in your config to override any rule you don't like. Reasoning as to why it's in the recommended set: Every single JS/TS codebase I've seen uses camelCase naming. Doing a quick google reveals two eslint plugins concerned with snake case [1] [2], which have a combined total of less than 300 weekly downloads. Which further supports my above assertion. As per our docs on configs, please provide reasoning as to why you think it should be removed. |
@bradzacher thanks for your reply. There are several references as to why enforcing any sort of stylistic rules isn’t deemed best practice and I believe Create React App’s ESLint config was probably one of the first key players to promote this idea.
Issue #651 actually mentions the removal of There are certain API’s that have underscores in them such as |
@NMinhNguyen Psst. Since I was pinged. If you’re struggling with typescript-eslint’s recommended ruleset, here’s something that I realized once I actually compared the eslint’s ruleset and typescript-eslint’s ruleset. The only rule which actually overlaps is "rules": {
"@typescript-eslint/no-unused-vars": "error",
"no-unused-vars": "off",
} along with the default eslint:recommended rules and call it a day. I audited the rules under the framework I describe in the linked issue for rules which catch bugs or whatever and there are actually very few which aren’t “opinionated” and the ones which catch additional bugs often require more configuration via manually setting a |
All of these reference style rules in general, and they are more talking about rules like I generally put no time into rules which do things prettier already does better. Prettier, however, does not mutate the AST by design, which means it will never enforce a naming convention, so in this department prettier doesn't count. For dan's case - at FB we don't use the camelcase rule, because the codebase (many, many years ago) used jshint, which didn't have a naming rule. Then when the codebase was migrated to eslint, there were many non-camelcase names, so the rule was noisy. Then nobody bothered to ever go and clean it up. Though all the code I've worked on there informally uses camelcase naming conventions, just without the rule (people just do it naturally).
They are outliers to the general case. What about angular users, or vue users, or plain node users? Why should they not be recommended the rule because react has some experimental, unstable APIs named with underscores?
Sorry, I was exaggerating when I said no one. What I mean by no one is "a mostly insignificant number of people". For something that has community support, the numbers I'm looking for are more like ~30+ users. The highest number of reactions on an issue was ~70, and the currently opened highest is ~40, so ~30 is something I see as having a decent community drive.
Sorry, I didn't quite understand your comment - are you saying the only rule of our plugin you use is I'm very much okay having a few opinionated rules in the recommended set, considering how simple it is for people to disable them, should they not like them. |
@brainkim thanks so much for the advice! That's definitely useful to know 🙂 I'll quote things that I think are applicable to
If
Given the above, I'd ask the opposite question - why should they be recommended a stylistic rule? If a team wants to enforce a certain naming convention, wouldn't it be better for them to opt in to it?
I interpreted that to mean he simply uses |
eslint-config-react-app is a different beast though.. It's enabled as part of create-react-app, and CRA is designed as a zero-config framework, so much so that adding your own config requires you to eject from the framework itself. So eslint-config-react-app has to be as un-opinionated as possible, or else people will want to eject from the framework to disable the rules they don't agree with (and then it's a pain to un-eject, so you get a fragmented userbase...). This makes it hard to compare our recommended set with that of eslint-config-react-app. The eslint recommended set is a fair comparison, and one people bring up often. They choose to include zero stylistic rules. It's a valid standpoint, and I adopted it to a degree (I disabled most of the layout rules, and I want to disable them all in 3.0). There were just a few "stylistic rules" that I think tread the line between style and best practices, and as I believe they are a best practice, I left them in. The community thinks the same or similar as well, because the original recommended set was built off of some relatively widely used community configs (it was an amalgamation of 3 or 4 community configs).
See the section in my original comment. Everyone does this standard anyway, so IMO it's good to enforce it from the get-go. Or else you end up in FB's case where you enable it too late and it's too hard to migrate your codebase to turn it on, and then you just rely upon code reviews to loosely enforce the standard. I've always been of the opinion that being a little opinionated is good. If people hate it, it's a 1 line config to turn it off.
I think there are a number of rules that we offer that catch bugs / potential issues, and there are a few that are a little opinionated, but can again often catch potential issues. But it's up to you if you use them. We offer two configs, recommended and recommended-requiring-type-checking, so you can use recommended rules without the typechecking parser config. I think there are a number of eslint rules that would be recommended, if they had type information built in. A few of those have made it in here (like require-await). |
It seems like many of the Twitter profiles I shared above actually discourage using it :) Ryan Florence put it this way:
And although CRA is zero-config, the ESLint config that they do have has been widely recommended in the community because it does what a linter is supposed to do which is catch bugs.
I did read the relevant portion in your original comment, however I still don’t think it’s good to recommend because it’s a stylistic choice and to me it doesn’t seem like it has anything to do with TypeScript or catching bugs. Given that it makes certain API’s more annoying to use (you can also imagine some REST API’s that return objects with kebab case properties), doesn’t help catch bugs, I don’t think it should be recommended. At this point I feel like I am starting to repeat the reasoning as to why I think it should be removed. Do you know what can be done to have it removed? Is it the number of votes? |
They do, but they are speaking as people that actively understand everything to do with linting and all the lint rules on offer. Speaking as someone who has been given the daunting task of setting up a lint config for a codebase (when nobody, not even myself understood linting), the airbnb config is great. Plug it in, adjust a few rules and it works perfectly. There's a reason it still has 1.5m weekly downloads. Now a days, I see that it is okay, but very opinionated. Some things are done better by other tools (like prettier), some parts I don't agree with. I think for a lot of devs setting up eslint, it's a great basis from which to build and learn about what you and your company's style actually is.
I disagree with this statement. That is just a piece of what linters are for. A linter is much broader than just bugs. Linters are also about enforcing code style and telling people how to do things. At FB we have a lot of custom internal lint rules which do things from telling people not to use deprecated APIs (and giving alternatives), to ensuring imports are ordered in the same way. If for you all a linter is about is catching bugs, then our recommended set is not for you, and I don't intend it to be you. Happy to accept a PR from anyone if they want to create a small, targeted set about only catching bugs, but the recommended set won't be it. But nobody has wanted to do this yet.
As I mentioned earlier - if there is significant response from the community, then it's something we maintainers will consider and discuss. If not, then sorry, it's staying in. |
Correct me if I’m wrong but it seems like the definition of
This was Dan’s quote and a sentiment that seems to be shared by many other thought leaders in the space like Kent Dodds, Ryan Florence etc. |
Great discussion and thanks so much for the history @bradzacher, very interesting background here. FWIW I had a similar experience using an internal closed API with kebab case. I migrated our linting system from tslint to eslint-typescript and reading some article opted into eslint-typescript:recommended. For the most part this was a great experience because eslint-typescript catches so many more code quality issues. After fixing some issues and disabling others I raised a tech debt ticket to fix all the ‘eslint-disable’ instances. But the one that stood out was this camelCase rule which was an exception. My OCD kicked in and this made me question my expectation of a linter. I decided that a linter should help us find code quality issues and nothing more. Makes it easy to mark a ticket as done and to definitively say “tech debt paid”. There are lots of tools out there as you mentioned to help us on our path stylistically. Luckily as Brian pointed out I can opt out of a contrived rule set and go with the base eslint recommended rule set. Sorry about the length of this story but I hope it helps provide some context of a real world use case and potential OCD friction :) |
This plugin's config is in a special sort of gray area whereby it needs to toggle certain eslint rules off, and turn on it's own for anything to work at all. I'm looking through and it seems the choices of config are Is there a config that matches Could one be added? ( re: naming, it would be exceedingly confusing to have an additional config that mirrors |
We are a community run project with volunteer maintainers. The maintainers are mostly here to oversee the direction, triage issues, review and merge PRs, and maintain the parser internals (which are usually too extensive for new contributors to jump into). As mentioned in my previous comment:
We recommend that you use a rule to enforce a naming convention. Which is why it's in the recommended set. If someone wants to PR a If someone wants to PR to enhance the |
See proposed recommended changes in #1423 |
I'd like to request that the
camelcase
rule is removed from therecommended
config to match ESLint: https://eslint.org/docs/rules/camelcasePrior art: #651 and #729.
Repro
// your repro code case
Expected Result
Actual Result
Additional Info
Versions
@typescript-eslint/eslint-plugin
2.12.0
@typescript-eslint/parser
2.12.0
TypeScript
3.7.3
ESLint
6.7.2
node
10.18.0
npm
6.13.4
The text was updated successfully, but these errors were encountered: