5 ms·
Rubocop-obsession: RuboCop extension focused on higher-level concepts
- henning 2y agoThe world runs on code that violates some or all of these rules. Following them won't fix any of the problems they have. It doesn't matter.
- hrdwdmrbl 2y agoIt does help at some margin to make code more readable. Humans just aren't that great at reading and understanding code. It has been said: "Write for humans, not computers because computers will understand what you wrote no matter how badly written". So if you're writing code on a team, do your co-workers and your future-self a favour and write code that's easy to read. It won't run any better or with fewer bugs, but it will be easier to understand later, easier to be understood by others, and "wishful thinking here": easier to debug.
- codesnik 2y agoproblem is that it does too much out of the box. Finding some sloppy formatting - ok. Fixing it automatically? even better. But rubocop tries to sniff "code smells", security problems, and it's not that great with it, not everything you can get about the logic and intent just from AST. There are so many rules that developers spent significant time appeasing rubocop and this sometimes takes away effort to make code actually readable by humans. Have you ever seen a tidy mess? Even worse, it gives simple tools to write plugins to sniff more logic related stuff, and I've seen projects where developers really went overboard with it.
- xtracto 2y agoOne of the things i miss the most from developing in ruby is the code quality instrumentation: metric-fu, reek, rubocop and lots of other gems that allowed us (in a previous ruby shop) understand and monitor the quality of our code like ABC, Cyclomatic complexity, duplicated code, etc). Now in Typescript, I haven't found a lot of tools to calculate,visualize and track these stats. Metric-fu was amazing.
- Alifatisk 2y agoDon't forget about Brakeman!
- MrJohz 2y agoYou can get a lot of mileage out of ESLint + typescript-ESLint + various other plugins. It's more of a "choose your own adventure" kind of experience, but the defaults are a good start, and if you're looking for cyclomatic complexity and all that jazz, there's various plugins that can calculate that. And the typescript ESLint plugin is great because it uses the types as part of the hints, which is great for finding places where you no longer need optional chaining, or where a condition is always true/false because you forgot what types things were. That said, I tend to take a much more lean approach to linting these days. I try to only include lints that are actionable, likely to lead to real bugs, and have no false positives. Everything else feels like it's better handled in code review. If you don't know why your function is too complex and difficult to read, I don't want you to rewrite it just to satisfy a robot that's following arbitrary rules! I want to be able to have a discussion with you about proper techniques for splitting apart code. But there's definitely people who go the other way entirely and build incredibly strict ESLint configurations, so looking for those might help you if that's what you want.
- erulabs 2y agoI wonder if anyone here has a good set of Typescript/ESlint addons to suggest? I also miss my duplicate code alert from Ruby!
- emmanueloga_ 2y agoI'm pretty happy with Biome's defaults [1]. From time to time, I disable some rules that are too restrictive (like "noExplicitAny", which I turn into info instead of an error). -- 1: https://biomejs.dev/linter/ https://biomejs.dev/linter/
- burnt-resistor 2y ago[flagged]
- deleted 2y ago[deleted]
- Alifatisk 2y agoI'm getting this right away!
- codesnik 2y agoNice. Now we can probably ask to move there half of the too nosy rubocop rules from the main rubocop repo. And then to never install rubocop-obsession!
- bioneuralnet 2y agoRight? I seem to be the only high-level SWE at my company who hates RuboCop. Some of it's fine (e.g. no globals, use x.count { ... } instead of x.select { ... }.count). But so many of the rules are obsessed with trivial details like the "right" style of blocks to use (do vs {}) or "" vs '' for strings. Pointless busy work. I think the dumbest is requiring "def (x=true)" over "def (x = true)". Seriously, why could that possibly matter??
- hrdwdmrbl 2y agoWhy does it matter when there is auto-fix-on-save? I just write whatever, hit ctrl+s and the code is fixed. The result: The code is "fixed" based on whatever rule and it doesn't cost me a thing. I don't think about it and I don't lift a finger. But I do personally appreciate the tidiness of code-consistency.
- bioneuralnet 2y agoThat's my argument - if we collectively care, it should happen automatically. Alas, no one else seems bothered by the status quo.
- imoverclocked 2y agoIt’s been quite some time since I’ve used Rubocop but I did fight an uphill battle to get it into place. One of the things I had a difficult time explaining was that rules subtly interact with each other. When one rule makes a change, it might simplify something such that another rule can then also make a change. Once I enabled enough rules, there were some pretty impressive chains that were whittled down to almost nothing… but the same application of those rules elsewhere caused hemming and hawing by the naysayers. I think the best thing that these tools give, above all else, is a way to settle petty opinions in a team. It’s why there is value in rules that either conflict with each other or are configurable so as to meet the expectations of a given team.
- RangerScience 2y agoYep. I introduced Rubocop at a past gig… only to watch my colleague write worse code playing whackamole trying to adhere to the rules. I kept telling him that the whackamole is a sign to rework things at a higher level - that the Rubocop rule catches symptoms, and that he needed to address the cause, but… PS - to be clear, I love Rubocop and swear by it. In that circumstance, I needed to introduce it differently, is all.
- Gigachad 2y ago> is a way to settle petty opinions in a team. Yeah this is huge. So often I get my PRs rejected because one dev has their own personal preference for formatting something. With Rubocop I can tell them to go submit a PR themselves to make that preference a rule and we can all discuss it and enforce it / autoformat it going forward. But for now, it won't be blocking my change going out.
- block_dagger 2y agoHopefully rubocop-rails-omakase [1] will pull in stuff like this. I've gone from custom Rubocop rules in various projects to just using rubocop-rails-omakase, which finally feels like a consensus of sorts. I think Standard [2] is harmfully redundant, personally. [1] https://github.com/rails/rubocop-rails-omakase https://github.com/rails/rubocop-rails-omakase [2] https://github.com/standardrb/standard https://github.com/standardrb/standard
- caseyohara 2y agoI'm curious why you think Standard is "harmfully redundant"?
- stevebmark 2y agoRubocop is one of the worst Ruby tools there is. Flog and reek are also unhelpful, but Rubocop is style nonsense that doesn’t belong in a linter. The ESLint community used to be big on useless opinion based rule overload, until everyone realized how bad of an idea it was.
- leoh 2y agoCan you be kore specific? I haven't used it for a few years but found it yo be a perfectly competent and helpful linter at minimum.
- ukoki 2y ago> # This cop checks for `next` (and sometimes `break`) in loops. > ... > # - For small loops, you can just use normal conditions instead of `next`. This rule will just end up with devs writing this: array.each do |elem| if condition if another_condition if yet_another_condition do_something end end end end Rather than the much easier to parse: array.each do |elem| next if !condition next if !another_condition next if !yet_another_condition do_something end
- jdalbert 2y agoThat cop is disabled by default in `config/default.yml`.