How can I use the jshint configuration file to disable warnings? - jshint

i have a pattern that is used all over my codebase that throws a frivolous warning on jshint.
I got the reason for the warning using --verbose. it is W002.
I can disable that warning on each js file by adding /*jshint -W002*/
but i can't see any way to disable that warning by instead of editing every single file, adding an option on my global jshint.json configuration file.
Is there any way to do that?
edit:
seems to be a common problem

I was about to ask this question, then I found the answer myself.
Get the warning ID. Eg, for
A trailing decimal point can be confused with a dot
The warning ID is W047. jslinterrors can help find the warning IDs.
In your .jshintrc:
}
"-W047": true
}
The syntax is really poor with the magic numbers (commonly regarded as a bad idea in programming) - eslint does it better - but that's how to globally ignore a warning.

Related

Rcpp can't find nloptrAPI.h header

I'm trying to find an Rcpp replacement for the base optimize function. This link
https://github.com/eddelbuettel/rcppnloptexample/blob/master/src/nlopt.cpp
is a potential solution but I can't get past the sourceCpp error
Error in Rcpp::sourceCpp("R/nlopt.cpp") :
Error 1 occurred building shared library.
> library('nloptr')
> Rcpp::sourceCpp("R/nlopt.cpp")
nlopt.cpp:4:10: fatal error: 'nloptrAPI.h' file not found
The header file is in fact on my computer at /Library/Frameworks/R.framework/Versions/4.1/Resources/library/nloptr/include
I can include the whole path to the header and it seems to work fine but that seems a bit kludgy.
What do I need to do to tell R or Rcpp where to look?
This link as some useful discussion about the issue of finding headers.
https://stackoverflow.com/questions/13995266/using-3rd-party-header-files-with-rcpp has useful information.
To find out where your 'missing' header is located, the /Library/Frameworks ... link above is useful, replacing nloptr with the name of the package that has the header you are looking for.

RDCOMClient log file

I have been using RDCOMClient for a while now to interact with vendor software. For the most part it has worked fine. Recently, however, I have the need to loop through many operations (several hundred). I am running into problems with the RDCOM.err file growing to a very large size (easily GBs). This file is put in C: with no apparent option to change that. Is there some way that I can suppress this output or specify another location for the file to go? I don't need any of the output in the file so suppressing it would be best.
EDIT: I tried to add to my script a file.remove but R has the file locked. The only way I can get the lock released is to restart R.
Thanks.
Setting the permissions to read only was going to be my suggested hack.
A slightly more elegant approach is to edit one line of the C code in the package in src/RUtils.h from
\#define errorLog(a,...) fprintf(getErrorFILE(), a, ##__VA_ARGS__); fflush(getErrorFILE());
to
\#define errorLog(a, ...) {}
However, I've pushed some simple updates to the package on github that add a writeErrors() function that one can use to toggle whether errors are written or not. So this allows this to be turned on and off dynamically.
So
library(RDCOMClient)
writeErrors(FALSE)
will turn off the error logging to the file.
I found a work around for this. I created the files C:\RDCOM.err and C:\RDCOM_server.err and marked them both as read-only. I am not sure if there is a better way to accomplish this, but for now I am running without logging.

"Non-exhaustive patterns in case" error while parsing the BNFC file

I am getting
bnfc: src/LexBNF.x:(80,13)-(86,20): Non-exhaustive patterns in case
error. What does it mean?
It doesn't really say what's wrong my BNF grammar, and I have no idea how to find the error. I tried looking for it for past few days, unsuccessfully.
I checked if every symbol is defined somewhere in the file, I fixed some rules, nothing helped.
I used to have 2.6, and had this same problem. However, on the tool's webpage, it says that some improvements about error messages have been made since earlier versions, so I installed the latest version (2.8), and that gave me a more informative error message. I'd recommend that you do the same.
Could be because you forgot the backslash on the grammar definition.
The link show a similar case: https://groups.google.com/forum/#!topic/proglang-course-2013/guL-rKm4Q_8

Can I check if roxygenize failed?

Is it possible to detect if there was a problem when running roxygenize (package roxygen2)?
I want to automate the process documenting, checking and building a package, and would like to stop when documenting goes wrong.
The roxygenize help says the return value is NULL, and I searched stackoverflow without success. Currently, I need to look at the output and search if there was a line starting with "Error".
Any hint appreciated!
When roxygenize finds an error, for example, you included stop("Raise an error") in your code, then roxygenize will return an error.
The other scenario (which is what you are getting at), is that roxygenise is able to finish, but some aspects of the documentation process are incorrect. In this case, these errors are stored as warnings. So one solution is to change warnings to errors.
For example, suppose you had a file containing the line:
#' #XXX
This would cause:
roxygenise("pkg/")
to raise a warning
Warning: XXX is an unknown key in block AllGenerics.R:5
If we changed warnings to errors:
##All warnings are now errors
options(warn=2)
Then
roxygenise("pkg/")
would raise the error:
Error: (converted from warning) XXX is an unknown key in block AllGenerics.R:5
You can then use the standard tryCatch technique for dealing with errors.

When to use `source()` or `attach()`

Part of my project directory structure looks like:
\projects\project\main.R
\projects\project\src
where \src contains a bunch of 1-function-per-file, project-specific functions.
Q: What's the best practice way to add these functions to the working directory projects\project?
There are a few solutions I see:
attach("./src"). I'm trying to avoid this because (1) the Google Styleguide recommends avoiding the use of attach() and (2) I receive the
Warning messages:
1: Reading Unix style database directory (./tmp) from Splus on Windows: may
have problems finding some datasets, especially those whose names
differ only by case (file tmp-script1.ssc should not have been made by
Splus on Windows) in: exists(name, where = db)
when doing this.
lapply(paste("./src/",list.files("./src/"),sep=""),source). This works perfectly fine, it just seems clunky. There has to be a better way, right?
Refer to my functions by their full name ./src/myfunc. This will get ugly very quick. I'm sure there's a better way.
Get rid of the ./src part of my directory and just throw all the functions in the main working directory. The problem with this is that I'd prefer to keep with a directory structure that is close to that of John Myles White's ProjectTemplate
Throw all the functions in one file, ./src/func.R and source that. I guess this approach avoids the ugliness of "2." above, but I'd really like to have one function per file. Just seems cleaner that way.
Try
lapply(list.files("src", full.names = TRUE), source)
EDIT
or
lapply(Sys.glob("src/*"), source)
If you don't want to put everything into a local package, then I'd go for option 2.

Resources