Skip to content
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

Support disabling/enabling rules from source code comments #4

Closed
jpsim opened this issue May 18, 2015 · 15 comments
Closed

Support disabling/enabling rules from source code comments #4

jpsim opened this issue May 18, 2015 · 15 comments

Comments

@jpsim
Copy link
Collaborator

jpsim commented May 18, 2015

For example:

// swiftlint:disable_rule:line_length
... some long line
// swiftlint:enable_rule:line_length
@aarondaub
Copy link

@jpsim do we want to make this purely additive or subtractive (additive would be having no rules on by default, subtractive would be having all rules on by default)? I don't think we should support both - that would complicate things unnecessarily.

How do you feel about using introspection to map YAML properties to rules? Another option would be to add a property to each Rule for a YAML identifier.

@segiddins
Copy link
Contributor

I like rubocops approach -- sensible defaults, can override in either direction.

@regexident
Copy link

I would vote for an approach based on a context-stack akin to clang analyzer:

Instead of simple serial switches one would be able to have elaborate nested configurations.

And instead of binary enable_rule/disable_rule switches one would be offered to choose from the same options that clang offers: ignored, note, remark, warning, error, fatal.

// swiftlint: push
// swiftlint: ignored some_rule

... some code

// swiftlint: pop

Or a more complex scenario:

// swiftlint: push
// swiftlint: warning rule_1
// swiftlint: error rule_2
// swiftlint: error rule_3

... some code

// swiftlint: push
// swiftlint: ignored rule_3

... some code

// swiftlint: pop

... some code

// swiftlint: pop

With sensible defaults of course.

People should be fairly familiar with this approach by now and can just apply their knowledge of clang-analyzer to swiftlint, making swiftlint feel kinda like a community-based extension to clang-analyzer. With Apple being more than likely to come up with a stack-based equivalent for #pragma clang diagnostic for Swift in the future, migrating from one stack-based system to another would be much easier than from a stack-less one.

@aarondaub
Copy link

👍 stack approach. Not sure if we should add the non-binary options in this issue or open another.

@regexident
Copy link

I'll add a separate issue for non-binary warning types if desired.

@aarondaub aarondaub mentioned this issue May 20, 2015
5 tasks
@aarondaub
Copy link

@regexident I have an implementation of the stack approach in #24. It'll be pretty easy to add options for enabling/disabling rules within a LinterContext (but I'll open a new PR for that if/when #24 is merged)

@regexident
Copy link

@aarondaub that's great! Looking forward to it!

@aarondaub
Copy link

@jpsim curious about your thoughts on something: if we decide to go with the stack approach should commands in a stack apply to that context regardless of order. E.g.

// swift-lint:begin-context
// swift-lint:disable-rule:line-length
... some code
// swift-lint:disable-rule:force-cast
... some more code
// swift-lint:end-context

Should both rules be disabled for both ... some code and ... some more code? Doing it that way might be a bit counter intuitive but if we don't we'll need to jump through some more hoops. Thoughts?

@jpsim
Copy link
Collaborator Author

jpsim commented May 26, 2015

No, I don't think it makes sense to apply commands retro-actively across the same stack. The more I think of it, I really dislike the stack-based approach, both from a user's perspective and in terms of how it would add additional complexity to the parsing implementation.

@alexanderjarvis
Copy link

Can we also provide a global configuration file where users of SwiftLint can specify their own coding style to enable/disable certain rules as they see fit? This is what is stopping me from keeping SwiftLint in my project because I either didn't agree with one of the rules, or one of the warnings was too verbose to warrant having it in my build.

@jpsim
Copy link
Collaborator Author

jpsim commented Jun 4, 2015

@alexanderjarvis we're tracking that in #3 😄

@alexanderjarvis
Copy link

alexanderjarvis commented Jun 5, 2015 via email

@keith
Copy link
Collaborator

keith commented Aug 11, 2015

Any thoughts on implementing this on a per file basis, without the push/pop first? Meaning that you could disable one or more rules for the entire file? I've implemented this on a fork by checking that the comment at the top of the file contains a string matching the rules identifier to remove it.

@keith
Copy link
Collaborator

keith commented Aug 11, 2015

Ah I see that something similar has been implemented in #76

jpsim added a commit that referenced this issue Sep 1, 2015
Disable/re-enable rules from within source code comments. Fixes #4.
@LeonidKokhnovich
Copy link

Does it somehow address the issue when you have the code like this:

    /// Function used to test swiftlint.
    ///
    /// - Returns: Some bool.
    // swiftlint:disable:next function_body_length
    func test() -> Bool {
      // very long function, 100+ lines of code, triggers "function_body_length" rule violation
      ...
    }

If the "swiftlint disable" statement is added as shown above, the documentation won't be displayed in Xcode quick documentation (Option + Click).

jpsim added a commit that referenced this issue Jan 17, 2023
This frequently crashes and I don't think it's due to a real TSan race.

E.g. https://buildkite.com/swiftlint/swiftlint/builds/4912#0185c098-a803-4525-8df1-827d1c97ed01

```
swiftlint(373,0x1ecdd3a80) malloc: nano zone abandoned due to inability to preallocate reserved vm space.
Linting Swift files in current working directory
1 of 538 [                              ] ETA: 0s (13129 files/s)
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
ThreadSanitizer:DEADLYSIGNAL
==373==ERROR: ThreadSanitizer: SEGV on unknown address 0x000000000008 (pc 0x000102cbe380 bp 0x00016f50ee00 sp 0x00016f50edc0 T30753687)
==373==The signal is caused by a UNKNOWN memory access.
==373==Hint: address points to the zero page.
    #0 __tsan::ThreadClock::release(__tsan::DenseSlabAllocCache*, __tsan::SyncClock*) <null>:46801128 (libclang_rt.tsan_osx_dynamic.dylib:arm64e+0x2a380)
    #1 __tsan::Release(__tsan::ThreadState*, unsigned long, unsigned long) <null>:46801128 (libclang_rt.tsan_osx_dynamic.dylib:arm64e+0x7456c)
    #2 swift::runJobInEstablishedExecutorContext(swift::Job*) <null>:46801128 (libswift_Concurrency.dylib:arm64e+0x40588)
    #3 swift_job_runImpl(swift::Job*, swift::ExecutorRef) <null>:46801128 (libswift_Concurrency.dylib:arm64e+0x41404)
    #4 _dispatch_root_queue_drain <null>:46801128 (libdispatch.dylib:arm64e+0x15f90)
    #5 _dispatch_worker_thread2 <null>:46801128 (libdispatch.dylib:arm64e+0x167bc)
    #6 _pthread_wqthread <null>:46801128 (libsystem_pthread.dylib:arm64e+0x30c0)
    #7 start_wqthread <null>:46801128 (libsystem_pthread.dylib:arm64e+0x1e1c)

==373==Register values:
 x[0] = 0x0000000102a53458   x[1] = 0x0000000000000538   x[2] = 0x0000000000000000   x[3] = 0x0000000000000000
 x[4] = 0x0000000000000001   x[5] = 0x0000000000000000   x[6] = 0x0095000004220122   x[7] = 0x0000000000000001
 x[8] = 0x0000000000000008   x[9] = 0x0000000000000000  x[10] = 0x0000000000000000  x[11] = 0x0000000000000000
x[12] = 0x0000000000000020  x[13] = 0x0000000110904040  x[14] = 0x0000000000000000  x[15] = 0x0000000106251910
x[16] = 0x0000000104190960  x[17] = 0x0000000000200018  x[18] = 0x0000000000000000  x[19] = 0x000000010f5d3488
x[20] = 0x0000000109ca03f0  x[21] = 0x0000000102a53458  x[22] = 0x0000000109ca03f0  x[23] = 0x0000000109cc0078
x[24] = 0x00040c0000fd77c4  x[25] = 0x0000010000000000  x[26] = 0x00000002287898f8  x[27] = 0x0000000000000000
x[28] = 0x000000016f50f0e0     fp = 0x000000016f50ee00     lr = 0x0000000102cbe360     sp = 0x000000016f50edc0
ThreadSanitizer can not provide additional info.
SUMMARY: ThreadSanitizer: SEGV (libclang_rt.tsan_osx_dynamic.dylib:arm64e+0x2a380) in __tsan::ThreadClock::release(__tsan::DenseSlabAllocCache*, __tsan::SyncClock*)+0x174
==373==ABORTING
```
jpsim added a commit that referenced this issue Jan 17, 2023
This frequently crashes and I don't think it's due to a real TSan race.

E.g. https://buildkite.com/swiftlint/swiftlint/builds/4912#0185c098-a803-4525-8df1-827d1c97ed01

```
swiftlint(373,0x1ecdd3a80) malloc: nano zone abandoned due to inability to preallocate reserved vm space.
Linting Swift files in current working directory
1 of 538 [                              ] ETA: 0s (13129 files/s)
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
ThreadSanitizer:DEADLYSIGNAL
==373==ERROR: ThreadSanitizer: SEGV on unknown address 0x000000000008 (pc 0x000102cbe380 bp 0x00016f50ee00 sp 0x00016f50edc0 T30753687)
==373==The signal is caused by a UNKNOWN memory access.
==373==Hint: address points to the zero page.
    #0 __tsan::ThreadClock::release(__tsan::DenseSlabAllocCache*, __tsan::SyncClock*) <null>:46801128 (libclang_rt.tsan_osx_dynamic.dylib:arm64e+0x2a380)
    #1 __tsan::Release(__tsan::ThreadState*, unsigned long, unsigned long) <null>:46801128 (libclang_rt.tsan_osx_dynamic.dylib:arm64e+0x7456c)
    #2 swift::runJobInEstablishedExecutorContext(swift::Job*) <null>:46801128 (libswift_Concurrency.dylib:arm64e+0x40588)
    #3 swift_job_runImpl(swift::Job*, swift::ExecutorRef) <null>:46801128 (libswift_Concurrency.dylib:arm64e+0x41404)
    #4 _dispatch_root_queue_drain <null>:46801128 (libdispatch.dylib:arm64e+0x15f90)
    #5 _dispatch_worker_thread2 <null>:46801128 (libdispatch.dylib:arm64e+0x167bc)
    #6 _pthread_wqthread <null>:46801128 (libsystem_pthread.dylib:arm64e+0x30c0)
    #7 start_wqthread <null>:46801128 (libsystem_pthread.dylib:arm64e+0x1e1c)

==373==Register values:
 x[0] = 0x0000000102a53458   x[1] = 0x0000000000000538   x[2] = 0x0000000000000000   x[3] = 0x0000000000000000
 x[4] = 0x0000000000000001   x[5] = 0x0000000000000000   x[6] = 0x0095000004220122   x[7] = 0x0000000000000001
 x[8] = 0x0000000000000008   x[9] = 0x0000000000000000  x[10] = 0x0000000000000000  x[11] = 0x0000000000000000
x[12] = 0x0000000000000020  x[13] = 0x0000000110904040  x[14] = 0x0000000000000000  x[15] = 0x0000000106251910
x[16] = 0x0000000104190960  x[17] = 0x0000000000200018  x[18] = 0x0000000000000000  x[19] = 0x000000010f5d3488
x[20] = 0x0000000109ca03f0  x[21] = 0x0000000102a53458  x[22] = 0x0000000109ca03f0  x[23] = 0x0000000109cc0078
x[24] = 0x00040c0000fd77c4  x[25] = 0x0000010000000000  x[26] = 0x00000002287898f8  x[27] = 0x0000000000000000
x[28] = 0x000000016f50f0e0     fp = 0x000000016f50ee00     lr = 0x0000000102cbe360     sp = 0x000000016f50edc0
ThreadSanitizer can not provide additional info.
SUMMARY: ThreadSanitizer: SEGV (libclang_rt.tsan_osx_dynamic.dylib:arm64e+0x2a380) in __tsan::ThreadClock::release(__tsan::DenseSlabAllocCache*, __tsan::SyncClock*)+0x174
==373==ABORTING
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants