Skip to content

Bug 18757 - Refine and test .editorconfig to set R Core style #104

@hturner

Description

@hturner

A recurring annoyance for both contributors and R Core developers is that whitespace and other style changes can be introduced as a result of the contributor's IDE settings. An EditorConfig file is intended to address this exact issue.

@krlmlr shared a draft .editorconfig file in Bug 18757.

I think a useful contribution would be to refine the .editorconfig and test it with Editorconfig-Checker to identify any conflicts between the configuration and the R sources. This may help to refine the .editorconfig further and assess the impact of any unresolvable conflicts.

Here is an updated version of @krlmlr' .editorconfig:

# EditorConfig: https://EditorConfig.org

# Don't search for .editorconfig files in parent directories (may conflict)
root = true

# Global settings:
[*]
# Unix-style newlines with a newline ending every file
end_of_line = lf
insert_final_newline = true
# Set default charset
charset = utf-8
# In an ideal world, the setting below would be true, but we want to remove the existing
# spaces at EOL first before turning that on.
trim_trailing_whitespace = false

# DESCRIPTION is special, don't remove trailing spaces after :
[DESCRIPTION]
trim_trailing_whitespace = false

# C files: indentation = 4 spaces; every 8 spaces in indentation replaced with tab
[*.c]
indent_style = tab
indent_size = 4
tab_width = 8

# R files: indentation = 4 spaces (always); any tab should be displayed as 8 spaces
[*.R]
indent_style = space
indent_size = 4
tab_width = 8

# Rd files: indentation = 2 spaces (always)
[*.Rd]
indent_style = space
indent_size = 2

# Makefiles: Tab indentation (no size specified)
[Makefile]
indent_style = tab

The indentation rules for R and C files are consistent with @mmaechler's Comment 1 in the bug report. I have tested this with Vim and Emacs. Unfortunately the C configuration doesn't work in VS Code or Positron, as VS Code can not be set to replace spaces with tabs (see microsoft/vscode#42740, microsoft/vscode#5394). In that case, the best we can do is to use VS Code settings directly to get a close as possible to the right configuration - I'll open another issue about that.

Extension task

An extension to this task would be to add a section to the R Dev Guide, sharing the .editorconfig and how to use it Vim and Emacs. It could go in a new chapter "IDE Setup".

While there is no .editorconfig in the R sources, it is best to put it in a directory one level out from the source repository. E.g. you might have, e.g. svn/.editorconfig, then check out to svn/R-devel or similar.

Emacs

I did not need to install anything, just add (editorconfig-mode 1) to my init.el.

Vim

Install the EditorConfig plugin as a Vim8 plugin: https://github.com/editorconfig/editorconfig-vim#install-as-vim8-plugin (although I have Vim 9.1 on my mac, the EditorConfig plugin wasn't bundled in, you can check via :scriptnames).

Metadata

Metadata

Assignees

No one assigned

    Labels

    MiscIssues that cannot be classified otherwise

    Type

    No type

    Projects

    Status

    To Do

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions