Is there a script to fix opentelemetry lint errors? - open-telemetry

When running the make golint target in opentelemetry-collector-contrib, sometimes a lint error will appear. It seems like the kind of lint-check which could be easily fixed as well, but make gofmt will not fix such.
Is there a way to use one of the tools vendored by make install-tools in GIT_REPO_ROOT/.tools to automatically reformat the project in a way which makes the golangci-lint happy?
-- details --
The specific error is File is not `gci`-ed with --skip-generated -s standard,default,prefix(github.com/open-telemetry/opentelemetry-collector-contrib)
neither make gofmt, ./.tools/goimports -w -local "github.com/open-telemetry/opentelemetry-collector-contrib" work for this, and
The particular command in the make target manifesting this problem is .tools/golangci-lint run --allow-parallel-runners --build-tags integration
However, none of these flags seem to be valid for the gci tool
❯ ./.tools/gci --skip-generated -s standard,default,prefix\(github.com/open-telemetry/opentelemetry-collector-contrib\)
Error: unknown flag: --skip-generated
Usage:
gci [-diff | -write] [--local localPackageURLs] path... [flags]
gci [command]
Available Commands:
completion Generate the autocompletion script for the specified shell
diff Prints a git style diff to STDOUT
help Help about any command
print Outputs the formatted file to STDOUT
write Formats the specified files in-place
Flags:
-d, --diff display diffs instead of rewriting files
-h, --help help for gci
-l, --local strings put imports beginning with this string after 3rd-party packages, separate imports by comma
-v, --version version for gci
-w, --write write result to (source) file instead of stdout
Use "gci [command] --help" for more information about a command.

This seems to work, need to add the write command and replace {} with your filename
./.tools/gci write {} --skip-generated -s standard,default,prefix\(github.com/open-telemetry/opentelemetry-collector-contrib\)

Related

Set and check for empty var inside a target

I created a make target which fetches a list of files from git ls-files and passes them to phpcs, a coding standards utility.
The problem is that I don't want to run it if no files are returned. (because it then tries to analyze the entire codebase)
phpcs:
FS=$$(git ls-files -om --exclude-standard '*.php'); \
vendor/bin/phpcs --encoding=utf-8 --extensions=php $$FS
How would I exit if $FS (which is set in the first line) is empty?
I'm running the default gnu-make which comes with OSX. (3.8.1)
This isn't really a makefile question. You are using shell commands to perform these operations so you have to come up with a shell solution for your problem: make doesn't enter into it.
You can do something like this:
phpcs:
FS=$$(git ls-files -om --exclude-standard '*.php'); \
test -z "$$FS" || vendor/bin/phpcs --encoding=utf-8 --extensions=php $$FS
PS. There's no such release as GNU make 3.8.1. You mean, I assume, GNU make 3.81.

Syntax for executing a script using Git Bash on Windows 10 pro/docker/ddev

I am executing the following command:
wget -O -https://raw.githubusercontent.com/drud/ddev/master/scripts/windows_ddev_nfs_setup.sh | bash
And I get the following:
wget: missing URL
Usage: wget [OPTION]... [URL]...
Looks as if I have the syntax wrong, but I have been searching to find out how to fix this and haven't found an answer.
I checked the command on shellcheck.net and learned the following:
SC2148: Tips depend on target shell and yours is unknown. Add a shebang.
That sounds great, but I don't (yet) know what it means.
You are using -O, which means that the next argument is the output file. Hence,
-https://raw.githubusercontent.com/drud/ddev/master/scripts/windows_ddev_nfs_setup.sh
is the name of your output file, and there is no URL in your command.
Since you are piping the result of wget into bash, you don't need an output file, I think.

How to run command and checking exit status from windows make files

I am new to windows make files.I am trying to understand a few things. How to run commands (DOS commands) from windows mk files. I ran the following command from cmd command prompt--
find testsuite
and it gives proper output. Now I try to run the same from windows mk file as follows -- $(shell find testsuite). However, it gives error "FIND: Parameter format not correct". Is $(shell commandname ...) the correct way or if not what does $(shell...) indicate? Also how to capture the exit status of the command.Adding logline like below after the command doesn't print anything $(warning $(errorlevel)
However, it gives error "FIND: Parameter format not correct".
This is Windows own find utility. It searches for strings in files, kind of grep without regexp :-(. So it requires at least two arguments.
Also how to capture the exit status of the command.
For $(shell ...) function it's in .SHELLSTATUS variable.

How do you run pre-written lldb commands?

I have this file with lldb commands in it that I want to run.
Is there a way to run pre-written lldb commands?
lldb's help system is a good way to answer this sort of question:
(lldb) help command
Commands for managing custom LLDB commands.
Syntax: command <subcommand> [<subcommand-options>]
The following subcommands are supported:
alias -- Define a custom command in terms of an existing command. Expects 'raw' input (see 'help raw-input'.)
delete -- Delete one or more custom commands defined by 'command regex'.
history -- Dump the history of commands in this session.
Commands in the history list can be run again using "!<INDEX>". "!-<OFFSET>" will re-run the command that is <OFFSET> commands from the end of the list (counting the current command).
regex -- Define a custom command in terms of existing commands by matching regular expressions.
script -- Commands for managing custom commands implemented by interpreter scripts.
source -- Read and execute LLDB commands from the file <filename>.
unalias -- Delete one or more custom commands defined by 'command alias'.
For more help on any particular subcommand, type 'help <command> <subcommand>'.
command source looks promising:
(lldb) help command source
Read and execute LLDB commands from the file <filename>.
Syntax: command source <cmd-options> <filename>
Command Options Usage:
command source [-e <boolean>] [-c <boolean>] [-s <boolean>] <filename>
-c <boolean> ( --stop-on-continue <boolean> )
If true, stop executing commands on continue.
-e <boolean> ( --stop-on-error <boolean> )
If true, stop executing commands on error.
-s <boolean> ( --silent-run <boolean> )
If true don't echo commands while executing.
This command takes options and free-form arguments. If your arguments resemble option specifiers (i.e., they start with a - or --), you must use ' -- ' between the end of the command options and the beginning of the arguments.
There's also an apropos command that will search for keywords in the help. Unfortunately apropos command returns too many hits to be particularly helpful in your case. apropos file is a little less noisy, but just looking at the command subcommands is probably easiest. help with no arguments will list the top level commands which might also help you get started.
Note, you can also tell lldb to source a random file of commands when you launch it from the command line (with the -s option). To find out more about lldb's command line options, run:
> lldb --help

Git diff without comments

Let's say I added two lines to the file hello.rb.
# this is a comment
puts "hello world"
If I do git diff, it will show that I added two lines.
I don't want git to show any line which is a Ruby comment. I tried using git diff -G <regular expression>, but it didn't work for me. How do I do git diff so that it won't show any Ruby comments?
One possibility would be (ab)using git's textconv filters which are applied before the diff is created, so you can even transform binary formats to get a human-readable diff.
You can use any script that reads from a file and writes to stdout, such as this one which strips all lines starting with #:
#!/bin/sh
grep -v "^\s*#" "$1" || test $? = 1
(test $? = 1 corrects the exit code of grep, see https://stackoverflow.com/a/49627999/4085967 for details.)
For C, there is a sed script to remove comments, which I will use in the following example. Download the script:
cd ~/install
wget http://sed.sourceforge.net/grabbag/scripts/remccoms3.sed
chmod +x remccoms3.sed
Add it to your ~/.gitconfig:
[diff "strip-comments"]
textconv=~/install/remccoms3.sed
Add it to the repository's .gitattributes to enable it for certain filetypes:
*.cpp diff=strip-comments
*.c diff=strip-comments
*.h diff=strip-comments
The main downside is that this will be always enabled by default, you can disable it with --no-textconv.
Git cares a lot about the data that you give to it, and tries really hard not to lose any information. For Git, it doesn't make sense to treat some lines as if they haven't changed if they had.
I think that the only reasonable way to do this is to post-process Git output, as Dogbert had already shown in his comment.

Resources