r-lib / lintr

Static Code Analysis for R
https://lintr.r-lib.org
Other
1.19k stars 184 forks source link

Unexpected `indentation_linter` and `trailing_whitespace_linter` lints for `.Rtex` #2013

Open jabenninghoff opened 1 year ago

jabenninghoff commented 1 year ago

Linting this file, adapted from https://github.com/r-lib/lintr/blob/main/tests/testthat/dummy_packages/package/vignettes/test.Rtex, generates unexpected lints:

test.Rtex:

\documentclass{article}
\usepackage{graphicx}
\title{Test}

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
no sea takimata sanctus est Lorem ipsum dolor sit amet.

%% begin.rcode test_chunk
% b <- function(x) {
%   x
% }
%
% c <- 2
%% end.rcode
% Rscript -e 'lintr::lint("test.Rtex", lintr::linters_with_defaults())' 
/Users/agamemnon/GitHub/rdev/tests/testthat/test-ci/test.Rtex:11:2: style: [indentation_linter] Indentation should be 0 spaces but is 2 spaces.
  b <- function(x) {
~^
/Users/agamemnon/GitHub/rdev/tests/testthat/test-ci/test.Rtex:14:1: style: [trailing_whitespace_linter] Trailing whitespace is superfluous.

^
/Users/agamemnon/GitHub/rdev/tests/testthat/test-ci/test.Rtex:15:2: style: [indentation_linter] Indentation should be 0 spaces but is 2 spaces.
  c <- 2
~^

Previous versions of lintr, including 3.0.2 did not generate indentation_linter lints, but do generate the trailing_whitespace_linter lint. I expected this test file to be lint-free.

MichaelChirico commented 1 year ago

indentation_linter() is new for 3.1.0, and was not part of 3.0.2.

AshesITR commented 1 year ago

This is a known issue with Rtex, see #1043. You'll unfortunately have to disable indentation linter manually for .Rtex files, or altogether until we fix the underlying issue.