How can I find out which config file(s) rubocop is using? - path

I'm clear on the rules rubocop follows to find the config file or files it uses to build up the list of cops it uses -- it is explained here: RuboCop Configuration
However, the rules allow for several different possibilities, and what I am looking for would be some way to get rubocop to display the path(s) of the file(s) it has found to use.
For example, if I edit a file that I think is the active rubocop config file, but find out when I run rubocop that the change I've made isn't incorporated (ergo rubocop must not be getting its config from there after all, or it's being overridden somewhere else) then it would help to know which file(s) rubocop is in fact getting its config from.
Ideally there would be a command option like rubocop --display_config_paths, which would display the path or paths of all config files it will use as currently invoked -- but given that such an option doesn't exist, is there any way to find this out?

Short Answer:
Add debug option when calling rubocop then you will see config files loaded:
$ rubocop --config ~/.rubocop.yml --debug zpl/bin/zpl_csv
configuration from /home/user/.rubocop.yml
Default configuration from
/home/lcs/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/rubocop-1.25.1/config/default.yml
Inspecting 1 file`
...
Others things:
Take a look to 'Config file locations' paragraph from rubocop documentation, and check priority of configs files, note the following sentence:
'then RuboCop will use the config as specified inside the first of the following files'
If you want to use several files you may have to use 'Inheriting from another configuration file in the project'

Related

Why isn't telegraf reading environmental variables?

My goal is to put my telegraf config into source control. To do so, I have a repo in my user's home directory with the appropriate config file which has already been tested and proven working.
I have added the path to the new config file in the "default" environment variables file:
/etc/default/telegraf
like this:
TELEGRAF_CONFIG_PATH="/home/ubuntu/some_repo/telegraf.conf"
... as well as other required variables such as passwords.
However, when I attempt to run
telegraf --test
It says No config file specified, and could not find one in $TELEGRAF_CONFIG_PATH etc.
Further, if I force it by
telegraf --test --config /home/ubuntu/some_repo/telegraf.conf
Then the process fails because it is missing the other required variables.
Questions:
What am I doing wrong?
Is there not also a way of specifying a config directory too (I would like to break my file down into separate input files)?
Perhaps as an alternative to all of this... is there not a way of specifying additional configuration files to be included from within the default /etc/telegraf/telegraf.conf file? (I've been unable to find any mention of this in documentation).
What am I doing wrong?
See what user:group owns /etc/default/telegraf. This file is better used when running telegraf as a service via systemd. Additionally, if you run env do you see the TELEGRAF_CONFIG_PATH variable? What about your other variables? If not, then you probably need to source the file first.
Is there not also a way of specifying a config directory too (I would like to break my file down into separate input files)?
Yes! Take a look at all the options of telegraf with telegraf --help and you will find:
--config-directory <directory> directory containing additional *.conf files
Perhaps as an alternative to all of this... is there not a way of specifying additional configuration files to be included from within the default /etc/telegraf/telegraf.conf file? (I've been unable to find any mention of this in documentation).
That is not the method I would suggest going down. Check out the config directory option above I mentioned.
Ok, after a LOT of trial and error, I figured everything out. For those facing similar issues, here is your shortcut to the answer:
Firstly, remember that when adding variables to the /etc/default/telegraf file, it must effectively be reloaded. So for example using ubuntu systemctl, that requires a restart.
You can verify that the variables have been loaded successfully using this:
$ sudo strings /proc/<pid>/environ
where <pid> is the "Main PID" from the telegraf status output
Secondly, when testing (eg telegraf --test) then (this is the part that is not necessarily intuitive and isn't documented) you will have to ALSO load the same environmental variables into the current user (eg: SET var=value) such that running
$ env
shows the same results as the previous command.
Hint: This is a good method for loading the current env file directly rather than doing it manually.

Not able to use linterconfigs command

I want to use Schemacrawler lint in my project and wants to use custom lints only. Based on documentation , it says we can use command -linterconfigs=[path to linter XML configuration file] But when I tried creating XML configuration file and use the custom lints only, I still see default linters are running. Am I doing anything wrong ?
Here is the steps I followed:
download and unzip the package
create dump database named example.database
created schemacrawler-linter-configs.xml with one of the existing lint
Using following command to run the lint on dump database from _schemacrawler directory
./schemacrawler.sh --server=postgresql -command=lint -linterconfigs=schemacrawler-linter-configs.xml -database=example.database
Rashmi, SchemaCrawler runs all linters by default. You need to turn off any linters you don't need in the linters config file. Here is an example of how you can do it:
<schemacrawler-linter-configs>
<linter id="schemacrawler.tools.linter.LinterForeignKeyMismatch">
<run>false</run>
</linter>
</schemacrawler-linter-configs>
Sualeh Fatehi, SchemaCrawler

What is wrong with this rails template?

I am attempting to take a whack at creating my first Rails application template and I am running into a slight issue with the copy_file method.
First some background.... Apparently the Ruby OpenSSL package does not ship with a CA store, so any attempt to connect to an HTTPS service will fail out of the box. The way around this(for Rails 3 apps) is to add the line OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE to the top of your config/environment.rb file. I need to do this on the fly in my template so I can install jQuery.
So I have that all figured out, my general thought is to:
Make a backup of my config/environment.rb file.
Prepend the data to original
Run the jquery:install --ui task
Restore the original config/environment.rb file.
See my template Gist, Lines 25..34 is the relevant section.
So all of that works until step #4 which fails with Error: Could not find "env.orig" in any of your source paths on line #31.
This is VERY perplexing to me because line #28 works, I can see the env.orig file on disk, so why won't the reverse work?
What am I doing wrong?
Update 1:
After looking at the Thor source thor\actions.rb it became clear that Thor uses different paths (not your current project path) for the source and destination. Furthermore my copy was actually not working, it was actually coping the ERB template file, not the already generated file.
After a breather it occurred to me use the right tool for the job so now I have: run 'cp environment.rb environment.~' and run 'mv environment.~ environment.rb' which works just fine. I am fairly certain this would not work on a windows box without the unix tools installed, but I can live with that. Does anyone have a better way?
See my Update for a Why, but the solution was to use the right tool for the job so now I have: run 'cp environment.rb environment.~' and run 'mv environment.~ environment.rb' which works just fine. I am fairly certain this would not work on a windows box without the unix tools installed, but I can live with that.

Where is the .rspec configuration file located exactly?

Working through the Ruby on Rails Tutorial and stuck here "To run RSpec and Spork with Autotest, we need to configure RSpec to use the --drb option by default, which we can arrange by adding it to the .rspec configuration file in the Rails root directory (Listing 3.14)."
When I search my file structure I can not find a single file with .rspec file extension? How do I access this file to update the configuration?
If you are using a mac you will not see these files just like you will not see the gitignore file
what you need to do in order to access this file is from the root directory of the app just click (command line)
mate .rspec
this will open the file if it's there, and if not, it will create it.
If you add gem 'rspec-rails' to your Gemfile, you can use the rails g rspec:install command.
This will create the .rspec file in the root of the Rails application. It will also create a spec folder and a file inside it 'spec_helper.rb'
If you do not want to write this command, you may simply create the file manually. If you are using a linux machine, the hidden files can be seen with a <ctrl-h> command. You may also try the ls -a in any unix terminal to see all hidden and non hidden files.
Files on mac that begin with . are not shown by default. In Terminal, if you type ls -a you'll see all of the "dotfiles" that are in the folder.
If this file doesn't exist yet (it probably doesn't) then you just need to create it using your favorite editor.

.gemrc file specification

I searched everywhere to find the .gemrc file specification but I haven't succeed.
Does anyone know where I can find it?
gem looks for a configuration file .gemrc in your home directory, although you can specify another file on the command-line if you wish (with the --config-file modifier).
There are three things you can specify in the configuration file:
command-line arguments to be used every time gem runs
command-line options for ’’RDoc’’ (used when generating documentation)
GEM_PATH settings
More at gem environment command doc.
'Home' is a Linux/Mac term. What is refers to is the folder where a user's settings appear. You can find out where your settings directory is by doing the following:
on Unix/Linux, open a terminal and type the following command:
echo $HOME
on Windows, open a command-prompt and type the following command:
echo %USERPROFILE%
For me (in Windows 7), this is C:\Users[name]. However, looks like Ruby doesn't set up your .gemrc in that folder by default. Instead, you have to create the file. Open a text editor, copy the YAML style code you need (documentation), and save the file as .gemrc in your home directory (make sure you select all files, not '.txt').
These settings will only affect that individual user. If it's your personal computer, however, you probably don't need to change the settings for all users.
An updated gemrc specification is available at RubyGems Guides (under 'gem environment'). Note that /etc/gemrc applies to all users, while ~/.gemrc applies to an individual.
If the key is a gem command (for example, install:), it specifies arguments to be used with that command.
Here are the other keys that can be specified:
:sources: A YAML array of remote gem repositories to install gems from
:verbose: Verbosity of the gem command. false, true, and :really are the levels
:update_sources: Enable/disable automatic updating of repository metadata
:backtrace: Print backtrace when RubyGems encounters an error
:gempath: The paths in which to look for gems
All of the answers here at time of writing are wrong because the obnoxious website keeps changing. It is at this moment here:
https://guides.rubygems.org/command-reference/#gem-environment
Obviously you should expect it to change constantly at this point.

Resources