ansible / team-devtools

Shared practices, workflows and decisions impacting Ansible devtools projects

Home Page:https://ansible.readthedocs.io/projects/team-devtools/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

proposal: consolidating quoting on devtools projects

ssbarnea opened this issue · comments

Executive summary

In order to avoid confusions across our projects I would like to propose declaring double quotes as preferred for most file formats, unless that would require extra escaping.

Note that this consolidation approach does also happen to match default configuration of our linters/formatters such black, prettier, eslint, so applying requires only to remove few custom config.

There is no impact on Python files, as we already use it everywhere with these settings.

Details

The proposed rule is bit nuanced as avoiding escapes takes precedence. It means that if you have a string with double quotes inside, the prefered way is to enclose it with single quotes. I do think that prettier rationale for string quoting does describe it very well and happens to also match black behavior.

Please note that we do not want to add any linters to our projects that would tell user to fix quotes. If we can have an auto-fixer that can correct them we can enforce them but if we fail to find one, we will likely prefer not to enforce it. The reasoning for this is to minimize annoying contributors.

File formats targeted so far python, javascript, typescript, yaml. We will have to decide for others once we encounter them.

Reasoning

  • Black defaults to prefer double quotes and we already have multiple projects where we do enforce these, molecule and its plugins, ansible-compat and ansible-navigator.
  • Prettier seems to also prefer double quotes by default.
  • If we try to override tools configuration we risk getting into conflicts. I was able to identify a conflict between prettier and black on vscode-ansible repository, one that does not happen if we follow the defaults.
  • Microsoft own guidelines recommend double quotes for contributions to TypeScript itself since 2015. That is also backed by another comment explaining the reasoning:

All those languages either require double quotes for strings (e.g. C#, C++, F#) or at least allow double quotes for strings (e.g. Python, Ruby). It's easier not to ask people to shift their muscle memory when switching back and forth between languages.

Identified impact

  • We will have to remove prettier custom config that prefers single quotes from vscode-ansible and ansible-language-server projects. I checked with @tomaciazek and he will likely support this change as he said that the only reason why he did it was because Microsoft examples were using single quotes and he only wanted consistency inside the code base.
  • It seems that custom-use of single quotes can cause conflicts between prettier and eslint. I observed once such recursive issue with vscode-ansible project, but going for default-double-quotes does not produce any conflicts. The language server project is not affected by such conflict but I would really want to keep the same rules everywhere.
  • Eventually remove the skip-string-normalization from black config on ansible-lint. I added it while adopting black in order to make transition easier more than an year ago. DONE

I must say that it is weird to see double quotes in anything from the JS land. Historically, the convention was that the double quotes are used in HTML attributes and single quotes are used for scripting, minimizing collision. I don't see a strong case not to follow this guidance. Except when there is a need to avoid escaping.
Besides, MS is known to replace standards for its own convenience so I wouldn't blindly rely on them (/me recalls the existence of JScript and ActiveX).
Black is an even more terrible example. We never accepted it and it's currently legacy that needs to stop harassing people and preventing code readability in its current state.
FWIW single quotes are easier to work with.

P.S. It may be a bad idea in general to try applying standards for one ecosystem to another. The contributors coming from one ecosystem would be rather surprised by some decisions.

To summarize (subjective):
+0: For JavaScript/TypeScript use of either is allowed with no strong recommendation in either direction.
+0: We're doing application-side programming, with no HTML involved so we do not need to worry about collisions.
+1: Most languages that do resemble JavaScript, enforce use of double quotes, so it is easier for most programmers to read such code and rely on already trained muscle memory.

P.S. It may be a bad idea in general to try applying standards for one ecosystem to another. The contributors coming from one ecosystem would be rather surprised by some decisions.

Well, since use of either is allowed and adopted as a standard widely, I don't see a problem.

+1: It is default in Prettier and ESLint. Default means that most projects don't change it, more wide-spread use of double quotes, more programmers used to them.
-1: It will require changing current code to adapt to that standard.
-0.5: Yes, it does require shift to type in a double quote ;)

To me double quotes win by a slight margin.

+0: We're doing application-side programming, with no HTML involved so we do not need to worry about collisions.

I think in the VS Code extension there may be some.

By the way, here's what the most popular style guides in TS/JS use: https://airbnb.io/javascript/#strings--quotes & https://airbnb.io/javascript/react/#quotes.

So I would rather go for using https://npmjs.com/eslint-config-airbnb-base preset.

Numbers speak for themselves :)
eslint-config-airbnb-base:
image

eslint-config-prettier:
image