Skip to content

new lint: "no fancy createState" #58079

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

Closed
pq opened this issue Dec 6, 2019 · 5 comments · Fixed by dart-archive/linter#1877
Closed

new lint: "no fancy createState" #58079

pq opened this issue Dec 6, 2019 · 5 comments · Fixed by dart-archive/linter#1877
Labels
customer-flutter devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. linter-lint-request type-enhancement A request for a change that isn't a bug

Comments

@pq
Copy link
Member

pq commented Dec 6, 2019

Follow-up from dart-archive/linter#1867 (and related to: #58075).

Bad:

MyState global;

class MyStateful extends StatefulWidget {
  @override
  MyState createState() {
    global = MyState();
    return global;
  } 
}

Good:

class MyStateful extends StatefulWidget {
  @override
  MyState createState() {
    return MyState();
  }
}
@pq pq added type-enhancement A request for a change that isn't a bug linter-lint-request customer-flutter labels Dec 6, 2019
@pq
Copy link
Member Author

pq commented Dec 6, 2019

Naming is hard. @rrousselGit, @bwilkerson: any ideas?

no_state_create_logic ?

@bwilkerson
Copy link
Member

no_logic_in_create_state?

@pq
Copy link
Member Author

pq commented Dec 6, 2019

@rrousselGit:

how literally should we interpret this advice?

Ultimately, createState has just a single possible implementation, that is:

@override
MyState createState() {
  return MyState();
}

With maybe replacing {} + return with () =>.
But other than that, it shouldn't change, ever.

Literally should we only except a block w/ one statement (a return statement instantiating a new State instance)?

@rrousselGit
Copy link

Yes, with no constructor parameter, no if, ternary, cascade...

@bwilkerson
Copy link
Member

That does appear to trump the previous lint.

@devoncarew devoncarew added devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. labels Nov 18, 2024
@devoncarew devoncarew transferred this issue from dart-archive/linter Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-flutter devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. linter-lint-request type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants