-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Regex for custom rule not matching (works in xcode search, not from linting) #2040
Comments
I believe the |
Can you provide a sample file? I've tried with this snippet and it triggered the violation: class Test {
let x: Int
} |
The negative case also triggers the violation, though. If you enter a blank line between the class declaration and the property declaration, it still catches it (also try searching in xcode; works properly there)
|
@ornithocoder thanks for the suggestion, though the rest of the regex wouldn't work if that was the case; it's extremely close to working, but it seems something is failing in checking for that next line. |
@bryantv I still only get one violation with that example 🤔 Can you try running |
@marcelofabri same results, it finds both the positive and negative case. |
@marcelofabri it sounds like it's working correctly for you? same config file/xcode version? I'm wondering if the logic is correct and I have an environmental issue... |
@bryantv you're right. I didn't realize it's defined using single quotation marks instead of double quotation marks. No need to escape the backslash character. The logic seems right: Maybe SwiftLint doesn't handle multiline regex? |
@bryantv This is the configuration file I'm using: whitelist_rules:
- custom_rules
custom_rules:
space_after_class:
name: "No Space After Class"
message: "Empty line required after class declarations"
regex: '^(open|internal|private|public)*class\s(?!func).*\{$\n(?!^\s*$)'
severity: error
I'm using Xcode 9.2. |
@marcelofabri That's actually an interesting idea; perhaps one of the other rules in interfering with mine somehow. I'll do some experimenting and report back. |
@marcelofabri Afraid using that exact config and linting yielded the same results - both cases fire. Could there be something related to project layout? spaces vs. tabs, anything else you can think of? |
Hi :-) I still believe it's given the multiline nature of the rule. For the examples below I created four files with different code combinations: 01_file.swift: Single test that should throw a violation // Should error
class Test {
let x: Int
}
Results:
02_file.swift: Single test that should not throw a violation // Should not error
class Test {
let x: Int
}
Results:
03_file.swift: Two classes where the first one should throw a violation // Should error
class Test {
let x: Int
}
// Should not error
class Test {
let x: Int
}
Results:
04_file.swift: Two classes where the second one should throw a violation // Should not error
class Test {
let x: Int
}
// Should error
class Test {
let x: Int
}
Results:
|
Any reason to keep this open? |
Closing this due to lack of activity. |
New Issue Checklist
Bug Report
Complete output when running SwiftLint, including the stack trace and command used
I've created regex to determine if a class has an empty line following it. When searching in xcode, this works perfectly. However, swiftlint does not seem to work properly.
Environment
xcode-select -p
)? 9.2Example of search in xcode:
Example of linting (notice the blank line- this is not found by the same regex using ctrl+f):
The text was updated successfully, but these errors were encountered: