Using RuboCop, I want to disallow method argument formatting that looks like this:
some_method(arg_1,
arg_2)
And allow formatting that looks like this:
some_method(
arg_1,
arg_2
)
I also want to allow formatting that looks like this:
some_method(arg_1, arg_2)
How can I achieve this?
Seems this is the rule you are looking for:
https://www.rubydoc.info/gems/rubocop/0.45.0/RuboCop/Cop/Style/FirstMethodArgumentLineBreak
to enable it just write this in your rubocop.yml file:
Style/FirstMethodArgumentLineBreak:
Enabled: True
Related
For example, if I write:
Notepad++ is *great*, I like Notepad++
it treats ++something++ as an escape construct which ignores the * bold and produces:
<p>Notepad is *great*, I like Notepad</p>
instead of the desired:
<p>Notepad++ is <strong>great</strong>, I like Notepad++</p>
Upstream discussion: https://github.com/asciidoctor/asciidoctor/issues/1864
Tested on Asciidoctor 2.0.10.
A few options that do what I want:
Notepadpass:[++] is *great*, I like Notepadpass:[++]
Notepad{blank}pass:[++] is *great*, I like Notepad{blank}pass:[++]
Notepad{plus}{plus} is *great*, I like Notepad{plus}{plus}
I'm not 100% sure if the Notepadpass:[++] is meant to work of just an accident. I think I'm just going with {plus}{plus}.
Where {plus} is documented at: https://asciidoctor.org/docs/user-manual/#charref-attributes
For the specific case of C++ there is also {cpp}.
Another option is to use a backslash to escape the first ++:
Notepad\++ is *great*, I like Notepad++
This works in a similar way on other formatting as well.
I have a CSV document like this:
RL|S1|C19.concoct_part_0 concoct.26
RL|S1|C26.concoct_part_4 concoct.7
RL|S1|C26.concoct_part_5 concoct.7
I want it to be like this:
RL|S1|C19 concoct.26
RL|S1|C26 concoct.7
RL|S1|C26 concoct.7
How do I do it in Vim?
Thanks to #oguz ismail the solution is the following
:%s/\.[^\t]*//
Using command line mode you can run:
:%norm f.dt<space><enter>
Note: you must to type space and enter instead of writing it.
The multi sub MAIN() command line parsing in Perl6 is sweet!
As far as I can tell from the Command Line Interface docs there is only one option supported in the dynamic hash %*SUB-MAIN-OPTS to manipulate the option processing (that being :named-anywhere).
Perhaps I've missed the obvious, but is there an existing/supported option to take 'old fashioned' single dash options?
For example:
#Instead of this...
myprogram.p6 --alpha=value1 --beta==value2 --chi
#... short options like this
myprogram.p6 -a value1 -bvalue2 -c
Or is this best processed manually or with an external module?
You can sort of emulate this as-is, although you still have to an = ala -a=foo, and still technically have --a=foo in addition to --alpha and -a
sub MAIN(:a(:$alpha)!) {
say $alpha;
}
...so you probably want to use https://github.com/Leont/getopt-long6
use Getopt::Long;
get-options("alpha=a" => my $alpha);
I'm reading through the jison documentation and one of the examples gives a lexer rule that matches the end of file (<<EOF>>). However, that can only be used if you are writing the grammar in JISON format. Instead, I am using the JSON format to describe my grammar, but I cannot find anything in the documentation describing how to match the end of file. I have tried using "<<EOF>>" as the lexer rule, but that literally matches the string <<EOF>>.
How do I do this? Is there more documentation for jison somewhere that I'm missing?
After digging into the source code for lex-parser, it looks like $ does what I want. Instead of matching the end of a line, it matches the end of a file. <<EOF>> actually gets converted to $ when parsing the lex section of a jison file.
I would like Rubocop to ignore lines with comments (just a comment or some code with an end of line comment) when checking if a line is too long. Is there a way to do this?
There is a way to ignore cops on a per line basis.
There is also a way to do it via configuration file.
Run rubocop --auto-gen-config and it will generate a file that you can use to disable the offenses.
The command also gives a hint on what to do to load those options.
On a line per line basis, you can enable and disable the cops as well.
# rubocop:disable RuleByName
This is a long line
# rubocop:enable RuleByName
You can also do more than one rule at a time in your code.
# rubocop:disable BlockComments, AsciiComments
By using an inline directive, the directive becomes valid only for that
line, and it would look like this:
# Thanks to #jnt30 for the comment!
method(argument) # rubocop:disable SomeRule, SomeOtherRule
You can read a ton more about RuboCop in its official manual.
To find all the rule names its worth looking in the rubocop config files
cyberwiz says - "run rubocop -D when I need the rule names rather than looking in the documentation." Update: This is now the default behavior without the flag.
The -D is now default, so we would get that for "free" now.
It's possible to define regex patterns to automatically ignore certain lines in rubocop.yml, so you could choose to ignore all lines starting with a # character:
Layout/LineLength:
Max: 80
AllowedPatterns: ['\A#']
This could be improved so that "indented" comment lines (i.e. whitespace followed by a # character) are also ignored, if that's what you want.
Note that this doesn't account for lines of code that end with a comment, though:
some_code(that_does_something) # This line would NOT be ignored by Rubocop.
You can use the following comment with rubocop to ignore a specific rule:
# rubocop:disable Layout/LineLength
def this_could_be_a_very_long_line_that_extends_forever_into_infinity
end
# rubocop:enable Layout/LineLength
You can also ignore whole files by adding them to .rubocop.yml:
AllCops:
Exclude:
- path/to/file.rb
i think the basic idea here is that you want to enforce line length, no matter what is after n characters. the default to 80 characters is some cargo cult for old terminal windows that could only hold that number of chars. the only option that i saw in the code is an option to allow urls that might exceed the character limit.
you can ignore whole files, i guess that's not what you are looking for.
The following configuration worked for me:
Layout/LineLength:
AllowedPatterns: ['^(\s*#)']
This regex only works when the entire line is commented out. Code followed by a long comment on the same line will still trigger a Rubocop lint error, which is by design.