Modify coffeelint rule on code by comment - coffeescript

Is it possible to add some comment to ignore or modify coffeeling rules on a certain block (indented)?
I use the rule for max 80 columns on script, but I have some string values for a objetc that surpasses that value, and break the lines will make the code worse to read.
Ex.:
##
# #coffeelint ignore max_line_length
##
object:
attr: "some/huge/line/string/with/embed/#{values}.that/surpasses/the/max/column/width"

Here is the syntax for that.
# coffeelint: disable=max_line_length
object:
attr: "some/huge/line/string/with/embed/#{values}.that/surpasses/the/max/column/width"
# coffeelint: enable=max_line_length

Related

Mandatory empty line after function definition SwiftLint

I am integrating swiftlint in my xcode project and setting it's configuration. But I am not able to get the rule which enforces an empty line after function definition
func test1() {
}
func test2() {
}
If I add multiple spaces between two functions there is a rule for that.
Is there any rule which can be used to enable empty line between two functions or I need to write custom one
Doing swiftlint rules will give you a list of rules that are available. What I usually do to find the rule applicable is change different rules in the yaml file until i find the one that does what I want.
If your rule does not exist, I suggest writing a custom rule using regex such as:
custom_rules:
pirates_beat_ninjas: # rule identifier
included: ".*\\.swift" # regex that defines paths to include during linting. optional.
excluded: ".*Test\\.swift" # regex that defines paths to exclude during linting. optional
name: "Pirates Beat Ninjas" # rule name. optional.
regex: "([nN]inja)" # matching pattern
capture_group: 0 # number of regex capture group to highlight the rule violation at. optional.
match_kinds: # SyntaxKinds to match. optional.
- comment
- identifier
message: "Pirates are better than ninjas." # violation message. optional.
severity: error # violation severity. optional.
no_hiding_in_strings:
regex: "([nN]inja)"
match_kinds: string
This rule makes it so that every time you see the word Ninja, it causes a violation

ruamel.yaml.cmd rt breaks lists, if containing long string, or hash

I just notices that the command line tool, called like this: "ruamel.yaml.cmd rt --save $YAML_FILE", will break lists that either contain long strings, or hashes:
Example list containing a hash:
Source:
telegraf::inputs:
cpu:
- percpu: true
totalcpu: true
report_active: true
output:
telegraf::inputs:
cpu:
- percpu: true
totalcpu: true
report_active: true
example list containing long string:
source:
rsyslog::config::snippets:
00_forward:
ensure: 'present'
lines:
- 'if $syslogfacility != 1 then {'
- 'action(Name="collector-syslog" Type="omfwd" Target="%{hiera("rsyslog_server")}" Port="514" Action.ResumeInterval="5" Protocol="tcp")'
- '}'
output:
rsyslog::config::snippets:
00_forward:
ensure: present
lines:
- if $syslogfacility != 1 then {
- action(Name="collector-syslog" Type="omfwd" Target="%{hiera("rsyslog_server")}"
Port="514" Action.ResumeInterval="5" Protocol="tcp")
- '}'
I already created a bug report for this, but it was deleted with a comment pointing to https://yaml.readthedocs.io/en/latest/example.html?highlight=indent#output-of-dump-as-a-string.
But I am not sure how this code snipped should help me with the command line tool.
Or is the tool deprecated, and I have to roll my own?
The automatic detection of the indent seems incorrect for your input, as that input is inconsistent (your mappings are indented 2 positions and your sequences 4 positions with an offset for the block sequence indicator of 2). ruamel.yaml.cmd as on PyPI doesn't support different indentation levels for sequences and mappings (ruamel.yaml didn't when that was written, it does now).
Apart from that you cannot set the line width for the output in ruamel.yaml.cmd for older versions ( before 2020-12-01), and those versions are using the default 80 characters for the wrapping.
I recommend you upgrade to 0.5.6 and use the command line options:
yaml rt --indent 2 --width 1024 --save <yourfile>
The appropriate repository for ruamel.yaml.cmd is https://sourceforge.net/p/ruamel-yaml-cmd/code/ci/default/tree/ . A bug report on ruamel.yaml which can only be used from a Python program, should include the minimal source code of the program that reproduces the error, and if not provided, issues will be removed as announced on its create issue page.

Snakemake ancient tag with wildcards

I have few SRA files which I download from NCBI website. Now I want to add them to my snakemake workflow. However, I want to retain ability to download them with prefetch if they are not available. I had following simple rule,
BASE = "/path/to/working/folder"
rule all:
input: [f"{BASE}/fastq/SRR000001.sra_1.fastq", f"{BASE}/fastq/SRR000001.sra_2.fastq"]
shell:
"echo Finished"
rule get_sra:
input: ancient("config/config.yaml")
output:"{BASE_FOLDER}/sra/{SSR_ID}.sra"
shell:
"prefetch -p {wildcards.SSR_ID} --output-file {output} "
rule get_fastq:
input: expand("{folder}/sra/{srr}.sra", folder=BASE, srr="{SRR_ID}")
output:
expand("{folder}/fastq/{srr}.sra_{i}.fastq", folder=BASE,
srr="{SRR_ID}", i=[1, 2])
shell:
"fasterq-dump {input} --outdir {BASE}/fastq"
If I use above rule, my workflow will recreate my SRA files as their timestamp will be older. However, I do not want to download full SRA file again from the server and use the already downloaded one.
For this purpose I am trying to use the ancient tag. But I am not able to use this tag with any of the wildcards.
input: ancient("{BASE_FOLDER}/sra/{SSR_ID}.sra")
Above rule gives error as
Wildcards in input files cannot be determined from output files:
Any solution to this problem? This also does not work when I use expand.
The problem is that not everything that you specify in curly braces is actually a wildcard. You may have 3 different use cases where you may use the curly braces:
expand functon
f-string
wildcards
In the first two cases (expand and f-string) the result is a fully specified string without any wildcards at all. If you have something like that:
rule dummy:
input: "{wildcard}.input"
output: expand("{wildcard}.output", wildcard=["1", "2"])
the result would be simply:
rule dummy:
input: "{wildcard}.input"
output: ["1.output", "2.output"]
As you can see, there are no wildcards in the output section at all, so the input cannot determine the value for it's wildcard.
The typical solution is to separate this rule into two rules:
rule all:
input: expand("{wildcard}.output", wildcard=["1", "2"])
rule do_some_work:
input: "{wildcard}.input"
output: "{wildcard}.output"
Note however that something that I called {wildcard} in the rule all: is not a wildcard per se but just an arbitrarily selected name in the local context of the expand function.

TXR: How to combine all lines where the following line begins with a tab?

I am trying to parse the text output of a shell command using txr.
The text output uses a tab indented line following it to continue the current line (not literal \t characters as I show below). Note that on other variable assignment lines (that don't represent extended length values), there are leading spaces in the input.
Variable Group: 1
variable = the value of the variable
long_variable = the value of the long variable
\tspans across multiple lines
really_long_variable = this variable extends
\tacross more than two lines, but it
\tis unclear how many lines it will end up extending
\tacross ahead of time
Variable Group: 2
variable = the value of the variable in group 2
long_variable = this variable might not be that long
really_long_variable = neither might this one!
How might I capture these using the txr pattern language? I know about the #(freeform) directive and it's optional numeric argument to treat the next n lines as one big line. Thus, it seems to me the right approach would be something like:
#(collect)
Variable Group: #i
variable = #value
#(freeform 2)
long_variable = #long_value
#(set long_value #(regsub #/[\t ]+/ "" long_value))
#(freeform (count-next-lines-starting-with-tab))
really_long_variable = #really_long_value
#(set really_long_value #(regsub #/[\t ]+/ "" really_long_value))
#(end)
However, it's not clear to me how I might write the count-next-lines-starting-with-tab procedure with TXR lisp. On the other hand, maybe there is another better way I could approach this problem. Could you provide any suggestions?
Thanks in advance!
Let's apply the KISS principle; we don't need to bring in #(freeform). Instead we can separately capture the main line and the continuation lines for the (potentially) multi-line variables. Then, intelligently combine them with #(merge):
#(collect)
Variable Group: #i
variable = #value
long_variable = #l_head
# (collect :gap 0 :vars (l_cont))
#l_cont
# (end)
really_long_variable = #rl_head
# (collect :gap 0 :vars (rl_cont))
#rl_cont
# (end)
# (merge long_variable l_head l_cont)
# (merge really_long_variable rl_head rl_cont)
#(end)
Note that the big indentations in the above are supposed to be literal tabs. Instead of literal tabs, we can encode tabs using #\t.
Test run on the real data with \t replaced by tabs:
$ txr -Bl new.txr data
(i "1" "2")
(value "the value of the variable" "the value of the variable in group 2")
(l_head "the value of the long variable" "this variable might not be that long")(l_cont ("spans across multiple lines") nil)
(rl_head "this variable extends" "neither might this one!")
(rl_cont ("across more than two lines, but it" "is unclear how many lines it will end up extending"
"across ahead of time") nil)
(long_variable ("the value of the long variable" "spans across multiple lines")
("this variable might not be that long"))
(really_long_variable ("this variable extends" "across more than two lines, but it"
"is unclear how many lines it will end up extending" "across ahead of time")
("neither might this one!"))
We use a strict collect with :vars for the continuation lines, so that the variable is bound (to nil) even if nothing is collected. :gap 0 prevents these inner collects from scanning across lines that don't start with tabs: another strictness measure.
#(merge) has "special" semantics for combining lists of strings that haver different nesting levels; it's perfect for assembling data from different levels of collection and is basically tailor made for this kind of thing. This problem is very similar to extracting HTTP, Usenet or e-mail headers, which can have continuation lines.
On the topic of how to write a Lisp function to look ahead in the data, the most important aspect is how to get a handle on the data at the current position. The TXR pattern matching works by backtracking over a lazy list of strings (lines/records). We can use the #(data) directive to capture the list pointer at the given input position. Then we can just treat that as a list:
#(data here)
#(bind tab-start-lines #(length (take-while (f^ #/\t/) here))
Now tab-start-lines has a count of how many lines in the input start with tabs. However, take-while has a termination condition bug, unfortunately; if the following data consists of nothing but one or more tab lines, it misbehaves.⚠ Until TXR 166 is released, this requires a little workaround: (take-while [iff stringp (f^ #/\t/)] here).

can #+BIND: be wrapped?

Correct Version:
#+BIND: org-html-postamble-format (("en" "abcxyz"))
but if the format string is very long, is there a way to wrap it to multilines?
something like this:
#+BIND: org-html-postamble-format (("en" "abc ~
# xyz"))
Unfortunately no. Keywords in org-mode are constrained to a single line and there is no wrapping character. If you feel strongly about your line length you might consider:
Using the #+SETUPFILE mechanism (see: In-buffer settings)
Defining that format in your dotemacs file so you can span multiple lines.
Using some form of local file or directory variables. For example local variables may span multiple lines:
# Local Variables:
# eval: (setq org-html-postamble t)
# eval: (setq org-html-postamble-format '(("en" "foo
# bar \
# baz")))
# End:
Note: You may notice that some some particular keywords have "wrapping" behavior such as node properties (http://orgmode.org/manual/Property-syntax.html):
#+PROPERTY: var foo=1
#+PROPERTY: var+ bar=2
Behavior like this is special and limited to those keywords. No equivalent wrapping behavior exists for the BIND keyword.
Current org-mode version (as of this post): 8.3.4