GitHub Super Linter: one linter to rule them all
github.blog
github.blog
After using Prettier for a few years I'm firmly in the camp of mandatory/enforced code formatters. As long as it's a half decent formatter like Prettier I believe my personal opinions on the specific formatting choices are much less important than essentially never having to think about formatting again, in particular having to ask people to fix formatting in code reviews (or fix it myself).
I also love just banging out code, saving, and having my editor clean up the formatting for me.
You don't have to deal with anything as long as you're using the same formatter everyone else is using.
The simplest and safest would be to apply the formatter to both the old and the new copy before diffing it. It ceases to be the actual difference at that point, but there are definitely two distinct use cases for diffs - one for humans to read and one for the machine to apply.
The other case that would be amazing but even more of a stretch would be to rewrite the entire history. It seems like there is a spot for "different views of history" and you could do a no-difference merge to join the to histories as of now so that the actual history did not get lost. As I write this, it starts to sound like just a caching system for the idea above.
This needs a highly reliable formatter of course... I have on occasion had code broken when formatting.
[blame]
ignoreRevsFile = ".git-ignore-revs-file"
markIgnoredLines
markUnblamableLinesLooking at this another way, formatters are designed to "frustrate" devs into working only 1 way. If you think it's more helpful to have a codebase with mixed spaces/tabs with commits that express each developer's unique flair, then a formatter is not for your team.
This could be the case if you have extreme confidence in the formatter, but I have def seen some very funky black outputs. It seems like when writing people will likely do so with a model of how black will yield the final code in mind. (Eg "if I add more characters to this one line list statement, it will get exploded across 5 lines", and affect readability, etc..)
rubocop -a
For the win.Some of its defaults? Fine, whatever. Others? They’re just _wrong_.
There was a good quote from Rob Pike in his Go proverbs talk: "Gofmt's style is nobody's favourite, but gofmt is everybody's favourite."
What are some other great formatters out there?
[0]: https://prettier.io [1]: https://github.com/apple/swift-format [2]: https://github.com/rust-lang/rustfmt
For public code I do not recommend changing the defaults since it may make PRs a mess.
Apostrophes occur so often in English that it makes it easier to type strings like "I'm a dog". With single quoting you have to go 'I\'m a dog'.
If I hit double quotes in a string, I just triple-quote.
"""He said "hah" sarcastically""".
I know Guido (van Rossum) prefers single quotes -- I'm not sure why exactly -- so it's become a default Python style. I tried to adopting it but always ended up reverting to double quotes.
Might be ease of typing? Eg: `foo = 'bar'` doesn't require any shift chords, whereas `foo = "bar"` requires two. Though then I'd expect similar preference for kebab-case in identifies, for similar reason.
'The class of \'72 didn\'t think much of Sam\'s speech'
vs
"The class of '72 didn't think much of Sam's speech"
To me, the shift chord is an almost negligible price to pay for more aesthetically pleasing strings, especially since on a QWERTY keyboard, the shift key is literally right next to the ' key. For emacs users who are used to complex key chords, it's even more negligible.
I do use single quotes for strings frequently in interpolated f-strings though:
f"The date is {result['year']}"
edit: seems https://github.com/dotnet/format is the closest thing
Resharper has a free command line tool that supports wrapping long lines. https://www.jetbrains.com/help/resharper/CleanupCode.html
I made a wrapper for it to try and make it easier to use. https://github.com/sethreno/ReGitLint#regitlint
rubyfmt for Ruby
I don't care about the specific formatting/linting rules as much as I care about consistency. Auto formatting is great to reduce friction for those on the team who can't/won't convert change how they write code locally.
So not like prettier/black/goftm.
You get to choose. It's more of a way to group things.
Which make sense. I don't mind being dictated code formatting, but linters will complain about branching, number of arguments, comments and so on. I change the settings of my linter for each project.
Those should not be fixed.
I like to solve interesting problems, and concentrate on crafting high quality software. Manual code formatting contributes to neither of these disciplines. Code formatting is BORING robot work, not human work. Total pointless drudgery. Toiling away because you like your bracket with a different spacing is IDIOTIC. Run the formatter and move on.
Not arguing about style is nice, but having to resort to this brutalist architecture style of code formatting doesn't seem great to me. "Its just holding people, who CARES what the building looks like!"
Fwiw, i use an auto formatter but its got problems with certain rules so i switch them off.
The reason we dont have it turned on in ci is because these rules break code.
"Pretty", yes, but we're literally talking about using language to communicate. Consistency taken to extremes is harmful to communication.
I don't understand the worship that people have for consistency. STUPID inconsistencies are bad, yes, and yes, there are certainly arguments that about subjective matters that are a waste of time. But distilling everything down to the lowest common denominator of grunt-talking is very consistent and terrible communication. (Does that feel like a strawman? I'd love for it to be! Once people stop talking about consistency uber-alles we'll be discussing the things that I consider important.) Right now, the most common reaction is to dismiss any idea of communication through language as irrelevant, subjective, and a waste of time."
Unless you are enforcing weird autoformat choices, everything should look pretty enough.
Working in a team with 15 people on the same code base I disagree with this. Count the computer as one teammate
There's a beauty that comes from simplicity, and code for matters, at least for me, are good of reminding me of that.
This is the same for programming. Each dev have their own taste in term of code style and code formatting preferences. I was an early employee in a startup, and at some point I was able to tell who wrote a chunk of code just from the code style, it was fun :) but as company grown, and team got bigger, it got more "professional", now we have prettier which erases a big part of our code personality. If you believe like me that coders are artists you might find that a bit sad, but the truth is that most Enterprise software building is wall painting, and art doesn't have its place there. That doesn't prevent us from painting Mona Lisa at home though :)
One simple example is when you're parsing text and you have a long list of simple one-line if statements. I personally think it's wasteful and harder to read that block of code if you impose curly braces and new lines on that list of conditionals. This kind of formatting convention has been around for at least 40 years, and it makes the code more readable. I have yet to see an auto-formatter that doesn't turn that kind of code section into an unreadable mess.
There's also plenty of room for art in the choice of materials and colours as well as the shapes of buildings. Likewise, with code, if you limit yourself to only what one person can do, you'll end up with a very constrained view of what "art" means.
I also think formatting should be separate from linting but because they both require a parser people seem to think theyre the same thing.
Anyway, my point still stands, drop rules about line length and rules that care about inter line break positions and most of these problems go away.
If youre adding more attributes to a jsx component later and know it you might format to multiline early. It decides to undo your work and slow you down, because some arbitrary line length.
Similarly, if you go over that line length, on something you want single line for readability of structure, it just straight up does what it wants.
Im 100% on the auto format train but it has to go the gofmt route and only apply rules that are actually important and incredibly uncontroversial.
What you're missing here is that you're supposed to be using it all along, all the time. Format on save. Format on commit. Format on server pipelines. Format all the time. It can never 'undo' anything if it's what's providing the formatting in the first place.
If the rule never works for you, turn that one off.
If the rule is what you want 99% of the time but it made this one line look dumb, mark that one block #ignore and let the team decide in CR if that was the right call.
My two cents: Write the comment's purpose inside it. "// Comment inserted to force prettier line break until more attributes are added"
https://prettier.io/docs/en/rationale.html#multi-line-object...
If your contributor is changing thousands of lines in a diff to fix a typo, ask them not to do that :)
Now the code is formatted and additions won’t trigger reformatting the line or the file.
Of course, a lot of tooling simply isn't there for that, unfortunately, but that's what I see as the ideal solution.
I also believe that formatters should be "light-touch" and not have an opinion about every last thing. At that point I start thinking, "if you so smart, why don't you write the bloody code!"
BUT
I'm tired of seeing diff chunks on github where 95% of the chunk is because black/gofmt decided to change the formatting / indentation / grouping / whatever. I want language-agnostic, AST-aware diffing, that de-emphasizes the part of a chunk that is irrelevant-in-the-world-of-auto-matic-code-formatting.
The challenge is that version control on text files (list of lines) is fairly straight forward and language agnostic, while OTOH the VCS would have to run after the language parser processes on the text file, and then be able to interface with the AST generated by the parser (for multiple languages). I presume this would become easy if different languages have the same parsing setup, or we have language/project-specific VCS tools. While the answers are not obvious (to me, at least) this definitely seems like the right direction to move in, instead of getting hung up on plain text and formatting issues.
But yeah, otherwise everyone could just have their own preferred formatter/settings and we could commit whatever representation is most optimal for diffing to version control (e.x. multi-line object literals, trailing commas in arrays/args, etc).
You could use something more compact like a binary AST but for compatibility with "legacy" tools that deal with text I think it would be better to use a more verbose text-based representation.
Python 2.7.15 (default, Feb 14 2019, 16:26:56)
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.10.44.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ast
>>> ast.dump(ast.parse('print "foo"'))
"Module(body=[Print(dest=None, values=[Str(s='foo')], nl=True)])"
but in python 3.7: Python 3.7.2 (default, Feb 14 2019, 16:12:42)
[Clang 10.0.0 (clang-1000.10.44.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ast
>>> ast.parse('print "foo"')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/philsnow/.pyenv/versions/3.7.2/lib/python3.7/ast.py", line 35, in parse
return compile(source, filename, mode, PyCF_ONLY_AST)
File "<unknown>", line 1
print "foo"
^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print("foo")?
nothing changed in the text, but the AST is different. What should get committed to this hypothetical "git-ast"?The answer probably lies in creating a different abstraction , different building blocks. In git we have bytes -> blobs -> trees -> commits, where the bytes of a given file get annotated with a file name (and mode bits etc etc, gross posix things) by the tree object.
In git-ast, maybe the abstraction is bytes -> lexemes (which annotates the bytes with a language version, and thus lexer version) -> tree? I haven't gone down the thought experiment that far.
I tried to make an example with `with`, because that was introduced between 2.4 and 2.5 IIRC, and 2.4 and 2.5 aren't nearly as far apart as 2.* and 3.*, but I didn't find an easy way to install a 2.4 python (it didn't compile in pyenv on my mac, and I looked at a couple docker images before giving up).
The worst case is that you export it with the old version of the converter, and then the code changes meaning. You have silent corruption. But if you stored raw text this would always happen.
The good case is that you export it with the new version of the converter. It will notice that a variable name matches a keyword, and alert you to fix it.
Of course that doesn't help if you're setting up the formatter for the first time, or want to upgrade to a new version.
Some tools like GitHub's diff do try to deemphasize whitespace but it's pretty limited.
1. Use a tracked directory for Git hooks: `git config --local core.hooksPath 'git-hooks'`.
2. Create format.bash and lint.bash.
2.1. Run `black` and `isort` in format.bash.
2.2. Run `flake8`, `mypy`, `black` and `isort` in lint.bash.
2.3. Run lint.bash in the pre-commit hook.
2.4. By default, lint/format only files which are different from origin/master to save time: `git diff --diff-filter=d --name-only -z origin/master "[asterisk].py"`.
3. In CI, run lint.bash with `--all` or some other keyword to verify formatting on every file: `git ls-files -z -- "[asterisk].py"`.
After more than a year with this setup I absolutely adore it.
I've found git hooks to be more trouble than they're worth.
But as long as it's enforced in CI you can leave it up to individual team members how they want to do it.
You can do a format run over the whole codebase then ignore the commit in blame.
https://www.moxio.com/blog/43/ignoring-bulk-change-commits-w...
This seems like a cool tool, but I don't know if I would use it at this point. I would _pay_ for having autoformatters from Github -- it was a pain to set it up and would love to just enable on new projects.
If you find formatting discussions with your teammates painful, Maybe some fraction of your team are stubborn jerks?
I've worked where formatting discussions were always friendly and constructive. It can be done.
It also really democratizes the language, because even folks brand new to Python or who are inexperienced with programming in general end up with code that is well-formatted and consistent with everything else.
Things like changing names to affect line breaks, inlining or outlining expressions etc.
Small things can turn 1 line into 8, and vice versa.
Now, to be clear, I’m sure it’s possible to find some examples where most programmers would come together and agree that black made the wrong decision. But my experience using it across entire teams is that this is surprisingly rare.
I aim higher than that.
I think there are few subjective style choices that are so egregious that a robot would have done a better job. Where I want enforcement is likely correctness and safety mistakes.
But totally agree on forced lining.
Stopping things like reassign function parameters, no unused variables and the like really makes code far nicer.
I also love auto formatting in vscode saves a lot of time.
In general, I tend not to care a whole lot about style, except to try and match whatever is pre-existing, as long as it’s vaguely readable. Otherwise, it’s basically whatever python-mode on emacs does, subject to a reasonable line length. Formatting nitpicks in code review bug me enough that I always just give in and do what they suggest.
I personally find ESLint to be a nightmare of configurability and silly defaults.
Enforcing a code style where adding a single byte can result in an unlimited-number-of-lines block in a diff is pure idiocy.
It's bad enough having to review someone's changes when they're polluted with this garbage, but it also makes merges fail more often and pollutes `git blame`.
The idea that people will put up with this crap because they can't just unclench about a few spaces here and there I will never understand.
"But it minimizes diffs because it stops people committing simple spacing changes" - people shouldn't be adding those hunks to their commits in the first place and such changes need to be pulled out in review. This will also get people out of the habit of just blindly doing a `git add`.
edit: I'm certain that if slightly non-uniform formatting really sets off your OCD then this should be solvable to some degree at the editor level, but please keep your obsessions out of my repository. In return I'll keep mine out of yours.
The serialisation should be normalised automatically, preferably in a way that minimises line-based diffs.
The way code is formatted for display should be distinct, and can usually be more of a personal preference. Most people seem to be happy for their editor to use syntax highlighting to make things more readable, but not much else. Indentation, line length, aligning sub-expressions, etc. can also help readability, but showing those things differently from the bytes on disk is usually avoided.
Perhaps this is due to a conflation of meaning for certain bytes. For example, \n can mean "token separator" to the language, "long line splitter" or "intent separator" to the developer, "unit of comparison separator" to version control, etc.
We spent a lot of time on making the code look like it at least came from the same company. And weeks of my life has been wasted trying to get people to agree on code formatting and coding style.
Fast forward a few years and we start using Go. I didn't agree with some of the formatting choices or code conventions. And pretty much everyone on the team had at least one thing that would grind their gears.
But we agreed that we'd use the gofmt tool to format the code. As everyone now does: by ensuring whatever IDE or editor we use pipes the code through that.
It took less than a week for everyone to adapt and I have hardly heard anyone complain since. There are still things I think could have been different, but for me, that's a very low price to pay for not needing to have these discussions.
I get why it's probably not ideal as a local tool, and integration with Status API is nice and all, but I personally prefer to see devs linting their code before pushing for review.
Correction: it can run locally in Docker, as pointed out below: https://github.com/github/super-linter/blob/master/docs/run-...
(Also, I guess this is one more reason that docker is a big red flag for 'hastily hacked together unportable software that would be hell to ship.')
but your comment made me think of this meme, which I can't not link to https://i.imgflip.com/24ac74.jpg
text for people who don't want to click:
It works on my machine
Then we'll ship your machine
And that is how docker was bornIt just opens a whole box of problems, that do nothing to actually further the tool you are building.
Alternatively you ask people to install linters themselves, and refuse to run if they're outdated. Language X devs likely already have reasonably up-to-date language X linters installed, or know how to install them anyway.
A lot of effort: probably. Many different platforms: there are three platforms that carry any weight. See GitHub Actions runner environments.
Docker on the dev machines is easy for the project, but (1) performance is subpar on macOS and Windows due to virtualization; (2) it also gets outdated; (3) the image is easily gone if you like pruning, then you need to pull the image all over again. (Thankfully the image isn't huge, ~380MB at the moment.)
Having to use docker certainly affirms "I get why it's probably not ideal as a local tool" to some extent, though...
I wrote an article a while ago arguing this point: https://jonathan.bergknoff.com/journal/run-more-stuff-in-doc...
Thankfully Microsoft rewrote WSL 2 in a way that makes it work much better with Docker.
But since its release, you still can't do public pulls: https://github.community/t/docker-pull-from-public-github-pa...
admiralawkbar accounts for 80% of the commits in the repository and over 98% of the code churn. I'm guessing this was a side project of his (Lucas Gravley aka admiralawkbar) and the docker image was just something that was overlooked when it became an officially advertised GitHub repo.
Perhaps it would have been better pitched a Lint-runner for CI jobs rather than a real linter.
Css Eslint
Etc
I ended up using jest and the linter plugins for that, just so I would get readable inline reports. Otherwise it just fails and my devs have to search for the raw log in the checks panel.
I didn't do any others because it's too much work to set up and runs longer, burns more carbon.
[0]: https://github.com/github/super-linter/blob/master/Dockerfil...
Now, if we're saying that Microsoft should be spending more of their time on interop and portability but chooses not to prioritize their resources on that, then that just falls into the category of common complaints that people have with all open-source projects and what the contributors choose to spend their valuable developer hours on.
> There are only two ways to make money in business: One is to bundle; the other is to unbundle. [1]
[1]: https://twitter.com/eriktorenberg/status/1214671238552940544
In one case, we started with a monolith, broke it down to a service oriented architecture, realised the SOA was not scalable enough, so rebuilt the monolith. Good way to waste a couple of years!
Yes, this is a bit different, but, you know, having a super-linter around would be kinda handy. It gets old installing and configuring these things sometimes.
— Dogbert, Build a Better Life by Stealing Office Supplies (Dogbert’s Big Book of Business), Scott Adams, 1991
The pain being solved here is that setting up the right development environment is hard, especially for those still learning to program. Many would be much more productive if we skip this step.
Another prediction: Once the development environment moves to the cloud, it will be tied directly to the deployment to a specific platform, such as Azure if this is offered by GitHub. Then Amazon and Google will have to build their own IDEs in the cloud to compete. We'll no longer be developing locally but in the browser, and it will cost a lot more.
Disclaimer, I helped make these :)
Indeed. It's interesting that GitHub Classroom uses Repl.it (and another MS web IDE) rather than Github Codespaces:
https://github.blog/2020-05-26-code-in-the-browser-with-gith...
https://classroom.github.com/help/online-ide-integrations
Seems like a friendly ecosystem for the moment.
Things I want in my IDE:
- monitoring/alerting (how many times is this method executed, how long does it take, how many errors, etc)
- discussions as in Google Docs on code fragments, rather than "comments" that are part of the git history (comments are an orthogonal concern from checked in code)
- visual representation of my code base
- ultra fast automated test that cover only what I recently changed
- a documentation system that makes sense
This such a good observation. I will be using this quote in the future.
I've seen what integration of the development environment looks like inside a big company (Facebook) and it's just amazing how seamless everything can be when all your tools are built with an awareness of each other. I think we'll see that soon outside these big companies.
The Perl validation seems to be restricted to "compile with warnings", despite "perlcritic" being now almost 15 years old, predating both some other linters' and even some other languages' very existence.
I'll try to see how feasible it'd be to add it as a ("the"?) Perl linter to be used as using just the compilation step to infer everything's fine doesn't really satisfy the role a linter is meant to have.
$ echo 'BEGIN{`cowsay pwned > /dev/tty`}' > test.pm
$ perl -Mstrict -cw test.pm
_______
< pwned >
-------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
test.pm syntax OKJava is the only major language without any sane default coding standard (no, google-java-format is google-specific, outdated, not up-to-date with recent versions and not maintained by community). It's a pity really.
This is just completely false.
- https://madnight.github.io/githut/#/pull_requests/2020/1
- https://insights.stackoverflow.com/survey/2020#technology-pr...
I could link many other links showing Java as an extremely widespread language. There is just nothing comparable in the corporate world.
Nah, it's a pretty safe bet that the language with the most new code being written is JavaScript. If it weren't JavaScript, I'd actually guess Excel next. (Okay, maybe not in terms of LOC, but certainly in number of applications.)
With Python or C++ being next.
But they don't count Excel :)
[1] https://docs.gitlab.com/ee/user/project/merge_requests/code_...
We have also seen that SuperLinter can be run as part of a GitLab pipeline without too much hassle.
-James H Product Manager - Testing
Just a poor experience all around.
GitHub's approach here seems much more sane.
Is it? In my company I maintain a set of exemplars for all of our commonly used repository types. When someone wants to make a new one they just copy and paste stuff from one of the exemplars.
Over the years I've come to value "white box" code re-use over "black box" re-use. In my experience many projects will outgrow their tools and need custom tooling, so it makes sense to keep the black boxes tiny and copy over large tooling in a white box fashion. For example, what if I want to change the Python linter for Pylint to flake8? I'll need a separate fork of superlinter or something. I'd prefer to just edit the tooling that is build in to my project.
Anyone know how this compares with https://relaxed.ruby.style ? The default rubocop is very angry about meaningless shit, curious where github falls on that spectrum.
Btw, you don't have to respond with the talking points I've heard all my life on why it's supposedly great, I've obviously heard them and think they're bogus.
I just find it strange that I'm the only one.
Because some things are better expressed in different rules.
That's why some syntax is optional in the first place, that's the reason it was made that way. The flexibility is a very intentional feature. It wasn't an accident.
Maybe you want multiple spaces to vertically align code in a complex set of logic. Maybe you want to express things on multiple lines to break them up. Maybe you have deep nesting so you want to go from 4 spaces to 2. Maybe you want no braces in a single line if statement except in certain cases. This could go for pages. Poof! All gone. You can't do any of it anymore.
Not following optional syntax like having a space after a comma or a space before a parenthesis is not a software bug. It's a waste of time. The compiler doesn't care and I don't either.
Instead it becomes a literal Blocking Issue most of the time. So instead of working on the actual blocking issues of the code base, you spend time doing "you did this here because of some context I don't understand and I'm not allowing it" You can't commit your code without conforming to it.
Also because linters are dumb. They "spot" things that are perfectly fine as supposed bugs (because they don't actually know types or logic, they're just dumb syntax checkers) and you have to work around them to satiate them with the possibility of introducing new bugs to prevent some tripwire system from false positives.
Compiler writers and language designers are the only people I've found who agree with me.
It's fine for protecting against profound levels of incompetence but I don't do that and you probably don't either.
I mean, I'll be the first to agree that blocking your development in the heat of it over some stylistic issue like quote styles is counter-productive, but if those rules are turned off and the rest help you catch actual bugs (and it's hard to argue that it does not), then that's surely a plus?
(Also, why wouldn't linters know types?)
It's not like I'm some grumpy malcontent that hasn't given it a go.
If you want to use it go ahead, I just thought I'd be standing in a larger crowd
Aside, it’s funny that you dismiss linters as being for “type A folks who must have everything in its right place”, but your concerns seem to be that you want things in their right place and the linters won’t let you. The folks who use linters have decided worrying about it isn’t worth it and just let the linter do its thing, which is less “Type A” than how you describe yourself.
I'd say it's mostly hammers on porcelain. A coder carefully creates something (porcelain) and then the hammer comes around and insists it has to be a perfectly shaped commodity thing.
Same reason and emotion I guess behind both.
In my case, 99% of the time I’m fine with what the linter spits out. In cases where I want a particular structure I just wrap ignore directives around the section and move on with my life
I've got my linters set up pretty loosely, but the things that are enabled have definitely helped me detect bugs earlier and quicker, and I really don't see how anyone could be against that.
For instance something where I am the culprit would be in PHP. I like PHP. I think it's a convenient and powerful language. Someone could take my linter arguments and weaponize them against PHP because it's too easy to do terrible things with it. Then I'd be the one on the other side of the argument all of a sudden, standing in defence of this easy to use language with handy powerful abstractions that can trash a system in a few keystrokes.
I think the difference is when we can come to an agreement that say, PHP is a very powerful tool in competent hands and a very dangerous tool for the foolish.
Going back to the topic at hand, I think the foolish side of linting is the dominant application I see in the wild. I used to use a barrage of proto-linting static analysis tools in my CVS scripts during the wild C days because pointer logic and memory management was notoriously tricky and gcc 2.x was notoriously forgiving. These tools could save days of debugging, really, yes, days.
If we can do that for say python it'd be great. Something saying "Oh I see you are doing a list[1:] in a tight loop, have you thought about collections.dequeue? it may be a better option" - those things are things I do actually forget about and would find helpful.
It'd have to be voluntary though. Prod me a bit but then let me dig my own grave if it's a mistake. That's what the power of computing is also about.
That said, I'd argue against strict stylistic rules, not against linters in general. For example, the common Javascript linter (ESLint) has a setup wizard that allows you to choose whether you just want to check for bugs, or also enforce style conventions, and will enable a predefined set of rules depending on your choice. The bug-spotter is the one that's preselected. This is a very reasonable approach to me.
> Maybe you want multiple spaces to vertically align code in a complex set of logic. Maybe you want to express things on multiple lines to break them up. Maybe you have deep nesting so you want to go from 4 spaces to 2. Maybe you want no braces in a single line if statement except in certain cases. This could go for pages. Poof! All gone. You can't do any of it anymore.
Literally none of these should be flagged by a linter IMO, except maybe the braceless if[1]. If those checks are present I would disable them. Those sound more like a code-styling tool, and is particularly egregious because every single thing you mentioned could be automatically changed by a code formatter!
Examples of things a good linter will pick up on: Unused variables, dead code, use before initialization.
The most absurd case of a linter helping was when fixing an unused variable lint warning actually allowed me to speed up a program by almost a factor of 100 (it precomputed a value and then called the version of the function that didn't use the precomputed value in a tight loop).
[edit]
Do you disable warnings in compiled languages? Note that linters for non-compiled languages are used at least partly to catch things that would be warnings or errors in a compiled language.
1: No braces in an if statement should probably be flagged when the THEN clause is on a separate line because it's a future bug waiting to happen, but I can see the argument for allowing it when it's a single-line statement. OTOH if (foo) {bar();} is only 2 characters longer and 4 if you put whitespace between the braces
The purpose of linters on a team - so I've been told - is so that no one has to argue about formatting anymore.
So now we just get to argue about what rules we can enable/disable?
Even though it's perfectly legal to disable linting for lines or files, most of the time when I do it, it's flagged by someone in review, and there's some discussion and I'm forced to rewrite and remove my disable and go back to whatever the linter was forcing. "These rules are there for a reason, and were put together by people with more experience and smarter than us - we shouldn't go disabling things whenever we want just because we don't like them or think we know better". (amalgamation of multiple comments from people stopping me disabling lint checks in specific situations).
This doesn't happen every time, but enough that the occasional 'disable' isn't something I can just do without worrying it will end in multiple hour discussions. Which is probably what people want - unquestioning conformity to "the one true way".
Code formatting is just one feature a linter may have (e.g. shellcheck[1] and pyflakes[2] are definitely linters but don't have code formatting checks).
I disable all the formatting checks in my linters because if I want to enforce a formatting standard, a code reformatter is probably a better way to do it.
People who argue this are, I believe, missing the forest for the trees. A short on-the-spot version of something I've had in mind for a long time:
almost everyone has a slightly different style that they fall into and the individual styles arent necessarily difficult to understand
AT LEAST WHEN USED ON THEIR OWN, AND NOT MIXED WITH OTHER STYLES.
Your Brain Adapts To A Given One, When Reading That Style. It May Still Feel Like Stuttering, But Once Adapted It's Fully Readable.
Evensomeonewithareallybizarrestylecanbereadwithalittleefforttofigureoutwhatthatstyleis.
The problemcomeswhen You have MULTIPLE people OnA team, and THE SYLES getallmixedupsoittakes a lot moreefforttofigureoutwhatTHEFUCKisgoingon.
Linting is all about picking a style and sticking with it so the code doesn't end up with multiple personality disorder.
> Even though it's perfectly legal to disable linting for lines or files, most of the time when I do it, it's flagged by someone in review, and there's some discussion and I'm forced to rewrite and remove my disable and go back to whatever the linter was forcing. "These rules are there for a reason, and were put together by people with more experience and smarter than us - we shouldn't go disabling things whenever we want just because we don't like them or think we know better". (amalgamation of multiple comments from people stopping me disabling lint checks in specific situations).
When this happens, I think it should open a wider team conversation about whether that particular rule is actually worthwhile, or whether it goes against what your team wants and should be altered/disabled. Unfortunately, I have encountered a couple rules where the linter wasn't configurable enough to get what we wanted as a team, so there's definitely reason to allow per-instance disabling...
Everybody starts at a profound level of incompetence. If you want a junior to be able to make a contribution and you don't want to spend half of the pull request discussing mundane aspects of their code style, then linters and formatters improve the situation somewhat.
many things "highlighted as you type" aren't "bugs".
let greeting = "Hello " + user.name;
Auto-fixing immediately flags this with "DAMN YOU USE A CONST!!!!" (multiple red squiggles that I have to hover and review).but... I might be making a change to it a few minutes later... but I've got some damn visual shit flashing in my eyes that "USE A CONST"
concat strings? PREFER TEMPLATE!!!
OK, ESlint, have it your way, please auto-correct that...
`Hello ${ user.name}`;
WTF?And... this is just one set of 'best practices' to learn - change per language/framework/team multiple times (sometimes in the same week) and it's... difficult.
Yes, I'm an old-fogey. I have close to 30 years of muscle memory of using string concat and double quotes. "auto-fixing as I type" brings a huge interruption of flow, and THESE ARE NOT BUGS. They are style choices someone else is imposing on me. It doesn't make the code less buggy. It doesn't make the client any happier. If someone else coming in to the code is genuinely confused, confounded or severely impeded by
let greeting = "Hello " + user.name;
to the point where they have trouble deciphering the work, perhaps they're not terribly good at their job?Goodness help folks when new management comes in and demands a new 'better' style.
Again, an issue with switching between projects/styles, for me - one client/project insists on "const" in JS. Another client/project is supporting a product on IE9 for a client of theirs, but doesn't use any build tool for some of that JS, so we're not even supposed to use "let" or anything else "new" for some of that project. Mentally switching between those two worlds is like jumping between 2019 and 2009 every few days.
Realistically, could we introduce a transpiler? Technically yes, but operationally? It's a Frankenstein project that has so many larger issues that's low on the list for people (sections of the functionality are being migrated over to react altogether, and throwing 'more tools' in to the mix on legacy stuff is not desired).
I'd always argue for using it that way, which is very reasonable to me.
(A bit weird to have 30 years of muscle memory writing `let`, btw :) )
You're right, I much prefer de-linting, but to each their own.
(it's probably just an artifact of ancient unix history that these tools are called "linters" instead of "delinters", because they preferred vry shrt nms bck thn)
Care to explain why you dislike it?
That’s not really that beneficial, and I can understand why you may dislike this sort of thing.
I think the real benefits come when... - you can enforce a very consistent style, more than a typical linter - you start adding custom linters for things that matter in your codebase
The second point here I’ve used to help move Python 2 to Python 3, move from one library to another by showing linter warnings for importing the old one, enforce new call patterns that might be tricky to enforce in code (like always calling function A before B). It’s less about “linting” and more about flexible static analysis and warnings, and while there will always be other ways to implement those it’s another tool that can be useful to have in your team’s toolbox.
As a freelance/contractor, my environments change, often daily/weekly.
I routinely switch between Java, PHP, Vue, React and some other tools. Doesn't matter WHAT I do, I end up having some stupid red squiggles telling me I can't use "double-quotes" or that I can't use 'single-quotes', depending on context. Multiple languages and 'community standards' conflict with each other, and I'm always constantly having to double check things and 'clean up' stuff.
And... conforming to all of these various 'standards' has not increased the speed of development, nor the robustness, nor the client satisfaction. It does mean that some people who place a high value on standards and listing and visual style are placated.
Increase of automated testing and documentation have more value - long term and short term. And I understand it's not an 'either/or', but visual style and 'linting' standards are low-hanging fruit that are immediately visible, so tend to get more attention (and ongoing).
And then in group discussions, I end up being the person who is apparently "AGAINST CODE STANDARDS". I'm not terribly against them, but in the projects I end up being involved in, it's lower value.
I've got project one which insisted - the point of blocking PRs - that "Yoda style" for null checks was mandatory. Guess what? Another project I'm on, Yoda-style is prohibited, because "it's confusing". Every keystroke I'm having to wonder/worry about what context am I in, and always battling stupid red squiggles.
If you spend 40+ hrs/week using one and one one tech platform where you can have one standard to follow and adhere to - great. I switch platforms, teams and projects regularly, and it's soured me on the huge importance some people place on linting.
This times a million. It doesn't help that the advocates of linting are so dogmatic about the whole idea (as demonstrated so colorfully in this thread and this sub-thread in particular). I mean, I understand why. Linting is an all or nothing type of thing. But I'm still going to remember the lint-advocate as a developer too concerned with the wrong things.
As someone in the former group, I completely agree that these sorts of things bring little value; the fact that the code works is the most important, regardless of how it looks. If your coworkers are writing code that's not working or misleading, talk to them about it.
I've got project one which insisted - the point of blocking PRs - that "Yoda style" for null checks was mandatory. Guess what? Another project I'm on, Yoda-style is prohibited, because "it's confusing". Every keystroke I'm having to wonder/worry about what context am I in, and always battling stupid red squiggles.
That sort of insignificant minutiae really irritates me. It shouldn't matter at all, yet some people love to make mountains out of molehills. (I personally use the "if(ptr)" style because it's the simplest, but I wouldn't care if my coworkers used "if(NULL != ptr)", "if(ptr != NULL)", "if(ptr != 0)", or "if(0 != ptr)"; they're all equivalent, and anyone who doesn't know that, doesn't know the language. "if((NULL != ptr ) == true)" will cause me to raise a comment, however, although not a blocking one.)
"It means we don't have to argue about style"
Well... for the most part, I wasn't arguing about your style in the first place. You're trying to get stuff done your way under the guise of "let's all stop fighting and just get along". I didn't start the fight.
"It makes things easier to read"
If it's harder for me (and some others) to write it that way, it's because it's not natural/default, and, actually, it might actually be harder for me (and some others) to read as well.
I routinely work with folks who like to 'omit' 'unnecessary' lines - omitting a curly brace block in a one-line if is a regular example.
if (foo) {
bar
}
ends up as if (foo) bar
or if (foo)
bar
Honestly I can't remember which. Had 'feedback' from people removing my braces saying "these are unnecessary". But now there's two styles I have to be able to read/write, and... there's almost never a time when one line without braces is sufficient forever - whenever I need logging or another piece of code in the block - bam - now I have to add braces, and that whole area of the code looks more 'different' than it used to.Hyper-concern of linting is in my top 10 red flags of an engineer that is likely unable to prioritize without significant and continuous direction from a PM. It definitely does not mean that are not a skilled developer. Often it does indicate they are quite good. But it also indicates they can not be left alone too long without supervision.
Had a Java PR blocked because I'd used "Integer" instead of "int" and "the compiler's going to have to do more work autoboxing".
There was some other feedback on the diffs too. While technically 'correct', the use case for the code is a 10-15 second process that is run around 200 times per week for one specific client on one server (not clustered, just housing that client and maybe a dozen others). This Integer is housing a sequence counter that may go up to 10 in some cases so... we may be saving a fraction of a second 200 times per week, based on this PR change.
MEANWHILE... the 'in house' team - who reviews themselves - somehow manages to push code in to the main develop branch which, once it's pulled down, results in a system where the initial "dashboard" screen is literally broken after login. That will get pushed to the 'testing' server where 15-20 people do routine 'testing' for various client work, meaning... one bad push puts 30+ people out of commission for hours. This has happened 5 times I'm aware of this year.
But... int/Integer merits holding up a PR.
See its the opposite for me. If I cant trust you with something as dead simple as "npm run lint:fix", how can I trust you to respect any of our more important policies? It's completely disrespectful to the whole team.
In my experience a little hand crafting tweaks to formatting go a long way to increasing understandability.
It feels like a lot of people are having issues with bikeshedding and they're using enforced autoformatters to impose their will and stifle debate they may not like.
Not arguing about style is nice, but having to resort to this brutalist architecture style of code formatting doesn't seem great to me. "Its just holding people, who CARES what the building looks like!"
Also thing like line-length limits. I'm with Linus on this one, enforce line-length limits causes a lot of problems, like breaking context in greps. And an autoformatter that breaks at a certain number of characters is never going to be able to understand the context to break it intelligently.
Are people using editors that don't display long lines wrapping properly? Do people think everybody uses the same resolution, the same window size, the same columns per terminal, etc?
almost every rule has an exception where understandability could be improved by violating the rule, ex. line length. code format is huge for understandability/readability, which makes it worth paying attention to while you're writing.
in my experience the loudest advocates for code formatters are the ones who write really complicated code; which makes sense that they just hammer on code until it works without being able to reduce and simplify their logic and naming.
Bad linters are expensive. They add complexity to workflows and pipelines, slow down iteration speed, and create a nitpicky culture where most discussions miss the point. Multiply this by a whole engineering team, yikes.
Yet there are some good (parts of) linters, such as catching actual issues rather than preferences. If we bet on linters, they should increase our value multifold to be worth it.
They use the excuse of the linter sometimes highlighting potential bugs to impose their preferred formatting style wholesale over everyone. And it's purely an exercise of power of one person over others -- the computer doesn't care about your style.
And it's not enough, some people will ask you to move sections of code around and start arguing about naming once they have no inconsistent white spaces to complain about -- that's how you know it's not the linter or formatter that they want, they want to control people.
I use SwiftLint for my code (Swift, not supported in SuperLinter, and I don't expect it to be).
https://littlegreenviper.com/miscellany/swiftwater/swiftlint...
I am real big on code quality. LINT is not a silver bullet, but every little bit helps. I also use things like -wall (or the equivalent, thereof, in Swift), and heavy-duty code commenting.
https://medium.com/chrismarshallny/leaving-a-legacy-1c2ddb0c...
It's lovely somebody's picking up the torch here!
- UPM: universal package manager https://github.com/replit/upm
- Prybar: universal REPL interface for interpreters https://github.com/replit/prybar
I imagine the latter is possible thanks to it being a docker image.
So far I've been using this script I built for similar purposes:
https://gist.github.com/silviogutierrez/3dca60a6b5b8fe214052...
Runs locally, and only on changed files against master. Fixes all my python, JS, yaml, terraform, etc. And you can run it against a single file too so I integrated it with vim to replace all my linters.
I really hope the GitHub initiative projects takes off as a standard API (à la language server) for linters and fixers. Seems every single IDE needs to reinvent a plugin for applying a specific linter.
[0]: https://sourcelevel.io/blog/what-is-a-linter-and-why-your-te...
If possible for C as well, to a less extent.
for clang-format, it can not even add blank lines between functions, and it can not indent "public, private, protect" inside class sanely, which are two very basic needs. The rest options are worse, however, but I hope something better than clang-format.
http://clang.llvm.org/extra/clang-tidy/
cpplint?
Of course C was a different languange back then. But I am rather sure modern variants exist.
Clang-tidy comes to my mind, but I don't write any significant amount of C/C++ these days.
It seems like people are having more of an issue with bike shedding than actual code formatting.
Then I checked the code and see that this is a bash script which just runs the language-specific linters packaged in a Docker container :(.
CI linting/testing should be a final check, not a part of your iterative workflow. Any linting or testing you do in CI should have already been done locally by the dev.
If you're trying to enforce something locally you can definitely enforce it on CI automatically. Once people realized their PRs were failing due to linting issues they started checking them locally as well.
The problem I've seen is that the error message isn't obvious. It just says that the "build failed", which sounds more like a compilation error than a lint problem.