Why does Swift lint ignore my custom regular expression? - ios

My .swiftlint.yml file:
disabled_rules:
- trailing_whitespace
- mark
- line_length
- force_cast
- variable_name
- force_try
- cyclomatic_complexity
- function_body_length
- type_body_length
- file_length
- type_name
excluded:
- Pods
custom_rules:
press_enter_after_object_definition:
regex: "(class|enum).*"
The result is following:
Why it has found only first match?
I need to find every line with enum or class keyword.

Remove the .*, this means match anything except a line break. So it appears to die in SwiftLint after the first line break of a successful match.
This works:
press_enter_after_object_definition:
regex: "(class|enum)"

Related

How to add to AllowedNames in Naming cop of rubocop

recently I have a problem with rubocop. It says:
service/job/some_module.rb:80:37: C: Naming/UncommunicativeMethodParamName: Method parameter must be at least 3 characters long.
def job_capabilize(*fields, of: [], autodefine: false)
^^
so I updated my .rubocop.yml file with
Naming/UncommunicativeMethodParamName:
AllowedNames:
- of
after that my rubocop started to argue on:
another_service/another_service_mod.rb:13:24: C: Naming/UncommunicativeMethodParamName: Method parameter must be at least 3 characters long.
def create(at:)
^^
"at" is a name from rubocop gem by default.
So the question is how to add "of" to AllowedNames, to use both names from gem and names I allowed without duplicating them all in my yml?
UPDATE
Thanks to #Siim Liiser I resolved this by:
[...snipet...]
inherit_mode:
merge:
- AllowedNames
Naming/UncommunicativeMethodParamName:
AllowedNames:
- of
- as
[...snipet...]
inherit_mode:
merge:
- AllowedNames
See rubocop docs

Too deeply nested at just fourth nesting level using pandoc with markdown?

The following code is not accepted by pandoc:
1. Code Behaviors
1. Logging
1. No "bare" `System.out.println`'s
1. Logging level can be calibrated by simple change(s) to logging.xml and/or log4j.properties
1. Errors and exceptions go to appropriate WARN and/or ERROR logging levels
1. Errors and Exceptions
1. Almost never "swallowed"
1. Can only happen for well understood situations
1. Must be documented clearly in code why they are swallowed
1. Only a specific exception or error may be swallowed this way
- In particular can not be done for general Exception.
- Throwable can never be handled this way
Which should look like this:
Code Behaviors
Logging
No "bare" System.out.println's
Logging level can be calibrated by simple change(s) to logging.xml and/or log4j.properties
Errors and exceptions go to appropriate WARN and/or ERROR logging levels
Errors and Exceptions
Almost never "swallowed"
Can only happen for well understood situations
Must be documented clearly in code why they are swallowed
Only a specific exception or error may be swallowed this way
In particular can not be done for general Exception.
Throwable can never be handled this way
Using the command line
pandoc --toc --toc-depth=6 -V fontsize=10pt --pdf-engine xelatex
-V geometry:"left=1.5cm,right=1.5cm,top=2cm,bottom=2cm" -o review.pdf review.md
We get
Error producing PDF.
! LaTeX Error: Too deeply nested.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.159 \begin{enumerate}
Update I tried to add in additional levels using enumitem package to the preamble as suggested here https://tex.stackexchange.com/a/464459/45938 - but to no effect (same error produced):
---
title: My Review
subtitle: My subtitle
documentclass: extarticle
author: First Last Sept 15, 2019
geometry: "left=1.5cm,right=1.5cm,top=2cm,bottom=2cm"
header-includes:
- \usepackage{unicode-math}
- \setmainfont{TeX Gyre Schola}
- \setmathfont{TeX Gyre Schola Math}
- \usepackage{enumitem}
- \setlistdepth{20}
- \renewlist{itemize}{itemize}{20}
- \setlist[itemize]{label=$\cdot$}
- \setlist[itemize,1]{label=\textbullet}
- \setlist[itemize,2]{label=--}
- \setlist[itemize,3]{label=*}
output:
rmarkdown::html_document:
theme: lumen
fig_caption: yes
---
Using enumitem is the correct approach. However, you have to extend both enumerate and itemize environments:
---
header-includes:
- \usepackage{enumitem}
- \setlistdepth{20}
- \renewlist{itemize}{itemize}{20}
- \renewlist{enumerate}{enumerate}{20}
- \setlist[itemize]{label=$\cdot$}
- \setlist[itemize,1]{label=\textbullet}
- \setlist[itemize,2]{label=--}
- \setlist[itemize,3]{label=*}
output:
rmarkdown::pdf_document:
keep_tex: yes
---
1. Code Behaviors
1. Logging
1. No "bare" `System.out.println`'s
1. Logging level can be calibrated by simple change(s) to logging.xml and/or log4j.properties
1. Errors and exceptions go to appropriate WARN and/or ERROR logging levels
1. Errors and Exceptions
1. Almost never "swallowed"
1. Can only happen for well understood situations
1. Must be documented clearly in code why they are swallowed
1. Only a specific exception or error may be swallowed this way
- In particular can not be done for general Exception.
- Throwable can never be handled this way
Output:
Note: The output.rmakrdown::pdf_document.keep_tex flag means that the intermediate tex file is retained.

Where can I put test data that is not part of a model?

I want to test against a list of invalid email addresses. At the moment, they live in my setup method:
def setup
#invalid_email_addresses = [
'plainaddress',
'##%^%#$##$##.com',
'#domain.com',
'Joe Smith <email#domain.com>',
'email.domain.com',
'email#domain#domain.com',
'.email#domain.com',
'email.#domain.com',
'email..email#domain.com',
'あいうえお#domain.com',
'email#domain.com (Joe Smith)',
'email#domain',
'email#-domain.com',
'email#domain.web',
'email#111.222.333.44444',
'email#domain..com'
]
end
This makes the method rather long. I would like to move them to a yml file:
# test/fixtures/email_addresses.yml
invalid_email_addresses:
- 'plainaddress'
- '##%^%#$##$##.com'
- '#domain.com'
- 'Joe Smith <email#domain.com>'
- 'email.domain.com'
- 'email#domain#domain.com'
- '.email#domain.com'
- 'email.#domain.com'
- 'email..email#domain.com'
- 'あいうえお#domain.com'
- 'email#domain.com (Joe Smith)'
- 'email#domain'
- 'email#-domain.com'
- 'email#domain.web'
- 'email#111.222.333.44444'
- 'email#domain..com'
But that results in an error for each test:
ActiveRecord::Fixture::FormatError: fixture key is not a hash: /Users/stefan_edberg/Rails/tennis_app/test/fixtures/emaild_addresses.yml, keys: ["invalid_email_addresses"]
If not in fixtures, where should I put these email addresses?
The error shared itself conveys that there is some problem in parsing the YAML contents. I saved the following contents in a file test.yml on my Desktop
# test/fixtures/email_addresses.yml
invalid_email_addresses:
- 'plainaddress'
- '##%^%#$##$##.com'
- '#domain.com'
- 'Joe Smith <email#domain.com>'
- 'email.domain.com'
- 'email#domain#domain.com'
- '.email#domain.com'
- 'email.#domain.com'
- 'email..email#domain.com'
- 'あいうえお#domain.com'
- 'email#domain.com (Joe Smith)'
- 'email#domain'
- 'email#-domain.com'
- 'email#domain.web'
- 'email#111.222.333.44444'
- 'email#domain..com'
and then tried loading it from irb and it successfully loaded:
Please Note: Initially when I copied the YAML contents as it is in my file and tried loading it, I encountered parsing error and then I removed the following entry and tried again and the parse was successful
- 'あいうえお#domain.com'`
That entry contains Unicode characters. As YAML is indentation-sensitive copying that entry as it is in my file made the indentation inconsistent which caused parse error. Fixing the indentation for that entry made the parse successful.

How to disable the character limit in swiftlint config file

I am working on a project and i need to how to disable the character limit in swiftlint config file , so how to disable the character limit ??
Here is the swiftlint file
disabled_rules:
- force_cast
- force_try
- variable_name
- type_name
- file_length
- type_body_length
- cyclomatic_complexity
- function_body_length
- valid_docs
- trailing_whitespace
opt_in_rules:
- empty_string
excluded:
- Carthage
- Pods
- SwiftLint/Common/3rdPartyLib
line_length:
warning: 150
error: 200
ignores_function_declarations: true
ignores_comments: true
ignores_urls: true
custom_rules:
smiley_face:
name: "Smiley Face"
regex: '( :\))'
match_kinds:
- comment
- string
message: "A closing parenthesis smiley :) creates a half-hearted smile, and thus is not preferred. Use :]"
severity: warning
If you face some problem with this warning:
Identifier Name Violation: Variable name should be between 3 and 40 characters long: 'by' (identifier_name)
You can add these command to your configuration file:
variable_name:
max_length:
warning: 45
error: 60
min_length:
warning: 1
I hope this helps you and fits with your question.
I guess you can do it adding line_length inside disabled_rules, if that's what you mean.

Implementing check in policy in swift 4

Suppose I have a class like this:
class person{
}
I need to implement a policy to check my code and warn me using camel case for my class name (use Person instead of person)
How can I do it in Swift?
I think you make use of SwiftLint for all kinds of Coding guidelines and you can set rules in your yml file, Please refer to SwiftLint for more details
As an example, the yml file looks like,
opt_in_rules:
- force_unwrapping
- empty_count
- explicit_init
- closure_spacing
- overridden_super_call
- redundant_nil_coalescing
- nimble_operator
- attributes
- operator_usage_whitespace
- closure_end_indentation
- first_where
- object_literal
- number_separator
- prohibited_super_call
- fatal_error_message
disabled_rules:
- type_name
- trailing_whitespace
- identifier_name
- class_delegate_protocol
- nesting
file_length:
warning: 1000
error: 1200
type_body_length:
- 200 # warning
- 300 # error
identifier_name:
excluded:
- id
line_length: 300
number_separator:
minimum_length: 5
function_parameter_count:
warning: 6
error: 9

Resources