Coder Social home page Coder Social logo

lint's People

Contributors

halpo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

lint's Issues

Overall slowness

Hi,

When I run multiple tests on a file, a lot of time is wasted running the same things for each test. find_region is the main culprit.

I'd like to suggest that the lint package make use of the memoise package. For example, add memoize(find_region). Doing this made my process run four times faster but I had to insert memoize in an unconventional and hacky way (via unlockBinding, assignInNamespace, etc.).

Thanks for considering it.

Errors when calling from command line

I am attempting to write a wrapper script to call lint on an R code file and am running into and error when I call things from the command line using Rscript, while things work in the R console. See the example script in this gist:

https://gist.github.com/cameronbracken/6176642

on the command line I get:

$ ./Rlint.R lint_test.R 
Lint checking: lint_test.R
Error in valid_find(result) : could not find function "is"
Calls: lint ... FUN -> do.call -> <Anonymous> -> stopifnot -> valid_find
Execution halted

while in the R interpreter I get:

> lint('lint_test.R')
Lint checking: lint_test.R
Lint: Equal sign assignments: found on lines 1
Lint: Assignments are not allowed to be nested in function calls.: found on lines 1

P.S. that second lint comment in the R interpreter may be a separate issue

`spacing.spacearoundinfix` and operators at the end of a line

In R, it is recommended to break long lines after a binary operator, so that in script mode the interpreter knows that the statement is not complete and that the rest of it is on the next line. For example,

x <- 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1

should be broke as follows:

x <- 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 +
1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1

If the linebreak is put right after the + operator on the first of the two lines above, spacing.spacearoundinfix will complain. I wish spacing.spacearoundinfix treated linebreaks like any other white space when checking after a binary operator.

Thanks.

`text ` argument to `lint` function does not work

I suppose the text argument to the lint function is for testing things like:

lint(text = "a=1+1")

I get

Error in inherits(.data, "split") : object 'files' not found

Quick look at the code for lint and it seems that the file variable defined as file <- textConnection(text) should be named files.

when using indentation check, find_function_args gets confused by calls to other functions within the args

code to reproduce the issue; the first raises a flag, the second passes. The only difference between the two texts is the order of the arguments.

mytest <- list(pattern = "^(   )*( )\\S",
               message = "indentation should be by 3 spaces.", 
               exclude.region = c("find_function_args", "find_call_args")
               )

mytext1 <- "
   foo <- function(x,
                   y = attr(x, 'bar'),
                   z){
      return(x)
   }
"

mytext2 <- "
   foo <- function(x,
                   z,
                   y = attr(x, 'bar')){
      return(x)
   }
"

writeLines(text = mytext1, "file1.R")
writeLines(text = mytext2, "file2.R")

# flagged
check1 <- lint(file    = "file1.R",
               style   = list(mytest),
               recurse = FALSE
               )

# passes
check2 <- lint(file    = "file2.R",
               style   = list(mytest),
               recurse = FALSE
               )

R CMD check NOTE

I'm seeing

checking R code for possible problems ... NOTE
autotest_style: no visible global function definition for ‘test_that’
test_style: no visible global function definition for
  ‘expect_equivalent’

Environment Checking

Add Environment checking for supporting naming conventions. Functions can be checked at runtime. There may need to be a way to examine within functions for naming conventions of inside of functions. At the global level everything that is not a function could be considered a constant.

`styles.assignment.notinfcall` and functions like `system.time`, `within`, `local`

This may be related to halpo's issue #5.

system.time, within, local are some of R's function where using assignments inside the arguments are perfectly ok, e.g:

GOOD

system.time(a <- sleep(1))

BAD

system.time(a = sleep(1))

GOOD

within(cars, speed.dist <- speed * dist)

BAD

within(cars, speed.dist = speed * dist)

Would it be possible to modify styles.assignment.notinfcall to handle such exceptions? If not, I would consider removing styles.assignment.notinfcall from lint's default list of tests: lint.style.

unexpected file content requirements

I can't put a finger on them, but there seems to be minimum file content requirements (other than syntactically valid R code) for the function lint to work fine.

For example, lint dies if provided an empty file, or a file with the following contents:

a <- "HELLO"
mysum <- sum
z <- 1:12

Here is the error message I am seeing:

lint(file = "/tmp/Rtmpc5W4Xl/file4c7f408cd504")
Lint checking: /tmp/Rtmpc5W4Xl/file4c7f408cd504
Error in [.data.frame(ldply(parse.data, parse2find), names(empty.find)) :
undefined columns selected
15: lint(file = "/tmp/Rtmpc5W4Xl/file4c7f408cd504")
14: llply(files, lint_file, style = style)
13: structure(lapply(pieces, .fun, ...), dim = dim(pieces))
12: lapply(pieces, .fun, ...)
11: FUN(X[[1L]], ...)
10: llply(style, dispatch_test, file = file, parse.data = parse.data,
lines = lines)
9: structure(lapply(pieces, .fun, ...), dim = dim(pieces))
8: lapply(pieces, .fun, ...)
7: FUN(X[[3L]], ...)
6: find_region(exclude.region, file = file, lines = lines, parse.data = parse.data)
5: fun.region[[i]](file = file, lines = lines, parse.data = parse.data)
4: parse2find(call.args)
3: ldply(parse.data, parse2find)[names(empty.find)]
2: [.data.frame(ldply(parse.data, parse2find), names(empty.find))
1: stop("undefined columns selected")

`spacing.spacearoundequals`

spacing.spacearoundequals is ok with this:

print(paste("x =", x))

... but not with this:

print(paste("x =",
x))

I feel both styles should be accepted.

Span difference chokes on single line find

As reported by Adam Wolenc:

I find that lint bails out on the following 2-line input:

which(a[,'b'])
print('a =')

I get the following stack trace:

> lint('bubbles/pathological.R')
Error in apply(overlaps, 1, any) : dim(X) must have a positive length

Enter a frame number, or 0 to exit   

1: lint("bubbles/pathological.R")
2: llply(lint.tests, dispatch_test, file = file, parse.data = parse.data, line
3: structure(lapply(pieces, .fun, ...), dim = dim(pieces))
4: lapply(pieces, .fun, ...)
5: FUN(X[[2]], ...)
6: span_difference(test.result, exclude.spans)
7: apply(overlaps, 1, any)

`spacing.spacearoundinfix` also catches unary operators

This will require a new finder function for finding unary operators. There was a possible fix in the development of parser that was an identifier for unary operators. The patches for parser need to be more thoroughly tested for integration as the class attribute in the data has changed.

Write documentation objects to `./man`

To fill the promise of creating a full documentation solution there needs to be a function that creates the Rd files from all the objects in a package.

This will have to

  1. Have the objects loaded.
  2. Have all example blocks associated.
  3. Have a way to combine documentation objects into the same file for output.
  4. Be able to infer the filename.

Then run the format_Rd function for each object to create the resulting files.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.