|
1 | | -# Summary: coding style configuration for editors that read .editorconfig. |
| 1 | +# Copyright 2025 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 16 | +# Common editor configurations for this project. |
2 | 17 | # |
3 | 18 | # EditorConfig defines a file format for specifying some common coding style |
4 | | -# parameters. Many editors recognize .editorconfig files automatically, and |
5 | | -# there exist plugins for other editors. See https://spec.editorconfig.org/. |
| 19 | +# parameters. Many IDEs and editors read .editorconfig files, either natively |
| 20 | +# or via plugins. A few formatters also read .editorconfig; shfmt and Prettier |
| 21 | +# are two examples (as of early 2025). |
| 22 | +# |
| 23 | +# We mostly follow Google's style guides (https://google.github.io/styleguide/) |
| 24 | +# with very few deviations. |
| 25 | +# |
| 26 | +# Miscellaneous notes: |
| 27 | +# |
| 28 | +# - The EditorConfig property `max_line_length` is not set here because its |
| 29 | +# intended behavior is poorly specified. (See the discussion in the comments |
| 30 | +# at https://github.com/editorconfig/editorconfig/issues/387) It *would* have |
| 31 | +# been desirable to define a project convention for the line width here, but |
| 32 | +# we must instead use editor-specific configuration files to do that. |
| 33 | +# |
| 34 | +# - With few exceptions (e.g., shfmt), `.editorconfig` files are not read by |
| 35 | +# linters or formatters, which means the project needs separate config files |
| 36 | +# for those tools. This includes markdownlint, yamllint, and others. |
| 37 | +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
6 | 38 |
|
7 | 39 | root = true |
8 | 40 |
|
9 | 41 | [*] |
10 | 42 | charset = utf-8 |
11 | | -end_of_line = lf |
| 43 | +indent_style = space |
12 | 44 | insert_final_newline = true |
13 | 45 | spelling_language = en-US |
| 46 | +# It would be preferable not to set tab_width, but some EditorConfig plugins |
| 47 | +# (e.g., Emacs's) set it equal to indent_size if it's not set otherwise. |
| 48 | +tab_width = 8 |
| 49 | +# Trailing whitespace on lines is almost always noise. An exception is in |
| 50 | +# Markdown, where two spaces = line break; however, that's such a foot-gun in |
| 51 | +# practice that we avoid it. So, it's okay to set this next value globally. |
14 | 52 | trim_trailing_whitespace = true |
15 | 53 |
|
| 54 | +[{BUILD,*.BUILD,*.bzl,*.bazel}] |
| 55 | +# Google doesn't have a style guideline for Bazel files. Most people use 4. |
| 56 | +indent_size = 4 |
| 57 | + |
| 58 | +[{*.cc,*.h}] |
| 59 | +# This matches Google style guidelines. |
| 60 | +indent_size = 2 |
| 61 | + |
| 62 | +[{*.ts,*.js}] |
| 63 | +# This matches Google style guidelines. |
| 64 | +indent_size = 2 |
| 65 | + |
| 66 | +[*.json] |
| 67 | +# Not stated explicitly in Google's guidelines, but the examples use 2. |
| 68 | +indent_size = 2 |
| 69 | + |
16 | 70 | [*.py] |
| 71 | +# This matches Google style guidelines. |
17 | 72 | indent_size = 4 |
18 | | -indent_style = space |
19 | | -max_line_length = 100 |
| 73 | + |
| 74 | +[*.rst] |
| 75 | +# Google doesn't have a style guideline for reStructuredText. Many people use 3. |
| 76 | +indent_size = 3 |
20 | 77 |
|
21 | 78 | [*.sh] |
| 79 | +# Google style guidelines use 2. |
22 | 80 | indent_size = 4 |
23 | | -indent_style = space |
24 | | -max_line_length = 100 |
| 81 | +# The following are used by shfmt. These bring it closer to Google's style. |
| 82 | +binary_next_line = true |
| 83 | +shell_variant = bash |
| 84 | +space_redirects = true |
| 85 | +switch_case_indent = true |
| 86 | + |
| 87 | +# If this repository has a "third_party" directory, ignore it entirely. |
| 88 | +# Note: shfmt also respects this if you run it with --appply-ignore. |
| 89 | +[third_party/**] |
| 90 | +ignore = true |
25 | 91 |
|
26 | | -[*.yml,*.yaml] |
| 92 | +[{*.yaml,*.yml}] |
| 93 | +# Google doesn't have style guidelines for YAML. Most people use indent = 2. |
27 | 94 | indent_size = 2 |
0 commit comments