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
Related
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.
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.
Is there a way to suppress PSScriptAnalyzer from highlighting alias warnings? e.g.
'rm' is an alias of 'Remove-Item'. Aliases can introduce possible problems and make scripts hard to maintain. Please consider changing alias to its full content.
Aliases in PowerShell are extremely useful. I have a simple rule: I only ever use the rational built-in aliases in scripts (I ignore the strange ones). Why? Well, most of these particular aliases are now 13 years old and have never changed (PowerShell 1.0 release November 14, 2006). So, for example, % or ls or cd are reliable in 99.99% of cases. I consider 99.99% reliability to be "good enough". Possibly the single-most-over-repeated comment on all PowerShell StackOverflow questions is "Note: it is not recommended to use aliases in PowerShell scripts as they can change!" (not recommended by whom I often wonder? God? ;-) )
However, PSScriptAnalyzer in VSCode highlights all aliases as problems so that my current 7,000 line script has 488 such "problems". Is there a way to tell PSScriptAnalyzer that I like aliases, I intend to use aliases for the vastly more concise code, clarity, and greatly improved readability that they give me, and so I do not consider them to be problems?
Mathias' comment states to search for "Select PSScriptAnalyzer Rules" but I was not able to find that setting (VS 1.58.2, ms-vscode.powershell 2021.6.2).
The solution I found was to change the "Script Analysis: Settings Path" to point to a created file that contains the following code1 to whitelist certain aliases. Below I've un-commented the relevant section.
#{
# Only diagnostic records of the specified severity will be generated.
# Uncomment the following line if you only want Errors and Warnings but
# not Information diagnostic records.
#Severity = #('Error','Warning')
# Analyze **only** the following rules. Use IncludeRules when you want
# to invoke only a small subset of the default rules.
IncludeRules = #('PSAvoidDefaultValueSwitchParameter',
'PSMisleadingBacktick',
'PSMissingModuleManifestField',
'PSReservedCmdletChar',
'PSReservedParams',
'PSShouldProcess',
'PSUseApprovedVerbs',
'PSAvoidUsingCmdletAliases',
'PSUseDeclaredVarsMoreThanAssignments')
# Do not analyze the following rules. Use ExcludeRules when you have
# commented out the IncludeRules settings above and want to include all
# the default rules except for those you exclude below.
# Note: if a rule is in both IncludeRules and ExcludeRules, the rule
# will be excluded.
#ExcludeRules = #('PSAvoidUsingWriteHost')
# You can use rule configuration to configure rules that support it:
Rules = #{
PSAvoidUsingCmdletAliases = #{
Whitelist = #("cd")
}
}
}
[1] https://github.com/PowerShell/vscode-powershell/blob/master/examples/PSScriptAnalyzerSettings.psd1
Here's an example from the Markdown source:
sub _StripLinkDefinitions{ somecode }
What does it mean? Is it just a convention or a part of the language?
It is an convention, documented in the perlstyle:
You can use a leading underscore to indicate that a variable or
function should not be used outside the package that defined it.
Also, in the Perl best practices page 49, says:
Prefix “for internal use only” subroutines with an underscore.
with the explanation:
A utility subroutine exists only to simplify the implementation of a
module or class. It is never supposed to be exported from its module,
nor ever to be used in client code.
Always use an underscore as the
first “letter” of any utility subroutine’s name. A leading underscore
is ugly and unusual and reserved (by ancient C/Unix convention) for
non-public components of a system. The presence of a leading
underscore in a subroutine call makes it immediately obvious when part
of the implementation has been mistaken for part of the interface.
Related: The underscore has an special meaning too, as a part of a language - e.g.:
the variable what's name is only the underscore, (check perlvar) - e.g:
$_ - The default input and pattern-searching space.
#_ - list of all subroutine arguments
_ - The special file handle what caches the information from the last stator file test operator (such -f)
language constructions what starts and ends with a double underscore, such: __DATA__, __END__, __FILE__, __PACKAGE__, __LINE__
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