-
-
Notifications
You must be signed in to change notification settings - Fork 43
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
Automatic formatting of Inko code #334
Comments
Please do these two things.
|
@spartanatreyu My plan is to do the exact opposite 😄: No configuration settings whatsoever (e.g. like gofmt), and use 2 spaces for indentation like we do now. The moment you introduce any settings, the value of an automatic formatter begins to diminish.
Are you referring to screen readers? As far as I know, such setups are perfectly capable of handling space based indentation, albeit through configuration, which one likely needs to do anyway, because having it read "curly open brace" out loud every time is too time consuming.
Neither of which are supported by any of the well known editing environments as far as I know, and the use of proportional fonts is such a niche I'm not sure it's even worth considering (and again, no widespread support in the first place).
That's the whole point of using spaces though: to ensure that no matter what tool you use to view the code, it looks consistent. This combined with it being more difficult to mix spaces and tabs by accident (because if spaces are used, editors typically map Tab to the appropriate amount of spaces), makes it much easier to get started as you don't need to fiddle with your indentation settings. |
Hopefully we can agree on this single point:
If not, I think the focus needs to be on that point first. If you do, I have some responses, and some questions: Responses to points:
Questions about points:
|
@spartanatreyu The goal of Inko's code formatter is to enforce a single style across all Inko projects. Enforcing the style preferences of a specific project is specifically a non-goal, and never will. This is what Go did right and rustfmt in my opinion did wrong (besides choosing 120 as a line length limit). Ensuring there's only a single style across all projects makes jumping between projects much easier, and removes the whole debate on how certain things should be formatted, what indentation should be used, etc.
Not at all. If you introduce a setting to change the formatting rules, some projects will start using it. When that happens, you no longer have a consistent formatting style across projects. This gets worse as the number of settings and projects increases, as the number of combinations of the two increases.
Which is exactly why there won't be a configuration file 😃
Perhaps, but it's still not relevant to Inko. I have no interest in elastic tab stops myself, and even if Inko were to use it and get popular, editors simply aren't going to bother. Even if they did, elastic tab stops don't offer any benefits over just using spaces and not fuzzing about the few bytes per file you might save from using tabs. To put it differently, arguing over tabs versus spaces is very much a case of bike shedding. I don't want such a debate to keep taking place, so Inko's formatter will only support spaces for indentation.
I'm honestly not sure what argument you're trying to make here. The "If the point is to make the code look consistent, then that would mean the language mandating an editor and a theme used." bit is also a slippery slope fallacy that isn't useful, because following that same train of thought we should just ship everybody the exact same computer. The goal of a formatter with an ironclad set of rules it enforces is to ensure that the formatting is consistent everywhere, not how it's presented in terms of colors, font sizes, etc. Some users may disagree with this, but you'll always find such people and I'm not going to cater towards a tiny vocal minority With that all said: I very much appreciate the feedback and thoughts, but the plan for Inko's formatter remains the same: no configuration, and a single style it enforces, and spaces for indentation. Of course certain aspects of that formatting may change based on feedback (e.g. how long lines are wrapped), but only if there's actual examples/use cases/etc, not artificial cases people come up with to further their own preferences. |
This fixes #334. Changelog: added
This fixes #334. Changelog: added
This fixes #334. Changelog: added
This fixes #334. Changelog: added
This fixes #334. Changelog: added
This fixes #334. Changelog: added
This fixes #334. Changelog: added
This fixes #334. Changelog: added
This fixes #334. Changelog: added
This fixes #334. Changelog: added
This fixes #334. Changelog: added
This fixes #334. Changelog: added
This fixes #334. Changelog: added
This fixes #334. Changelog: added
This fixes #334. Changelog: added
This fixes #334. Changelog: added
This fixes #334. Changelog: added
This fixes #334. Changelog: added
This fixes #334. Changelog: added
This fixes #334. Changelog: added
This fixes #334. Changelog: added
This fixes #334. Changelog: added
This fixes #334. Changelog: added
This fixes #334. Changelog: added
This fixes #334. Changelog: added
This fixes #334. Changelog: added
This fixes #334. Changelog: added
This fixes #334. Changelog: added
This fixes #334. Changelog: added
This fixes #334. Changelog: added
This fixes #334. Changelog: added
This fixes #334. Changelog: added
This fixes #334. Changelog: added
This fixes #334. Changelog: added
This add the command `inko fmt`, used for formatting (or checking the formatting of) source files. The command supports formatting both existing files as well as input read from STDIN. This commit also includes changes to string literals: both single and double quoted strings are now semantically the same, meaning they both support escape sequences and string interpolation. This change makes formatting string literals a lot easier, and solves the debate of "should I use single or double quoted?". This fixes #334. Changelog: added
This add the command `inko fmt`, used for formatting (or checking the formatting of) source files. The command supports formatting both existing files as well as input read from STDIN. This commit also includes changes to string literals: both single and double quoted strings are now semantically the same, meaning they both support escape sequences and string interpolation. String interpolation syntax is also changed from this: let name = 'Alice' "hello {name}" To this: let name = 'Alice' "hello ${name}" These changes make the syntax more consistent and less ambiguous, and as a result make formatting the code less of a challenge. This fixes #334. Changelog: added
This add the command `inko fmt`, used for formatting (or checking the formatting of) source files. The command supports formatting both existing files as well as input read from STDIN. This commit also includes changes to string literals: both single and double quoted strings are now semantically the same, meaning they both support escape sequences and string interpolation. String interpolation syntax is also changed from this: let name = 'Alice' "hello {name}" To this: let name = 'Alice' "hello ${name}" These changes make the syntax more consistent and less ambiguous, and as a result make formatting the code less of a challenge. This fixes #334. Changelog: added
This add the command `inko fmt`, used for formatting (or checking the formatting of) source files. The command supports formatting both existing files as well as input read from STDIN. Style wise, the way closures are formatted is changed: closure arguments are always passed inside the parentheses, with the purpose of removing the trailing closure syntax in the release _after_ the one that includes `inko fmt`. This means that instead of this: foo.bar(10, 20) fn { ... }.baz(30) The code is formatted like so: foo.bar(10, 20, fn { ... }).baz(30) The purpose of this change is to make the syntax more familiar, and to make both parsing and formatting less complicated. Parsing in particular is made more difficult by the presence of trailing closures. This commit also includes changes to string literals: both single and double quoted strings are now semantically the same, meaning they both support escape sequences and string interpolation. String interpolation syntax is also changed from this: let name = 'Alice' "hello {name}" To this: let name = 'Alice' "hello ${name}" These changes make the syntax more consistent and less ambiguous, and as a result make formatting the code less of a challenge. This fixes #334. Changelog: added
This add the command `inko fmt`, used for formatting (or checking the formatting of) source files. The command supports formatting both existing files as well as input read from STDIN. Style wise, the way closures are formatted is changed: closure arguments are always passed inside the parentheses, with the purpose of removing the trailing closure syntax in the release _after_ the one that includes `inko fmt`. This means that instead of this: foo.bar(10, 20) fn { ... }.baz(30) The code is formatted like so: foo.bar(10, 20, fn { ... }).baz(30) The purpose of this change is to make the syntax more familiar, and to make both parsing and formatting less complicated. Parsing in particular is made more difficult by the presence of trailing closures. This commit also includes changes to string literals: both single and double quoted strings are now semantically the same, meaning they both support escape sequences and string interpolation. String interpolation syntax is also changed from this: let name = 'Alice' "hello {name}" To this: let name = 'Alice' "hello ${name}" These changes make the syntax more consistent and less ambiguous, and as a result make formatting the code less of a challenge. This fixes #334. Changelog: added
This add the command `inko fmt`, used for formatting (or checking the formatting of) source files. The command supports formatting both existing files as well as input read from STDIN. Style wise, the way closures are formatted is changed: closure arguments are always passed inside the parentheses, with the purpose of removing the trailing closure syntax in the release _after_ the one that includes `inko fmt`. This means that instead of this: foo.bar(10, 20) fn { ... }.baz(30) The code is formatted like so: foo.bar(10, 20, fn { ... }).baz(30) The purpose of this change is to make the syntax more familiar, and to make both parsing and formatting less complicated. Parsing in particular is made more difficult by the presence of trailing closures. This commit also includes changes to string literals: both single and double quoted strings are now semantically the same, meaning they both support escape sequences and string interpolation. String interpolation syntax is also changed from this: let name = 'Alice' "hello {name}" To this: let name = 'Alice' "hello ${name}" These changes make the syntax more consistent and less ambiguous, and as a result make formatting the code less of a challenge. This fixes #334. Changelog: added
This add the command `inko fmt`, used for formatting (or checking the formatting of) source files. The command supports formatting both existing files as well as input read from STDIN. Style wise, the way closures are formatted is changed: closure arguments are always passed inside the parentheses, with the purpose of removing the trailing closure syntax in the release _after_ the one that includes `inko fmt`. This means that instead of this: foo.bar(10, 20) fn { ... }.baz(30) The code is formatted like so: foo.bar(10, 20, fn { ... }).baz(30) The purpose of this change is to make the syntax more familiar, and to make both parsing and formatting less complicated. Parsing in particular is made more difficult by the presence of trailing closures. This commit also includes changes to string literals: both single and double quoted strings are now semantically the same, meaning they both support escape sequences and string interpolation. String interpolation syntax is also changed from this: let name = 'Alice' "hello {name}" To this: let name = 'Alice' "hello ${name}" These changes make the syntax more consistent and less ambiguous, and as a result make formatting the code less of a challenge. This fixes #334. Changelog: added
This add the command `inko fmt`, used for formatting (or checking the formatting of) source files. The command supports formatting both existing files as well as input read from STDIN. Style wise, the way closures are formatted is changed: closure arguments are always passed inside the parentheses, with the purpose of removing the trailing closure syntax in the release _after_ the one that includes `inko fmt`. This means that instead of this: foo.bar(10, 20) fn { ... }.baz(30) The code is formatted like so: foo.bar(10, 20, fn { ... }).baz(30) The purpose of this change is to make the syntax more familiar, and to make both parsing and formatting less complicated. Parsing in particular is made more difficult by the presence of trailing closures. This commit also includes changes to string literals: both single and double quoted strings are now semantically the same, meaning they both support escape sequences and string interpolation. String interpolation syntax is also changed from this: let name = 'Alice' "hello {name}" To this: let name = 'Alice' "hello ${name}" These changes make the syntax more consistent and less ambiguous, and as a result make formatting the code less of a challenge. This fixes #334. Changelog: added
This add the command `inko fmt`, used for formatting (or checking the formatting of) source files. The command supports formatting both existing files as well as input read from STDIN. Style wise, the way closures are formatted is changed: closure arguments are always passed inside the parentheses, with the purpose of removing the trailing closure syntax in the release _after_ the one that includes `inko fmt`. This means that instead of this: foo.bar(10, 20) fn { ... }.baz(30) The code is formatted like so: foo.bar(10, 20, fn { ... }).baz(30) The purpose of this change is to make the syntax more familiar, and to make both parsing and formatting less complicated. Parsing in particular is made more difficult by the presence of trailing closures. This commit also includes changes to string literals: both single and double quoted strings are now semantically the same, meaning they both support escape sequences and string interpolation. String interpolation syntax is also changed from this: let name = 'Alice' "hello {name}" To this: let name = 'Alice' "hello ${name}" These changes make the syntax more consistent and less ambiguous, and as a result make formatting the code less of a challenge. This fixes #334. Changelog: added
This add the command `inko fmt`, used for formatting (or checking the formatting of) source files. The command supports formatting both existing files as well as input read from STDIN. Style wise, the way closures are formatted is changed: closure arguments are always passed inside the parentheses, with the purpose of removing the trailing closure syntax in the release _after_ the one that includes `inko fmt`. This means that instead of this: foo.bar(10, 20) fn { ... }.baz(30) The code is formatted like so: foo.bar(10, 20, fn { ... }).baz(30) The purpose of this change is to make the syntax more familiar, and to make both parsing and formatting less complicated. Parsing in particular is made more difficult by the presence of trailing closures. This commit also includes changes to string literals: both single and double quoted strings are now semantically the same, meaning they both support escape sequences and string interpolation. String interpolation syntax is also changed from this: let name = 'Alice' "hello {name}" To this: let name = 'Alice' "hello ${name}" These changes make the syntax more consistent and less ambiguous, and as a result make formatting the code less of a challenge. This fixes #334. Changelog: added
This add the command `inko fmt`, used for formatting (or checking the formatting of) source files. The command supports formatting both existing files as well as input read from STDIN. Style wise, the way closures are formatted is changed: closure arguments are always passed inside the parentheses, with the purpose of removing the trailing closure syntax in the release _after_ the one that includes `inko fmt`. This means that instead of this: foo.bar(10, 20) fn { ... }.baz(30) The code is formatted like so: foo.bar(10, 20, fn { ... }).baz(30) The purpose of this change is to make the syntax more familiar, and to make both parsing and formatting less complicated. Parsing in particular is made more difficult by the presence of trailing closures. This commit also includes changes to string literals: both single and double quoted strings are now semantically the same, meaning they both support escape sequences and string interpolation. String interpolation syntax is also changed from this: let name = 'Alice' "hello {name}" To this: let name = 'Alice' "hello ${name}" These changes make the syntax more consistent and less ambiguous, and as a result make formatting the code less of a challenge. This fixes #334. Changelog: added
This add the command `inko fmt`, used for formatting (or checking the formatting of) source files. The command supports formatting both existing files as well as input read from STDIN. Style wise, the way closures are formatted is changed: closure arguments are always passed inside the parentheses, with the purpose of removing the trailing closure syntax in the release _after_ the one that includes `inko fmt`. This means that instead of this: foo.bar(10, 20) fn { ... }.baz(30) The code is formatted like so: foo.bar(10, 20, fn { ... }).baz(30) The purpose of this change is to make the syntax more familiar, and to make both parsing and formatting less complicated. Parsing in particular is made more difficult by the presence of trailing closures. This commit also includes changes to string literals: both single and double quoted strings are now semantically the same, meaning they both support escape sequences and string interpolation. String interpolation syntax is also changed from this: let name = 'Alice' "hello {name}" To this: let name = 'Alice' "hello ${name}" These changes make the syntax more consistent and less ambiguous, and as a result make formatting the code less of a challenge. This fixes #334. Changelog: added
Inko should provide an official code formatter (i.e.
inko format
). This formatter should be opinionated and not offer any settings to configure.The formatter won't preserve custom whitespace outside of comments and strings, instead always formatting files according to its own style. This makes things a bit easier as preserving custom whitespace is difficult.
The formatter likely has to operate at the lexer level. If we operate at the parser level we have to first change the parser such that we can preserve comments.
For linting purposes the formatter should have two modes: format a bunch of files (or all of them in the project), or simply check if they would be changed by formatting. The latter could be used in a CI environment to ensure changed code is formatted accordingly.
The text was updated successfully, but these errors were encountered: