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

The Nesting Rule #190

Closed
kmikael opened this issue Nov 10, 2015 · 10 comments
Closed

The Nesting Rule #190

kmikael opened this issue Nov 10, 2015 · 10 comments

Comments

@kmikael
Copy link

kmikael commented Nov 10, 2015

What is the nesting rules supposed to do? I think it doesn't work.

For example, with the nesting rule enabled, I get a warning, Nesting Violation: Types should be nested at most 1 level deep (nesting):

class View: UIView {
    enum State {
        case Ready, Executing, Finished
    }
}

But the nesting is correct.

@jpsim jpsim closed this as completed in 2131613 Nov 10, 2015
@jpsim
Copy link
Collaborator

jpsim commented Nov 10, 2015

The nesting rule will throw a violation when types are nested more than 1 level, or statements more than 5 levels. For example:

OK

class Class0 {
    class Class1 {
    }
}
Done linting! Found 0 violations, 0 serious in 1 file.

Style Violation

class Class0 {
    class Class1 {
        class Class2 {
        }
    }
}
file.swift:3:9: warning: Nesting Violation: Types should be nested at most 1 level deep (nesting)
Done linting! Found 1 violation, 0 serious in 1 file.

What you're found is a bug which treated enum cases as a type declaration, which meant that enum cases could also only be nested one level deep, which is not the intention. I just fixed in 2131613. Thanks for reporting this!

@eaigner
Copy link
Contributor

eaigner commented Feb 25, 2016

I still have this issue

@jpsim
Copy link
Collaborator

jpsim commented Feb 25, 2016

@eaigner based on this and the several other bug reports you've filed, you need to update your version of SwiftLint version to the latest (0.9.1), which has all these features.

You can tell which version of SwiftLint you're using by running swiftlint version.

@eaigner
Copy link
Contributor

eaigner commented Feb 25, 2016

Yep. Totally my fault. Sorry. (was 0.3.0)

@AlexIzh
Copy link

AlexIzh commented Oct 21, 2016

Can I change settings for this rule? I mean, what if I want to have this rule but I want to have level for type = 3 or something like this

@jpsim
Copy link
Collaborator

jpsim commented Oct 26, 2016

You can't change the thresholds for nesting_rule at the moment, but the rule could easily be modified to allow such configuration.

@erenkabakci
Copy link

The issue still persists on 0.18.1

I get the warning with following setup

struct A {
  func Foo {
    enum Boo {
      // Warning is caused because of this
  }
}

Is it because of the enum inside a func in a struct, or am I missing out something here.

@sureshxaton
Copy link

sureshxaton commented Dec 28, 2017

I am using 0.24.0 and still facing this

struct S 
{
        enum Value: String { 
           //Warning caused
            case a, b
        }
 }

@sbrighiu
Copy link

sbrighiu commented May 7, 2018

Still facing this issue "nesting: 3" does not do anything in the config file

@ornithocoder
Copy link
Contributor

ornithocoder commented May 7, 2018

@sbrighiu try this (assuming you want 3 for nesting)

  nesting:
    type_level: 3

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

8 participants